This is the new home of the egghelp.org community forum.
All data has been migrated (including user logins/passwords) to a new phpBB version.


For more information, see this announcement post. Click the X in the top right-corner of this box to dismiss this message.

adduser help

Help for those learning Tcl or writing their own scripts.
Post Reply
C
Cerberus
Voice
Posts: 7
Joined: Mon Sep 01, 2008 6:37 pm

adduser help

Post by Cerberus »

hope you guys can help i have this in a proc in one of the tcl files, i use but for some reason it only work on first channel bot is on and not all channels

Code: Select all

proc msg_+user {nick uhost hand rest} {
	global botnick thehosts default-flags cmdtbslg
	if {![matchattr $hand Q]} {puthelp "NOTICE $nick :$cmdtbslg You haven't authenticate Yourself. Type: \[/msg $botnick auth <password>\] to do so." ; return 0}
	set who [lindex $rest 0]
	if {$who == ""} {puthelp "NOTICE $nick :$cmdtbslg Command: /msg $botnick +user <handle> \[ip_address\] \[flags\]" ; return 0}
	if {[validuser $who]} {puthelp "NOTICE $nick :$cmdtbslg $who already exist in my user list." ; return 0}
	set hostmask [lindex $rest 1]
	if {$hostmask == ""} {
		foreach chan [channels] {
			if {[onchan $who $chan]} {set hostmask [getchanhost $who $chan]} else {puthelp "NOTICE $nick :$cmdtbslg $who is not on my channel(s), a <hostmask> must be included in the command." ; return 0}
		}
		set hostmask [maskhost $nick!$hostmask]
	} else {
		foreach hostsuser $thehosts {
			set hostuser $hostsuser
			if {$hostmask == $hostuser} {puthelp "NOTICE $nick :$cmdtbslg Hostmask: \[$hostmask\] is not a valid hostmask." ; return 0}
		}
	}
	adduser $who $hostmask ; puthelp "NOTICE $nick :$cmdtbslg $who is now added to my user list with hostmask: \[$hostmask\]."
	set addflags [lindex $rest 2]
	if {$addflags == ""} {puthelp "NOTICE $nick :$cmdtbslg No user flags included, I'm going to use my default flag \[${default-flags}\] for this user."}
	chattr $who ${default-flags} ; puthelp "NOTICE $nick :$cmdtbslg Standard user's flags ${default-flags} now added for handle: $who ."
	save ; puthelp "NOTICE $nick :$cmdtbslg Saving user file."
	puthelp "NOTICE $who Welcome $who pleaase set a password by typing /msg $botnick pass <your new pass>."
	puthelp "NOTICE $who Once you have set a pass type /msg $botnick auth <yourpassword> each time you connect to irc to login"
	putcmdlog "$cmdtbslg <<$nick>> !$hand! +user $who \[$hostmask\]." ; return 0
}
it seems to fail at the foreach command but i dont know why can anyone help me out ??
Last edited by Cerberus on Tue Apr 24, 2012 3:05 pm, edited 2 times in total.
n
nml375
Revered One
Posts: 2860
Joined: Fri Aug 04, 2006 2:09 pm

Post by nml375 »

My first guess would be that your test for "onchan $who $chan" fails, having your script return instantly.
NML_375
C
Cerberus
Voice
Posts: 7
Joined: Mon Sep 01, 2008 6:37 pm

Post by Cerberus »

agreed by how to fix it?
n
nml375
Revered One
Posts: 2860
Joined: Fri Aug 04, 2006 2:09 pm

Post by nml375 »

Change it to something like this

Code: Select all

...
foreach chan [channels] {
  if {[onchan $who $chan]} {
    set hostmask [getchanhost $who $chan]
    break
  }
}
if {![info exists hostmask]} {
  puthelp "NOTICE $nick :$cmdtbslg Hostmask: \[$hostmask\] is not a valid hostmask."
  return 0
}
...
NML_375
C
Cerberus
Voice
Posts: 7
Joined: Mon Sep 01, 2008 6:37 pm

