variable not found.

Help for those learning Tcl or writing their own scripts.
Post Reply
User avatar
iamdeath
Master
Posts: 323
Joined: Fri Feb 11, 2005 2:32 pm
Location: *HeLL*
Contact:

variable not found.

Post by iamdeath »

I am trying to write a small DCC code, in which I will type
.bonus username reason
That will add +5 of the current access of a username in X (Undernet)

Code: Select all

set ac(chan) "#channel"
set notifyusers "owner"
set ac(bot_username) "botusername"
set ac(owner_username) "ownerusername"
bind notc - "USER: * ACCESS: *" ac:bonus_points
bind dcc n bonus ac:bonus

proc ac:bonus_points {nick uhost hand text dest} {
set text [split $text]
set baccess [lindex $text 3]
}
proc ac:bonus { handle idx text } {
global ac user_names notifyusers baccess
set text [split $text]
set username1 [lindex $text 0]
set reason1 [lrange $text 1 end]
if {$username1 == ""} { putdcc $idx "Syntax: .bonus <CService Username> <Reason>"; return }
if {$username1 == "$ac(bot_username)"} { putdcc $idx "You can't bonus me or I can't modify myself."; return }
if {$username1 == "ac(owner_username)"} { putdcc $idx "Do you think $ac(owner_username) needs modification?, get a life."; return } 
if {$reason1 == ""} { putdcc $idx "Syntax: .bonus <CService Username> <Reason>. You're required to mention reason for bonus."; return }
puthelp "PRIVMSG X :ACCESS $ac(chan) $username1"
puthelp "PRIVMSG X :MODINFO $ac(chan) ACCESS $username1 [expr $baccess + 5]"
if {$notifyusers != "" && $notifyusers != " "} {
foreach notfuser $notifyusers {
sendnote IDA_SYSTEM $notfuser "Bonus +5 given to $username1 by $handle in $ac(chan). The reason was: $reason1"
}
}
}
but I am getting this error.

Code: Select all

[17:54] Tcl error [ac:bonus]: can't read "baccess": no such variable
normal X reply when someone types: /msg x access #Channel username

Code: Select all

-X- USER: cricket ACCESS: 400 LU
-X- CHANNEL: #Cricket -- AUTOMODE: OP
-X- LAST SEEN: 0 days, 00:07:16 ago.
-X- LAST MODIFIED: (iamdeath) |AmDeAtH!~iamdeath@iamdeath.users.undernet.org (1 day, 21:12:14 ago)
-X- End of access list
Can you suggest me.
Thanks.
Last edited by iamdeath on Sun May 07, 2006 2:24 pm, edited 1 time in total.
User avatar
Sir_Fz
Revered One
Posts: 3793
Joined: Sun Apr 27, 2003 3:10 pm
Location: Lebanon
Contact:

Post by Sir_Fz »

In your code, baccess is set only when the bot recieves a notice. What you need to do is initialize to some number (probably 0) outside the procs.
User avatar
iamdeath
Master
Posts: 323
Joined: Fri Feb 11, 2005 2:32 pm
Location: *HeLL*
Contact:

Post by iamdeath »

could you please give me an idea how could I do that?
Thanks
User avatar
Sir_Fz
Revered One
Posts: 3793
Joined: Sun Apr 27, 2003 3:10 pm
Location: Lebanon
Contact:

Post by Sir_Fz »

Code: Select all

set ac(chan) "#channel"
set notifyusers "owner"
set ac(bot_username) "botusername"
set ac(owner_username) "ownerusername"
set baccess 0 ;# initialized baccess to 0
User avatar
iamdeath
Master
Posts: 323
Joined: Fri Feb 11, 2005 2:32 pm
Location: *HeLL*
Contact:

Post by iamdeath »

Did'nt work actually, the actuall access of tht person was 300 so the bot was supposed to add 5 but the bot makes it "5" the whole removed 300 :P
User avatar
De Kus
Revered One
Posts: 1361
Joined: Sun Dec 15, 2002 11:41 am
Location: Germany

