| View previous topic :: View next topic |
| Author |
Message |
Joel Voice
Joined: 06 Sep 2005 Posts: 11
|
Posted: Fri Sep 09, 2005 5:23 am Post subject: Binding commands to a single set of channels |
|
|
--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 |
|
| Back to top |
|
 |
demond Revered One

Joined: 12 Jun 2004 Posts: 3073 Location: San Francisco, CA
|
Posted: Fri Sep 09, 2005 5:38 am Post subject: |
|
|
| you can't [bind pub] to channel, but you can check inside the proc if $chan is allowed for that command |
|
| Back to top |
|
 |
Joel Voice
Joined: 06 Sep 2005 Posts: 11
|
Posted: Fri Sep 09, 2005 7:22 am Post subject: |
|
|
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 |
|
| Back to top |
|
 |
oxygen Voice
Joined: 05 Sep 2005 Posts: 22 Location: Germany
|
Posted: Fri Sep 09, 2005 7:52 am Post subject: |
|
|
hi Joel
maybe because:
| Code: | | if {($chan != $radiochans) || ($chan != $adminchans)}{ |
must be:
| Code: | | if {($chan != $radiochans) || ($chan != $adminchans)} { |
but to check allowed chans try this:
| Code: | 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 |
|
| Back to top |
|
 |
Joel Voice
Joined: 06 Sep 2005 Posts: 11
|
Posted: Fri Sep 09, 2005 9:03 am Post subject: |
|
|
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
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 |
|
| Back to top |
|
 |
oxygen Voice
Joined: 05 Sep 2005 Posts: 22 Location: Germany
|
Posted: Fri Sep 09, 2005 9:21 am Post subject: |
|
|
hi Joel
I think a proc is missing. maybe something like that?
| Code: | | proc shrink { calc number string start bl} { return [expr [string first "$string" $bl $start] $calc $number] } |
hope it helps
friendly regards
oxygen |
|
| Back to top |
|
 |
Joel Voice
Joined: 06 Sep 2005 Posts: 11
|
Posted: Fri Sep 09, 2005 9:31 am Post subject: |
|
|
| Doh, what a plonker... |
|
| Back to top |
|
 |
Joel Voice
Joined: 06 Sep 2005 Posts: 11
|
Posted: Fri Sep 09, 2005 10:03 am Post subject: |
|
|
| Code: |
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 |
|
| Back to top |
|
 |
Joel Voice
Joined: 06 Sep 2005 Posts: 11
|
Posted: Mon Sep 12, 2005 4:39 am Post subject: |
|
|
Anyone any ideas
Joel |
|
| Back to top |
|
 |
caesar Mint Rubber

Joined: 14 Oct 2001 Posts: 3741 Location: Mint Factory
|
Posted: Mon Sep 12, 2005 12:30 pm Post subject: |
|
|
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. |
|
| Back to top |
|
 |
|