version = "2.0"
sysinfo_version = "2.0"
__module_name__ = "lemmings IRC Script"
__module_version__ = version
__module_description__ = "Python module for xchat2"

###################################################################
#     Trilliji and FuzzyTheBear's Hacked up Onion Script          #
#                                                                 #
#   Come an join us sometime on irc.freenode.com #lemmings        #
#                                                                 #
#   This script was originally written by Onion under the terms   #
#   of the GNU Public License, v2 or later and Copyleft 2003      #
#   onioN. It was modified and extended by Trilliji,ProGuy (xmms) #
#   and FuzzyTheBear.                                             #
#                                                                 #
###################################################################
import xchat
import string
import os
import sys
import time

try:
  import xmms
  xmms_installed=1
except:
  xmms_installed=0
preview="Off"
def sysinfo(word, word_el, userdata):
    XCString = ''
    fd_osinfo = os.popen("uname -a","r")
    for data_osinfo in fd_osinfo.readlines():
        temp_osinfo=string.split(data_osinfo)
        info_os=temp_osinfo[0]+" "+temp_osinfo[2]
    fd_osinfo.close()
        
    fd_cpuinfo = os.popen("cat /proc/cpuinfo","r")
    cpu_count=0
    info_cpu = {}
    info_clock = {}
    for data_cpuinfo in fd_cpuinfo.readlines():
        if string.find(data_cpuinfo,'model name') > -1 :
           temp_cpu=string.replace(data_cpuinfo,'\n','')
           temp_cpu=string.replace(temp_cpu,'model name','')
           info_cpu[cpu_count]=string.replace(temp_cpu,': ','')
	if string.find(data_cpuinfo,'cpu MHz') > -1 :
           temp_clock=string.split(string.replace(data_cpuinfo,'\n',''))
           info_clock[cpu_count]=temp_clock[3]
           cpu_count=cpu_count+1
    fd_cpuinfo.close()

    # I'm not sure if this works for all Unices, but it at least does
    # for Linux. 
    fd_uptimeinfo = os.popen("uptime","r")
    for data_uptimeinfo in fd_uptimeinfo.readlines():
        temp_uptimeinfo=data_uptimeinfo
        start=string.find(temp_uptimeinfo, "up")+3
        end=string.index(temp_uptimeinfo, ",", start)
        info_uptime=string.strip(temp_uptimeinfo[start:end])
    fd_osinfo.close()

    fd_meminfo = os.popen("cat /proc/meminfo","r")
    for data_meminfo in fd_meminfo.readlines():
        if string.find(data_meminfo,'MemTotal') > -1 :
           temp_mem1=string.replace(data_meminfo,'\n','')
           info_mem1=string.replace(temp_mem1,'MemTotal:      ','')
        if string.find(data_meminfo,'MemFree') > -1 :
           temp_mem2=string.replace(data_meminfo,'\n','')
           info_mem2=string.replace(temp_mem2,'MemFree:       ','')
    fd_meminfo.close()

    fd_vgainfo = os.popen("cat /proc/pci","r")
    for data_vgainfo in fd_vgainfo.readlines():
        if string.find(data_vgainfo,'VGA') > -1 :
           temp_vga=string.split(data_vgainfo,':')
           info_vga=string.replace(temp_vga[1],'\n','')
           if string.find(data_vgainfo,'Display') > -1 :
              temp_vga=string.replace(data_vgainfo,'\n','')
              info_vga=string.replace(temp_vga,'    ','')
    fd_vgainfo.close()
			
    fd_xinfo = os.popen("xdpyinfo","r")
    for data_xinfo in fd_xinfo.readlines():
        if string.find(data_xinfo,'vendor string') > -1 :
           temp_xvender=string.replace(data_xinfo,'\n','')
           info_xvender=string.replace(temp_xvender,'vendor string:    ','')
        if string.find(data_xinfo,'XFree86 version') > -1 :
           temp_xversion=string.split(string.replace(data_xinfo,'\n',''))
           info_xversion=temp_xversion[2]
        if string.find(data_xinfo,'dimensions') > -1 :
           temp_xresolution=string.replace(data_xinfo,'\n','')
           temp_xresolution=string.replace(temp_xresolution,'  dimensions:    ','')
           info_xresolution=temp_xresolution
        if string.find(data_xinfo,'depth of root window') > -1 :
           temp_xdepth=string.split(string.replace(data_xinfo,'\n',''))
           info_xdepth=temp_xdepth[4]
    fd_xinfo.close()

    info_sound=""
    fd_soundinfo = os.popen("cat /proc/pci","r")
    for data_soundinfo in fd_soundinfo.readlines():
        if string.find(data_soundinfo,'audio') > -1 :
           temp_sound=string.replace(data_soundinfo,'\n','')
           info_sound=string.replace(temp_sound,'    Multimedia audio controller: ','')

    fd_soundinfo = os.popen("cat /proc/isapnp","r")
    for data_soundinfo in fd_soundinfo.readlines():
        if string.find(data_soundinfo,'Audio') > -1 :
           temp_sound=string.replace(data_soundinfo,'\n','')
           info_sound=string.replace(temp_sound,'    Multimedia audio controller: ','')
    fd_soundinfo.close()

    XCString = ('Kernel: %s\x039' % (info_os))
    count=0
    for count in info_cpu :
        XCString = '%s CPU[%s]: %s@%s MHz' % ( XCString, count, info_cpu[count], info_clock[count] ) 
        count=count+1
        XCString = '%s\x0311 Mem/Use: %s/%s' % (XCString, info_mem1, info_mem2)
        XCString = '%s\x038 Vid:%s \x0313XInfo:%s @ %s/%s bit' \
                    % (XCString, info_vga, info_xversion, info_xresolution, info_xdepth )

    if info_sound<>"" :
       XCString = '%s\x0310 Sound:%s' % ( XCString, info_sound )

    XCString = '%s\x038 Uptime: %s' % (XCString, info_uptime)

    return XCString

