| View previous topic :: View next topic |
| Author |
Message |
Reserve Voice
Joined: 18 Apr 2005 Posts: 6 Location: Nottingham, UK
|
Posted: Mon Dec 26, 2005 1:00 pm Post subject: Different bot responses on private and public channels |
|
|
Ive searched and seen several questions about this kind of thing but with my limited tcl skills i just cant seem to get it working on my bot.
My bot sits in a private channel for gameserver admins and several public channels including a public channel for gameserver players. I want to use the same trigger in different channels but the responses will be different depending on what channel the trigger was called from.
In its current form, the trigger is the bot then compares the arg to a sql table and if a match for <arg> is found then a url is sent as a notice to the user that called the trigger.
My current script is as follows
| Code: | bind pub - !link pub_link
proc pub_link {nick host hand chan arg} {
if {[string compare $chan #admin-channel]} {
return
}
global mysql
if {[llength $arg] < 1} then {
putquick "NOTICE $nick : You might want to tell me what link you want to look for....."
return
}
set extra [lindex $arg 0]
mysqlsel $mysql "SELECT trigger,link,details from irc_bot_links where trigger='$extra'"
set mycount [mysqlresult $mysql rows?]
mysqlmap $mysql {trigger link details} {
putquick "NOTICE $nick :$link - $details"
}
if {$mycount == 0} {
putquick "NOTICE $nick : No URL found for link $extra, for a list of links type !links"
}
} |
What im trying to do is something like..
| Code: | bind pub - !link pub_link
proc pub_link {nick host hand chan arg} {
if {[string compare $chan #admin-channel]} {
return
}
global mysql
if {[llength $arg] < 1} then {
putquick "NOTICE $nick : You might want to tell me what link you want to look for....."
return
}
set extra [lindex $arg 0]
mysqlsel $mysql "SELECT trigger,link,details from irc_bot_links where trigger='$extra' and status='private'"
set mycount [mysqlresult $mysql rows?]
mysqlmap $mysql {trigger link details} {
putquick "NOTICE $nick :$link - $details"
}
if {$mycount == 0} {
putquick "NOTICE $nick : No URL found for link $extra, for a list of links type !links"
}
elseif {[string compare $chan #public-channel]} {
return
}
global mysql
if {[llength $arg] < 1} then {
putquick "NOTICE $nick : You might want to tell me what link you want to look for....."
return
}
set extra [lindex $arg 0]
mysqlsel $mysql "SELECT trigger,link,details from irc_bot_links where trigger='$extra' and status='public'"
set mycount [mysqlresult $mysql rows?]
mysqlmap $mysql {trigger link details} {
putquick "NOTICE $nick :$link - $details"
}
if {$mycount == 0} {
putquick "NOTICE $nick : No URL found for link $extra, for a list of links type !links"
}
}
} |
I cant seem to figure out how to achieve this, the above example doest work. Ive tried putting the if chan and elseif commands in various places but at best only get the script to work in one of the channels.
Can anyone offer any help or suggestions?
Regards
Reserve |
|
| Back to top |
|
 |
demond Revered One

Joined: 12 Jun 2004 Posts: 3073 Location: San Francisco, CA
|
Posted: Mon Dec 26, 2005 1:37 pm Post subject: |
|
|
[string compare] returns 0 if the strings are identical, otherwise 1 or -1; so you need to change your if's to:
| Code: |
if {[string compare $chan #somechannel] == 0} {
# do stuff for that channel
}
|
you might also want to include -nocase option for [string] command, for case-insensitive comparison _________________ connection, sharing, dcc problems? click <here>
before asking for scripting help, read <this>
use [code] tag when posting logs, code |
|
| Back to top |
|
 |
Reserve Voice
Joined: 18 Apr 2005 Posts: 6 Location: Nottingham, UK
|
Posted: Mon Dec 26, 2005 4:25 pm Post subject: |
|
|
Thanks demond, a little bit of re-organising in my script, adding your suggestion and now it all works as i wanted
Re: "-nocase"
do i just add this inline like...
| Code: | | if {[string compare -nocase $chan #somechannel] == 0} { |
or somewhere else? |
|
| Back to top |
|
 |
Ehlanna Voice
Joined: 21 Jul 2005 Posts: 15
|
Posted: Mon Dec 26, 2005 6:34 pm Post subject: |
|
|
| It may be just me (that or it's my paranoia) but you may want to do something with your $extra field in the way of quoting things like apostrophes, ec., in the input. |
|
| Back to top |
|
 |
demond Revered One

Joined: 12 Jun 2004 Posts: 3073 Location: San Francisco, CA
|
Posted: Mon Dec 26, 2005 7:25 pm Post subject: |
|
|
| Reserve wrote: | Thanks demond, a little bit of re-organising in my script, adding your suggestion and now it all works as i wanted
Re: "-nocase"
do i just add this inline like...
| Code: | | if {[string compare -nocase $chan #somechannel] == 0} { |
or somewhere else? |
check out Tcl docs ("manpage") for [string] command at tcl.tk website _________________ connection, sharing, dcc problems? click <here>
before asking for scripting help, read <this>
use [code] tag when posting logs, code |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|