egghelp.org community Forum Index
[ egghelp.org home | forum home ]
egghelp.org community
Discussion of eggdrop bots, shell accounts and tcl scripts.
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Request songs limit to 2 songs per person

 
Post new topic   Reply to topic    egghelp.org community Forum Index -> Script Support & Releases
View previous topic :: View next topic  
Author Message
mabrook
Halfop


Joined: 14 Jun 2021
Posts: 55

PostPosted: Wed Jun 23, 2021 1:53 pm    Post subject: Request songs limit to 2 songs per person Reply with quote

Hi all,

hope you can help..

Code:
#Tido's Modified Icecast2 Script
#Heavily Modified by Sircrazy
#Version 1.01
#July 12, 2010
######################################################################
#This program is free software; you can redistribute it and/or modify
#it under the terms of the GNU General Public License as published by
#the Free Software Foundation; version 2 of the License.
#
#This program is distributed in the hope that it will be useful,
#but WITHOUT ANY WARRANTY; without even the implied warranty of
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#GNU General Public License for more details.
######################################################################
#Credits:
#Influenced by Domsen's shoutcast1.03.tcl
#Special thanks to the TCL MAN files :D
#Special Release updated by Sircrazy
######################################################################
#Change these varibles to the one for your stream/bot/channel

#Name of Radio Station
set streamname "EDIT THIS"

#IP of the Icecast server.
set streamip "MAKE SURE IT IS THE IP"

#Port that Icecast is using, default is 8000.
set streamport "EDIT THIS"

#Main channel for the radio bot.
set radiochan "#EDIT THIS"

#Other channel that the bot can advertise to. Bot must be in this channel for this to work. Ice2.tcl only
# sends stream advertisements to this channel and does not send song info.
set otherchan "EDIT THIS OR REMOVE THIS TEXT"

#URL/Link to the stream for listening. This is what listeners need to click to tune in.
set streamurl "http://ssh.shellium.org/~sircrazy/sircrazy.m3u"

#How often the bot checks the stream when it knows it is down in minutes. Recommend 1 minute.
set offlinetimer "1"

#How often the bot checks the stream when it knows it is online in seconds. Recommend 15 seconds.
set onlinetimer "15"

#Default interval for how often the bot advertises (in minutes). You want to set it to something that isn't
# pure spammage.
set adtimer "30"

#Enables advertising set to the above frequency. 1 for ON and 0 for OFF. This reminds people that the stream
# is online.
set enableadvertise "1"

#Enables Special Announcement, 1 for ON and 0 for OFF. Special announcements are displayed every 720 minutes.
# This feature of the script is very undeveloped and I don't recommend using it.
set specialannounce "0"

#Special Announcement Message
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"

###########################################################################
#  Don't edit past this stuff unless you're Tido, Henkes, or Sircrazy :P  #
#       Except Line 387 where you need to add DJs and Line 281 where      #
#                    you need to put your mount point.                    #
###########################################################################


# Binds
bind pub - "%commands" showcommands
#Shows a list of all commands

bind pub - "%help" showcommands
#same as %commands

bind pub - "%status" status
#Displays the status of the stream

bind pub - "%listeners" listenercheck
#Reports how many listeners there are

bind pub - "%request" request
#Allows users to request songs

bind msg - "request" request_pm
#Allows users to make requests via pm

bind msg - "djon" dj_on
#turns on dj status

bind pub - "%djoff" dj_off
#turns off dj status

bind msg - "djoff" dj_off_pm
#turns off dj status

bind pub - "%fadvert" forceadvertise
#Forces an advertising message to be sent

bind pub - "%version" iceversion
#Displays the Ice2.tcl version

# Varible Resets
set ice2version "1.01 - 07.12.10"
set streamstatus "0"
set djnickname ""
set dj ""
set oldsong ""
set newsong ""
set newlistener ""
set oldlistener "0"
set forceadsent "0"
set sessionpeak "0"

# Check to make sure StatusCheck timer isn't running when bot rehashes.
if {![info exists statuscheck_running]} {
  timer $offlinetimer [list statuscheck]
  set statuscheck_running 1
}

# Check to make sure Special Announce timer isn't running when bot rehashes.
if {![info exists specialannounce_running]} {
  if {$specialannounce == "1"} {
    timer 720 [list specialmessage]
    set specialannounce_running 1
  }
}


# Check to make sure Advertise timer isn't running when bot rehashes.
if {![info exists adtimer_running]} {
  if {$enableadvertise == "1"} {
    timer $adtimer [list advertise]
    set adtimer_running 1
  }
}

# Output for %help or %commands
proc showcommands {nick uhost hand chan arg} {
  global ice2version streamname botnick dj
  if {$dj == "$nick" && $arg != ""} {
    putserv "notice $arg :>>> $botnick Commands - $ice2version<<<"
    putserv "notice $arg :%status >>> Displays the stream's status. If online it shows the song."
    putserv "notice $arg :%request (artist+track) >>> Sends a Request for a future song."
    putserv "notice $arg :/msg $botnick request (artist+track) >>> Sends a Request for a future song by PM."
  }
  if {$dj != "$nick"} {
    set arg ""
    putserv "notice $nick :>>> $botnick Commands - $ice2version<<<"
    putserv "notice $nick :%status >>> Displays the stream's status. If online it shows the song."
    putserv "notice $nick :%request (artist+track) >>> Sends a Request for a future song."
    putserv "notice $nick :/msg $botnick request (artist+track) >>> Sends a Request for a future song by PM."
  }
}

# Turns on and off Advertising. Also lets you set the interval: !advertise X
proc toggle_advertise {nick uhost hand chan arg} {
  global radiochan enableadvertise adtimer
  if {$enableadvertise == "1"} {
    set enableadvertise "0"
    set timerinfo [gettimerid]
    killtimer $timerinfo
    putserv "PRIVMSG $chan :Advertising OFF"
  } else {
    set enableadvertise "1"
    if {$arg == ""} {
      putserv "PRIVMSG $chan :Advertising ON. Frequency set to $adtimer minutes."
    } else {
      set adtimer $arg
      putserv "privmsg $chan :Advertising ON. Frequency changed to $adtimer minutes."
      timer $adtimer [list advertise]
    }
  }
}

