| View previous topic :: View next topic |
| Author |
Message |
kennycheung21 Voice
Joined: 02 Mar 2011 Posts: 10
|
Posted: Thu Mar 03, 2011 3:26 am Post subject: change channel dynamic |
|
|
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 |
|
 |
caesar Mint Rubber

Joined: 14 Oct 2001 Posts: 3741 Location: Mint Factory
|
Posted: Thu Mar 03, 2011 3:59 pm Post subject: |
|
|
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.
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 |
|
 |
kennycheung21 Voice
Joined: 02 Mar 2011 Posts: 10
|
Posted: Fri Mar 04, 2011 3:37 am Post subject: |
|
|
Thanks Caesar,
Could you provide some details? |
|
| Back to top |
|
 |
caesar Mint Rubber

Joined: 14 Oct 2001 Posts: 3741 Location: Mint Factory
|
Posted: Sat Mar 05, 2011 4:55 am Post subject: |
|
|
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"?  _________________ Once the game is over, the king and the pawn go back in the same box. |
|
| Back to top |
|
 |
kennycheung21 Voice
Joined: 02 Mar 2011 Posts: 10
|
Posted: Tue Mar 08, 2011 4:10 am Post subject: |
|
|
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 |
|
 |
caesar Mint Rubber

Joined: 14 Oct 2001 Posts: 3741 Location: Mint Factory
|
Posted: Tue Mar 08, 2011 6:33 am Post subject: |
|
|
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 |
|
 |
kennycheung21 Voice
Joined: 02 Mar 2011 Posts: 10
|
Posted: Tue Mar 08, 2011 1:45 pm Post subject: |
|
|
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 |
|
 |
caesar Mint Rubber

Joined: 14 Oct 2001 Posts: 3741 Location: Mint Factory
|
Posted: Tue Mar 08, 2011 2:32 pm Post subject: |
|
|
| 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.  _________________ Once the game is over, the king and the pawn go back in the same box. |
|
| Back to top |
|
 |
kennycheung21 Voice
Joined: 02 Mar 2011 Posts: 10
|
Posted: Wed Mar 09, 2011 3:50 am Post subject: |
|
|
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 |
|
 |
caesar Mint Rubber

Joined: 14 Oct 2001 Posts: 3741 Location: Mint Factory
|
Posted: Wed Mar 09, 2011 6:03 am Post subject: |
|
|
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
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 |
|
 |
|