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 

change channel dynamic

 
Post new topic   Reply to topic    egghelp.org community Forum Index -> Scripting Help
View previous topic :: View next topic  
Author Message
kennycheung21
Voice


Joined: 02 Mar 2011
Posts: 10

PostPosted: Thu Mar 03, 2011 3:26 am    Post subject: change channel dynamic Reply with quote

Hi please help me,

I would like to implement a feature which will allow the bot create a new channel and talk in it after receive a specific command.
For example,

Bot#1 is on channel #t1, and then user send out a command, Bot#1 create a channel #t2, and join it before notifying the user.

Is this possible? I have no idea how to start?

Thanks
Back to top
View user's profile Send private message
caesar
Mint Rubber


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

PostPosted: Thu Mar 03, 2011 3:59 pm    Post subject: Reply with quote

With a combination of a few commands you can get quite a nice script serving this purpose. To add a channel use 'channel add'. Consult the tcl-commands.doc file for instructions.

The commands I'm referring to are:
1. 'string equal -nocase' to compare the current channel with the channel the user specified and stop any other checks

2. 'validchan' - that checks if the bot has a channel record for the specified channel. Note that this does not necessarily mean that the bot is ON the channel, meaning the channel can be set as +inactive. To detect this we check the status of this setting at step #3.

3. 'botonchan' - a check that return 1 if the bot is on the specified channel and 0 otherwise.

4. 'channel get #channel inactive' - to check if the specified (in this example #channel) channel is set to +inactive.

5. if you want to complicate things a bit you can throw in a "bind need - "#channel *" need:all" to detect exactly what it needs to join that specific channel. Smile

If you want me to elaborate more on things just drop a message.
_________________
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
kennycheung21
Voice


Joined: 02 Mar 2011
Posts: 10

PostPosted: Fri Mar 04, 2011 3:37 am    Post subject: Reply with quote

Thanks Caesar,

Could you provide some details?
Back to top
View user's profile Send private message
caesar
Mint Rubber


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

PostPosted: Sat Mar 05, 2011 4:55 am    Post subject: Reply with quote

Sure. Have you tried out something, got stuck at some command I mentioned above or this topic just turned from a "help me out" to "do this for me instead"? Smile
_________________
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
kennycheung21
Voice


Joined: 02 Mar 2011
Posts: 10

PostPosted: Tue Mar 08, 2011 4:10 am    Post subject: Reply with quote

Hi,

I've try this:

Code:

bind dcc -|- mul dcc:mul

proc dcc:mul {hand idx arg chan}
{
#to join channel c1 specified in $chan
   if {[string equal -nocase "#c1" $chan]}
   {
      if {[validchan "#c1"]}
      {
         if {[botonchan]}
         {
            #do sth else if the bot is already on this channel
         }
         else{
            if {[channel get $chan inactive]}
            {#join c1 channel
               JOIN $chan
            }
         }
      }
   }
}

I'm not sure what's wrong, could you help me to correct it?
PS: I want this command (.mul) to be a DCC command. I'm not sure how to let the bot join another channel specified in the chanfile.
Back to top
View user's profile Send private message
caesar
Mint Rubber


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

PostPosted: Tue Mar 08, 2011 6:33 am    Post subject: Reply with quote

The dcc bind expects only 3 arguments: <handle> <idx> <text>

Code:

bind dcc * mul dcc:mul

proc dcc:mul {hand idx text} {
   # grab the channel from user's input in $chan variable and warn if no channel is specified
   if {[scan $text %s chan] != 1} {
      putdcc $idx "Syntax: .mul #channel"
      return
   }
   # check if channel is valid
   if {[validchan $chan]} {
      # continue with checking if bot is on the channel
      if {![botonchan $chan]} {
         # check is the channel is set to +inactive
         if {[channel get $chan inactive]} {
            putdcc $idx "Channel $chan is set to +inactive"
         } else {
            putdcc $idx "I'm not on $chan channel due to one of the following reasons: I'm banned, channel is set to invite only or need a key to join"
         }
      }
   } else {
      # we add the new channel
      channel add $chan
   }
}

If you really need the reason the bot can't join the specified channel this can be "complicated" a bit by adding a bind need for that specific channel, wait to grab exactly what it needs to join it and then remove the bind.

Haven't tested this but should work.
_________________
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
kennycheung21
Voice


Joined: 02 Mar 2011
Posts: 10

PostPosted: Tue Mar 08, 2011 1:45 pm    Post subject: Reply with quote

Thanks Caesar,

From your code, I'm still not sure how to make the bot join the new channel the user specified ($chan).

Maybe there is something I don't quite understand, pls correct me.
Back to top
View user's profile Send private message
caesar
Mint Rubber


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

PostPosted: Tue Mar 08, 2011 2:32 pm    Post subject: Reply with quote

Code:

if {[scan $text %s chan] != 1} {

This line dose two things:
1. it grabs the text from user's input and creates a variable chan
2. checks if the variable $chan isn't empty, meaning the user didn't specified a channel

All you have to do now is to '.mul #channel' from party line with the bot and it will try to join that channel if isn't there already. Smile
_________________
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
kennycheung21
Voice


Joined: 02 Mar 2011
Posts: 10

PostPosted: Wed Mar 09, 2011 3:50 am    Post subject: Reply with quote

Oh, I see.
But I'm wondering if I'd like to let the bot do something in the new channel after receiving this command, say print out a sentence, where I should put the statement in this script?

Thanks
Back to top
View user's profile Send private message
caesar
Mint Rubber


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

PostPosted: Wed Mar 09, 2011 6:03 am    Post subject: Reply with quote

Add the following line:
Code:

utimer 5 [list putserv "PRIVMSG $chan :something"]

that delays the sending of the message with 5 seconds to allow it to join it first after
Code:

channel add $chan


If you wish to trigger multiple actions after this 5 seconds delay then create this proc outside the dcc:mul one:
Code:

proc timed:message {chan} {
putserv "PRIVMSG $chan :something"
# and any other things you wish
}

and replace the utimer line with:
Code:

utimer 5 [list timed:message $chan]

_________________
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 -> Scripting Help 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