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.

If statment for command only on that channel ?

Requests for complete scripts or modifications/fixes for scripts you didn't write. Response not guaranteed, and no thread bumping!
Post Reply
G
Gemster
Halfop
Posts: 51
Joined: Mon Oct 04, 2010 5:43 pm

If statment for command only on that channel ?

Post by Gemster »

Hi,

had a look through a links that i have bookmarked from willyw :D

Anyways im looking for an if statment where a command can only responded to on a channel.

for example if a user types .help in the channel #help the bot will respond but if they type .help in another channel like #lobby it wont respond.

Thanks
Gemster
w
willyw
Revered One
Posts: 1203
Joined: Thu Jan 15, 2009 12:55 am

Re: If statment for command only on that channel ?

Post by willyw »

Gemster wrote: ...
for example if a user types .help in the channel #help the bot will respond but if they type .help in another channel like #lobby it wont respond.
Here's a rough idea (not tested):

Code: Select all

bind pub - ".help" foo

proc foo {nick uhost handle chan text} {

     if {"$chan" != "#help"} {
        return
        }

# whatever other commands you want go here

}
Even though I didn't test it for errors, I bet you get the idea. :)
User avatar
caesar
Mint Rubber
Posts: 3778
Joined: Sun Oct 14, 2001 8:00 pm
Location: Mint Factory

Post by caesar »

Since FOO is not equal with foo you have to either use 'string tolower' on $chan where all upper (or title) case letters are converted to lower case OR 'string equal -nocase' where the strings are compared in a case-insensitive manner.

Examples:

Code: Select all

if {[string tolower $chan] == "#help"} {
# do whatever
}
or:

Code: Select all

if {[string equal -nocase $chan "#help"]} {
# do whatever
}
Edit: fixed minor typo.
Last edited by caesar on Sun Feb 27, 2011 2:17 pm, edited 1 time in total.
Once the game is over, the king and the pawn go back in the same box.
d
doggo
Halfop
Posts: 97
Joined: Tue Jan 05, 2010 7:53 am
Contact:

Post by doggo »

seems there is a few ways..

this way is my fav

Code: Select all

if {$chan != "#help"} {putquick "privmsg $chan :!help dont work in here;return}
//return, with a chan msg explaining why

if {$chan != "#help"} {return}
//return, without a channel msg
G
Gemster
Halfop
Posts: 51
Joined: Mon Oct 04, 2010 5:43 pm

Post by Gemster »

Thanks guys for the help.

Using willyw's vsrsion as its the simplest and works great :D

caesar,

Code: Select all

if {[string tolower $chan] = "#help"} { 
# do whatever 
} 
It dont make any difference if the chan name is upper or lower case :D

doggo,

Some channel have botserv where !help does work.

Thanks
Gemster
w
willyw
Revered One
Posts: 1203
Joined: Thu Jan 15, 2009 12:55 am

Post by willyw »

Gemster wrote: ...
Using willyw's vsrsion as its the simplest and works great :D
...
Don't gloss over the word "rough" in my other post above. :)

I just wanted to get you pointed in the right direction.

There could be loopholes to fall through, with what I quickly did.
Caesar may very well have a point - experiment carefully and be sure.

I'm glad it got you going though.
w
willyw
Revered One
Posts: 1203
Joined: Thu Jan 15, 2009 12:55 am

Post by willyw »

doggo wrote:seems there is a few ways..

this way is my fav
...

I like this one... makes it easy to turn the script ON and OFF, on a per channel basis:

Code: Select all


setudef flag whatever

bind pub - "!command"  someproc


proc someproc {nick uhost handle chan text} {

    if {([lsearch -exact [channel info $chan] {+whatever}] != -1)} {


       # your procedure code
       # line by line
       # goes here
    
    } 
}

Use:
.chanset #channel +whatever
to enable, on a given channel
and
.chanset #channel -whatever
to disable it on a given channel.
n
nml375
Revered One
Posts: 2860
Joined: Fri Aug 04, 2006 2:09 pm

Post by nml375 »

willyw,
You can simplify that code further, since you've defined "whatever" as a flag.

Code: Select all

..
if {[channel get "whatever"]} {
...
Gemster,
Case-matching with channel names is generally an issue, as on most networks, clients are free to use whatever case they prefer. Also, most irc clients preserve the case the user used to join the channel:
Thus, someone joining #help and then typing .help, would then trigger the code, while someone joining #Help (same channel, different case) and then typing .help, would not. That is why you should use the code suggested by Caesar
NML_375
w
willyw
Revered One
Posts: 1203
Joined: Thu Jan 15, 2009 12:55 am

Post by willyw »

nml375 wrote:willyw,
You can simplify that code further, since you've defined "whatever" as a flag.

Code: Select all

..
if {[channel get "whatever"]} {
...
...
Cool. Thanks for coming in. :)

Now that you mention it, vaguely I remember finding more than one way to do it.

Honestly, I have no idea where I got that bit of code. I have no doubt that I borrowed it from someone else's scripts.
User avatar
caesar
Mint Rubber
Posts: 3778
Joined: Sun Oct 14, 2001 8:00 pm
Location: Mint Factory

Post by caesar »

Gemster wrote:Thanks guys for the help.

Using willyw's vsrsion as its the simplest and works great :D

caesar,

Code: Select all

if {[string tolower $chan] = "#help"} { 
# do whatever 
} 
It dont make any difference if the chan name is upper or lower case :D
ahh snap.. should have been == not =, meaning:

Code: Select all

if {[string tolower $chan] == "#help"} { 
# do whatever 
} 
Once the game is over, the king and the pawn go back in the same box.
Post Reply