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.

Different bot responses on private and public channels

Help for those learning Tcl or writing their own scripts.
Post Reply
R
Reserve
Voice
Posts: 6
Joined: Mon Apr 18, 2005 5:25 am
Location: Nottingham, UK

Different bot responses on private and public channels

Post by Reserve »

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

Code: Select all

!link <arg>
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: Select all

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: Select all

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
User avatar
demond
Revered One
Posts: 3073
Joined: Sat Jun 12, 2004 9:58 am
Location: San Francisco, CA
Contact:

Post by demond »

[string compare] returns 0 if the strings are identical, otherwise 1 or -1; so you need to change your if's to:

Code: Select all

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: Select all

 tag when posting logs, code
R
Reserve
Voice
Posts: 6
Joined: Mon Apr 18, 2005 5:25 am
Location: Nottingham, UK

Post by Reserve »

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: Select all

if {[string compare -nocase $chan #somechannel] == 0} { 
or somewhere else?
E
Ehlanna
Voice
Posts: 15
Joined: Thu Jul 21, 2005 12:08 pm

Post by Ehlanna »

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.
User avatar
demond
Revered One
Posts: 3073
Joined: Sat Jun 12, 2004 9:58 am
Location: San Francisco, CA
Contact:

Post by demond »

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: Select all

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: Select all

 tag when posting logs, code
Post Reply