# Function that finds out the ID of the advertising timer.
proc gettimerid {} {
    set adtimerinfo [timers]
    set loc1 [string first "advertise" $adtimerinfo]
    set loc1 [expr $loc1 + 10]
    set str1 [string range $adtimerinfo $loc1 999]
    set endloc [string first "\}" $str1]
    set endloc [expr $endloc -1]
    set timerinfo [string range $str1 0 $endloc]
    return $timerinfo
}

# Messages that are displayed when Advertising is enabled.
proc advertise {} {
  global radiochan streamstatus otherchan enableadvertise adtimer forceadsent streamurl streamname
  if {$streamstatus != "0" && $enableadvertise == "1"} {
    putserv "PRIVMSG $radiochan :$streamname is currently broadcasting live! Listen in @ $streamurl"
    putserv "PRIVMSG $otherchan :$streamname is currently broadcasting live! Listen in @ $streamurl"
    if {$forceadsent == "0"} {timer $adtimer [list advertise]} else {set forceadsent "0"}
    return 1
  }
  return 0
}

# Forces the advertising messages to appear
proc forceadvertise {nick uhost hand chan arg} {
  global streamstatus enableadvertise forceadsent
  if {$streamstatus == "0"} {
    putserv "notice $nick :The stream isn't on-air. Unable to advertise."
    return 0
  } else {
    if {$enableadvertise == "0"} {
      putserv "notice $nick :Advertising isn't enabled."
      return 0
    } else {
      set forceadsent "1"
      set forceadvertised [advertise]
      if {$forceadvertised == "1"} {
        putserv "notice $nick :Done!"
      } else {
        putserv "notice $nick :Advertising message was not sent!"
      }
    }
  }
}

# Special Announcement Message.
proc specialmessage {} {
  global radiochan specialannounce announcemsg
  putserv "PRIVMSG $radiochan : $announcemsg"
  timer 720 [list specialmessage]
  return 0
}

# StatusCheck
# Function that takes the information from Icecast_Online and creates the proper responses.
proc statuscheck {} {
  global radiochan streamstatus newsong oldsong newlistener oldlistener sessionpeak dj enableadvertise otherchan onlinetimer offlinetimer streamurl streamname

  if {$streamstatus == "0"} {
    set oldstatus "0"
  } else {
    set oldstatus "1"
  }
  set newstatus "[icecast_online]"
  if {$newstatus =="0" && $oldstatus == "0"} {
    timer $offlinetimer [list statuscheck]
  }
  if {$newstatus == "1" && $oldstatus == "0"} {
    putserv "PRIVMSG $radiochan :$streamname is now ON-AIR!! Click to listen: $streamurl"
    putlog "(RADIO) On-Air detected."
    utimer $onlinetimer [list statuscheck]
    if {$enableadvertise == "1"} {
      putserv "PRIVMSG $otherchan :$streamname is now ON-AIR!! Click to listen: $streamurl"

    }
  }
  if {$newstatus == "0" && $oldstatus == "1"} {
    putserv "PRIVMSG $radiochan :$streamname is now off-air."
    set oldlistener "0"
    set sessionpeak "0"
    if {$enableadvertise == "1"} {
      putserv "PRIVMSG $otherchan :$streamname is now off-air."
    }
    putlog "(RADIO) Off-Air detected."
    timer $offlinetimer [list statuscheck]
  }
  if {$newstatus == "1" && $oldstatus == "1"} {
    utimer $onlinetimer [list statuscheck]
    if {$newsong != $oldsong && $newsong != ">inbetween" && $newsong != ">inbetween1" && $newsong != ">inbetween2" && $newsong != ">whatutalkinbout" && $newsong != ">tmsradio80sintro"} {
      putserv "PRIVMSG $radiochan :Now playing on $streamname: $newsong @ $streamurl"
      set oldsong "$newsong"
    }
  }
}
 
# Icecast_Online
# This is the HTTP Parser that gathers the various data from the status.xsl file.
proc icecast_online { } {
  global streamip streamport streamstatus newsong newlistener
  set pagedata ""
  if {[catch {set sock [socket $streamip $streamport] } sockerror]} {
    putlog "error: $sockerror"
    return 0
  } else {
    puts $sock "GET /status.xsl?mount=/sircrazy HTTP/1.1"
    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]} { append pagedata "[read $sock]" }
  }
  if {[string match *streamdata* $pagedata] == 1} {
    set streamstatus "1"
    set songlocation [string first "Current Song:" $pagedata]
    set songdata1 [string range $pagedata $songlocation 99999]
    set location2 [string first "</tr>" $songdata1]
    set songdata2 [string range $songdata1 0 $location2]
    set songdata3 [string range $songdata2 42 9999]
    set location3 [string first "</td>" $songdata3]
    set location3 [expr $location3 - 1]
    set newsong [string range $songdata3 0 $location3]

    set llocation [string first "Listeners:" $pagedata]
    set countdata1 [string range $pagedata $llocation 99999]
    set llocation2 [string first "</tr>" $countdata1]
    set countdata2 [string range $countdata1 0 $llocation2]
    set countdata3 [string range $countdata2 39 9999]
    set llocation3 [string first "</td>" $countdata3]
    set llocation3 [expr $llocation3 - 1]
    set newlistener [string range $countdata3 0 $llocation3]
    close $sock
    return 1
   
  } else {
    set streamstatus "0"
    close $sock
    return 0
  }
}

# %status function. Diplays the current status of the stream.
proc status {nick uhost hand chan arg} {
  global dj radiochan newsong newlistener streamstatus streamurl streamname
  if {$streamstatus == 1} {
    if {$newsong != "" &&  $dj == "$nick" && $arg != ""} {putserv "notice $arg :The current song is |$newsong| @ $streamurl"}
    if {$newsong != "" &&  $dj != "$nick"} {
      putserv "notice $nick :The current song is |$newsong| @ $streamurl"
    }
  } else {putserv "notice $nick :$streamname is currently offline."
    }
}

