mIRC Homepage
Posted By: CeraVea mIRC ShoutCast Radio Script, Help! - 19/07/22 12:45 AM
I'd like to see if anyone can help me get this mIRC script for the radio bot going...
I found this somewhere, I couldn't remember where exactly, forgive me. I tried to paste it on my remotes and edited it with our channel's radio stream SHOUTcast settings but I can't get it to work. I am also getting line /sockwrite: 'sc' not connected (line 253, radio.mrc)

Code
; This script allows for a simple SHOUTcast stream management bot to reside in your channel while announcing current
; playing songs. 
; Sourced this somewhere I couldn't remember anymore where but line 253 is getting an error 
; Script seems to no longer be working but perhaps can be worked out...
===============================
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 (anyone can use):
!DJ - messages user current DJ
!song - messages user current song
!tune/!URL/!listen - messages using the link to the stream
!listeners - messages the user with the current listener amount
=================================

This code is released under the public domain.

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;                 ;; 
;;  CONFIGURATION  ;;
;;                 ;;
;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

alias sc_cfg {

  ; website URL
  set %stream.site STREAM_SITE_HERE

  ; stream url (without http:// or trailing slash)
  set %stream.url STREAM_URL_HERE

  ; radio stations name
  set %stream.name RADIO_NAME

  ; port that the server runs on
  set %stream.port 0000

  ; admin username (usually admin)
  set %stream.user admin

  ; admin password
  set %stream.adpass STREAM_ADMIN_PASSWORD

  ; dj password
  set %stream.djpass DJ_PASSWORD

  ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

  ; 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 BOT_NICK

  ; bots alt nick
  set %irc.anick BOT_NICK1`

  ; bots username
  set %irc.user BOT_USERNAME

  ; bots realname
  set %irc.name BOT_REAL_NAME_HERE

  ; irc server
  set %irc.server IRC.SERVER.HERE

  ; irc port (prepend + for SSL servers)
  set %irc.port 6667

  ; irc channel
  set %irc.chan #RADIO_CHANNEL

  ; NickServ password
  set %irc.pass _none_
}

; 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   ;I GET AN ERROR ON THIS LINE
  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
  }
}




thank you!!
Posted By: Trinity Re: mIRC ShoutCast Radio Script, Help! - 21/07/22 04:12 AM
I have seen that script and it looks old. Don't quote me, but I think it's that old it is trying to connect to the old Shoutcast V1 server.
Drawing data from an XML will give you lag, and the current song will most likely be posted in the chat room when the song is finished.
The script is signing in to so much information, no wonder it's giving you problems.
I will post a simple radio bot here shortly that I use through my network of radio stations. Just have to tidy it up for you to edit.
Cheers
Posted By: CeraVea Re: mIRC ShoutCast Radio Script, Help! - 21/07/22 12:36 PM
Thank you so much!
Posted By: Trinity Re: mIRC ShoutCast Radio Script, Help! - 22/07/22 12:50 AM
Ok, this bot does not need to connect as admin. It simply reads the index page of the server and is fast.
The triggers it can do, you can edit or keep up to you. It will also whisper the current DJ requests, so not lost in chat.
This is not my coding, but edited by me to suite my needs.
Almost Every thing in CAPS needs editing for your station, you can work it out, I'm sure.
Don't forget to set channel in channel menu.
Code
menu channel {
  Radio Test
  .Set Channel: { set %radiotest.room # | echo -a Radio set to # }
  .$iif($timer(.radiotest),$style(2)) Turn On: { radiotest | .timer.radiotest 0 10 radiotest | echo -a radiotest msg on }
  .$iif(!$timer(.radiotest),$style(2)) Turn Off: { unset %radiotest.song | unset %radiotest.lastsong | .timer.radiotest off | echo  -a radiotest msg off }
}
alias radiotest { sockclose radiotest | sockopen radiotest SHOUTCASTIP PORT }
on *:sockopen:radiotest: {
  sockwrite -n $sockname GET /7.html HTTP/1.0
  sockwrite -n $sockname User-Agent: SHOUTcast Song Status (Mozilla Compatible)
  sockwrite -n $sockname Host: $+(SHOUTCASTIP,:,PORT)
  sockwrite -n $sockname $crlf
}
on *:sockread:radiotest: {
  if ($sockerr > 0) return
  var %radiotest | sockread -fn %radiotest
  if ($regex(%radiotest,/<body>(.*)<\/body>/)) {
    set %radiotest.song $html2ascii( $gettok($regml(1),7-,44) )
    if (%radiotest.song != %radiotest.lastsong) {

      msg %radiotest.room 12 DJ 4 %dj 12 : %radiotest.song 
      set %radiotest.lastsong %radiotest.song
    }
  }
}
on *:connect:#: { radiotest | .timer.radiotest 0 10 radiotest | echo -a radiotest msg on }

on 1:text:*!dj *:*:{
  set %dj $2
  msg # 4 ;dj DJ %dj 12Is now Rockin STATION Radio(8) ^^:
  if ( %dj == BOTNAME ) {
   
    halt
  }
  else{
  .whisper $chan %dj 0,1---7>11 You Are Now The DJ (4ON AIR11)7<0---
 }
on 1:text:*!radio:*:{
  if ( %status == up ) {
    .msg $chan 4 Our home page STATION URL
  }
} 
on 1:text:*!tune:#:{
  .msg $chan (8) 5 %radiotest.song ~mu 2 Top Song ;dr ~rc :ro  
}
on 1:text:*!FB:*:{
  if ( %status == up ) {
    .msg $chan 4 Our Facebook page FACEBOOK URL
  }
} 

on 1:text:*!ftune:#:{
  .msg $chan (8) 5 %radiotest.song ~mu 2 One of my Fav Tunes!!!! ^^: ;rok ~rm
}
on 1:text:*!song:#:{
  .msg $chan 4 Playing (8) 5 %radiotest.song (*) 2 With DJ %dj 
}
on 1:text:*!request*:#:{
  if ( %dj == BOTNAME ) {
  .msg # 4 Sorry $nick No Dj's are available Right now! }
  else {
    .msg # 4Thank you $nick ;dj DJ 12 %dj 4Got your Request! 
    .whisper $chan %dj Special Request $nick Asked For ( $+ $2- $+ )
  }
}


Now load this alias to tidy up Variables.
Code
alias html2ascii return $regsubex($1-,/&(.{2,6});/Ug,$ht2chr(\t))
alias -l ht2chr if (#x* iswm $1) return $chr($base($mid($1, 3), 16, 10)) | elseif (#* iswm $1) return $chr($mid($1, 2)) | else return $ht2as($1)
alias -l ht2as {
  var %A quot amp apos lt gt nbsp iexcl cent pound curren yen brvbar sect uml copy ordf laquo not shy reg macr deg plusmn sup2 sup3 acute micro para middot cedil sup1 ordm raquo frac14 frac12 frac34 iquest Agrave Aacute Acirc Atilde Auml Aring AElig Ccedil Egrave Eacute Ecirc Euml Igrave Iacute Icirc Iuml ETH Ntilde Ograve Oacute Ocirc Otilde Ouml times Oslash Ugrave Uacute $&
    Ucirc Uuml Yacute THORN szlig agrave aacute acirc atilde auml aring aelig ccedil egrave eacute ecirc euml igrave iacute icirc iuml eth ntilde ograve oacute ocirc otilde ouml divide oslash ugrave uacute ucirc uuml yacute thorn yuml,%B 34 38 39 60 62 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 $&
    192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255
  return $chr($gettok(%B,$findtokcs(%A,$1,32),32))
}

Any problems, let me know.
Cheers
Posted By: Trinity Re: mIRC ShoutCast Radio Script, Help! - 22/07/22 08:30 AM
Sorry, If you run an Icecast server this code won't work.
Honestly, why would to run Icecast?
Up for debate..
Posted By: CeraVea Re: mIRC ShoutCast Radio Script, Help! - 25/07/22 03:54 AM
Thanks my friend it seems to work for me, but I do have a couple of questions.

- There were several instances that my radio bot will display only the name of the dj with : and nothing else. Not sure why is that.
- How I can make that the !dj set command can only be performed by whoever's going to dj? Seems like anyone can set it,even a regular nick can.
- I also couldn't tell what the !tune and !ftune does?
- Typing !song displays "Playing (8) (*) With DJ (name of the DJ)

Otherwise, the script is nice.
Posted By: Trinity Re: mIRC ShoutCast Radio Script, Help! - 25/07/22 08:46 PM
The bot will only display what is on your Shoutcast server page. So if no metadata is sent to your server or your tags are wrong, that will happen.

I have never had any issues with chatters playing with that trigger. There are a number of ways to fix that by giving people privileges to your Bot.
On admin text or op text.

!tune and !ftune. It's just a trigger for chatters if they like the tune that's being played.

Typing !song displays "Playing (8) (*) . Those chars are just emotes for web chat, you can take them out.
Posted By: CeraVea Re: mIRC ShoutCast Radio Script, Help! - 05/09/22 02:32 PM
Do you know how to set up just played, or you happen to have that in your script? I kinda like to add that but when I was trying to write one, it doesn't work LOL.
© mIRC Discussion Forums