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.

Binding commands to a single set of channels

Old posts that have not been replied to for several years.
Locked
J
Joel
Voice
Posts: 11
Joined: Tue Sep 06, 2005 7:26 am

Binding commands to a single set of channels

Post by Joel »

--new code below--


Is what i have, but my bot sits in a load of channels, but i only want the commands to be available in #chan and #chan.admin? How do i bind the script to those channels?

Joel
Last edited by Joel on Fri Sep 09, 2005 8:58 am, edited 3 times in total.
User avatar
demond
Revered One
Posts: 3073
Joined: Sat Jun 12, 2004 9:58 am
Location: San Francisco, CA
Contact:

Post by demond »

you can't [bind pub] to channel, but you can check inside the proc if $chan is allowed for that command
J
Joel
Voice
Posts: 11
Joined: Tue Sep 06, 2005 7:26 am

Post by Joel »

Ah, right, updated the code above, but i'm getting a silly error that i cant seem to see whats causing it

12:24 <KryptoBot>12:21] Tcl error [stats_run]: extra characters after
close-brace

is it something to do with newline chars?

Joel
o
oxygen
Voice
Posts: 22
Joined: Mon Sep 05, 2005 2:22 pm
Location: Germany

Post by oxygen »

hi Joel

maybe because:

Code: Select all