# /msg %botnick listeners: displays how many current listeners there are.
proc listenercheck {nick uhost hand arg} {
  global newlistener radiochan streamstatus streamname
  if {$streamstatus == "1"} {
    if {$newlistener == "0"} {
      putserv "notice $nick :There aren't any listeners tuned into $streamname :(."
    } elseif {$newlistener =="1"} {
      putserv "notice $nick :There is 1 listener tuned into $streamname."
    } else {
      putserv "notice $nick :There are $newlistener listeners tuned into $streamname."
    }
  } else {
    putserv "notice $nick :$streamname isn't on-air."
  }
}

# %request: sends a message to dj about the request that was made.
proc request {nick uhost hand chan arg} {
  global dj
  if {$dj != ""} {
    if {$arg == ""} {putserv "notice $nick :You didn't request anything!"
    return 0
    } else {
      putserv "privmsg $dj :REQUEST($nick) => $arg"
      putserv "notice $nick :Your request was sent to $dj. Thank you!"
      return 0
      }
  } else {
    putserv "notice $nick :There is no DJ online taking requests."
    return 0
  }
}

# /msg $botnick request X: sends a message to dj about the request that was made.
proc request_pm {nick uhost hand arg} {
  global dj
  if {$dj != ""} {
    if {$arg == ""} {putserv "notice $nick :You didn't request anything!"
    return 0
    } else {
      putserv "privmsg $dj :REQUEST($nick) => $arg"
      putserv "notice $nick :Your request was sent to $dj. Thank you!"
      return 0
      }
  } else {
    putserv "notice $nick :There is no DJ online taking requests."
    return 0
  }
}

# /msg $botnick djon [password]: Turns DJ on for user
proc dj_on {nick uhost hand arg} {
  global dj radiochan
  if {$dj == ""} {
    if {$arg == ""} {putserv "privmsg $nick :You must enter your password"
      return 0
    } else {
# This is a Test DJ Entry. the $arg here is the password.
# You can have as many of these as you want, just paste
# them directly under one another, within the else { }.   
#      if {$arg == "Test"} {
#        set dj "$nick"
#        putserv "PRIVMSG $nick :You are logged in as $dj."
#        putserv "PRIVMSG $radiochan :$dj is now rocking the turntables and accepting requests via %request, enjoy."
#        return 0
#      }
    }
  }
  if {$dj != ""} {
    putsrv "notice $nick :$dj is already active. &dj needs to sign off before you can log in."
    return 0
  }
}

# %djoff: Turns DJ off for user
proc dj_off {nick uhost hand chan arg} {
  global dj radiochan
  if {$dj != $nick} {
    putserv "notice $nick :You are not the current DJ or you changed your nickname since becoming one."
  } else {
    putserv "PRIVMSG $radiochan :$dj is signing off and no longer accepting requests."
    set dj ""
    putserv "notice $nick :Your DJ'ness has been deactivated"
  }
}

# /msg $botnick djoff: Turns DJ off for user
proc dj_off_pm {nick uhost hand arg} {
  global dj radiochan
  if {$dj != $nick} {
    putserv "notice $nick :You are not the current DJ or you changed your nickname since becoming one."
  } else {
    putserv "PRIVMSG $radiochan :$dj is signing off and no longer accepting requests."
    set dj ""
    putserv "notice $nick :Your DJ'ness has been deactivated"
  }
}

# !version: displays the current version of the Ice2.tcl script.
proc iceversion {nick host hand chan arg} {
   global ice2version radiochan botnick
   if {$chan == $radiochan} {
     putserv "notice $nick :I am $botnick running Ice2.tcl Version $ice2version by Tido, Henkes, and Sircrazy."
   }
}

putlog "Ice2 Version $ice2version by Tido, Henkes, and Sircrazy is loaded! :)"



anyone please help, the script is working fine. but need to add something in regards for requesting a song.

every person can request 2 songs at the same time only, and then after sometime maybe around 15min-20min, she/he can again request 2 songs.


thank you for helping ...
Back to top
View user's profile Send private message
SpiKe^^
Owner


Joined: 12 May 2006
Posts: 689
Location: Tennessee, USA

PostPosted: Thu Jun 24, 2021 12:32 am    Post subject: Limit requests to 2 per nick per 15 minutes Reply with quote

This code should limit script requests to 2 per nick for any 15 minute period

First add all of this code to the bottom of your script...
Code:

proc too_many {nick uhost hand arg} {
  global toomany
  set nk [string tolower $nick]
  set ut [unixtime]
  set nowls [list]

  if {[info exists toomany($nk)]} {
    foreach expire $toomany($nk) {
      if {$ut < $expire} {  lappend nowls $expire  }
    }
  }
  set toomany($nk) $nowls

  if {[llength $nowls] >= 2} {
    putserv "notice $nick :No more than 2 requests in 15 minutes!"
    return 1
  }
  lappend toomany($nk) [expr {$ut + (60 * 15)}]
  return 0
}

bind cron - {*/10 * * * *} expire_too_many

proc expire_too_many {mn hr da mo wd} {
  global toomany
  set ut [unixtime]

  foreach {aname avalue} [array get toomany] {
    set nowls [list]
    foreach expire $avalue {
      if {$ut < $expire} {  lappend nowls $expire  }
    }

    if {![llength $nowls]} {  unset toomany($aname)
    } else {  set toomany($aname) $nowls  }
  }
}



Then add this line to the top of each request process you would like to limit...
Code:

  if {[too_many $nick $uhost $hand $arg]} {  return 0  }



In "Tido's Modified Icecast2 Script", you have 2 request procs you will want to modify:
proc request (for public requests)
and:
proc request_pm (for private message requests)

That would make the beginning of your 2 request procs look something like this...
Code:

proc request {nick uhost hand chan arg} {
  if {[too_many $nick $uhost $hand $arg]} {  return 0  }
  global dj
  if {$dj != ""} {




This all untested, please let me know how it all works out.
_________________
SpiKe^^

Get BogusTrivia 2.06.4.7 at www.mytclscripts.com
or visit the New Tcl Acrhive at www.tclarchive.org
.
Back to top
View user's profile Send private message Visit poster's website
mabrook
Halfop


Joined: 14 Jun 2021
Posts: 55

PostPosted: Thu Jun 24, 2021 1:08 am    Post subject: Reply with quote

Code:
#Tido's Modified Icecast2 Script
#Heavily Modified by Sircrazy
#Version 1.01
#July 12, 2010
######################################################################
#This program is free software; you can redistribute it and/or modify
#it under the terms of the GNU General Public License as published by
#the Free Software Foundation; version 2 of the License.
#
#This program is distributed in the hope that it will be useful,
#but WITHOUT ANY WARRANTY; without even the implied warranty of
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#GNU General Public License for more details.
######################################################################
#Credits:
#Influenced by Domsen's shoutcast1.03.tcl
#Special thanks to the TCL MAN files :D
#Special Release updated by Sircrazy
######################################################################
#Change these varibles to the one for your stream/bot/channel

#Name of Radio Station
set streamname "EDIT THIS"

#IP of the Icecast server.
set streamip "MAKE SURE IT IS THE IP"

#Port that Icecast is using, default is 8000.
set streamport "EDIT THIS"

#Main channel for the radio bot.
set radiochan "#EDIT THIS"

#Other channel that the bot can advertise to. Bot must be in this channel for this to work. Ice2.tcl only
# sends stream advertisements to this channel and does not send song info.
set otherchan "EDIT THIS OR REMOVE THIS TEXT"

#URL/Link to the stream for listening. This is what listeners need to click to tune in.
set streamurl "http://ssh.shellium.org/~sircrazy/sircrazy.m3u"

#How often the bot checks the stream when it knows it is down in minutes. Recommend 1 minute.
set offlinetimer "1"

#How often the bot checks the stream when it knows it is online in seconds. Recommend 15 seconds.
set onlinetimer "15"

#Default interval for how often the bot advertises (in minutes). You want to set it to something that isn't
# pure spammage.
set adtimer "30"

#Enables advertising set to the above frequency. 1 for ON and 0 for OFF. This reminds people that the stream
# is online.
set enableadvertise "1"

#Enables Special Announcement, 1 for ON and 0 for OFF. Special announcements are displayed every 720 minutes.
# This feature of the script is very undeveloped and I don't recommend using it.
set specialannounce "0"

#Special Announcement Message
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"

###########################################################################
#  Don't edit past this stuff unless you're Tido, Henkes, or Sircrazy :P  #
#       Except Line 387 where you need to add DJs and Line 281 where      #
#                    you need to put your mount point.                    #
###########################################################################


# Binds
bind pub - "%commands" showcommands
#Shows a list of all commands

bind pub - "%help" showcommands
#same as %commands

bind pub - "%status" status
#Displays the status of the stream

bind pub - "%listeners" listenercheck
#Reports how many listeners there are

bind pub - "%request" request
#Allows users to request songs

bind msg - "request" request_pm
#Allows users to make requests via pm

bind msg - "djon" dj_on
#turns on dj status

bind pub - "%djoff" dj_off
#turns off dj status

bind msg - "djoff" dj_off_pm
#turns off dj status

bind pub - "%fadvert" forceadvertise
#Forces an advertising message to be sent

bind pub - "%version" iceversion
#Displays the Ice2.tcl version

# Varible Resets
set ice2version "1.01 - 07.12.10"
set streamstatus "0"
set djnickname ""
set dj ""
set oldsong ""
set newsong ""
set newlistener ""
set oldlistener "0"
set forceadsent "0"
set sessionpeak "0"

# Check to make sure StatusCheck timer isn't running when bot rehashes.
if {![info exists statuscheck_running]} {
  timer $offlinetimer [list statuscheck]
  set statuscheck_running 1
}

# Check to make sure Special Announce timer isn't running when bot rehashes.
if {![info exists specialannounce_running]} {
  if {$specialannounce == "1"} {
    timer 720 [list specialmessage]
    set specialannounce_running 1
  }
}


# Check to make sure Advertise timer isn't running when bot rehashes.
if {![info exists adtimer_running]} {
  if {$enableadvertise == "1"} {
    timer $adtimer [list advertise]
    set adtimer_running 1
  }
}

# Output for %help or %commands
proc showcommands {nick uhost hand chan arg} {
  global ice2version streamname botnick dj
  if {$dj == "$nick" && $arg != ""} {
    putserv "notice $arg :>>> $botnick Commands - $ice2version<<<"
    putserv "notice $arg :%status >>> Displays the stream's status. If online it shows the song."
    putserv "notice $arg :%request (artist+track) >>> Sends a Request for a future song."
    putserv "notice $arg :/msg $botnick request (artist+track) >>> Sends a Request for a future song by PM."
  }
  if {$dj != "$nick"} {
    set arg ""
    putserv "notice $nick :>>> $botnick Commands - $ice2version<<<"
    putserv "notice $nick :%status >>> Displays the stream's status. If online it shows the song."
    putserv "notice $nick :%request (artist+track) >>> Sends a Request for a future song."
    putserv "notice $nick :/msg $botnick request (artist+track) >>> Sends a Request for a future song by PM."
  }
}

# Turns on and off Advertising. Also lets you set the interval: !advertise X
proc toggle_advertise {nick uhost hand chan arg} {
  global radiochan enableadvertise adtimer
  if {$enableadvertise == "1"} {
    set enableadvertise "0"
    set timerinfo [gettimerid]
    killtimer $timerinfo
    putserv "PRIVMSG $chan :Advertising OFF"
  } else {
    set enableadvertise "1"
    if {$arg == ""} {
      putserv "PRIVMSG $chan :Advertising ON. Frequency set to $adtimer minutes."
    } else {
      set adtimer $arg
      putserv "privmsg $chan :Advertising ON. Frequency changed to $adtimer minutes."
      timer $adtimer [list advertise]
    }
  }
}

# Function that finds out the ID of the advertising timer.
proc gettimerid {} {
    set adtimerinfo [timers]
    set loc1 [string first "advertise" $adtimerinfo]
    set loc1 [expr $loc1 + 10]
    set str1 [string range $adtimerinfo $loc1 999]
    set endloc [string first "\}" $str1]
    set endloc [expr $endloc -1]
    set timerinfo [string range $str1 0 $endloc]
    return $timerinfo
}

# Messages that are displayed when Advertising is enabled.
proc advertise {} {
  global radiochan streamstatus otherchan enableadvertise adtimer forceadsent streamurl streamname
  if {$streamstatus != "0" && $enableadvertise == "1"} {
    putserv "PRIVMSG $radiochan :$streamname is currently broadcasting live! Listen in @ $streamurl"
    putserv "PRIVMSG $otherchan :$streamname is currently broadcasting live! Listen in @ $streamurl"
    if {$forceadsent == "0"} {timer $adtimer [list advertise]} else {set forceadsent "0"}
    return 1
  }
  return 0
}

# Forces the advertising messages to appear
proc forceadvertise {nick uhost hand chan arg} {
  global streamstatus enableadvertise forceadsent
  if {$streamstatus == "0"} {
    putserv "notice $nick :The stream isn't on-air. Unable to advertise."
    return 0
  } else {
    if {$enableadvertise == "0"} {
      putserv "notice $nick :Advertising isn't enabled."
      return 0
    } else {
      set forceadsent "1"
      set forceadvertised [advertise]
      if {$forceadvertised == "1"} {
        putserv "notice $nick :Done!"
      } else {
        putserv "notice $nick :Advertising message was not sent!"
      }
    }
  }
}

# Special Announcement Message.
proc specialmessage {} {
  global radiochan specialannounce announcemsg
  putserv "PRIVMSG $radiochan : $announcemsg"
  timer 720 [list specialmessage]
  return 0
}

# StatusCheck
# Function that takes the information from Icecast_Online and creates the proper responses.
proc statuscheck {} {
  global radiochan streamstatus newsong oldsong newlistener oldlistener sessionpeak dj enableadvertise otherchan onlinetimer offlinetimer streamurl streamname

  if {$streamstatus == "0"} {
    set oldstatus "0"
  } else {
    set oldstatus "1"
  }
  set newstatus "[icecast_online]"
  if {$newstatus =="0" && $oldstatus == "0"} {
    timer $offlinetimer [list statuscheck]
  }
  if {$newstatus == "1" && $oldstatus == "0"} {
    putserv "PRIVMSG $radiochan :$streamname is now ON-AIR!! Click to listen: $streamurl"
    putlog "(RADIO) On-Air detected."
    utimer $onlinetimer [list statuscheck]
    if {$enableadvertise == "1"} {
      putserv "PRIVMSG $otherchan :$streamname is now ON-AIR!! Click to listen: $streamurl"

    }
  }
  if {$newstatus == "0" && $oldstatus == "1"} {
    putserv "PRIVMSG $radiochan :$streamname is now off-air."
    set oldlistener "0"
    set sessionpeak "0"
    if {$enableadvertise == "1"} {
      putserv "PRIVMSG $otherchan :$streamname is now off-air."
    }
    putlog "(RADIO) Off-Air detected."
    timer $offlinetimer [list statuscheck]
  }
  if {$newstatus == "1" && $oldstatus == "1"} {
    utimer $onlinetimer [list statuscheck]
    if {$newsong != $oldsong && $newsong != ">inbetween" && $newsong != ">inbetween1" && $newsong != ">inbetween2" && $newsong != ">whatutalkinbout" && $newsong != ">tmsradio80sintro"} {
      putserv "PRIVMSG $radiochan :Now playing on $streamname: $newsong @ $streamurl"
      set oldsong "$newsong"
    }
  }
}
 
# Icecast_Online
# This is the HTTP Parser that gathers the various data from the status.xsl file.
proc icecast_online { } {
  global streamip streamport streamstatus newsong newlistener
  set pagedata ""
  if {[catch {set sock [socket $streamip $streamport] } sockerror]} {
    putlog "error: $sockerror"
    return 0
  } else {
    puts $sock "GET /status.xsl?mount=/sircrazy HTTP/1.1"
    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]} { append pagedata "[read $sock]" }
  }
  if {[string match *streamdata* $pagedata] == 1} {
    set streamstatus "1"
    set songlocation [string first "Current Song:" $pagedata]
    set songdata1 [string range $pagedata $songlocation 99999]
    set location2 [string first "</tr>" $songdata1]
    set songdata2 [string range $songdata1 0 $location2]
    set songdata3 [string range $songdata2 42 9999]
    set location3 [string first "</td>" $songdata3]
    set location3 [expr $location3 - 1]
    set newsong [string range $songdata3 0 $location3]

    set llocation [string first "Listeners:" $pagedata]
    set countdata1 [string range $pagedata $llocation 99999]
    set llocation2 [string first "</tr>" $countdata1]
    set countdata2 [string range $countdata1 0 $llocation2]
    set countdata3 [string range $countdata2 39 9999]
    set llocation3 [string first "</td>" $countdata3]
    set llocation3 [expr $llocation3 - 1]
    set newlistener [string range $countdata3 0 $llocation3]
    close $sock
    return 1
   
  } else {
    set streamstatus "0"
    close $sock
    return 0
  }
}

