Exemple #1
0
def c**t(bot, update):
    if not isNewCommand(update): return
    if not checkAccess(update): return 

    message = [1]

    if len(update.message.text.split(" ", 1)) > 1:
        message = update.message.text.split(" ", 1)[1].strip()
    else:
        message = randomCunt()
    send(bot, message)

    count = 5
    while count:
        send(bot, "{}".format(count))
        time.sleep(1)
        count -= 1

    send(bot, "PLAY!")

    config = loadConfig()
    if config['isPlaying'] == True: return

    # also call /new
    if config['lastRoll'] is not None:
        newAlbumSetPosition(bot, config['lastRoll'])

        # newAlbumSetPosition updates config, need to reload it from disk
        config = loadConfig() 
        config['lastRoll'] = None 
        saveConfig(config)
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.")
def c**t(bot, update):
    if not isNewCommand(update):
        return
    if checkAccess(update):
        message = [1]

        if len(update.message.text.split(" ", 1)) > 1:
            message = update.message.text.split(" ", 1)[1].strip()
        else:
            message = randomCunt()
        send(bot, message.encode('utf-8'))

        count = 5
        while count:
            send(bot, "{}".format(count))
            time.sleep(1)
            count -= 1

        send(bot, "PLAY!")

        # also call /new
        config = loadConfig()
        if config['lastRoll'] is not None:
            newAlbumSetPosition(bot, config['lastRoll'])
            config['lastRoll'] = None
            saveConfig(config)
def removeRoll(bot, update):
    if not isNewCommand(update):
        return
    if update.message.from_user.username == "ysoftware":
        config = loadConfig()
        config['lastRoll'] = None
        saveConfig(config)
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))
Exemple #6
0
def suggest(bot, update):
    if not isNewCommand(update): return
    
    config = loadConfig()
    if config['isPlaying'] == False:
        send(bot, "<b>Anyone in for a </b>#musictheatre<b> session?</b>", parse_mode="HTML")
    else:
        send(bot, "Another session is still in place.")
def archive(bot, update):
    if not isNewCommand(update):
        return
    if not checkAccess(update):
        return
    position = int(update.message.text.split(" ")[1])
    archiveDo(bot, position)
    send(bot, "Suggestion moved to the archive.")
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")
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")
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 update(bot, update):
    if not isNewCommand(update):
        return
    if not checkDevAccess(update):
        return
    bot.sendMessage(update.message.from_user.id, "Running the update...")
    subprocess.call("sudo /usr/local/tgbots/musictheatrebot/update.sh",
                    shell=True)
def sticker(bot, update):
    if not isNewCommand(update):
        return
    if not checkAccess(update):
        return
    if isNewSeeds(update):
        return
    message = update.message.text.split(" ", 1)[1].strip()
    bot.sendSticker(newseeds, message)
def say(bot, update):
    if not isNewCommand(update):
        return
    if not checkAccess(update):
        return
    if isNewSeeds(update):
        return
    message = update.message.text.split(" ", 1)[1].strip()
    send(bot, message.encode('utf-8'), parse_mode="HTML")
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")
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.")
def test(bot, update):
    if not isNewCommand(update):
        return
    if not checkDevAccess(update):
        return

    p = subprocess.Popen("cd /usr/local/tgbots/musictheatrebot; git log -1",
                         shell=True,
                         stdout=subprocess.PIPE,
                         stderr=subprocess.PIPE).communicate()[0]
    bot.sendMessage(update.message.from_user.id, p)
    bot.sendMessage(update.message.from_user.id, loadConfig())
def ball(bot, update):
    if isNewCommand(update):
        message = random.choice([
            "It is certain", "It is decidedly so", "Without a doubt",
            "Yes - definitely", "You may rely on it", "As I see it, yes",
            "Most likely", "Outlook good", "Signs point to yes", "Yes",
            "Reply hazy, try again", "Ask again later",
            "Better not tell you now", "Cannot predict now",
            "Concentrate and ask again", "Don’t count on it", "My reply is no",
            "My sources say no", "Outlook not so good", "Very doubtful"
        ])
        send(bot, message.encode('utf-8'))
Exemple #18
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.")
Exemple #19
0
def newAlbum(bot, update):
    if not isNewCommand(update): return
    if not checkAccess(update): return

    message = update.message.text.split(" ", 1)[1].strip()

    # new artist - album
    if " - " in message:
        artistName = message.split(" - ", 1)[0].strip()
        albumName = message.split(" - ", 1)[1].strip()
        newAlbumSet(bot, config, artistName, albumName, None, None)
    # new {number}
    else:
        newAlbumSetPosition(bot, message)
Exemple #20
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.")
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())

    if year > 2020 or year < 1900:
        reply(update, "Wrong year")
        return

    suggestionNames = filter(fNonEmpty, map(fValue, wks.range('B4:B100')))
    foundRows = 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

    wks.update_cells(newCells)

    reply(
        update,
        "{} by {} ({}) is now suggested by {}.".format(album.encode('utf-8'),
                                                       artist.encode('utf-8'),
                                                       year,
                                                       name.encode('utf-8')))
def tagPeople(bot, update):
    if not isNewCommand(update):
        return
    if not checkAccess(update):
        return
    if not isNewCommand(update):
        return
    config = loadConfig()
    if 'tagList' in config and len(config['tagList']) > 0:
        send(
            bot, "Notifying {} people... (/taginfo to learn).".format(
                len(config['tagList'])))
        send(bot,
             "<b>Anyone in for a </b>#musictheatre<b> session?</b>",
             parse_mode="HTML")
        for id in config['tagList']:
            if id != update.effective_user.id:
                try:
                    bot.sendMessage(id, "#musictheatre How about some music?")
                except:
                    print("{} blocked the bot.".format(id))
    else:
        send(bot, "No one is subscribed for /tag updates.")
Exemple #23
0
def nextSong(bot, update):
    if not isNewCommand(update): return
    if not checkAccess(update): return

    config = loadConfig()
    if config['isPlaying'] == True:
        trackName = update.message.text.split(" ", 1)[1].strip()
        if len(trackName) > 0 and len(
                config['artist']) > 0 and trackName != config['track']:
            config['track'] = trackName
            text = "#musictheatre {0} - {1}".format(config['artist'],
                                                    config['track'])
            send(bot, text)
            saveConfig(config)
    else:
        send(bot, "What album was that again?")
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.")
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.")
Exemple #26
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")
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)
Exemple #28
0
def today(bot, update):
    if not isNewCommand(update):
        return
    message = renew()
    send(bot, message)
def russian(bot, update):
    if not isNewCommand(update):
        return
    send(bot, "Putin Hates Us All", parse_mode="HTML")
def archive(bot, update):
    if not isNewCommand(update): return
    if not checkAccess(update): return
    
    position = int(update.message.text.split(" ")[1])
    archiveDo(bot, position)