Post by Cerberus »

ok will try that thanks have put full code at top now to make debugging easier :)
n
nml375
Revered One
Posts: 2860
Joined: Fri Aug 04, 2006 2:09 pm

Post by nml375 »

Ohh, you'll have to replace the "info exists" test with $hostmask == "" in my example
NML_375
C
Cerberus
Voice
Posts: 7
Joined: Mon Sep 01, 2008 6:37 pm

Post by Cerberus »

nml375 your awesome that worked perfectly first time and had been blindly staring at that for hours not realising why it failed.

thanks so much now to sort my other little bug and bot is perfect :) (new thread for that)
User avatar
speechles
Revered One
Posts: 1398
Joined: Sat Aug 26, 2006 10:19 pm
Location: emerald triangle, california (coastal redwoods)

Post by speechles »

Code: Select all

proc msg_+user {nick uhost hand rest} {
	global botnick thehosts default-flags cmdtbslg
	if {![matchattr $hand Q]} {puthelp "NOTICE $nick :$cmdtbslg You haven't authenticate Yourself. Type: \[/msg $botnick auth <password>\] to do so." ; return 0}
	set who [lindex [split $rest] 0]
	if {![string length $who]} { puthelp "NOTICE $nick :$cmdtbslg Command: /msg $botnick +user <handle> \[ip_address\] \[flags\]" ; return 0}
	if {[validuser $who]} { puthelp "NOTICE $nick :$cmdtbslg $who already exist in my user list." ; return 0}
	set hostmask [lindex [split $rest] 1]
	if {![string length $hostmask]} {
		foreach chan [channels] {
			if {[onchan $who $chan]} {
				set hostmask [getchanhost $who $chan] ; set found 1
			}
		}
		if {![info exists found]} {
			puthelp "NOTICE $nick :$cmdtbslg $who is not on my channel(s), a <hostmask> must be included in the command." ; return 0
		}
		set hostmask [maskhost $who!$hostmask]
	} else {
		foreach hostsuser $thehosts {
			set hostuser $hostsuser
			if {[string equal $hostmask $hostuser]} {puthelp "NOTICE $nick :$cmdtbslg Hostmask: \[$hostmask\] is not a valid hostmask." ; return 0}
		}
	}
	adduser $who $hostmask ; puthelp "NOTICE $nick :$cmdtbslg $who is now added to my user list with hostmask: \[$hostmask\]."
	set addflags [lindex [split $rest] 2]
	if {![string length $addflags]} {
		puthelp "NOTICE $nick :$cmdtbslg No user flags included, I'm going to use my default flag \[${default-flags}\] for this user."
		set addflags ${default-flags}
	}
	chattr $who $addflags
	puthelp "NOTICE $nick :$cmdtbslg Standard user's flags $addflags now added for handle: $who ."
	puthelp "NOTICE $nick :$cmdtbslg Saving user file."
	save
	puthelp "NOTICE $who :Welcome $who pleaase set a password by typing /msg $botnick pass <your new pass>."
	puthelp "NOTICE $who :Once you have set a pass type /msg $botnick auth <yourpassword> each time you connect to irc to login"
	putcmdlog "$cmdtbslg <<$nick>> !$hand! +user $who \[$hostmask\]." ; return 0
}
Here is the code corrected. It had several issues besides the one you mentioned. Here it is all cleaned up and ready for the big show.
User avatar
caesar
Mint Rubber
Posts: 3778
Joined: Sun Oct 14, 2001 8:00 pm
Location: Mint Factory

Post by caesar »

Guess you didn't noticed this part of getchanhost documentation:
If a channel is not specified, bot will check all of its channels. If the nickname is not on the channel(s), "" is returned.
So, your foreach loop not only it should break on first match but it's useless by definition.