def sysinfo_cb(word, word_el, userdata):
    XCString = "msg %s %s" % (xchat.get_info('channel'),sysinfo( word, word_el, userdata))
    xchat.command(XCString)
    return xchat.EAT_ALL



#This section as a  whole contains little meters of all kinds
#Nothing scientific.Just plain old fun.

#This section has a few lines commented out.Hack to taste.
def crap_cb( word, word_eol, userdata):
    xchat.command("me Points to the amazingly high crap-o-meter's reading.") 
    xchat.command("me \x039   0   2   4  \x038 6  \x034 8   10")
    xchat.command("me \x034                       /")
    xchat.command("me \x038                     /")
#   xchat.command("me \x038                   /")
#   xchat.command("me \x038                 /")
    xchat.command("me \x038       crap-o-meter")
    return xchat.EAT_ALL

def bull_display(level):
    xchat.command('me \x038Points \x039out \x038The \x037Amazing \x039Crap-\x038O-\x034Meter \x039reading.')
    xchat.command("msg %s \x039 ` ` 1 ` ` 2 ` ` 3 ` ` 4\x038 ` ` 5 ` ` 6 ` ` 7\x034 ` ` 8 ` ` 9 ` ` 10   " % \
                  (xchat.get_info('channel')))
    color = ''
    if level > 10:
       level = 10
    elif level < 0:
       level = 0

    if level < 4:
       color = "\x03,3"
    elif level < 7:
       color = "\x03,8"
    else:
       color = "\x03,5"
    level = level * 6

    for i in range(60):
        if i == level:
           color = color + '\x03'
        color = color + ' '

    color = 'msg %s %s'%(xchat.get_info('channel'),color)
    xchat.command(color)        
    xchat.command("msg %s \x039             safe        \x038         normal     \x034         boots" % \
                  (xchat.get_info('channel')))  

def bull_cb(word, word_eol, userdata):
    if len(word) < 1:
       xchat.prnt('Usage:')
       xchat.prnt('    level> Location on scale')
    else:
       bull_display(int(word[1])) 
    return xchat.EAT_ALL

def bulllow_cb( word, word_eol, userdata):
    bull_display(1)
    return xchat.EAT_ALL

def bullmed_cb( word, word_eol, userdata):
    bull_display(5)
    return xchat.EAT_ALL

def bullhigh_cb( word, word_eol, userdata):
    bull_display(9)
    return xchat.EAT_ALL

def bulll_cb( word, word_eol, userdata):
    xchat.command('me \x038Points \x039out \x038The \x037Amazing \x039Crap-\x038O-\x034Meter \x039reading.')
    xchat.command("msg %s \x039 ` ` 1 ` ` 2 ` ` 3 ` ` 4 \x038 ` ` 5 ` ` 6 ` ` 7 \x034 ` ` 8 ` ` 9 ` ` 10   " % (xchat.get_info('channel')))
    xchat.command("msg %s              \x039,9 |" % (xchat.get_info('channel')))
    xchat.command("msg %s \x039             safe        \x038         normal     \x034         boots" % (xchat.get_info('channel')))       
    return xchat.EAT_ALL

def bullm_cb( word, word_eol, userdata):
    xchat.command('me \x038Points \x039out \x038The \x037Amazing \x039Crap-\x038O-\x034Meter \x039reading.')
    xchat.command("msg %s \x039 ` ` 1 ` ` 2 ` ` 3 ` ` 4 \x038 ` ` 5 ` ` 6 ` ` 7 \x034 ` ` 8 ` ` 9 ` ` 10   " % (xchat.get_info('channel')))
    xchat.command("msg %s                                         \x038,8 |" % (xchat.get_info('channel')))
    xchat.command("msg %s \x039             safe        \x038         normal     \x034         boots" % (xchat.get_info('channel')))       
    return xchat.EAT_ALL

def bullh_cb( word, word_eol, userdata):
    xchat.command('me \x038Points \x039out \x038The \x037Amazing \x039Crap-\x038O-\x034Meter \x039reading.')
    xchat.command("msg %s \x039 ` ` 1 ` ` 2 ` ` 3 ` ` 4 \x038 ` ` 5 ` ` 6 ` ` 7 \x034 ` ` 8 ` ` 9 ` ` 10   " % (xchat.get_info('channel')))
    xchat.command("msg %s                                                                 \x034,4 |" % (xchat.get_info('channel')))
    xchat.command("msg %s \x039             safe        \x038         normal     \x034         boots" % (xchat.get_info('channel')))       
    return xchat.EAT_ALL


def littlemeter_cb(word, word_eol, userdata):
    if len(word) < 2:
       xchat.prnt('Usage:')
       xchat.prnt('    level> Location on scale')
       xchat.prnt('    caption> Meter Text')
    else:
       level = int(word[1])
       skipped = 0
       caption = ''
       for eachword in word:
           if skipped < 2:
              skipped = skipped + 1
           else:
              caption = caption + ' ' + eachword 
       if level > 10:
          caption = caption + ' * Off Scale *'
          level = 10 
       xchat.command('msg %s \x03,3|0    |     |     \x03,8|     |     5     |     \x03,5|     |     |   10'
                     %xchat.get_info('channel'))
       if level < 4:
          color = "\x03,3"
       elif level < 7:
          color = "\x03,8"
       else:
          color = "\x03,5"
       level = level * 6
       startcaption = (60 - len(caption))/2

       captionlocation = 0
       for i in range(60):
           if i == level:
              color = color + '\x03,15'
           if captionlocation < len(caption):
              if i >= startcaption:
                 color = color + caption[captionlocation]
                 captionlocation = captionlocation + 1
              else:
                 color = color + ' '
           else:
              color = color + ' '

       color = 'msg %s %s'%(xchat.get_info('channel'),color)
       xchat.command(color)
       return xchat.EAT_ALL

def tiny_cb(word, word_el, userdata):
    if len(word) < 2:
       xchat.prnt('Usage:')
       xchat.prnt('    level> Location on scale')
       xchat.prnt('    caption> Meter Text')
    else:
       level = int(word[1])
       skipped = 0
       caption = ''
       for eachword in word:
           if skipped < 2:
              skipped = skipped + 1
           else:
              caption = caption + ' ' + eachword 
       if level > 10:
          caption = caption + ' * Off Scale *'
          level = 10 
       if level < 4:
          color = "\x031,3"
       elif level < 7:
          color = "\x031,8"
       else:
          color = "\x031,4"
       level = level * 6
       startcaption = (60 - len(caption))/2

       captionlocation = 0
       for i in range(60):
           if i == level:
              color = color + '\x03,15'
           if captionlocation < len(caption):
              if i >= startcaption:
                 color = color + caption[captionlocation]
                 captionlocation = captionlocation + 1
              else:
                 color = color + ' '
           else:
              color = color + ' '

       color = 'msg %s %s'%(xchat.get_info('channel'),color)
       xchat.command(color)
       return xchat.EAT_ALL 

#Tricks and gags section ..  Here  anything goes :) 
#Soup up and pack a mean punch.

#This sub-section and the function is for ascii art display.
#Please keep that short.Most channels/servers dont like being flooded.

def aliens_cb( word, word_eol, userdata):
    xchat.command("msg %s \x038    _                       " % (xchat.get_info('channel')))
    xchat.command("msg %s \x038   /\\                      " % (xchat.get_info('channel')))
    xchat.command("msg %s \x038   \ \\  \__/ \__/          " % (xchat.get_info('channel'))) 
    xchat.command("msg %s \x038    \ \\ (oo) (oo)          " % (xchat.get_info('channel')))
    xchat.command("msg %s \x038     \_\\/~~\_/~~\_         " % (xchat.get_info('channel')))
    xchat.command("msg %s \x038    _.-~===========~-._     " % (xchat.get_info('channel'))) 
    xchat.command("msg %s \x038   (___________________)    " % (xchat.get_info('channel')))
    xchat.command("msg %s \x038         \_______/ jro      " % (xchat.get_info('channel')))
    
    return xchat.EAT_ALL

