Advertisement
Dj_Dexter

ice2.tcl

Apr 3rd, 2012
164
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
TCL 15.71 KB | None | 0 0
  1. #Tido's Modified Icecast2 Script
  2. #Heavily Modified by Sircrazy
  3. #Version 1.01
  4. #July 12, 2010
  5. ######################################################################
  6. #This program is free software; you can redistribute it and/or modify
  7. #it under the terms of the GNU General Public License as published by
  8. #the Free Software Foundation; version 2 of the License.
  9. #
  10. #This program is distributed in the hope that it will be useful,
  11. #but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. #MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13. #GNU General Public License for more details.
  14. ######################################################################
  15. #Credits:
  16. #Influenced by Domsen's shoutcast1.03.tcl
  17. #Special thanks to the TCL MAN files :D
  18. #Special Release updated by Sircrazy
  19. ######################################################################
  20. #Change these varibles to the one for your stream/bot/channel
  21.  
  22. #Name of Radio Station
  23. set streamname "Radio Linuxerz"
  24.  
  25. #IP of the Icecast server.
  26. set streamip "91.121.134.23"
  27.  
  28. #Port that Icecast is using, default is 8000.
  29. set streamport "8000"
  30.  
  31. #Main channel for the radio bot.
  32. set radiochan "#linuxerz"
  33.  
  34. #Other channel that the bot can advertise to. Bot must be in this channel for this to work. Ice2.tcl only
  35. # sends stream advertisements to this channel and does not send song info.
  36. set otherchan ""
  37.  
  38. #URL/Link to the stream for listening. This is what listeners need to click to tune in.
  39. set streamurl "http://radio.linuxerz.org"
  40.  
  41. #How often the bot checks the stream when it knows it is down in minutes. Recommend 1 minute.
  42. set offlinetimer "1"
  43.  
  44. #How often the bot checks the stream when it knows it is online in seconds. Recommend 15 seconds.
  45. set onlinetimer "15"
  46.  
  47. #Default interval for how often the bot advertises (in minutes). You want to set it to something that isn't
  48. # pure spammage.
  49. set adtimer "30"
  50.  
  51. #Enables advertising set to the above frequency. 1 for ON and 0 for OFF. This reminds people that the stream
  52. # is online.
  53. set enableadvertise "1"
  54.  
  55. #Enables Special Announcement, 1 for ON and 0 for OFF. Special announcements are displayed every 720 minutes.
  56. # This feature of the script is very undeveloped and I don't recommend using it.
  57. set specialannounce "0"
  58.  
  59. #Special Announcement Message
  60. #set announcemsg "SPECIAL ANNOUNCEMENT! On Novemeber 26th @ Midnight GMT, JA Radio will be ON-AIR with a show featuring some exclusive live tracks from some of our favorite bands! Click here for more info: http://www.thejediacademy.net/forums_detail_page.php?f_id=13532"
  61.  
  62. ###########################################################################
  63. #  Don't edit past this stuff unless you're Tido, Henkes, or Sircrazy :P  #
  64. #       Except Line 387 where you need to add DJs and Line 281 where      #
  65. #                    you need to put your mount point.                    #
  66. ###########################################################################
  67.  
  68.  
  69. # Binds
  70. #bind pub - "%commands" showcommands
  71. #Shows a list of all commands
  72.  
  73. #bind pub - "%help" showcommands
  74. #same as %commands
  75.  
  76. #bind pub - "!sonando" statuscheck
  77. #Displays the status of the stream
  78.  
  79. #bind pub - "%listeners" listenercheck
  80. #Reports how many listeners there are
  81.  
  82. #bind pub - "%request" request
  83. #Allows users to request songs
  84.  
  85. #bind msg - "request" request_pm
  86. #Allows users to make requests via pm
  87.  
  88. #bind msg - "djon" dj_on
  89. #turns on dj status
  90.  
  91. #bind pub - "%djoff" dj_off
  92. #turns off dj status
  93.  
  94. #bind msg - "djoff" dj_off_pm
  95. #turns off dj status
  96.  
  97. #bind pub - "%fadvert" forceadvertise
  98. #Forces an advertising message to be sent
  99.  
  100. #bind pub - "%version" iceversion
  101. #Displays the Ice2.tcl version
  102.  
  103. # Varible Resets
  104. set ice2version "1.01 - 07.12.10"
  105. set streamstatus "0"
  106. set djnickname ""
  107. set dj ""
  108. set oldsong ""
  109. set newsong ""
  110. set newlistener ""
  111. set oldlistener "1"
  112. set forceadsent "0"
  113. set sessionpeak "0"
  114.  
  115. # Check to make sure StatusCheck timer isn't running when bot rehashes.
  116. if {![info exists statuscheck_running]} {
  117.   timer $offlinetimer [list statuscheck]
  118.   set statuscheck_running 1
  119. }
  120.  
  121. # Check to make sure Special Announce timer isn't running when bot rehashes.
  122. if {![info exists specialannounce_running]} {
  123.   if {$specialannounce == "1"} {
  124.     timer 720 [list specialmessage]
  125.     set specialannounce_running 1
  126.   }
  127. }
  128.  
  129.  
  130. # Check to make sure Advertise timer isn't running when bot rehashes.
  131. if {![info exists adtimer_running]} {
  132.   if {$enableadvertise == "1"} {
  133.     timer $adtimer [list advertise]
  134.     set adtimer_running 1
  135.   }
  136. }
  137.  
  138. # Output for %help or %commands
  139. proc showcommands {nick uhost hand chan arg} {
  140.   global ice2version streamname botnick dj
  141.   if {$dj == "$nick" && $arg != ""} {
  142.     putserv "notice $arg :>>> $botnick Commands - $ice2version<<<"
  143.     putserv "notice $arg :%status >>> Displays stream's status. If online it shows the song."
  144.     putserv "notice $arg :%request (artist+track) >>> Sends a Request for a future song."
  145.     putserv "notice $arg :/msg $botnick request (artist+track) >>> Sends a Request for a future song by PM."
  146.   }
  147.   if {$dj != "$nick"} {
  148.     set arg ""
  149.     putserv "notice $nick :>>> $botnick Commands - $ice2version<<<"
  150.     putserv "notice $nick :%status >>> Displays the stream's status. If online it shows the song."
  151.     putserv "notice $nick :%request (artist+track) >>> Sends a Request for a future song."
  152.     putserv "notice $nick :/msg $botnick request (artist+track) >>> Sends a Request for a future song by PM."
  153.   }
  154. }
  155.  
  156. # Turns on and off Advertising. Also lets you set the interval: !advertise X
  157. proc toggle_advertise {nick uhost hand chan arg} {
  158.   global radiochan enableadvertise adtimer
  159.   if {$enableadvertise == "1"} {
  160.     set enableadvertise "0"
  161.     set timerinfo [gettimerid]
  162.     killtimer $timerinfo
  163.     putserv "PRIVMSG $chan :Aviso OFF"
  164.   } else {
  165.     set enableadvertise "1"
  166.     if {$arg == ""} {
  167.       putserv "PRIVMSG $chan :Aviso ON. Frecuencia cambiada a $adtimer minutes."
  168.     } else {
  169.       set adtimer $arg
  170.       putserv "privmsg $chan :Aviso ON. Frequencia cambiada a $adtimer minutes."
  171.       timer $adtimer [list advertise]
  172.     }
  173.   }
  174. }
  175.  
  176. # Function that finds out the ID of the advertising timer.
  177. proc gettimerid {} {
  178.     set adtimerinfo [timers]
  179.     set loc1 [string first "advertise" $adtimerinfo]
  180.     set loc1 [expr $loc1 + 10]
  181.     set str1 [string range $adtimerinfo $loc1 999]
  182.     set endloc [string first "\}" $str1]
  183.     set endloc [expr $endloc -1]
  184.     set timerinfo [string range $str1 0 $endloc]
  185.     return $timerinfo
  186. }
  187.  
  188. proc sonandoc {} {
  189.     if {$newstatus == "1" && $oldstatus == "1"} {
  190.     utimer $onlinetimer [list statuscheck]
  191.     if {$newsong != $oldsong && $newsong != ">inbetween" && $newsong != ">inbetween1" && $newsong != ">inbetween2" && $newsong != ">what$
  192.      putserv "PRIVMSG $radiochan :Esta Sonando $streamname: $newsong @ $streamurl"
  193.      set oldsong "$newsong"
  194.    }
  195. }
  196. }
  197.  
  198. # Messages that are displayed when Advertising is enabled.
  199. proc advertise {} {
  200.  global radiochan streamstatus otherchan enableadvertise adtimer forceadsent streamurl streamname
  201.  if {$streamstatus != "0" && $enableadvertise == "1"} {
  202.    putserv "PRIVMSG $radiochan :$streamname actualmente esta transmitiendo en vivo! Escuchar en @ $streamurl"
  203.    putserv "PRIVMSG $otherchan :$streamname actualmente esta transmitiendo en vivo! Escuchar en @ $streamurl"
  204.    if {$forceadsent == "0"} {timer $adtimer [list advertise]} else {set forceadsent "0"}
  205.    return 1
  206.  }
  207.  return 0
  208. }
  209.  
  210. # Forces the advertising messages to appear
  211. proc forceadvertise {nick uhost hand chan arg} {
  212.  global streamstatus enableadvertise forceadsent
  213.  if {$streamstatus == "0"} {
  214.    putserv "noticia $nick :El Stream no esta al-aire. No se puede avisar."
  215.    return 0
  216.  } else {
  217.    if {$enableadvertise == "0"} {
  218.      putserv "notice $nick :Aviso no esta activado."
  219.      return 0
  220.    } else {
  221.      set forceadsent "1"
  222.      set forceadvertised [advertise]
  223.      if {$forceadvertised == "1"} {
  224.        putserv "notice $nick :Terminado!"
  225.      } else {
  226.        putserv "notice $nick :Mensaje de aviso no se envio"
  227.      }
  228.    }
  229.  }
  230. }
  231.  
  232. # Special Announcement Message.
  233. proc specialmessage {} {
  234.  global radiochan specialannounce announcemsg
  235.  putserv "PRIVMSG $radiochan : $announcemsg"
  236.  timer 720 [list specialmessage]
  237.  return 0
  238. }
  239.  
  240. # StatusCheck
  241. # Function that takes the information from Icecast_Online and creates the proper responses.
  242. proc statuscheck {} {
  243.  global radiochan streamstatus newsong oldsong newlistener oldlistener sessionpeak dj enableadvertise otherchan onlinetimer offlinetimer streamurl streamname
  244.  
  245.  if {$streamstatus == "0"} {
  246.    set oldstatus "0"
  247.  } else {
  248.    set oldstatus "1"
  249.  }
  250.  set newstatus "[icecast_online]"
  251.  if {$newstatus =="0" && $oldstatus == "0"} {
  252.    timer $offlinetimer [list statuscheck]
  253.  }
  254.  if {$newstatus == "1" && $oldstatus == "0"} {
  255.    putserv "PRIVMSG $radiochan :$streamname esta al-aire Click para escuchar: $streamurl"
  256.    putlog "(RADIO) On-Air detected."
  257.    utimer $onlinetimer [list statuscheck]
  258.    if {$enableadvertise == "1"} {
  259.      putserv "PRIVMSG $otherchan :$streamname esta al-aire Click para escuchar: $streamurl"
  260.  
  261.    }
  262.  }
  263.  if {$newstatus == "0" && $oldstatus == "1"} {
  264.    putserv "PRIVMSG $radiochan :$streamname esta nuevamente fuera de linea."
  265.    set oldlistener "0"
  266.    set sessionpeak "0"
  267.    if {$enableadvertise == "1"} {
  268.      putserv "PRIVMSG $otherchan :$streamname esta fuera de linea."
  269.    }
  270.    putlog "(RADIO) Fuera de Linea detectado."
  271.    timer $offlinetimer [list statuscheck]
  272.  }
  273.  if {$newstatus == "1" && $oldstatus == "1"} {
  274.    utimer $onlinetimer [list statuscheck]
  275.    if {$newsong != $oldsong && $newsong != ">inbetween" && $newsong != ">inbetween1" && $newsong != ">inbetween2" && $newsong != ">whatutalkinbout" && $newsong != ">tmsradio80sintro"} {
  276.      putserv "PRIVMSG $radiochan :Esta Sonando $streamname: $newsong @ $streamurl"
  277.      set oldsong "$newsong"
  278.    }
  279.  }
  280. }
  281.  
  282. # Icecast_Online
  283. # This is the HTTP Parser that gathers the various data from the status.xsl file.
  284. proc icecast_online { } {
  285.  global streamip streamport streamstatus newsong newlistener
  286.  set pagedata ""
  287.  if {[catch {set sock [socket $streamip $streamport] } sockerror]} {
  288.    putlog "error: $sockerror"
  289.    return 0
  290.  } else {
  291.    puts $sock "GET /status.xsl?mount=/latam.ogg HTTP/1.1"
  292.    puts $sock "User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:0.9.9)"
  293.    puts $sock "Host: $streamip"
  294.    puts $sock "Connection: close"
  295.    puts $sock ""
  296.    flush $sock
  297.    while {![eof $sock]} { append pagedata "[read $sock]" }
  298.  }
  299.  if {[string match *streamdata* $pagedata] == 1} {
  300.    set streamstatus "1"
  301.    set songlocation [string first "Current Song:" $pagedata]
  302.    set songdata1 [string range $pagedata $songlocation 99999]
  303.    set location2 [string first "</tr>" $songdata1]
  304.    set songdata2 [string range $songdata1 0 $location2]
  305.    set songdata3 [string range $songdata2 42 9999]
  306.    set location3 [string first "</td>" $songdata3]
  307.    set location3 [expr $location3 - 1]
  308.    set newsong [string range $songdata3 0 $location3]
  309.  
  310.    set llocation [string first "Listeners:" $pagedata]
  311.    set countdata1 [string range $pagedata $llocation 99999]
  312.    set llocation2 [string first "</tr>" $countdata1]
  313.    set countdata2 [string range $countdata1 0 $llocation2]
  314.    set countdata3 [string range $countdata2 39 9999]
  315.    set llocation3 [string first "</td>" $countdata3]
  316.    set llocation3 [expr $llocation3 - 1]
  317.    set newlistener [string range $countdata3 0 $llocation3]
  318.    close $sock
  319.    return 1
  320.    
  321.  } else {
  322.    set streamstatus "0"
  323.    close $sock
  324.    return 0
  325.  }
  326. }
  327.  
  328. # %status function. Diplays the current status of the stream.
  329. proc status {nick uhost hand chan arg} {
  330.  global dj radiochan newsong newlistener streamstatus streamurl streamname
  331.  if {$streamstatus == 1} {
  332.    if {$newsong != "" &&  $dj == "$nick" && $arg != ""} {putserv "notice $arg :La cancion actual es |$newsong| @ $streamurl"}
  333.    if {$newsong != "" &&  $dj != "$nick"} {
  334.      putserv "noticia $nick :La cancion actual es |$newsong| @ $streamurl"
  335.    }
  336.  } else {putserv "noticia $nick :$streamname esta fuera de linea."
  337.    }
  338. }
  339.  
  340. # /msg %botnick listeners: displays how many current listeners there are.
  341. proc listenercheck {nick uhost hand arg} {
  342.  global newlistener radiochan streamstatus streamname
  343.  if {$streamstatus == "1"} {
  344.    if {$newlistener == "0"} {
  345.      putserv "noticia $nick :No hay ningun escucha para $streamname :(."
  346.    } elseif {$newlistener =="1"} {
  347.      putserv "noticia $nick :hay 1 escucha en $streamname."
  348.    } else {
  349.      putserv "noticia $nick :Hay $newlistener escuchas en $streamname."
  350.    }
  351.  } else {
  352.    putserv "noticia $nick :$streamname no esta al-aire."
  353.  }
  354. }
  355.  
  356. # %request: sends a message to dj about the request that was made.
  357. proc request {nick uhost hand chan arg} {
  358.  global dj
  359.  if {$dj != ""} {
  360.    if {$arg == ""} {putserv "noticia $nick :No puedes solitar ninguna!"
  361.    return 0
  362.    } else {
  363.      putserv "privmsg $dj :REQUEST($nick) => $arg"
  364.      putserv "noticia $nick :Su peticion fue enviada a $dj. Muchas Gracias."
  365.      return 0
  366.      }
  367.  } else {
  368.    putserv "noticia $nick :No Hay ningun Dj en linea para aceptar peticiones."
  369.    return 0
  370.  }
  371. }
  372.  
  373. # /msg $botnick request X: sends a message to dj about the request that was made.
  374. proc request_pm {nick uhost hand arg} {
  375.  global dj
  376.  if {$dj != ""} {
  377.    if {$arg == ""} {putserv "noticia $nick :No puedes solicitar ninguna!!"
  378.    return 0
  379.    } else {
  380.      putserv "privmsg $dj :REQUEST($nick) => $arg"
  381.      putserv "noticia $nick :Su peticion fue enviada a $dj. Muchas Gracias."
  382.      return 0
  383.      }
  384.  } else {
  385.    putserv "noticia $nick :No Hay ningun Dj en linea para aceptar peticiones."
  386.    return 0
  387.  }
  388. }
  389.  
  390. # /msg $botnick djon [password]: Turns DJ on for user
  391. proc dj_on {nick uhost hand arg} {
  392.  global dj radiochan
  393.  if {$dj == ""} {
  394.    if {$arg == ""} {putserv "privmsg $nick :Necesita escribir su contraseña"
  395.      return 0
  396.    } else {
  397. # This is a Test DJ Entry. the $arg here is the password.
  398. # You can have as many of these as you want, just paste
  399. # them directly under one another, within the else { }.
  400. #      if {$arg == "Test"} {
  401. #        set dj "$nick"
  402. #        putserv "PRIVMSG $nick :You are logged in as $dj."
  403. #        putserv "PRIVMSG $radiochan :$dj is now rocking the turntables and accepting requests via %request, enjoy."
  404. #        return 0
  405. #      }
  406.    }
  407.  }
  408.  if {$dj != ""} {
  409.    putsrv "noticia $nick :$dj ya esta activo. &dj necesita desloguearse antes de logearse."
  410.    return 0
  411.  }
  412. }
  413.  
  414. # %djoff: Turns DJ off for user
  415. proc dj_off {nick uhost hand chan arg} {
  416.  global dj radiochan
  417.  if {$dj != $nick} {
  418.    putserv "noticia $nick :No eres el DJ actual o debes cambiar el nick para ser uno."
  419.  } else {
  420.    putserv "PRIVMSG $radiochan :$dj se deslogueo y no acepta peticiones."
  421.    set dj ""
  422.    putserv "noticia $nick :Su DJ'ness esta desactivado"
  423.  }
  424. }
  425.  
  426. # /msg $botnick djoff: Turns DJ off for user
  427. proc dj_off_pm {nick uhost hand arg} {
  428.  global dj radiochan
  429.  if {$dj != $nick} {
  430.    putserv "noticia $nick :No eres el DJ actual o debes cambiar el nick para ser uno."
  431.  } else {
  432.    putserv "PRIVMSG $radiochan :$dj se deslogueo y no acepta peticiones."
  433.    set dj ""
  434.    putserv "noticia $nick :Su DJ'ness esta desactivado"
  435.  }
  436. }
  437.  
  438. # !version: displays the current version of the Ice2.tcl script.
  439. proc iceversion {nick host hand chan arg} {
  440.   global ice2version radiochan botnick
  441.   if {$chan == $radiochan} {
  442.     putserv "noticia $nick :Soy $botnick arrancando Ice2.tcl Version $ice2version Por Tido, Henkes, y Sircrazy."
  443.   }
  444. }
  445.  
  446. putlog "Ice2 Version $ice2version Por Tido, Henkes, y Sircrazy esta cargando :)"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement