Esempio n. 1
0
def rollInfo(bot, update):
    if not isNewCommand(update):
        return

    wks = auth()

    suggestions = filter(fNonEmpty, map(fValue, wks.range('B4:B100')))
    count = len(suggestions)

    if count < 2:
        return

    values = getWeights(count)

    array = update.message.text.split(" ")
    if len(array) > 1:
        try:
            position = int(array[1])
            prob = values[position - 4] * 100
            reply(
                update, "Probability of rolling {0} is {1:.1f}%".format(
                    position, prob))
            return
        except Exception as e:
            print(e)

    first = values[0] * 100
    last = values[-1] * 100
    reply(
        update,
        "Roll probability (linear distribution):\nOldest: {0:.1f}%\nNewest: {1:.1f}%"
        .format(first, last))
Esempio n. 2
0
def countSuggestions(bot, update):
    if not isNewCommand(update): return

    array = update.message.text.split(" ")
    if len(array) < 2:
        reply(update, "Enter the name to see how many albums he has suggested.")
        return

    name = update.message.text.split(" ")[1]
    wks = auth()

    originalRows = list(map(fValue, wks.range('B4:B100')))
    foundRows = list(filter(lambda value: value.lower() == name.lower(), originalRows))
    suggestionsCount = len(foundRows)

    originalArchive = list(map(fValue, wks.range('G4:G1300')))
    foundArchive = list(filter(lambda value: value.lower() == name.lower(), originalArchive))
    archiveCount = len(foundArchive)

    if suggestionsCount > 0:
        if archiveCount > 0:
            reply(update, "{} current suggestions by {}. Also {} in archive.".format(
                suggestionsCount, foundRows[0], archiveCount))
        else :
            reply(update, "{} current suggestions by {}.".format(
                suggestionsCount, foundRows[0]))
    elif archiveCount > 0:
        reply(update, "No current suggestion by {} but there are {} in archive.".format(
            foundArchive[0]))
    else:
        reply(update, "No such thing.")
Esempio n. 3
0
def adminList(bot, update):
    if not isNewCommand(update):
        return
    text = "These <i>(%username%)</i>s have access to the bot's #musictheatre session commands:\n"
    for name in admins:
        text += "- " + name + "\n"
    text += "If they are not around, God help you."
    reply(update, text.encode('utf-8'), parse_mode="HTML")
Esempio n. 4
0
def shit(bot, update):
    if not isNewCommand(update):
        send(bot,
             "Hey folks, our spreadshit is here: http://bit.ly/mtheatre",
             parse_mode="HTML")
    else:
        reply(update,
              "Here's the link to our spreadshit: http://bit.ly/mtheatre")
Esempio n. 5
0
def adminHelp(bot, update):
    if not isNewCommand(update):
        return
    reply(
        update,
        "Here's the list of admin commands:\n<b>/roll</b> to randomly pick a suggestion\n<b>/c**t</b> to initiate the countdown\n<b>/archive [roll]</b> to archive a suggestion\n<b>/new [roll]</b> will set current album playing and archive the suggestion\n\nUse these while in session:\n<b>/n</b> to set current song playing\n<b>/over or /abort</b> to end the session"
        .encode('utf-8'),
        parse_mode="HTML")
def over(bot, update):
    if not checkAccess(update):
        return
    config = loadConfig()
    if config['isPlaying'] == True:
        if isNewCommand(update):
            send(bot, "#musictheatre it's OVER.")
        endSession()
    else:
        reply(update, "You betcha it is.")
Esempio n. 7
0
def help(bot, update):
    if not isNewCommand(update):
        return
    if not checkAccess(update):
        return
    reply(
        update,
        "Here's the list of commands:\n<b>/sheet</b> gives you the link to our spreadsheet\n<b>/tagme</b> to subscribe to session notifications [private message only]\n<b>/suggest</b> will ask if anyone wants to start a session\n<b>/admins</b> for the list of people who have admin access\n\nUse these while in session:\n<b>/song</b> or <b>/album</b> to find out what's playing"
        .encode('utf-8'),
        parse_mode="HTML")
Esempio n. 8
0
def currentTrack(bot, update):
    if not isNewCommand(update): return

    config = loadConfig()
    if config['isPlaying'] == True:
        if len(config['artist']) > 0 and len(config['album']) > 0 and len(
                config['track']) > 0:
            text = "Now playing: {0} - {1} (from {2})".format(
                config['artist'], config['track'], config['album'])
            reply(update, text)
    else:
        reply(update, "Nothing is playing.")
Esempio n. 9
0
def currentAlbum(bot, update):
    if not isNewCommand(update): return

    config = loadConfig()
    if config['isPlaying'] == True:
        if len(config['artist']) > 0 and len(config['album']) > 0:
            text = "{0} by {1}".format(config['album'], config['artist'])
            if config['year'] is not None:
                text += " ({})".format(config['year'])
            if config['suggested'] is not None:
                text += " [Suggested by: {}]".format(config['suggested'])
            reply(update, text)
    else:
        reply(update, "Nothing is playing.")
