1. Hey Guest, are you looking for a place to host your IRC related project? Then check out the Resource Manager on IRCForums! Click the resources tab above this notice!
  2. Hello Guest, are you new to IRCForums? Why not introduce yourself in the introduction forum!
  3. We have updated the layout of our forums. Please see this thread for more information.

[msl] SHOUTCast Bot v.13

Discussion in 'Script Gallery (Depreciated)' started by Orihime, Jan 12, 2012.

  1. Offline

    Orihime Recruit

    Member Since:
    Dec 30, 2011
    Message Count:
    68
    Likes Received:
    5
    Trophy Points:
    16
    THIS IS NOT MY SCRIPT/CODE! I AM ONLY POSTING IT FOR EDUCATIONAL PURPOSES

    Find it at http://www.hawkee.com/snippet/8647/

    This script allows for a simple SHOUTcast stream management bot to reside in your channel, while announcing current playing songs.

    Configure:
    Set the variables under the "Configuration" section, then restart mIRC and the bot will do the rest. :)

    It includes:
    * Auto announce (for songs on the shoutcast stream)
    * Manage topic (changes topic when DJ changes)
    * Auto connect / identify (Anope; nickserv)

    Commands (that require the user to have @op to use):
    !kickdj - kicks active dj
    !info - messages user stream information (eg: url, port, dj pass, etc)
    !cycle - bot does a /hop

    Commands (anyone can use):
    !dj - messages user current DJ
    !song - messages user current song
    !tune/!url/!listen - messages user the link to the stream
    !listeners - messages the user with current listener amount


    Code (mirc):
    ; This code is released under the public domain.
     
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    ;;                ;;
    ;;  CONFIGURATION  ;;
    ;;                ;;
    ;;;;;;;;;;;;;;;;;;;;;
     
    alias sc_cfg {
     
      ; website URL
      set %stream.site http://google.com
     
      ; stream url (without http:// or trailing slash)
      set %stream.url listen.google.com
     
      ; radio stations name
      set %stream.name Google's Online Radio
     
      ; port that the server runs on
      set %stream.port 8000
     
      ; admin username (usually admin)
      set %stream.user admin
     
      ; admin password
      set %stream.adpass QW#h34h4sdfGHES
     
      ; dj password
      set %stream.djpass poiuytrewq
     
      ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
     
      ; manage topic (1 is on, 0 is off)
      set %cfg.top 1
     
      ; announce new song (1 is on, 0 is off)
      set %cfg.ann 1
     
      ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
     
      ; bots nick
      set %irc.nick Google
     
      ; bots alt nick
      set %irc.anick Google_
     
      ; bots username
      set %irc.user Google
     
      ; bots realname
      set %irc.name Google IRC Bot
     
      ; irc server
      set %irc.server irc.google.com
     
      ; irc port (prepend + for SSL servers)
      set %irc.port +7000
     
      ; irc channel
      set %irc.chan #radio
     
      ; NickServ password
      set %irc.pass q3w24yh%W$%Ty#Q$GF#5rGHERhsef
    }
     
    ; channel topic format
    alias sc.topic { return %stream.name $chr(124) Current DJ: $iif(%sc.status == 1,%sc.dj,None) $chr(124) %stream.site }
     
    ; song announce format
    alias sc.ann { return %sc.dj is playing %sc.song }
     
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    ;;                ;;
    ;;  ON FUNCTIONS  ;;
    ;;                ;;
    ;;;;;;;;;;;;;;;;;;;;
     
    on *:start: {
     
      ; set variables
      sc_cfg
     
      ; connect to server
      server %irc.server %irc.port -i %irc.nick %irc.anick %irc.user %irc.name
     
    }
     
    on *:notice:*This nickname is registered and protected.*:*: { .msg NickServ IDENTIFY %irc.pass }
     
    on *:notice:*Password accepted - you are now recognized.*:*: { .join %irc.chan }
     
    on *:join:%irc.chan: { $iif($nick == $me, .timercon 0 10 sc_con) }
     
    on *:disconnect: { .timers off }
     
    on *:kick:%irc.chan: { $iif($knick == $me, timers off) }
     
    on *:part:%irc.chan: { $iif($nick == $me, timers off) }
     
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    ;;              ;;
    ;;  SC COMMANDS  ;;
    ;;              ;;
    ;;;;;;;;;;;;;;;;;;;
     
    ; connect to shoutcast server
    alias sc_con {
      if ($sock(sc).to == $null) { sockopen sc %stream.url %stream.port  }
      elseif ($sock(sc).to > 8) { sockclose sc | sockopen sc %stream.url %stream.port }
    }
     
    ; kick dj
    alias sc_kick { sockopen sckick %stream.url %stream.port }
     
    ; topic change
    alias sc_topic { if (%cfg.top == 1) { topic %irc.chan $sc.topic } }
     
    ; song announce
    alias sc_msg { if (%cfg.ann == 1) { msg %irc.chan $sc.ann } }
     
    ; send error message to user
    alias sc_errmsg {
      if ($1 == op) { msg $2 You must have @ (operator) status to use this. }
      if ($1 == offline) { msg $2 The stream is currently offline. }
    }
     
    ; filters characters back from html ascii codes
    alias sc_filter { return $replace($1-, &#x26 $+ $chr(59), $chr(38), &#x27 $+ $chr(59), $chr(39)) }
     
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    ;;                ;;
    ;;  @OP TRIGGERS  ;;
    ;;                ;;
    ;;;;;;;;;;;;;;;;;;;;
     
    ; !cycle: bot /cycles in channel
    on *:text:!cycle:%irc.chan: {
      if ($nick isop %irc.chan) { hop %irc.chan }
      else { sc_errmsg op $nick }
    }
     
    ; !info: sends the required dj information
    on *:text:!info:%irc.chan: {
      if ($nick isop %irc.chan) {
        msg $nick host: %stream.url port: %stream.port pass: %stream.djpass
        msg $nick description: %stream.name url: %stream.site aim: Use your DJ name irc: %irc.chan
      }
      else { sc_errmsg op $nick }
    }
     
    ; !kickdj: kicks current dj
    on *:text:!kickdj:%irc.chan: {
      if ($nick isop %irc.chan) { sc_kick | msg %irc.chan Kicking current DJ.. }
      else { sc_errmsg op $nick }
    }
     
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    ;;                ;;
    ;;  USER TRIGGERS  ;;
    ;;                ;;
    ;;;;;;;;;;;;;;;;;;;;;
     
    ; !dj: sends active dj
    on *:text:!dj:%irc.chan: {
      if (%sc.status == 1) { msg $nick Current DJ: %sc.dj }
      else { sc_errmsg offline $nick }
    }
     
    ; !song: sends the current song
    on *:text:!song:%irc.chan: {
      if (%sc.status == 1) { msg $nick Playing: %sc.song }
      else { sc_errmsg offline $nick }
    }
     
    on *:text:!listeners:%irc.chan: {
      if (%sc.status == 1) { msg $nick Listeners: %sc.clisten $+ / $+ %sc.mlisten ( $+ %sc.dj $+ ) }
      else { errmsg offline $nick }
    }
     
    on *:text:!tune:%irc.chan: { msg $nick Tune in at: http:// $+ %stream.url $+ : $+ %stream.port $+ /listen.pls }
    on *:text:!url:%irc.chan: { msg $nick Tune in at: http:// $+ %stream.url $+ : $+ %stream.port $+ /listen.pls }
    on *:text:!listen:%irc.chan: { msg $nick Tune in at: http:// $+ %stream.url $+ : $+ %stream.port $+ /listen.pls }
     
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    ;;                ;;
    ;;  KICK SOCKETS  ;;
    ;;                ;;
    ;;;;;;;;;;;;;;;;;;;;
     
    on *:sockopen:sckick: {
      sockwrite -nt sckick GET /admin.cgi?mode=kicksrc HTTP/1.0
      sockwrite -nt sckick User-Agent: Mozilla/5.0
      sockwrite -nt sckick Accept: text/xml,application/xml,application/xhtml+xml,text/html
      sockwrite -nt sckick Authorization: Basic $encode(%stream.user $+ : $+ %stream.adpass, m)
      sockwrite -nt sckick $crlf
    }
     
    on *:sockread:sckick: {
      sockread -fn %tmp
      if (HTTP/1.0 302 Found isin %tmp) { msg %irc.chan ..DJ was successfully kicked. }
    }
     
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    ;;              ;;
    ;;  XML SOCKETS  ;;
    ;;              ;;
    ;;;;;;;;;;;;;;;;;;;
     
    on *:sockopen:sc: {
      sockwrite -nt sc GET /admin.cgi?mode=viewxml HTTP/1.0
      sockwrite -nt sc User-Agent: Mozilla/5.0
      sockwrite -nt sc Accept: text/xml,application/xml,application/xhtml+xml,text/html
      sockwrite -nt sc Authorization: Basic $encode(%stream.user $+ : $+ %stream.adpass, m)
      sockwrite -nt sc $crlf
    }
     
    on *:sockread:sc: {
      sockread -fn %xml
     
      ; assign variable in proper order, halt reading, scan info, relay, garbage collection!
      if (<?xml isin %xml) { set %a $mid(%xml,2033,$len(%xml)) }
      elseif (> isin %xml) { set %a %a $+ %xml }
     
      if (</SHOUTCASTSERVER> isin %a) {
     
        HALTDEF
        unset %xml
     
        ; dj
        var %z $sc_filter($left($gettok($replace(%a, <AIM>, $chr(189), </AIM>, $chr(189)),2,189),$len($gettok($replace(%a, <AIM>, $chr(189), </AIM>, $chr(189)),2,189))))
        if (%z != %sc.dj) && (%sc.dj) { set %sc.dj %z | sc_topic }
        else { set %sc.dj %z }
     
        ; status
        var %z $gettok($replace(%a, <STREAMSTATUS>, $chr(189), </STREAMSTATUS>, $chr(189)),2,189)
        if (%z != %sc.status) && (%sc.status) { set %sc.status %z | sc_topic }
        else { set %sc.status %z }
     
        ; current listeners
        var %z $gettok($replace(%a, <CURRENTLISTENERS>, $chr(189), </CURRENTLISTENERS>, $chr(189)),2,189)
        set %sc.clisten %z
     
        ; peak listeners
        var %z $gettok($replace(%a, <PEAKLISTENERS>, $chr(189), </PEAKLISTENERS>, $chr(189)),2,189)
        set %sc.plisten %z
     
        ; max listeners
        var %z $gettok($replace(%a, <MAXLISTENERS>, $chr(189), </MAXLISTENERS>, $chr(189)),2,189)
        set %sc.mlisten %z
     
        ; genre
        var %z $gettok($replace(%a, <SERVERGENRE>, $chr(189), </SERVERGENRE>, $chr(189)),2,189)
        set %sc.genre %z
     
        ; song title
        var %z $sc_filter($left($gettok($replace(%a, <SONGTITLE>, $chr(189), </SONGTITLE>, $chr(189)),2,189),$len($gettok($replace(%a, <SONGTITLE>, $chr(189), </SONGTITLE>, $chr(189)),2,189))))
        if (%z != %sc.song) { set %sc.song %z | sc_msg }
     
        unset %a
      }
    }
    Rix likes this.
  2. Offline

    Bully MyOwnGroup

    Member Since:
    Dec 17, 2011
    Message Count:
    247
    Likes Received:
    38
    Trophy Points:
    36
    This is interesting and i might need it the "future" ;) Thanks!
  3. Offline

    Napa182 Moderator

    Member Since:
    Dec 18, 2011
    Message Count:
    222
    Likes Received:
    83
    Trophy Points:
    56
    odd that you post other peoples work instead of your own... anyways this snippet could be updated an made more efficient. Thanks for sharing.
  4. Offline

    D3M0N Corporal

    Member Since:
    Jan 10, 2012
    Message Count:
    694
    Likes Received:
    63
    Trophy Points:
    103
    Wow... the exact script i have! Found this one on hawkee ages ago though... This one seems to have just a few more features...
  5. Offline

    Orihime Recruit

    Member Since:
    Dec 30, 2011
    Message Count:
    68
    Likes Received:
    5
    Trophy Points:
    16
    Why would I post my own work? lol..
    Medusa likes this.
  6. Offline

    Napa182 Moderator

    Member Since:
    Dec 18, 2011
    Message Count:
    222
    Likes Received:
    83
    Trophy Points:
    56
    Why not?

Share This Page