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.

I wrote my own shoutcast script but need help plz :o

Help for those learning Tcl or writing their own scripts.
Post Reply
N
NTHosts
Op
Posts: 100
Joined: Mon Oct 10, 2005 9:57 pm
Location: UK
Contact:

I wrote my own shoutcast script but need help plz :o

Post by NTHosts »

Ok heres the silly attempt at me writing tcl, well, i just poked around other ppls scripts and took bits out, but it all counts right ? :P

Code: Select all

set topictrigger "!topic"
set streamip "stream.lynxfm.info"
set streamport "9000"
set streampass "zigzag"
set radiochans "#LynxFM"

bind pub - $topictrigger  pub_topic
bind msg - $topictrigger  msg_topic

proc topic { target } { 
global streamip streamport streampass
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
while {[eof $sock] != 1} {
set bl [gets $sock]
if { [string first "standalone" $bl] != -1 } {
set topic "topic: [string range $bl [shrink + 13 "<SERVERTITLE>" 0 $bl] [shrink - 1 "</SERVERTITLE>" 0 $bl]]"
}}
putquick "PRIVMSG $target :$topic"

proc msg_topic { nick uhost hand arg } { topic $chan}
proc pub_topic { nick uhost hand chan arg } { global radiochans; if {([lsearch -exact [string tolower $radiochans][string tolower $chan]] != -1) || ($radiochans == "")} { topic $chan  }}}}
When i try the !topic.. i get this error..

[10:28] Tcl error [pub_topic]: invalid command name "pub_topic"

im pulling my hair out with this 1, i also dont really want it to msg then channel, but rather to change its topic.

Any ideas please ? :)
www.NT-Hosts.Net - More than just a host
User avatar
demond
Revered One
Posts: 3073
Joined: Sat Jun 12, 2004 9:58 am
Location: San Francisco, CA
Contact:

Post by demond »

1. post your script with proper indentation
2. don't use raw socket, use http package
3. your error is likely due to unbalanced braces
connection, sharing, dcc problems? click <here>
before asking for scripting help, read <this>
use

Code: Select all

 tag when posting logs, code
N
NTHosts
Op
Posts: 100
Joined: Mon Oct 10, 2005 9:57 pm
Location: UK
Contact:

hehe

Post by NTHosts »

demond wrote:1. post your script with proper indentation
2. don't use raw socket, use http package
3. your error is likely due to unbalanced braces
Proper Indentation ?
http package ?
unbalanced braces ??

omg sorry i have no idea what any of that means, like i said i just chopped a few other scripts and put them together.
I did do a little rewrite, now i dont get errors it just dont do anything.. heres the script..

Code: Select all

set topictrigger "!topic"
set streamip "stream.lynxfm.info"
set streamport "9000"
set streampass "password"
set radiochans "#LynxFM"

bind pub - $topictrigger  pub_topic
bind msg - $topictrigger  msg_topic

proc topic { target } { 
global streamip streamport streampass
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
while {[eof $sock] != 1} {
set bl [gets $sock]
if { [string first "standalone" $bl] != -1 } {
set topic [string range $bl [shrink + 13 "<SERVERTITLE>" 0 $bl] [shrink - 1 "</SERVERTITLE>" 0 $bl]]
}}
putquick "PRIVMSG $target : $topic "

proc msg_topic { nick uhost hand arg } { topic $chan}
proc pub_topic { nick uhost hand chan arg } { global radiochans; if {([lsearch -exact [string tolower $radiochans][string tolower $chan]] != -1) || ($radiochans == "")} { topic $chan  }}}}
Thanks for any help you can give :)
www.NT-Hosts.Net - More than just a host
User avatar
demond
Revered One
Posts: 3073
Joined: Sat Jun 12, 2004 9:58 am
Location: San Francisco, CA
Contact:

Post by demond »

  • 'proper indentation' means writing/posting like this:

    Code: Select all

    if {$flag} {
       set foo $bar
    }
    
    and not like this:

    Code: Select all

    if {$flag} {
    set foo $bar
    }
    
    the former is easier to read, the latter is harder
  • go to http package manpage ('manpage' means manual page) and learn about it
  • 'unbalanced braces' means you have different number of opening { and closing } characters; sometimes Tcl reports that directly, sometimes not; and if not, the error message is misleading
  • use .set errorInfo to obtain backtrace on the error
connection, sharing, dcc problems? click <here>
before asking for scripting help, read <this>
use

Code: Select all

 tag when posting logs, code
Post Reply