Example #1
0
def last_played(irc, args):
    total_search = True
    opts = get_long_opts(args)
    song = txtfunctions.acronym_replace(' '.join(opts['other']))

    if ((opts['range'] != None and opts['range'] != [-1,-1]) or
        opts['country'] != None or
        opts['tour'] != None):
        total_search = False
    
    if song.lower() in [s.lower() for s in filehandle.get_list('text/setlist')]:
        gig = filehandle.get_list('text/gig')
        if date_in_range(gig, opts['range']):
            irc.msg ('%s was last played at: %s' % (song, gig[0]))
            return

    if total_search:
        database = filehandle.get_list('text/archive.db')
        for entry in database:
            if entry.startswith('lp!'):
                db_song = entry.split('!')[1].split('::')[0]
                if song.lower() == db_song:
                    db_file = entry.split('!')[1].split('::')[1]
                    setlist = filehandle.get_list(db_file)
                    irc.msg('%s was last played at: %s' % (song, setlist[0]))
                    return
            
    tours = sorted(os.listdir('GigArchive'))
    for tour in reversed(tours):
        if opts['tour'] is not None:
            if opts['tour'] != tour_name(tour):
                continue
            
        gigs = sorted(os.listdir('GigArchive/%s' % tour))
        for filename in reversed(gigs):
            if (not date_in_range(filename, opts['range']) or
                (opts['country'] is not None and
                 opts['country'] != country_code(filename))):
                continue
            gig_file = 'GigArchive/%s/%s' % (tour, filename)
            setlist = filehandle.get_list(gig_file)
            if song.lower() in [s.lower() for s in setlist]:
                irc.msg('%s was last played at: %s' % (song, setlist[0]))
                if total_search:
                    if len(database) >= 100:
                        database.pop(0)
                        database.append('lp!%s::%s' % (song.lower(), gig_file))
                        filehandle.put_list('text/archive.db', database)
                return
    irc.msg('I do not seem to have information on that song for the given options.')
Example #2
0
def song_count(irc, args):
    total_search = True

    opts = get_long_opts(args)
    if ((opts['range'] != None and opts['range'] != [-1,-1]) or
        opts['country'] != None or
        opts['tour'] != None):
        total_search = False

    song = txtfunctions.acronym_replace(' '.join(opts['other']))

    database = filehandle.get_list('text/archive.db')
    if total_search:
        for entry in database:
            if entry.startswith('c!'):
                db_song = entry.split('!')[1].split('=')[0]
                if db_song == song.lower():
                    count = int(entry.split('!')[1].split('=')[1])
                    irc.msg("%s has been played %d times." % (song, count))
                    return
            
    count = 0
        
    tours = os.listdir('GigArchive')
    for tour in tours:
        if opts['tour'] == tour_name(tour):
            tours = [tour]
            break
        
    for tour in tours:
        gigs = os.listdir('GigArchive/%s' % tour)
        for filename in gigs:
            if not total_search:
                if (not date_in_range(filename, opts['range']) or
                    (opts['country'] is not None and
                     opts['country'] != country_code(filename))):
                    continue
            setlist = filehandle.get_list('GigArchive/%s/%s' % (tour, filename))
            if song.lower() in [s.lower() for s in setlist]:
                count = count + 1

    if total_search:
        if len(database) >= 100:
            database.pop(0)
        database.append('c!%s=%d' % (song.lower(), count))
        filehandle.put_list('text/archive.db', database)
    irc.msg("%s has been played %d times." % (song, count))