#This is where we packed the gestures.Hack to taste.

def automsg_cb( word, word_eol, userdata ):
    xchat.prnt(repr(word))
    if len(word) < 2:
       xchat.prnt('What should the message be?')
    else:           
       skipcount = 0
       message = ''
       for eachword in word:
          if skipcount < 3:
             skipcount = skipcount + 1
          else:
             message = message + ' ' + eachword 
       xchat.command('timer -refnum 1 -repeat %s %s me %s' % ( word[1], word[2], message ))
    return xchat.EAT_ALL

def bigpaste_cb(word, word_eol, userdata):
    maxlines = 10
    linecount = 0
    try:
      FileId=open(word[1],'r')
      try:
        FileText=string.replace(FileId.readline(),'\n','')
        while FileText<>'' and linecount < maxlines:
           linecount = linecount + 1
           xchat.command("msg %s %s"%(xchat.get_info('channel'),FileText))
           FileText=string.replace(FileId.readline(),'\n','')
           if linecount == maxlines:
              xchat.command("me has exceeded maximum line count - Klingon in the neutral zone")
      except:
           pass
      FileId.close()
    except:
        xchat.prnt('%s does not exist or cannot be opened'%word[1])
    return(xchat.EAT_ALL)

def ferret_cb(word, word_eol, userdata):
    if len(word) < 2:
       xchat.prnt("Tell me who to drop!")
    else:
       insult("drops a rabid ferret down %s's pants",word[1])
    return xchat.EAT_ALL

def fog_cb( word, word_eol, userdata):
    xchat.command("me Lost in a fog so thick you can cut it in chunks and make igloos with it.")
    return xchat.EAT_ALL

def greet_cb( word, word_eol, userdata ):
    if len(word) < 2:
       xchat.prnt("Tell me who to greet!")
    else:
       xchat.command("msg %s Welcome to %s %s" %
              (xchat.get_info('channel'),xchat.get_info('channel'), word[1]) )
    return xchat.EAT_ALL

def herring_cb(word, word_eol, userdata):
    if len(word) < 2:
       xchat.prnt("Tell me who to wack!")
    else:
       insult("dumps basket of herrings over %s's head",word[1] )
    return xchat.EAT_ALL

def induct_cb( word, word_eol, userdata ):
    if len(word) < 2:
       xchat.prnt("Tell me who to induct")
    else:
       insult("gets sacred channel mackerel, and ceremoniously smacks %s over the head",
              ( word[1] ) )

def insult(SmartRemark,Arguments):
    global preview
    if ( preview == "On"):
       xchat.prnt(SmartRemark%Arguments)
    else:
       xchat.command( ('me ' + SmartRemark) % Arguments)

def laugh_cb( word, word_eol, userdata):
    xchat.command("me rolls in the tall grass laughing his ass off, suddenly falls off cliff right in the lake below.. mumbles something about warning signs and calls team of crack attorneys.""")
    return xchat.EAT_ALL

def l33t(message):
    message=string.replace(message,'e','3')
    message=string.replace(message,'t','+')
    message=string.replace(message,'l','1')
    message=string.replace(message,'i','!')
    message=string.replace(message,'h','4')
    message=string.replace(message,'o','0')
    message=string.replace(message,'b','6')
    return(message)

def l33t_cb(word,word_eol, userdata):
    skipone=1
    message = ''
    for eachword in word:
        if skipone:
           skipone=0
        else:
           message = message + ' ' + eachword
    message=l33t(message)
    # My heart just isn't in this
    xchat.command("msg %s %s"%(xchat.get_info('channel'),message))
    return xchat.EAT_ALL

def lemming_cb( word, word_eol, userdata):
    xchat.command( \
    "me \x039Obviam marinus  \x038:=  \x0311:=  \x034:=  \x037O:=  \x036:=  \x0313:=  \x030:= ")
    return xchat.EAT_ALL     
       
def localinfo_cb(word, word_el, userdata):
    XCString = sysinfo( word, word_el, userdata)
    XCString = string.replace(XCString, "\t", "")
    xchat.prnt(XCString)
    return xchat.EAT_ALL  