Esempio n. 10
0
def addSuggestion(bot, update):
    
    if not isNewCommand(update): return

    array = re.split("[;\n]", update.message.text)

    if len(array) != 4:
        reply(update, "Enter suggester name, artist, year and title of release (use semicolon or new line to divide input)\nLike this: \"Yaro; Pink Floyd; The Dark Side of the Moon; 1973\"")
        return

    wks = auth()
    
    # name artist year album
    name = array[0].strip()[5:]
    artist = array[1].strip()
    album = array[2].strip()
    year = int(array[3].strip())

    currentYear = date.today().year

    if year > currentYear or year < 1900:
        reply(update, "Wrong year")
        return
    
    suggestionNames = list(filter(fNonEmpty, map(fValue, wks.range('B4:B100'))))
    foundRows = list(filter(lambda value: value.lower() == name.lower(), suggestionNames))

    if len(foundRows) >= 5:
        reply(update, "This one already has enough suggestions.")
        return

    newSuggestion = len(suggestionNames) + 4

    # add suggestion
    newCells = wks.range('B'+str(newSuggestion)+':E'+str(newSuggestion))
    newCells[0].value = name
    newCells[1].value = artist
    newCells[2].value = year
    newCells[3].value = album

    message = "{} by {} ({}) is now suggested by {}.".format(album, artist, year, name)

    if debug: 
        reply(update, message + " (not really)")
        return # todo move bot to a test sheet

    wks.update_cells(newCells)
    reply(update, message)
Esempio n. 11
0
def roll(bot, update):
    if not isNewCommand(update):
        return
    if not checkAccess(update):
        return
    config = loadConfig()

    if config['isPlaying'] == False:
        wks = auth()
        suggestionNames = filter(fNonEmpty, map(fValue, wks.range('B4:B100')))
        illegalNames = map(fLower,
                           filter(fNonEmpty, map(fValue, wks.range('G4:G9'))))
        suggestionsCount = len(suggestionNames)

        if suggestionsCount > 0:
            for _ in range(5):

                # get random (favor older suggestions)
                result = getRandom(suggestionsCount - 1)

                spreadsheetNumber = result + 4
                rolled = map(
                    fValue,
                    wks.range('A' + str(spreadsheetNumber) + ':E' +
                              str(spreadsheetNumber)))
                if not rolled[1].lower() in illegalNames:
                    config['lastRoll'] = spreadsheetNumber
                    saveConfig(config)

                    send(bot,
                         "<b>Rolled {}</b>\n{} - {} ({})\nSuggested by: {}".
                         format(spreadsheetNumber, rolled[2].encode('utf-8'),
                                rolled[4].encode('utf-8'),
                                rolled[3].encode('utf-8'),
                                rolled[1].encode('utf-8')),
                         parse_mode="HTML")
                    return
                else:
                    send(
                        bot, "Rolled {}. {} - illegal.".format(
                            spreadsheetNumber, rolled[1].encode('utf-8')))
        else:
            reply(update, "No suggestions found.")
    else:
        reply(update,
              "Another session is still on. I'm afraid I can't do that.")
Esempio n. 12
0
def abort(bot, update):
    if not checkAccess(update):
        return
    config = loadConfig()
    if config['isPlaying'] == True:
        endSession()

        if isNewCommand(update):
            send(bot, "#musictheatre it's ABORTED.")

            # add 'aborted'
            wks = auth()
            archiveCells = wks.range('F4:L4')
            if archiveCells[4].value.encode('utf-8') == config['album']:
                archiveCells[6].value = "aborted"
                wks.update_cells(archiveCells)
    else:
        reply(update, "I'll abort you, you f*****g bitch.")
Esempio n. 13
0
def roll(bot, update):
    if not isNewCommand(update): return
    if not checkAccess(update): return

    config = loadConfig()
    if config['isPlaying'] == True:
        reply(update, "Another session is still on. I'm afraid I can't do that.")
        return

    wks = auth()
    suggestionNames = list(filter(fNonEmpty, map(fValue, wks.range('B4:B100'))))
    illegalNames = list(map(fLower, list(filter(fNonEmpty, map(fValue, wks.range('G4:G9'))))))

    values = []
    for i in range(len(suggestionNames)):
        name = suggestionNames[i].lower()
        if name not in illegalNames:
            values.append({"number": i+4, "name": name })       

    validSuggestionsCount = len(values)

    if validSuggestionsCount == 0:
        reply(update, "No suggestions found.")
        return

    # get random (favor older suggestions)
    rolled_from_valid = getRandom(validSuggestionsCount-1)
    result = values[rolled_from_valid]["number"]

    spreadsheetNumber = result
    rolled = list(map(fValue, wks.range('A'+str(spreadsheetNumber) +':E'+ str(spreadsheetNumber))))
    
    config['lastRoll'] = spreadsheetNumber
    saveConfig(config)

    send(bot,
        "<b>Rolled {}</b>\n{} - {} ({})\nSuggested by: {}" .format(
            spreadsheetNumber, rolled[2], 
            rolled[4], rolled[3], 
            rolled[1]), parse_mode="HTML")
Esempio n. 14
0
def tagMe(bot, update):
    if not isNewCommand(update):
        return
    if isNewSeeds(update):
        reply(
            update,
            "You have to private message me this command, because I am forbidden to initiate a chat with you."
        )
    else:
        id = update.effective_user.id
        config = loadConfig()
        if 'tagList' not in config:
            config['tagList'] = []
        if id not in config['tagList']:
            config['tagList'].append(id)
            bot.sendMessage(
                id,
                "You are now subscribed to /tag updates. Use /stop to unsubscribe."
            )
        else:
            bot.sendMessage(id, "You are already subscribed to /tag updates.")
        saveConfig(config)
Esempio n. 15
0
def taginfo(bot, update):
    reply(update,
          "PM /tagme to the bot to subscribe to #musictheatre updates.")
Esempio n. 16
0
def start(bot, update):
    reply(
        update,
        "<b>Welcome to Music Theatre!</b>\nThis bot is designed to assist newseeds to discover music.\n",
        parse_mode="HTML")
    help(bot, update)