if {($chan != $radiochans) || ($chan != $adminchans)}{ 
must be:

Code: Select all

if {($chan != $radiochans) || ($chan != $adminchans)} { 
but to check allowed chans try this:

Code: Select all

set allowedchans "#chan #chan.admin"

bind * !stats stats_run 

proc stats_run {nick uhost hand chan rest} { 
   global streamip streamport streampass allowedchans 
      if {(([lsearch -exact [string tolower $allowedchans] [string tolower $chan]] != -1)||($allowedchans == "*"))} {
          if {[catch {set sock [socket $streamip $streamport] } sockerror]} { 
             putlog "error: $sockerror" 
             return 0 
          } else {
             blabla....
hope this helps. btw. the first if must be in one line

friendly regards
oxygen
J
Joel
Voice
Posts: 11
Joined: Tue Sep 06, 2005 7:26 am

Post by Joel »

Thankyou kindly for your help, added that, and sorted a problem with the position of my { and } (I think :S)

anyway, I now have this

Code: Select all


--- Code Cut ---

But get the error

[13:53] Tcl error [stats_run]: invalid command name "shrink"

Have i got something in the wrong place? excude my n00b ness, but I'm more familiar with PHP, just getting started in this arena :S

Oh and out of interest, what editor do people use? I could really do with one with auto indent? jEdit doesnt seem to do it.

Joel
Last edited by Joel on Fri Sep 09, 2005 9:58 am, edited 2 times in total.
o
oxygen
Voice
Posts: 22
Joined: Mon Sep 05, 2005 2:22 pm
Location: Germany

Post by oxygen »

hi Joel

I think a proc is missing. maybe something like that?

Code: Select all

proc shrink { calc number string start bl} { return [expr [string first "$string" $bl $start] $calc $number] }
hope it helps

friendly regards
oxygen
J
Joel
Voice
Posts: 11
Joined: Tue Sep 06, 2005 7:26 am

Post by Joel »

Doh, what a plonker...
J
Joel
Voice
Posts: 11
Joined: Tue Sep 06, 2005 7:26 am

Post by Joel »

Code: Select all


set allowedchans "#linod"
set streamip ""
set streamport "9000"
set streampass ""

bind pub * !stats stats_run

# Basic Edit Functions
proc shrink { calc number string start bl} { return [expr [string first "$string" $bl $start] $calc $number] }

#Command Functions
proc stats_run {nick uhost hand chan rest} {
   global streamip streamport streampass allowedchans
      if {(([lsearch -exact [string tolower $allowedchans] [string tolower $chan]] != -1)||($allowedchans == "*"))} {
          if {[catch {set sock [socket $streamip $streamport] } sockerror]} {
             putlog "error: $sockerror"
             return 0
	     } else {
		if {[catch {set sock [socket $streamip $streamport] } sockerror]} {
			putlog "error: $sockerror"
			return 0 
		} else {
			puts $sock "GET /admin.cgi?pass=$streampass&mode=viewxml&page=0 HTTP/1.0"
			puts $sock "User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:0.9.9)"
			puts $sock "Host: $streamip"
			puts $sock "Connection: close"
			puts $sock ""
			flush $sock
			putlog "debug 01 $chan"
			while {[eof $sock] != 1} {
				set bl [gets $sock]
				if { [string first "standalone" $bl] != -1 } {
					set streamstatus [string range $bl [shrink + 14 "<STREAMSTATUS>" 0 $bl] [shrink - 1 "</STREAMSTATUS>" 0 $bl]]
				}
			}
				close $sock
			} 
			if { $streamstatus == "1" } {
				putlog "shoutcast: $nick asked for serverstats from $chan"
				if {[catch {set sock [socket $streamip $streamport] } sockerror]} {
					putlog "error: $sockerror"
					return 0
				} else {
					puts $sock "GET /admin.cgi?pass=$streampass&mode=viewxml&page=0 HTTP/1.0"
					puts $sock "User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:0.9.9)"
					puts $sock "Host: $streamip"
					puts $sock "Connection: close"
					puts $sock ""
					flush $sock
					putlog "debug 02 $chan"
					while {[eof $sock] != 1} {
						putlog "debug 03 $chan"
						set bl [gets $sock]
						putlog "debug 04 $chan"
						if { [string first "standalone" $bl] != -1 } {
							putlog "Generating info"
							
							set streamstatus [string range $bl [shrink + 14 "<STREAMSTATUS>" 0 $bl] [shrink - 1 "</STREAMSTATUS>" 0 $bl]]
							set repl [string range $bl [shrink + 19 "<REPORTEDLISTENERS>" 0 $bl] [shrink - 1 "</REPORTEDLISTENERS>" 0 $bl]]
							set curhigh [string range $bl [shrink + 15 "<PEAKLISTENERS>" 0 $bl] [shrink - 1 "</PEAKLISTENERS>" 0 $bl]]
							set currentl [string range $bl [shrink + 18 "<CURRENTLISTENERS>" 0 $bl] [shrink - 1 "</CURRENTLISTENERS>" 0 $bl]]
							set surl [string range $bl [shrink + 11 "<SERVERURL>" 0 $bl] [shrink - 1 "</SERVERURL>" 0 $bl]]
							set maxl [string range $bl [shrink + 14 "<MAXLISTENERS>" 0 $bl] [shrink - 1 "</MAXLISTENERS>" 0 $bl]]
							set bitrate [string range $bl [shrink + 9 "<BITRATE>" 0 $bl] [shrink - 1 "</BITRATE>" 0 $bl]]
							set stitle [string range $bl [shrink + 13 "<SERVERTITLE>" 0 $bl] [shrink - 1 "</SERVERTITLE>" 0 $bl]]
							set sgenre [string range $bl [shrink + 13 "<SERVERGENRE>" 0 $bl] [shrink - 1 "</SERVERGENRE>" 0 $bl]]
							if {$sgenre != ""} {set sgenre " ($sgenre)"}
							set avgtime [string range $bl [shrink + 13 "<AVERAGETIME>" 0 $bl] [shrink - 1 "</AVERAGETIME>" 0 $bl]]
							set irc [string range $bl [shrink + 5 "<IRC>" 0 $bl] [shrink - 1 "</IRC>" 0 $bl]]
							set webhits [string range $bl [shrink + 9 "<WEBHITS>" 0 $bl] [shrink - 1 "</WEBHITS>" 0 $bl]]
							set streamhits [string range $bl [shrink + 12 "<STREAMHITS>" 0 $bl] [shrink - 1 "</STREAMHITS>" 0 $bl]]
							set version [string range $bl [shrink + 9 "<VERSION>" 0 $bl] [shrink - 1 "</VERSION>" 0 $bl]]

						}
						close $sock
					}
				}
					putchan $chan "$stitle$sgenre is online, running shoutcast $version and streaming at $bitrate kbps,  your dj is $dj. please visit $surl" 		
					putchan $chan "$stitle$sgenre is online, running shoutcast $version and streaming at $bitrate kbps,  your dj is $dj. please visit $surl"
					putchan $chan "there are currently $repl unique people listening, the listener maximum is $maxl, our user peak was at $curhigh listeners."
					putchan $chan "the average user is listening $avgtime seconds, our stream had $webhits webhits and $streamhits streamhits."
					putchan $chan "you can contact the team by irc on $irc"
				} else { 
					return 0
	}
			}
		}
	}
Right well after some broken bits, i think i'm nearly there, once i've cracked this bit i should be ok for the rest,

I'm getting a weird thing going on now, not sure what i've done, but when i do !stats in the chan i get a TCL error:

Tcl error [stats_run]: can not find channel named "sock24"

the 24 on the end incriments by one every time i run the command. I cant see where i've ended up looping the chan name into that :s

the last message i get to the party line is debug 04 $chan, so i think its after that that causes the problem, unless its further up and i just cant see it :s

Thanks in advance

Joel.... Slowly getting the hang of this :S
J
Joel
Voice
Posts: 11
Joined: Tue Sep 06, 2005 7:26 am

Post by Joel »

Anyone any ideas :(

Joel
User avatar
caesar
Mint Rubber
Posts: 3778
Joined: Sun Oct 14, 2001 8:00 pm
Location: Mint Factory

Post by caesar »

I'd go for 'setudef' and 'channel get' (check the tcl-commands.doc file) instead of a some specified in a variable way if you want to have commands just for one or some specific channels, this in case the list of allowed channels changes.

Post what errors you get (see this page for instructions).
Once the game is over, the king and the pawn go back in the same box.
Locked