def mackerel_cb(word, word_eol, userdata):
    if len(word) < 2:
       xchat.prnt("Tell me who to dump on!")
    else:
       insult("whacks %s over head with a mackerel",word[1])
    return xchat.EAT_ALL

def pastefile_cb(word, word_eol, userdata):
    try:
      FileId=open(word[1],'r')
      FileText=FileId.read()
      FileId.close()
      if len(FileText) > 2000:
       xchat.command("me tried to insert a file over 2000 characters - but we stopped it")
      else:
       xchat.command("me %s"%FileText)
    except:
      pass

def reverseit(topic):
    newtopic = ''
    for i in range( len(topic) ):
        j=len(topic) - i -1 
        newtopic = newtopic + topic[j]  
    return(newtopic)
   
def reverse_cb(word, word_eol, userdata):
    skipone=1
    topic = ''
    for eachword in word:
        if skipone:
           skipone=0
        else:
           topic = topic + ' ' + eachword

    newtopic = reverseit(topic)
    xchat.command("msg %s %s"%(xchat.get_info('channel'),newtopic))
    return xchat.EAT_ALL

def revl33t_cb(word,word_eol, userdata):
    skipone=1
    message = ''
    for eachword in word:
        if skipone:
           skipone=0
        else:
           message = message + ' ' + eachword
    message=reverseit(l33t(message))
    xchat.command("msg %s %s"%(xchat.get_info('channel'),message))
    return xchat.EAT_ALL

def say(Remark,Arguments):
    xchat.command('msg %s %s' % ( xchat.get_info('channel'),
                                 (Remark % Arguments) 
                                )
                 )

def squirrel_cb( word, word_eol, userdata ):
    if len(word) < 2:
       xchat.prnt("Tell me who to slap!")
    else:
       insult("slaps %s with a wet squirrel",word[1])
    return xchat.EAT_ALL

def stats_cb( word, word_eol, userdata):
    xchat.command("me Highly recommends http://arnolds.dhs.org/static/stats/lemmings.html for the latest in channel statistics.""")
    return xchat.EAT_ALL

def tst_cb(word, word_eol, userdata):
    xchat.command("msg %s \x034,2 This is a test" % (xchat.get_info('channel')))
    return xchat.EAT_ALL


#Administrative section.Everyting for channel administration goes here.

def credits_cb(word, word_eol, userdata):
    xchat.prnt('\x0307 Trilliji and FuzzyTheBear\x27s Hacked Up Onion Script')
    xchat.prnt('\x0309 Copyleft 2003 onioN - Under terms of GNU Public License v2 or later')
    xchat.prnt('\x0309 Copyleft 2003 Trilliji - Under terms of GNU Public License v2 or later')
    xchat.prnt('\x0309 Copyleft 2003 FuzzyTheBear - Under terms of GNU Public License v2 or later')
    xchat.prnt('\x0309 Copyleft 2003 ProGuy - Under terms of GNU Public License v2 or later')
    xchat.prnt('\x0313 Come an visit FuzzyTheBear, ProGuy and Trilliji - irc.freenode.net #lemmings')
    xchat.prnt('\x0313 If there is something you would like let us know') 
    return xchat.EAT_ALL

def newtopic_cb( word, word_eol, userdata ):
    if len(word) < 2:
       xchat.prnt('What should the Topic be?')
    else:
       xchat.command('msg ChanServ op %s' % (xchat.get_info('channel')))
       time.sleep(2)
       skipone=1
       topic = ''
       for eachword in word:
           if skipone:
              skipone=0
           else:
              topic = topic + ' ' + eachword 
       xchat.command('topic %s' % ( topic ))
       xchat.command('deop %s' % (xchat.get_info('nick')))
    return xchat.EAT_ALL

def opnkick_cb( word, word_eol, userdata ):
    if len(word) < 2:
       xchat.prnt('Tell me who to kick!')
    else:
       xchat.command('msg ChanServ op %s' % (xchat.get_info('channel')))
       time.sleep(2)
       xchat.command('kick %s' % ( word[1] ))
       xchat.command('deop %s' % (xchat.get_info('nick')))
    return xchat.EAT_ALL


#XMMS section . ProGuy did it under duress.Strong arm tactics have
#been used to get this work done.No animals were harmed during this phase.