# %status function. Diplays the current status of the stream.
proc status {nick uhost hand chan arg} {
  global dj radiochan newsong newlistener streamstatus streamurl streamname
  if {$streamstatus == 1} {
    if {$newsong != "" &&  $dj == "$nick" && $arg != ""} {putserv "notice $arg :The current song is |$newsong| @ $streamurl"}
    if {$newsong != "" &&  $dj != "$nick"} {
      putserv "notice $nick :The current song is |$newsong| @ $streamurl"
    }
  } else {putserv "notice $nick :$streamname is currently offline."
    }
}

# /msg %botnick listeners: displays how many current listeners there are.
proc listenercheck {nick uhost hand arg} {
  global newlistener radiochan streamstatus streamname
  if {$streamstatus == "1"} {
    if {$newlistener == "0"} {
      putserv "notice $nick :There aren't any listeners tuned into $streamname :(."
    } elseif {$newlistener =="1"} {
      putserv "notice $nick :There is 1 listener tuned into $streamname."
    } else {
      putserv "notice $nick :There are $newlistener listeners tuned into $streamname."
    }
  } else {
    putserv "notice $nick :$streamname isn't on-air."
  }
}

# %request: sends a message to dj about the request that was made.
proc request {nick uhost hand chan arg} {
if {[too_many $nick $uhost $hand $arg]} {  return 0  }
  global dj
  if {$dj != ""} {
    if {$arg == ""} {putserv "notice $nick :You didn't request anything!"
    return 0
    } else {
      putserv "privmsg $dj :REQUEST($nick) => $arg"
      putserv "notice $nick :Your request was sent to $dj. Thank you!"
      return 0
      }
  } else {
    putserv "notice $nick :There is no DJ online taking requests."
    return 0
  }
}