Example #3
0
def command_run(text, irc, commands):
    
    if text.IRCcmd == "JOIN" and irc.joinmsg() and irc.isAwake():
        if text.nick != irc.nick():
            irc.msg("Welcome to the sexy plane %s. "
                    "Enter !commands to view the bot functions." % text.nick)

    if text.nick in irc.modlist:
        if text.command in ("!wake\r\n", "!wake"):
            irc.wake()
            irc.resumeTimers()
            irc.msg("BellamyBot is online.")

        elif text.command in ("!sleep\r\n", "!sleep"):
            irc.sleep()
            irc.pauseTimers()
            irc.msg("Sleep mode activated")
        
        elif text.command == "!joinmsg":
            if text.argument in ("on\r\n", "on"):
                irc.activateJoinMsg()
                print("Join messages ON")
            elif text.argument in ("off\r\n", "off"):
                irc.deactivateJoinMsg()
                print("Join messages OFF")

        elif text.command == "!timers":
            if text.argument in ("on\r\n", "on"):
                irc.resumeTimers()
            elif text.argument in ("off\r\n", "off"):
                irc.pauseTimers()

        elif text.command == "!gamemode":
            if text.argument in ("on\r\n", "on"):
                irc.activateGames()
                print("Game mode ON")
            elif text.argument in ("off\r\n", "off"):
                irc.deactivateGames()
                print("Game mode OFF")
                
        elif text.command == "!setgig":
            try:
                filehandle.clear_file('text/gig')
                filehandle.list_append('text/gig', text.argument)
            except IOError as e:
                print(e)

        elif text.command == "!settour":
            try:
                filehandle.clear_file('text/tour')
                filehandle.list_append('text/tour', text.argument)
            except IOError as e:
                print(e)

        # Setlist controls
        elif text.command == "!add":
            txtfunctions.add_song(text.argument)
            undo.add()

        elif text.command == "!exp":
            original = filehandle.remove_nr(text.argument)
            check    = txtfunctions.acronym_replace(text.argument)
            if check == original:
                irc.msg("There is no expansion for " + original)
            else:
                irc.msg(original + " expands to " + check)
            
        elif text.command in ("!clearset\r\n", "!clearset"):
            try:
                filehandle.clear_file('text/setlist')
                undo.refresh()
            except IOError as e:
                print(e)
            irc.msg("Current setlist has been cleared.")

        elif text.command in ("!pop\r\n", "!pop"):
            try:
                txtfunctions.song_pop()
            except IOError as e:
                print(e)
                return
            except IndexError as i:
                print(i)
                return
            undo.add()
            irc.msg("The last song has been erased")

        elif text.command == "!insert":
            try:
                response = txtfunctions.insert_song(text.argument)
            except IOError as e:
                print(e)
                return
            if response.find('ERROR') == -1:
                undo.add()
            irc.msg(response)

        elif text.command == "!replace":
            try:
                response = txtfunctions.replace_song(text.argument)
            except IOError as e:
                print(e)
            if response.find('ERROR') == -1:
                undo.add()
            irc.msg(response)

        elif text.command == "!delete":
            try:
                response = txtfunctions.delete_song(text.argument)
            except IOError as e:
                print(e)
            if response != 'Could not delete any songs.':
                undo.add()
            irc.msg(response)
        
        elif text.command in ("!setprevious\r\n", "!setprevious"):
            try:
                response = txtfunctions.set_previous()
            except IOError as e:
                print(e)
            except RuntimeError as r:
                print(r)
            irc.msg(response)

        elif text.command in ("!undo\r\n", "!undo"):
            if undo.undo():
                irc.msg("Undid last change to setlist.")

        elif text.command in ("!redo\r\n", "!redo"):
            if undo.redo():
                irc.msg("Redid last change to setlist.")

        elif text.command == "!cmd":
            cmd.function(irc, commands, text.argument)
            
    # All user commands
    if text.command in ("!bot\r\n", "!bot"):
        statePhrase = ("BellamyBot version %s created by Kueller917. Status: "
                       % irc.version())
        if irc.isAwake():
            statePhrase = statePhrase + "ONLINE"
        else:
            statePhrase = statePhrase + "OFFLINE"

        irc.msg(statePhrase)

    elif text.command in ("!gig\r\n", "!gig"):
        try:
            gig = filehandle.get_list('text/gig')
        except IOError as e:
            print(e)
        irc.msg(gig[0])

    elif text.command in ("!previous\r\n", "!previous"):
        gigarchive.print_recent_setlist(irc)

    elif text.command == "!message":
        try:
            filehandle.list_append('text/ircmsg', "%s: %s" % (text.nick,
                                        filehandle.remove_nr(text.argument)))
        except IOError as e:
            print(e)
        if len(irc.owners) > 0:
            irc.memo(irc.owners[0], "You have a message from %s" % text.nick)

    elif text.command in ("!source\r\n", "!source"):
        sourceMsg = ("Get your own copy of BellamyBot today! %s" % irc.source())
        irc.msg(sourceMsg)

    # State dependent commands
    if irc.isAwake():
        
        # General commands
        if text.command in ("!setlist\r\n", "!setlist"):
            setmsg = "CURRENT SETLIST: "
            try:
                currentset = txtfunctions.print_set('text/setlist')
            except IOError as e:
                print(e)
            
            if currentset == '':
                currentset = "...is empty"
            setmsg = setmsg + currentset
            irc.msg(setmsg)

        elif text.command == "!count":
            gigarchive.song_count(irc, text.argument)

        elif text.command == "!lastplayed":
            song = txtfunctions.acronym_replace(text.argument)
            gigarchive.last_played(irc, song)

        elif text.command == "!findset":
            gigarchive.find_setlist(irc, text.argument.strip())

        elif text.command == "!loadset":
            date = text.argument.strip()
            setlist = gigarchive.print_set_by_date(irc, date)

        elif text.command == "!info":
            try:
                infolist = filehandle.get_list('text/info')
            except IOError:
                print('Error opening file info')
                return

            command = text.argument.strip()
            for line in infolist:
                if line.split(':')[0] == command:
                    irc.msg(line.split(':')[1])

        elif text.command == "!eval":
            ev = boteval.BotEval()
            ev.eval(irc, text.argument)

        elif text.command in ("!commands\r\n", "!commands"):
            irc.msg("Set commands: !gig, !setlist, !previous, !findset, "
                    "!loadset, !count, !lastplayed.")
            irc.msg("Other: !bot, !source, !closer, !opener, !realfan, "
                    "!roulette, !setfm, !ru-roulette, !setgen. Use !info "
                    "for a description of any command.")

        elif text.command.strip() in commands:
            cmd.execute(irc, commands, text)
            
        if irc.gamesActive():
            # Games
            if text.command in ("!closer\r\n", "!closer"):
                try:
                    closer = musegames.random_game('text/gigcloser')
                except IOError as e:
                    print(e)
                irc.msg("%s\'s gig has closed with %s!" % (text.nick, closer))

            elif text.command in ("!opener\r\n", "!opener"):
                try:
                    opener = musegames.random_game('text/opener')
                except IOError as e:
                    print(e)
                irc.msg("%s\'s gig has opened with %s!" % (text.nick, opener))

            elif text.command in ("!realfan\r\n", "!realfan"):
                if randint(0,1):
                    irc.msg("%s is a REAL FAN. Good for you." % text.nick)
                else:
                    irc.msg("%s is not a REAL FAN. Go away." % text.nick)

            elif text.command in ("!roulette\r\n", "!roulette"):
                output = musegames.T2L_roulette()
                if output != -1:
                    irc.msg(output)
                else:
                    irc.greenOn()
                    irc.greenNick(text.nick)
                    irc.msg("You landed on GREEN! Type !green to get your song")

            elif text.command in ("!green\r\n", "!green"):
                if irc.greenActive():
                    if irc.checkGreen(text.nick):
                        irc.greenOff()
                        irc.greenNick(None)
                        irc.msg(musegames.roulette_green(text.nick))
                    else:
                        irc.msg("You did not land on green.")

            elif text.command in ("!setfm\r\n", "!setfm"):
                setlist = setlistfm.get_setlist(irc.mbid())
                for messagePart in setlist:
                    irc.msg(messagePart)

            elif text.command in ("!manson\r\n", "!manson"):
                try:
                    mansons = musegames.manson_game(text.nick)
                except IOError as e:
                    print(e)
                except IndexError as i:
                    print(i)
                irc.msg(mansons)

            elif text.command in ("!ru-roulette\r\n", "!ru-roulette"):
                timercommands.russian_roulette(irc, text.nick)

            elif text.command in ("!setgen\r\n", "!setgen"):
                setlistgenerator.generate(irc)