if xmms_installed:
  class FuzzyXMMS:
    def __init__(self):
        self.currentlyPlaying = -1
        self.announceChannels = []

    def constructPlayingString(self):
        if xmms.is_playing():
            self.currentlyPlaying = xmms.get_playlist_pos()
            totalTime = xmms.get_playlist_time(self.currentlyPlaying)
            playedTime = xmms.get_output_time()
            return xmms.get_playlist_title(self.currentlyPlaying) +\
                       " (" + self.formatTime(playedTime) + " / " +\
                       self.formatTime(totalTime) + ")"
                
    def showPlaying(self):
        xchat.command("me is currently listening to " +
                      self.constructPlayingString())

    def announceToChannel(self, channel):
        xchat.command("msg " + channel + " I'm listening to " +
                      self.constructPlayingString())

    # Time is given in ms to formatTime, it will output a nice string
    def formatTime(self, time):
        mins = time / 60000
        rem = time % 60000
        secs = rem / 1000
        if mins < 10:
            shMins = "0"+str(mins)
        else:
            shMins = str(mins)
            
        if secs < 10:
            shSecs = "0"+str(secs)
        else:
            shSecs = str(secs)
            
        return shMins + ":" + shSecs

    def subscribe(self, channel):
        self.announceChannels.append(channel)

    def unsubscribe(self, channel):
        self.announceChannels.remove(channel)

    def showSubscribers(self):
        print self.announceChannels
                        
    def xchatcommand_cb(self, word, word_eol, userdata):
        if len(word) < 2:
            print "I need an argument, see /help XMMS for more information"
            return xchat.EAT_ALL
        else:
            if word[1] == "playing":
                self.showPlaying()
            elif word[1] == "next":
                xmms.playlist_next()
            elif word[1] == "prev":
                xmms.playlist_prev()
            elif word[1] == "pause":
                xmms.pause()
            elif word[1] == "play":
                xmms.play()
            elif word[1] == "stop":
                xmms.stop()
            elif word[1] == "subscribe" and len(word) >= 3:
                self.subscribe(word[2])
            elif word[1] == "unsubscribe" and len(word) >= 3:
                self.unsubscribe(word[2])
            elif word[1] == "show":
                self.showSubscribers()
            else:
                print "Unknown usage of /XMMS, see /help XMMS for help"
                return xchat.EAT_ALL
            return xchat.EAT_ALL

    def xchatTimeout_cb(self, userdata):
        playing = xmms.get_playlist_pos()
        if playing != self.currentlyPlaying:
            for i in range(len(self.announceChannels)):
                self.announceToChannel(self.announceChannels[i])

        return 1

    def helpText(self):
        return "/XMMS <command>\n"+\
               "      playing -- Tell the current channel what you are listening to\n"+\
               "      next -- Skip to next song in the playlist\n"+\
               "      prev -- Skip to the previous song in the playlist\n"+\
               "      stop -- Same as pressing the stop button in XMMS\n"+\
               "      pause -- Same as pressing the pause button in XMMS\n"+\
               "      play -- Same as pressing the play button in XMMS\n\n"+\
               "      subscribe <channel> -- subscribes channel to the announce system\n"+\
               "      unsubscribe <channel> -- Unsubscribes channel from the announce system\n"+\
               "      show -- Show channels in the announce system\n"

else:
  xchat.prnt("""Lemmings script loaded without XMMS Support.
  Get it at http://http://www.via.ecp.fr/~flo/2002/PyXMMS""")
  class NoXMMS:
    def xchatcommand_cb(self, word, word_eol, userdata):
        xchat.prnt("XMMS Python Module not installed.")
    def helpText(self):
        return("XMMS Python Module not installed.")
    def xchatTimeout_cb(self, userdata):
        return("XMMS Python Module not installed.")

# Create a new instance of the xmmsXchat module.

if xmms_installed:
  m = FuzzyXMMS()
else:
  m = NoXMMS()