# /msg $botnick request X: sends a message to dj about the request that was made.
proc request_pm {nick uhost hand arg} {
if {[too_many $nick $uhost $hand $arg]} {  return 0  }
  global dj
  if {$dj != ""} {
    if {$arg == ""} {putserv "notice $nick :You didn't request anything!"
    return 0
    } else {
      putserv "privmsg $dj :REQUEST($nick) => $arg"
      putserv "notice $nick :Your request was sent to $dj. Thank you!"
      return 0
      }
  } else {
    putserv "notice $nick :There is no DJ online taking requests."
    return 0
  }
}

# /msg $botnick djon [password]: Turns DJ on for user
proc dj_on {nick uhost hand arg} {
  global dj radiochan
  if {$dj == ""} {
    if {$arg == ""} {putserv "privmsg $nick :You must enter your password"
      return 0
    } else {
# This is a Test DJ Entry. the $arg here is the password.
# You can have as many of these as you want, just paste
# them directly under one another, within the else { }.   
#      if {$arg == "Test"} {
#        set dj "$nick"
#        putserv "PRIVMSG $nick :You are logged in as $dj."
#        putserv "PRIVMSG $radiochan :$dj is now rocking the turntables and accepting requests via %request, enjoy."
#        return 0
#      }
    }
  }
  if {$dj != ""} {
    putsrv "notice $nick :$dj is already active. &dj needs to sign off before you can log in."
    return 0
  }
}

# %djoff: Turns DJ off for user
proc dj_off {nick uhost hand chan arg} {
  global dj radiochan
  if {$dj != $nick} {
    putserv "notice $nick :You are not the current DJ or you changed your nickname since becoming one."
  } else {
    putserv "PRIVMSG $radiochan :$dj is signing off and no longer accepting requests."
    set dj ""
    putserv "notice $nick :Your DJ'ness has been deactivated"
  }
}

# /msg $botnick djoff: Turns DJ off for user
proc dj_off_pm {nick uhost hand arg} {
  global dj radiochan
  if {$dj != $nick} {
    putserv "notice $nick :You are not the current DJ or you changed your nickname since becoming one."
  } else {
    putserv "PRIVMSG $radiochan :$dj is signing off and no longer accepting requests."
    set dj ""
    putserv "notice $nick :Your DJ'ness has been deactivated"
  }
}

# !version: displays the current version of the Ice2.tcl script.
proc iceversion {nick host hand chan arg} {
   global ice2version radiochan botnick
   if {$chan == $radiochan} {
     putserv "notice $nick :I am $botnick running Ice2.tcl Version $ice2version by Tido, Henkes, and Sircrazy."
   }
}


proc too_many {nick uhost hand arg} {
  global toomany
  set nk [string tolower $nick]
  set ut [unixtime]
  set nowls [list]

  if {[info exists toomany($nk)]} {
    foreach expire $toomany($nk) {
      if {$ut < $expire} {  lappend nowls $expire  }
    }
  }
  set toomany($nk) $nowls

  if {[llength $nowls] >= 2} {
    putserv "notice $nick :No more than 2 requests in 15 minutes!"
    return 1
  }
  lappend toomany($nk) [expr {$ut + (60 * 15)}]
  return 0
}

bind cron - {*/10 * * * *} expire_too_many

proc expire_too_many {mn hr da mo wd} {
  global toomany
  set ut [unixtime]

  foreach {aname avalue} [array get toomany] {
    set nowls [list]
    foreach expire $avalue {
      if {$ut < $expire} {  lappend nowls $expire  }
    }

    if {![llength $nowls]} {  unset toomany($aname)
    } else {  set toomany($aname) $nowls  }
  }
}

putlog "Ice2 Version $ice2version by Tido, Henkes, and Sircrazy is loaded! :)"




can you please check if i am doing it right..



I put it here..

Code:
# %request: sends a message to dj about the request that was made.
proc request {nick uhost hand chan arg} {
if {[too_many $nick $uhost $hand $arg]} {  return 0  }
  global dj
  if {$dj != ""} {
    if {$arg == ""} {putserv "notice $nick :You didn't request anything!"
    return 0
    } else {
      putserv "privmsg $dj :REQUEST($nick) => $arg"
      putserv "notice $nick :Your request was sent to $dj. Thank you!"
      return 0
      }
  } else {
    putserv "notice $nick :There is no DJ online taking requests."
    return 0
  }
}