Post by De Kus »

well, how do you know whos baccess is in the var anyway? the expr expression is calculated before the access request leaves your bot, so there will of course be no reply yet either. You must include this calculation within the proc which handles the feedbacks. you should then of course also read whos feedback you are getting and, if you actually wanted to modify it (you never know when someone might make your bot to recieve a reply).
De Kus
StarZ|De_Kus, De_Kus or DeKus on IRC
Copyright © 2005-2009 by De Kus - published under The MIT License
Love hurts, love strengthens...
User avatar
iamdeath
Master
Posts: 323
Joined: Fri Feb 11, 2005 2:32 pm
Location: *HeLL*
Contact:

Post by iamdeath »

I did;nt get your point, sorry ;/
User avatar
Sir_Fz
Revered One
Posts: 3793
Joined: Sun Apr 27, 2003 3:10 pm
Location: Lebanon
Contact:

Post by Sir_Fz »

What you need to do, iamdeath, is issue the service command when the dcc command is triggered. Then, you wait for the notice and perform the needed action. Ofcourse you will need a variable which will contain the needed info for the notc proc to process it.
User avatar
iamdeath
Master
Posts: 323
Joined: Fri Feb 11, 2005 2:32 pm
Location: *HeLL*
Contact:

Post by iamdeath »

Code: Select all

set baccess ""
This works fine, do you think that's right?
User avatar
Sir_Fz
Revered One
Posts: 3793
Joined: Sun Apr 27, 2003 3:10 pm
Location: Lebanon
Contact:

Post by Sir_Fz »

What I mean is something like this:

Code: Select all

set ac(chan) "#channel"
set notifyusers "owner"
set ac(bot_username) "botusername"
set ac(owner_username) "ownerusername"

bind dcc n bonus ac:bonus
bind notc - "USER: * ACCESS: *" ac:bonus_points

proc ac:bonus {hand idx arg} {
 global ac baccess
 set text [split $text]
 set username1 [lindex $text 0]
 set reason1 [lrange $text 1 end]
 if {$username1 == ""} { putdcc $idx "Syntax: .bonus <CService Username> <Reason>"; return }
 if {$username1 == "$ac(bot_username)"} { putdcc $idx "You can't bonus me or I can't modify myself."; return }
 if {$username1 == "$ac(owner_username)"} { putdcc $idx "Do you think $ac(owner_username) needs modification?, get a life."; return }
 if {$reason1 == ""} { putdcc $idx "Syntax: .bonus <CService Username> <Reason>. You're required to mention reason for bonus."; return }
 puthelp "PRIVMSG X :ACCESS $ac(chan) $username1"
 set baccess([string tolower $username1]) [list $hand $reason1]
}

proc ac:bonus_points {nick uhost hand arg dest} {
 global ac baccess notifyusers
 if {![isbotnick $dest]} {return 0}
 if {![string equal -nocase X $nick]} {return 0}
 set user [string tolower [lindex [split $arg] 1]]
 if {![info exists baccess($user)]} {return 0}
 foreach {handle reason} $baccess($user) {break}
 set access [lindex [split $arg] 3]
 puthelp "PRIVMSG X :MODINFO $ac(chan) ACCESS $user [expr {$access + 5}]"
 if {$notifyusers != "" && $notifyusers != " "} {
  foreach notfuser $notifyusers {
   sendnote IDA_SYSTEM $notfuser "Bonus +5 given to $user by $handle in $ac(chan). The reason was: $reason"
  }
 }
}
Note that baccess is being used as an array here, so you might want to .restart after loading this (or .tcl unset baccess before loading).
User avatar
iamdeath
Master
Posts: 323
Joined: Fri Feb 11, 2005 2:32 pm
Location: *HeLL*
Contact:

Post by iamdeath »

That work, thanks alot :)
Thanks once again.
Post Reply