helpdict={
"aliens":
"""Displays a small text art of aliens in a saucer.""",

"automsg":
"""Provides a repeating message for limited repetition.
   /automsg <seconds delay> <# repetitions> <Message>""",

"bigpaste":
"""Pastes contents of file into channel. (Limited to 10 lines)
   /bigpaste <filename>""",

"bull":
"""Displays a bull meter.
   /bull <Level between 0 and 10>""",

"bullhigh":
"""Displays a bull meter with level 9.
   /bullhigh""",

"bulllow":
"""Displays a bull meter with level 1.
   /bulllow""",

"bullmed":
"""Displays a bull meter at level 5.
   /bullmed""",

"chanserv":
"""Transmits a semicolon delimited list of commands to chanserv
   /chanserv <options>""",

"crap":
"""Displays a VU Style meter with high reading.
   /crap""",

"credits":
"""Gives credit where credit is due.
   /credit""",

"ferret":
"""Drops a ferret down someone's shorts - fun to do to Bilbo.
   /ferret <nick>""",

"fog":
"""Displays the lost in fog message.
   /fog""",

"greet":
"""Welcomes someone to a channel with minimal typing.
   /greet <nick>""",

"helpme":
"""Provides either a list of commands, or help on a specific command.
  /helpme - list of commands
  /helpme <command> - Provides help on the <command>""",

"herring":
"""Dumps a basket of these critters over someones head.
   /herring <nick>""",

"induct":
"""Officially welcomes someone to channel.
   /induct <nick>""",

"info":
"""Displays channel information.
   /info""",

"identify":
"""Sends identification to nickserv.
   /identify <identification>""",

"laugh":
"""A descriptive, laugh with actions.
   /laugh""",

"l33t":
"""Does silly l33t stuff.
   /l33t <text>""",

"lemming":
"""Our motto.
   /lemming""",

"littlemeter":
"""Displays a small meter with descriptive text.
   /littlemeter <level> <text>""",

"localinfo":
"""Displays system information to local screen only.
   /localinfo""",

"mackerel":
"""Provides action for smacking someone on the head with a mackerel
   /mackerel <nick> - Smacks the <nick> on the head with a mackerel""",

"newtopic":
"""Ops you, and then sets the topic.
   /newtopic <topic>""",

"nickserv":
"""Sends a semicolon delimited list of commands to nickserv.
   /nickserv <options>""",

"opnkick":
"""Ops you, and then kicks someone.
   /opnkick <nick>""",

"pastefile":
"""Pastes a file into a channel. ( Limited to 2000 characters )
   /pastefile <filename>""",

"preview":
"""Turns on/off preview mode to view an insult before using it :).
   /preview  On|Off""",

"rev":
"""Reverses the order of a text string.
   /rev <text>""",

"revl33t":
"""Reverses and t33t's text. ( Why did we do this? )
   /revl33t <text>           ( because we could)""",

"stats":
"""Posts the stat engine URL for the channel.
   /stats""",

"squirrel":
"""Slaps someone with a wet squirel.
   /squirrel <nick>""",

"sysinfo":
"""Displays system information.
   /sysinfo""",

"test":
"""A test stub, enter with caution.
   /test <could be anything>""",

"tiny":
"""A one line meter with level and text.
   /tiny <level> <text>""",

"XMMS":
""" Controls XMMS posting to channel.
    /XMMS <option>
    Where options are:
       playing -- Tell the current channel what you are 
                  listening to
       next -- Skip to next song in the playlist
       prev -- Skip to the previous song in the playlist
       stop -- Same as pressing the stop button in XMMS
       pause -- Same as pressing the pause button in XMMS
       play -- Same as pressing the play button in XMMS
 
       subscribe <channel> -- subscribes channel to the 
               announce system
       unsubscribe <channel> -- Unsubscribes channel from 
               the announce system
       show -- Show channels in the announce system """
}
  
def helpme_cb( word, word_eol, userdata ):
    if len(word) < 2:
       xchat.prnt('Lemmings Commands')
       sequence = helpdict.keys()
       sequence.sort()
       for command in sequence:
           xchat.prnt(command);
    else:
       if helpdict.has_key(word[1]):
          xchat.prnt(helpdict[word[1]])
    return xchat.EAT_ALL

def preview_cb( word, word_eol, userdata ):
    global preview
    if len(word) < 2:
       xchat.prnt("Preview is set to %s"%preview)
    else:
       test = word[1].lower()
       xchat.prnt( test )
       if ( test == "off"):
          preview = "Off"
          xchat.prnt("Preview set to Off")
       else:
          preview = "On"
          xchat.prnt("Preview set to On")

    return xchat.EAT_ALL

def Send_To_Nickserv(message):
    xchat.command('msg Nickserv %s' % (message))

def identify_cb( word, word_eol, userdata):
    if len(word) < 2:
       xchat.prnt('You must identify with something')
    else:
       Send_To_Nickserv("IDENTIFY %s"%(word[1]))
    return xchat.EAT_ALL

def nickserv_cb( word, word_eol, userdata ):
    if len(word) < 2:
       xchat.prnt("nickserv requires options")
    else:
       BuildCommand = ""
       for wordx in word:
           if wordx == "nickserv":
              continue
           if wordx[len(wordx)-1] == ";":
              BuildCommand = BuildCommand + " " + wordx[0:len(wordx)-1]
              Send_To_Nickserv(BuildCommand)
              BuildCommand = ""
           else:
              BuildCommand = BuildCommand + " "  + wordx
           if len(BuildCommand) > 0:
              Send_To_Nickserv(BuildCommand)

    return xchat.EAT_ALL

