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.

change channel dynamic

Help for those learning Tcl or writing their own scripts.
Post Reply
k
kennycheung21
Voice
Posts: 10
Joined: Wed Mar 02, 2011 7:22 pm

change channel dynamic

Post by kennycheung21 »

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
User avatar
caesar
Mint Rubber
Posts: 3778
Joined: Sun Oct 14, 2001 8:00 pm
Location: Mint Factory

Post by caesar »

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.
k
kennycheung21
Voice
Posts: 10
Joined: Wed Mar 02, 2011 7:22 pm

Post by kennycheung21 »

Thanks Caesar,

Could you provide some details?
User avatar
caesar
Mint Rubber
Posts: 3778
Joined: Sun Oct 14, 2001 8:00 pm
Location: Mint Factory

Post by caesar »

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.
k
kennycheung21
Voice
Posts: 10
Joined: Wed Mar 02, 2011 7:22 pm

Post by kennycheung21 »

Hi,

I've try this:

Code: Select all

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.
User avatar
caesar
Mint Rubber
Posts: 3778
Joined: Sun Oct 14, 2001 8:00 pm
Location: Mint Factory

Post by caesar »

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

Code: Select all

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.
k
kennycheung21
Voice
Posts: 10
Joined: Wed Mar 02, 2011 7:22 pm

Post by kennycheung21 »

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.
User avatar
caesar
Mint Rubber
Posts: 3778
Joined: Sun Oct 14, 2001 8:00 pm
Location: Mint Factory

Post by caesar »

Code: Select all

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.
k
kennycheung21
Voice
Posts: 10
Joined: Wed Mar 02, 2011 7:22 pm

Post by kennycheung21 »

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
User avatar
caesar
Mint Rubber
Posts: 3778
Joined: Sun Oct 14, 2001 8:00 pm
Location: Mint Factory

Post by caesar »

Add the following line:

Code: Select all

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

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

proc timed:message {chan} {
putserv "PRIVMSG $chan :something"
# and any other things you wish
}
and replace the utimer line with:

Code: Select all

utimer 5 [list timed:message $chan]
Once the game is over, the king and the pawn go back in the same box.
Post Reply