# /msg $botnick request X: sends a message to dj about the request that was made.
proc request_pm {nick uhost hand arg} {
if {[too_many $nick $uhost $hand $arg]} {  return 0  }
  global dj
  if {$dj != ""} {
    if {$arg == ""} {putserv "notice $nick :You didn't request anything!"
    return 0
    } else {
      putserv "privmsg $dj :REQUEST($nick) => $arg"
      putserv "notice $nick :Your request was sent to $dj. Thank you!"
      return 0
      }
  } else {
    putserv "notice $nick :There is no DJ online taking requests."
    return 0
  }
}
Back to top
View user's profile Send private message
mabrook
Halfop


Joined: 14 Jun 2021
Posts: 55

PostPosted: Thu Jun 24, 2021 5:04 am    Post subject: Reply with quote

i tried it and it works.. but


after 2 songs request per user is ok..

Code:

-BotName- No more than 2 requests, you can make request again after 15 minutes!


then after 15 minutes, user make a request again..

the script disconnects the dj , it will show

Code:
-Botname- There isn't a DJ logged in at the moment to take requests.


and the bot itself restart
Back to top
View user's profile Send private message
mabrook
Halfop


Joined: 14 Jun 2021
Posts: 55

PostPosted: Thu Jun 24, 2021 3:26 pm    Post subject: Reply with quote

thank you SpiKe^^ for helping it out.


Now it is working great. Very Happy
Back to top
View user's profile Send private message
flink
Voice


Joined: 21 Feb 2021
Posts: 33
Location: Canarias

PostPosted: Thu Aug 19, 2021 9:51 am    Post subject: Re: Limit requests to 2 per nick per 15 minutes Reply with quote

Hi SpiKe, I tried it and it works perfectly, I was wondering if you can put a message so that when the time is up the nickname will be notified that he can requests again, thank you. sorry if my English is not good but I use translator
Back to top
View user's profile Send private message
SpiKe^^
Owner


Joined: 12 May 2006
Posts: 689
Location: Tennessee, USA

PostPosted: Sat Aug 21, 2021 11:26 pm    Post subject: Re: Limit requests to 2 per nick per 15 minutes Reply with quote

flink wrote:
I was wondering if you can put a message so that when the time is up the nickname will be notified that he can requests again, thank you.


Try replace this bind and proc...
Code:
bind cron - {*/10 * * * *} expire_too_many

proc expire_too_many {mn hr da mo wd} {
  global toomany
  set ut [unixtime]

  foreach {aname avalue} [array get toomany] {
    set nowls [list]
    foreach expire $avalue {
      if {$ut < $expire} {  lappend nowls $expire  }
    }

    if {![llength $nowls]} {  unset toomany($aname)
    } else {  set toomany($aname) $nowls  }
  }
}


with this new bind and proc...
Code:
bind cron - {*} expire_too_many

proc expire_too_many {mn hr da mo wd} {
  global toomany
  set ut [unixtime]

  foreach {aname avalue} [array get toomany] {
    set nowls [list]
    foreach expire $avalue {
      if {$ut < $expire} {  lappend nowls $expire  }
    }

    if {[llength $avalue] >= 2 && [llength $nowls] < 2 && [onchan $aname]} {
      putserv "notice $aname :You may make another request."
    }

    if {![llength $nowls]} {  unset toomany($aname)
    } else {  set toomany($aname) $nowls  }
  }
}


.restart the bot to load the new code and see what ya got.
_________________
SpiKe^^

Get BogusTrivia 2.06.4.7 at www.mytclscripts.com
or visit the New Tcl Acrhive at www.tclarchive.org
.
Back to top
View user's profile Send private message Visit poster's website
flink
Voice


Joined: 21 Feb 2021
Posts: 33
Location: Canarias

PostPosted: Sun Aug 22, 2021 10:15 am    Post subject: Re: Limit requests to 2 per nick per 15 minutes Reply with quote

SpiKe ^^ I haven't tried it yet, but it could be instead of
Code:
putserv "notice $aname :You may make another request."


that advertises like this
Code:
putserv "privmsg $chan :$aname :You may make another request."


thank you very much again for your time
_________________
Mi ingles: no es el mejor, Manda el traductor... Smile
Back to top
View user's profile Send private message
flink
Voice


Joined: 21 Feb 2021
Posts: 33
Location: Canarias

PostPosted: Thu Sep 09, 2021 12:12 pm    Post subject: Reply with quote

well I'll keep that I sent a notice to the nick, I would have liked a message per room but ... less is nothing and I have to be grateful for the help once again thanks SpiKe ^^
_________________
Mi ingles: no es el mejor, Manda el traductor... Smile
Back to top
View user's profile Send private message
mabrook
Halfop


Joined: 14 Jun 2021
Posts: 55

PostPosted: Sat Sep 18, 2021 10:00 am    Post subject: Reply with quote

i just want to continue this post in connection with the script above.



anyone can help out please,


- need to add this feature turn off and turn on command from the script.



Code:

<user> !radio off
<BOT> Radio turned off

----------------

<user> !radio on
<BOT> Radio turned on





once the radio is off, it will not display the auto-show in the channel.
once the radio is on, it will display the auto-show in the channel.



hope anyone can help.. thanks
Back to top
View user's profile Send private message
CrazyCat
Owner


Joined: 13 Jan 2002
Posts: 877
Location: France

PostPosted: Sun Sep 19, 2021 9:33 am    Post subject: Reply with quote

Well, the function (or near) exists but without bind:
Code:
# Turns on and off Advertising. Also lets you set the interval: !advertise X
proc toggle_advertise {nick uhost hand chan arg}


So, just add the following to enable it:
Code:
bind pub o|- !advertise toggle_advertise

_________________
https://www.eggdrop.fr
Offer me a coffee - Do not ask me help in PM, we are a community.
Back to top
View user's profile Send private message Visit poster's website
mabrook
Halfop


Joined: 14 Jun 2021
Posts: 55

PostPosted: Sun Sep 19, 2021 11:29 am    Post subject: Reply with quote

thank you for the response CrazyCat,


but i think the command;
Code:
bind pub o|- !advertise toggle_advertise