Instead of validuser $who I would go with nick2hand as user X may already be a known user to the bot registered when he had a different nick. If you don't want check if that handle already exists, then you should add the user check.

Here is how I would do this:

Code: Select all

# Available types are:
#   0: *!user@host 
#   1: *!*user@host 
#   2: *!*@host 
#   3: *!*user@*.host 
#   4: *!*@*.host 
#   5: nick!user@host 
#   6: nick!*user@host 
#   7: nick!*@host 
#   8: nick!*user@*.host 
#   9: nick!*@*.host 
#
# You can also specify types from 10 to 19 which correspond to types
# 0 to 9, but instead of using a * wildcard to replace portions of the 
# host, only numbers in hostnames are replaced with the '?' wildcard. 
# Same is valid for types 20-29, but instead of '?', the '*' wildcard 
# will be used.
set default-mask 1

proc msg_+user {nick uhost hand text} {
   global default-flags default-mask cmdtbslg
   if {![matchattr $hand Q]} {
    puthelp "PRIVMSG $nick :$cmdtbslg You haven't authenticate Yourself. Type: \[/msg $botnick auth <password>\] to do so."
    return
   }
   set count [scan $text {%s%s%s} user hostmask flags]
   if {!$count} {
    puthelp "PRIVMSG $nick :$cmdtbslg Command: /msg $botnick +user <handle> \[hostmask\] \[flags\]"
    return
   }
   if {[llength [nick2hand $user]]} {
    puthelp "PRIVMSG $nick :$cmdtbslg $user already exist in my user list."
    return   
   }
   if {$count == 1} {
    set hostmask [getchanhost $user]
    if {[!llength $hostmask]} {
        puthelp "PRIVMSG $nick :$cmdtbslg $user is not on my channel(s), a <hostmask> must be included in the command."
        return
    } else {
        set hostmask [maskhost "$user![getchanhost $user]" ${default-mask}]
    }
   }
   if {[scan $hostmask {%[^!]!%[^@]@%s} n u h] != 3} {
    puthelp "PRIVMSG $nick :$cmdtbslg Hostmask: \[$hostmask\] is not a valid hostmask."
    return
   }
   adduser $user $hostmask
   puthelp "PRIVMSG $nick :$cmdtbslg $user is now added to my user list with hostmask: \[$hostmask\]."
   if {$count != 3} {
    puthelp "PRIVMSG $nick :$cmdtbslg No user flags included, I'm going to use the standard user flags \[${default-flags}\] for this user."
    set flags ${default-flags}
   } else {
    puthelp "PRIVMSG $nick :$cmdtbslg Adding user $user with $flags flags."
   }
   chattr $hand $flags
   puthelp "PRIVMSG $nick :$cmdtbslg Saving user file."
   save
   puthelp "NOTICE $hand :Welcome $user pleaase set a password by typing /msg $botnick pass <your new pass>."
   puthelp "NOTICE $hand :Once you have set a pass type /msg $::botnick auth <your password> each time you connect to irc to login"
   putcmdlog "$cmdtbslg <<$nick>> !$handle! +user $user \[$hostmask\]."
}
Last edited by caesar on Sat Apr 28, 2012 12:22 pm, edited 1 time in total.
Once the game is over, the king and the pawn go back in the same box.
C
Cerberus
Voice
Posts: 7
Joined: Mon Sep 01, 2008 6:37 pm

Post by Cerberus »

caesar - your code fails with error, any ideas??

Tcl error [msg_+user]: can't read "text": no such variable

speachless - works perfectly thanks :)
User avatar
caesar
Mint Rubber
Posts: 3778
Joined: Sun Oct 14, 2001 8:00 pm
Location: Mint Factory

Post by caesar »

This is why I don't debug other people code. I forgot to replace rest with text. It should be fine now.
Once the game is over, the king and the pawn go back in the same box.
Post Reply