def Send_To_Chanserv(message):
    xchat.command('msg ChanServ %s' % (message))   
 

def chanserv_cb( word, word_eol, userdata):
    if len(word) < 2:
       xchat.prnt("chanserv requires options")
    else:
       BuildCommand = ""
       for wordx in word:
           if wordx == "chanserv":
              continue
           if wordx[len(wordx)-1] == ";":
              BuildCommand = BuildCommand + " " + wordx[0:len(wordx)-1]
              Send_To_Chanserv(BuildCommand)
              BuildCommand = ""
           else:
              BuildCommand = BuildCommand + " "  + wordx
           if len(BuildCommand) > 0:
              Send_To_Chanserv(BuildCommand)

    return xchat.EAT_ALL

def info_cb( word, word_eol, userdata ):
    Send_To_Chanserv("info %s"%(xchat.get_info('channel')))
   
#For good looks .. all xchat.hook* is in here ..  :) 
xchat.hook_command("aliens",aliens_cb,help="/aliens <No Args>")
xchat.hook_command("automsg",automsg_cb,help="/automsg <repeat> <delay> <Message>")
xchat.hook_command("bigpaste",bigpaste_cb,help="/bigpaste <filename>")
xchat.hook_command("bull", bull_cb, help="/bull <level between 0 and 10>")
xchat.hook_command("bullh", bullh_cb, help="/bullhigh <No Args>")
xchat.hook_command("bulll", bulll_cb, help="/bulllow <No Args>")
xchat.hook_command("bullm", bullm_cb, help="/bullmed <No Args>")
xchat.hook_command("bullhigh", bullhigh_cb, help="/bullhigh <No Args>")
xchat.hook_command("bulllow", bulllow_cb, help="/bulllow <No Args>")
xchat.hook_command("bullmed", bullmed_cb, help="/bullmed <No Args>")
xchat.hook_command("chanserv",chanserv_cb, help="/chanserv <options>")
xchat.hook_command("crap", crap_cb, help="/crap <No Args>")
xchat.hook_command("credits",credits_cb,help="/credits <No Args>")
xchat.hook_command("ferret", ferret_cb, help="/ferret <List of folks>")
xchat.hook_command("fog", fog_cb, help="/fog <No Agrs>")
xchat.hook_command("greet", greet_cb, help="/greet <who>")
xchat.hook_command("herring", herring_cb, help="/herring <List of folks>")
xchat.hook_command("helpme", helpme_cb, help="/helpme <command>")
xchat.hook_command("induct",induct_cb,help="/induct <who>")
xchat.hook_command("info",info_cb,help="/info <No Args>")
xchat.hook_command("identify",identify_cb,help="/identify <identification>")
xchat.hook_command("laugh",laugh_cb,help="/laugh <No Args>")
xchat.hook_command("l33t",l33t_cb,help="/l33t senseless garbage")
xchat.hook_command("lemming", lemming_cb, help="/lemming <No Args>")
xchat.hook_command("littlemeter",littlemeter_cb,help="/littlemeter <rating> <caption>")
xchat.hook_command("localinfo", localinfo_cb, help="/localinfo <No Args>")
xchat.hook_command("mackerel", mackerel_cb, help="/mackerel <List of folks>")
xchat.hook_command("newtopic",newtopic_cb,help="/newtopic <Topic>")
xchat.hook_command("nickserv",nickserv_cb,help="/nickserv <options>")
xchat.hook_command("opnkick",opnkick_cb, help="/opnkick <who>")
xchat.hook_command("pastefile",pastefile_cb,help="/pastefile <filename>")
xchat.hook_command("preview",preview_cb,help="/preview On|Off")
xchat.hook_command("rev",reverse_cb,help="/rev <text>")
xchat.hook_command("revl33t",revl33t_cb,"/l33t more sensless garbage")
xchat.hook_command("stats",stats_cb,help="/stats <No Args>")
xchat.hook_command("squirrel",squirrel_cb, help="/squirrel <who>")
xchat.hook_command("sysinfo", sysinfo_cb, help="/sysinfo <No Args>")
xchat.hook_command("test",tst_cb, help="/test <No Args>")
xchat.hook_command("tiny",tiny_cb,help="/tiny <rating> <caption>")

# Setup the callback function for the /XMMS command.
xchat.hook_command("XMMS", m.xchatcommand_cb, help=m.helpText())
# Setup the timer for the announce system. Once every 5 second should
# be good enough for most people
if xmms_installed:
   xchat.hook_timer(5000, m.xchatTimeout_cb)
xchat.prnt("lemmings module Version %s load complete! See /credits" % (version))

