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.

msg all channels/on channel? [solved]

Help for those learning Tcl or writing their own scripts.
Post Reply
r
raider2k
Op
Posts: 140
Joined: Tue Jan 01, 2008 10:42 am

msg all channels/on channel? [solved]

Post by raider2k »

The one post Weird behavior of FOREACH command gave me some idea in how to handle what I was thinking about a few days ago.

So I figured out this isnt a problem at all - but what is a problem is another feature that needs to be combined with that one, but lets start from the beginning ^^

Im up to let the bot catch specific messages from (make it a random number) 3 channels where it sits in. There are 3 different channels where other bots are going to announce news from 3 different news sites which will be catched from my bot. So now I want my bot to announce ALL of the 3 channels it is in except the one where it got the news message from. I hope I explained it well ^^

here is an example of what I tried:

Code: Select all

bind pub - !lol lolproc

set diffchans [list "#LOL" "#ROFL" "#OMGWTF"]

proc lolproc { nick uhost handle chan text } {
	set value [lindex $text 0]
	set dchans [split $::diffchans]
	if { [string equal -nocase $chan $dchans] } {
		set dchans [string map { "$chan" "" } $dchans]
	}
	foreach schan $diffchans {
		putquick "PRIVMSG $schan :\[NEWS\] - $value"
	}
}
This is just a testproc to see if the idea would even work so far. So I provide info to the bot by typing "!lol test". Somehow the whole if loop gets ignored and the bot just messages into all channels.

Im not sure if there is also another way to remove a item from a list temporarily - thats why I did the set dchans [string map { "$chan" "" } $dchans. Someone please keep the ball rolling so I can get a new impression on this one :)

appreciated :)
Last edited by raider2k on Sat Jan 12, 2008 7:46 am, edited 1 time in total.
m
metroid
Owner
Posts: 771
Joined: Wed Jun 16, 2004 2:46 am

Post by metroid »

You use split on lists, you shouldn't.
r
raider2k
Op
Posts: 140
Joined: Tue Jan 01, 2008 10:42 am

Post by raider2k »

mh weird .. can you get me an impression how to handle this please? ^^

//edit:

I was wondering if I shouldnt do it that way:

Code: Select all

bind pub - !lol lolproc 

set diffchans "#LOL #ROFL #OMGWTF"

proc lolproc { nick uhost handle chan text } { 
   set value [lindex $text 0] 
   set dchans [split $::diffchans " "] 
   if { [string equal -nocase $chan $dchans] } { 
      set dchans [string map { "$chan" "" } $dchans] 
   } 
   foreach schan $diffchans { 
      putquick "PRIVMSG $schan :\[NEWS\] - $value" 
   } 
}
removed [list when setting diffchans and added split $::diffchans " ". maybe that one is gonna work. what do you think?

//edit:

not working either :(
very weird thingie. Though Im trying to remove that channel where the bot is in temporarely so it wont get messaged ... very weird :/
t
tsukeh
Voice
Posts: 31
Joined: Thu Jan 20, 2005 6:22 am

Post by tsukeh »

Code: Select all

bind pub - !lol lolproc

set diffchans [list #LOL #ROFL #OMGWTF]

proc lolproc {nick uhost hand chan text} {
 set value [lindex [split $text] 0]
 foreach i $::diffchans {
  if ![string equal -nocase $chan $i] {
   putquick "PRIVMSG $i :\[NEWS\] - $value"
  }
 }
}
r
raider2k
Op
Posts: 140
Joined: Tue Jan 01, 2008 10:42 am

Post by raider2k »

thx tsukeh
working like a charm :)
Post Reply