def send(): text = u"<span style='color:red'>{}</span>".format(ui.lineEdit.text()) ui.plainTextEdit.appendHtml(text) data = ui.lineEdit.text() t = u"{}\n".format(data).encode('cp1251') session.send(t) ui.lineEdit.clear()
def input(): while True: wait_read(sys.stdin.fileno()) input_utf8 = sys.stdin.readline() input_unicode = input_utf8.decode('utf-8') input_unicode = u'{}\n'.format(input_unicode) input_cp1251 = input_unicode.encode('cp1251') session.send(input_cp1251)
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 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 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 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 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'))
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'] == 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 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 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.")
def russian(bot, update): if not isNewCommand(update): return send(bot, "Putin Hates Us All", parse_mode="HTML")
def today(bot, update): if not isNewCommand(update): return message = renew() send(bot, message.encode('utf-8'))