### # Copyright (c) 2004, Philip Freeman # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions are met: # # * Redistributions of source code must retain the above copyright notice, # this list of conditions, and the following disclaimer. # * Redistributions in binary form must reproduce the above copyright notice, # this list of conditions, and the following disclaimer in the # documentation and/or other materials provided with the distribution. # * Neither the name of the author of this software nor the name of # contributors to this software may be used to endorse or promote products # derived from this software without specific prior written consent. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE # POSSIBILITY OF SUCH DAMAGE. ### # # INSTALLATION : # $ # # """ this is a simple info plugin for halo_radio. DON'T FORGET TO INSTALL THE halo_radio LIBRARY from the main release distro. v.0.2.0pre3 """ import supybot __revision__ = "$Id$" __author__ = supybot.authors.unknown __contributors__ = {} import supybot.conf as conf import supybot.utils as utils from supybot.commands import * import supybot.plugins as plugins import supybot.ircutils as ircutils import supybot.privmsgs as privmsgs import supybot.registry as registry import supybot.callbacks as callbacks import HaloRadio def configure(advanced): # This will be called by setup.py to configure this module. Advanced is # a bool that specifies whether the user identified himself as an advanced # user or not. You should effect your configuration by manipulating the # registry as appropriate. from supybot.questions import expect, anything, something, yn conf.registerPlugin('Radio', True) conf.registerPlugin('Radio') # This is where your configuration variables (if any) should go. class Radio(callbacks.Privmsg): threaded = True def __init__(self): callbacks.Privmsg.__init__(self) def current(self, irc, msg, args): """ Returns the current song. """ import HaloRadio.PlayHistListMaker as PlayHistListMaker import HaloRadio.User as User import HaloRadio.Config as Config phlm = PlayHistListMaker.PlayHistListMaker() phlm.GetRecentPlays(1) ph = phlm.GetPlayHist(0) cur_song = ph.GetSong() if ph.requestby !=0: u = User.User(ph.requestby) curreqby = u.GetDisplayName() else: curreqby = "X" cfg = Config.Config() irc.reply(str("%d %s[%s](%s%%) {%s}"%( cur_song.id, cur_song.GetDisplayName(), cur_song.GetDisplayLength(), cfg.GetConfigItem("current_percent"), curreqby))) def last(self, irc, msg, args): """ Returns last song played. """ import HaloRadio.PlayHistListMaker as PlayHistListMaker import HaloRadio.User as User rlm = PlayHistListMaker.PlayHistListMaker() rlm.GetRecentPlays(2) if len(rlm.list) != 0: r = rlm.GetPlayHist(1) s = r.GetSong() if r.requestby != 0: u = User.User(r.requestby) irc.reply(str("%s [%s]"%(s.GetDisplayName(),u.GetDisplayName()))) else: irc.reply(str("%s"%(s.GetDisplayName()))) else: irc.reply(str("something fucked up.")) def next(self, irc, msg, args): """ Returns next song in queue. """ import HaloRadio.RequestListMaker as RequestListMaker import HaloRadio.User as User rlm = RequestListMaker.RequestListMaker() rlm.GetAll() if len(rlm.list) != 0: r = rlm.GetRequest(0) s = r.GetSong() u = User.User(r.requestby) irc.reply(str("%s [%s]"%(s.GetDisplayName(),u.GetDisplayName()))) else: irc.reply(str("no requests in queue.")) def who(self, irc, msg, args): """ Returns a list of active listeners and web users. """ import HaloRadio.SessionListMaker as SessionListMaker import HaloRadio.Util as Util import string active_users=[] slm = SessionListMaker.SessionListMaker() slm.GetActive() for i in range(0,len(slm.list)): s = slm.GetSession(i) u = s.GetUser() if u.id == 1: # Annymous Guest, eh ? active_users.append(str("%s-%s"% (u.GetDisplayName(),s.host))) else: active_users.append(str(u.GetDisplayName())) l = Util.GetListeners() if len(active_users) > 0: irc.reply(str("listeners: %s, web users: %s." % ( l, string.join(active_users, ", ")))) else: irc.reply(str("listeners: %s" % l )) Class = Radio # vim:set shiftwidth=4 tabstop=8 expandtab textwidth=78: