egghelp.org community Forum Index
[ egghelp.org home | forum home ]
egghelp.org community
Discussion of eggdrop bots, shell accounts and tcl scripts.
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

If statment for command only on that channel ?

 
Post new topic   Reply to topic    egghelp.org community Forum Index -> Script Requests
View previous topic :: View next topic  
Author Message
Gemster
Halfop


Joined: 04 Oct 2010
Posts: 51

PostPosted: Sat Feb 26, 2011 9:13 pm    Post subject: If statment for command only on that channel ? Reply with quote

Hi,

had a look through a links that i have bookmarked from willyw Very Happy

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
Back to top
View user's profile Send private message
willyw
Revered One


Joined: 15 Jan 2009
Posts: 1175

PostPosted: Sat Feb 26, 2011 10:46 pm    Post subject: Re: If statment for command only on that channel ? Reply with quote

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:

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. Smile
Back to top
View user's profile Send private message
caesar
Mint Rubber


Joined: 14 Oct 2001
Posts: 3741
Location: Mint Factory

PostPosted: Sun Feb 27, 2011 5:13 am    Post subject: Reply with quote

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:

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

or:
Code:

if {[string equal -nocase $chan "#help"]} {
# do whatever
}

Edit: fixed minor typo.
_________________
Once the game is over, the king and the pawn go back in the same box.


Last edited by caesar on Sun Feb 27, 2011 2:17 pm; edited 1 time in total
Back to top
View user's profile Send private message
doggo
Halfop


Joined: 05 Jan 2010
Posts: 97

PostPosted: Sun Feb 27, 2011 6:28 am    Post subject: Reply with quote

seems there is a few ways..

this way is my fav

Code:

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

_________________
NON geeky!! http://gotcode4u.com/
Back to top
View user's profile Send private message Visit poster's website
Gemster
Halfop


Joined: 04 Oct 2010
Posts: 51

PostPosted: Sun Feb 27, 2011 9:26 am    Post subject: Reply with quote

Thanks guys for the help.

Using willyw's vsrsion as its the simplest and works great Very Happy

caesar,

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


It dont make any difference if the chan name is upper or lower case Very Happy

doggo,

Some channel have botserv where !help does work.

Thanks
Gemster
Back to top
View user's profile Send private message
willyw
Revered One


Joined: 15 Jan 2009
Posts: 1175

PostPosted: Sun Feb 27, 2011 11:38 am    Post subject: Reply with quote

Gemster wrote:

...
Using willyw's vsrsion as its the simplest and works great Very Happy
...


Don't gloss over the word "rough" in my other post above. Smile

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.
Back to top
View user's profile Send private message
willyw
Revered One


Joined: 15 Jan 2009
Posts: 1175

PostPosted: Sun Feb 27, 2011 11:48 am    Post subject: Reply with quote

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:


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.
Back to top
View user's profile Send private message
nml375
Revered One


Joined: 04 Aug 2006
Posts: 2857

PostPosted: Sun Feb 27, 2011 1:32 pm    Post subject: Reply with quote

willyw,
You can simplify that code further, since you've defined "whatever" as a flag.
Code:
..
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, idling at #eggdrop@IrcNET
Back to top
View user's profile Send private message
willyw
Revered One


Joined: 15 Jan 2009
Posts: 1175

PostPosted: Sun Feb 27, 2011 1:51 pm    Post subject: Reply with quote

nml375 wrote:
willyw,
You can simplify that code further, since you've defined "whatever" as a flag.
Code:
..
if {[channel get "whatever"]} {
...

...


Cool. Thanks for coming in. Smile

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.
Back to top
View user's profile Send private message
caesar
Mint Rubber


Joined: 14 Oct 2001
Posts: 3741
Location: Mint Factory

PostPosted: Sun Feb 27, 2011 2:16 pm    Post subject: Reply with quote

Gemster wrote:
Thanks guys for the help.

Using willyw's vsrsion as its the simplest and works great Very Happy

caesar,

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


It dont make any difference if the chan name is upper or lower case Very Happy

ahh snap.. should have been == not =, meaning:
Code:
if {[string tolower $chan] == "#help"} {
# do whatever
}

_________________
Once the game is over, the king and the pawn go back in the same box.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    egghelp.org community Forum Index -> Script Requests All times are GMT - 4 Hours
Page 1 of 1

 
Jump to:  
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


Forum hosting provided by Reverse.net

Powered by phpBB © 2001, 2005 phpBB Group
subGreen style by ktauber