is for this;
Code:

#How often the bot checks the stream when it knows it is online in seconds. Recommend 15 seconds.
set onlinetimer "15"


and the proc is this;

Code:

# Turns on and off Advertising. Also lets you set the interval: !advertise X
proc toggle_advertise {nick uhost hand chan arg} {
  global radiochan enableadvertise adtimer
  if {$enableadvertise == "1"} {
    set enableadvertise "0"
    set timerinfo [gettimerid]
    killtimer $timerinfo
    putserv "PRIVMSG $chan :Advertising OFF"
  } else {
    set enableadvertise "1"
    if {$arg == ""} {
      putserv "PRIVMSG $chan :Advertising ON. Frequency set to $adtimer minutes."
    } else {
      set adtimer $arg
      putserv "privmsg $chan :Advertising ON. Frequency changed to $adtimer minutes."
      timer $adtimer [list advertise]
    }
  }
}





am i right? just want to make a clarification. Razz Razz Razz this is to advertise

Code:

# Messages that are displayed when Advertising is enabled.
proc advertise {} {
  global radiochan streamstatus otherchan enableadvertise adtimer forceadsent streamurl streamname
  if {$streamstatus != "0" && $enableadvertise == "1"} {
    putserv "PRIVMSG $radiochan :$streamname is currently broadcasting live! Listen in @ $streamurl"
    putserv "PRIVMSG $otherchan :$streamname is currently broadcasting live! Listen in @ $streamurl"
    if {$forceadsent == "0"} {timer $adtimer [list advertise]} else {set forceadsent "0"}
    return 1
  }
  return 0
}




I tried your suggestion but still the auto-show of the song still showing in the channel.


Code:

<@BOT> [ Auto Dj  ] - Justin Bieber,Kehlani - Get Me
<@BOT> [ Auto Dj  ] - Andy Williams - The First Time Ever (I Saw Your Face)
<@BOT> [ Auto Dj  ] - Billie Eilish - Come Out And Play



what i need is, when you type !radio off in the channel, it will completely turn-off the radio station and not showing the song/s in the channel ( from the bot).
and when you type !radio on , it will completely show the playing song/s based in the radio station (from the bot).

Code:


<USER> !radio off
<BOT> Radio is turned-off. Nothing to show.

<USER> !radio on
<BOT> Radio is turned-on. please wait..
<@BOT> [ Auto Dj  ] - Billie Eilish - Come Out And Play

Back to top
View user's profile Send private message
SpiKe^^
Owner


Joined: 12 May 2006
Posts: 689
Location: Tennessee, USA

PostPosted: Mon Sep 20, 2021 5:14 pm    Post subject: Reply with quote

mabrook:

This code is untested and could surely use some more work.

First, add this code somewhere in the script...
Code:

# script on/off bind and proc

bind pub n| !radio radio_off

proc radio_off {nick uhost hand chan arg} {
  set opt [string tolower [lindex [split $arg] 0]]

  if {$opt eq "off"} {
    if {[info exists ::radio_off]} {
      putserv "PRIVMSG $chan :Icecast2 script is already Off."
    } else {
      set ::radio_off 1
      putserv "PRIVMSG $chan :Icecast2 script is now Off."
    }

  } elseif {$opt eq "on"} {
    if {![info exists ::radio_off]} {
      putserv "PRIVMSG $chan :Icecast2 script is already On."
    } else {
      unset ::radio_off
      putserv "PRIVMSG $chan :Icecast2 script is now On."
    }

  } else {
    if {[info exists ::radio_off]} {
      putserv "PRIVMSG $chan :Icecast2 script is Off. To enable, use: !radio on"
    } else {
      putserv "PRIVMSG $chan :Icecast2 script is On. To disable, use: !radio off"
    }

  }
  return 0
}




Then find this existing code in the proc statuscheck
Code:
  if {$newstatus == "1" && $oldstatus == "1"} {
     utimer $onlinetimer [list statuscheck]
     if {$newsong != $oldsong && $newsong != ">inbetween" && $newsong != ">inbetween1" && $newsong != ">inbetween2" && $newsong != ">whatutalkinbout" && $newsong != ">tmsradio80sintro"} {
       putserv "PRIVMSG $radiochan :Now playing on $streamname: $newsong @ $streamurl"
       set oldsong "$newsong"
     }
   }

and make it look more like this...
Code:
  if {$newstatus == "1" && $oldstatus == "1"} {
     utimer $onlinetimer [list statuscheck]
     if {$newsong != $oldsong && $newsong != ">inbetween" && $newsong != ">inbetween1" && $newsong != ">inbetween2" && $newsong != ">whatutalkinbout" && $newsong != ">tmsradio80sintro"} {

       if {![info exists ::radio_off]} {
         putserv "PRIVMSG $radiochan :Now playing on $streamname: $newsong @ $streamurl"
       }

       set oldsong "$newsong"
     }
   }

This should allow the script to continue to run as it always has, just keeping the now playing line from being sent to the channel.
_________________
SpiKe^^

Get BogusTrivia 2.06.4.7 at www.mytclscripts.com
or visit the New Tcl Acrhive at www.tclarchive.org
.
Back to top
View user's profile Send private message Visit poster's website
mabrook
Halfop


Joined: 14 Jun 2021
Posts: 55

PostPosted: Tue Sep 21, 2021 1:53 am    Post subject: Reply with quote

thank you SpiKe^^ , this works for me. this is what i need. Very Happy Very Happy Very Happy



Now, this is an updated script now (to sum it up)


1. added 2 songs request per user / every 15minutes or the specific time you set
2. added bind for bind pub o|- !advertise toggle_advertise which proc is already in the script
3. added !radio on/off




Thank you Egghelp Community for helping out. Laughing Laughing Laughing
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    egghelp.org community Forum Index -> Script Support & Releases All times are GMT - 4 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Forum hosting provided by Reverse.net

Powered by phpBB © 2001, 2005 phpBB Group
subGreen style by ktauber