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 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))
def newAlbumSetPosition(bot, position): config = loadConfig() if config['isPlaying'] == False: if int(position) >= 4: wks = auth() info = map(fValue, wks.range("B{0}:E{0}".format(position, position))) newAlbumSet(bot, config, info[1], info[3], info[2], info[0]) # archive as well archiveDo(bot, position) else: send(bot, "We're still in session.")
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 archiveDo(bot, position): if debug: send(bot, "Suggestion moved to the archive. (not really)") return # todo move bot to a test sheet wks = auth() now = getTime() archiveNames = list(filter(fNonEmpty, map(fValue, wks.range('G4:G1300')))) suggestionNames = list(filter(fNonEmpty, map(fValue, wks.range('B4:B100')))) lastSuggestion = len(suggestionNames) + 4 archiveLastPosition = len(archiveNames) + 4 rolledCells = wks.range('B'+str(position)+':E'+ str(position)) rolled = list(map(fValue, rolledCells)) # move archive cells down 1 row archiveOldCells = wks.range('F4:L'+str(archiveLastPosition+1)) lenArchiveOld = len(archiveOldCells) for i in reversed(range(len(archiveOldCells))): if lenArchiveOld > i + 7: archiveOldCells[i+7].value = archiveOldCells[i].value wks.update_cells(archiveOldCells) # move suggestion to F4 archiveCells = wks.range('F4:L4') archiveCells[0].value = now.strftime("%d %b %y") archiveCells[1].value = rolled[0] archiveCells[2].value = rolled[1] archiveCells[3].value = rolled[2] archiveCells[4].value = rolled[3] archiveCells[5].value = "" archiveCells[6].value = "" wks.update_cells(archiveCells) # move suggestions up 1 row suggestionCells = wks.range('B'+str(position)+':E'+str(lastSuggestion)) lenSuggestionCells = len(suggestionCells) for i in range(len(suggestionCells)): if lenSuggestionCells > i + 4: suggestionCells[i].value = suggestionCells[i+4].value wks.update_cells(suggestionCells) send(bot, "Suggestion moved to the archive.")
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.")
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")