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.

Help please

Help for those learning Tcl or writing their own scripts.
Post Reply
L
LB_1981
Voice
Posts: 15
Joined: Mon Jun 08, 2009 5:53 am

Help please

Post by LB_1981 »

Hi can someone help me with this

Code: Select all

proc cmd:tempshun {nick uhost hand arg} {
  set nick [lindex [split $arg] 0] 
  set reason [lrange [split $arg] 1 end] 
  putserv "TEMPSHUN $nick :$reason"
  putserv "PRIVMSG #CWStats Tempshun Added To $nick (Reason) $reason"  
 
}


Is what i need it to do is message #cwstats with Tempshun Added To $nick by $username (Reason) $reason. need another set option which is for $username but am not sure how to add the extra set the above code works fine just need that extra set

need a small change to this one also

Code: Select all

proc cmd:tempakill {nick uhost hand args} {
  set args [join $args]
  set username [lindex $args 0]
  set reason [lrange $args 1 end]
  putserv "GLINE $username :$reason"
  putserv "PRIVMSG #CWStats Temporary GLINE added to $username (Reason) $reason" 
}
is what im trying to get this to do is the same as above
Tempgline Added To $nick by $username (Reason) $reason and also set it so it glines for 4 hours this code also works just need to add the two extras

many thanks
LB_1981
User avatar
username
Op
Posts: 196
Joined: Thu Oct 06, 2005 9:20 am
Location: Russian Federation, Podolsk
Contact:

Post by username »

Code: Select all

proc cmd:tempshun {nick uhost hand arg} {
  set victim [lindex [split $arg] 0]
  set reason [lrange [split $arg] 1 end]
  putserv "TEMPSHUN $nick :$reason"
  putserv "PRIVMSG #CWStats :Tempshun Added To $victim by $nick (Reason) $reason" 
 }
This is wrong code:

Code: Select all

set args [join $args]
set username [lindex $args 0] 
You cant use lindex in string. Lindex for lists only.
And you neednt use join with $args, because $args already a string.

Code: Select all

proc cmd:tempakill {nick uhost hand args} {
  set victim [lindex [split $args] 0]
  set reason [lrange [split $args] 1 end]
  putserv "GLINE $victim :$reason"
  putserv "PRIVMSG #CWStats :Temporary GLINE added to $victim by $nick (Reason) $reason"
}
And dont forget about : in putserv. It looks like this: putserv "Type Destination :Text"
Where Type can be PRIVMSG or NOTICE
Destination can be Nick or Chan and
Text is text to send to.
Архив TCL скриптов для ботов Eggdrop/Windrop:
http://egghelp.ru/
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 cmd:tempakill {nick uhost hand args} {
  set args [join $args]
  set username [lindex $args 0]
  set reason [lrange $args 1 end]
  putserv "GLINE $username :$reason"
  putserv "PRIVMSG #CWStats Temporary GLINE added to $username (Reason) $reason"
}
This entire code is incorrect, everything except the first putserv, the second is incorrect and will never message the channel intended. It is missing the seperating (space)colon after target nick/channel in the PRIVMSG, it simply has the (space)...

Code: Select all

proc cmd:tempakill {nick uhost hand arg} {
  set username [lindex [split $arg] 0]
  set reason [join [lrange [split $arg] 1 end]]
  putserv "GLINE $username :$reason"
  putserv "PRIVMSG #CWStats :Temporary GLINE ($reason -> $username) by $nick."
}
Now let me explain the subtle differences here....

Notice first off, I've removed your line 2.. and my code is 6 lines versus your 7. Now let's move onto bigger things...

# The proc header, aka, the first line of code
You never want to make the mistake of using "args" within your procedure header unless it is invoked by several binds/procedures using differing amounts of arguments. If you don't understand what that means then use "text" or "arg" or literally anything else instead. The reason for this you don't need to understand, but "args" is a reserved word when used within a procedure header. It allows for a variable number of arguments to be passed through the procedure without declaring each argument individually. These arguments are then passed to the procedure as a list. A procedure that is bound to PUB or MSG input will always have a static number of arguments passed making your use of $args in this case very inappropriate. You are having to use more code to return the list $args give you back into a string, and work around this issue than it would be to correctly build your procedure header.

# The lindex, aka line 2...
The problem here isn't quite as obvious. Since you have used $args to catch the text of the user you were given a list. But you then used [join $args] to return this to a string. Then you attempt to lindex this string before turning it into a list...But since we need to solve the problem of line 1 first, it is better to [split $arg] and then lindex properly on a list. Never use list commands on strings. Golden rule #1 - section 1

# The lrange, aka line 3...
The problem here has the same qualities as number 2. But.. There is a big difference here. Lrange will return a list, not a string like lindex will. Because of this you will need to [join] your lrange back into a string, or risk curly bracings appearing when displaying any contents containing special characters. Doing it correctly special tcl characters never effect your script. Golden rule #1 - section 2

# The solution, aka advice for life...
follow all the steps above and this time listen. Follow the golden rules (all your issues are discussed here: lindex, lrange, and args). Treat these golden rules as "tcl law" and correct your flawed use of $args and pretend that it is equivalent to typing .die in your bot. Just forget it exists unless you want to kill your eggdrop.. ;)
Post Reply