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 removeRoll(bot, update): if not isNewCommand(update): return if update.message.from_user.username == "ysoftware": config = loadConfig() config['lastRoll'] = None saveConfig(config)
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 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 endSession(): config = loadConfig() config.pop('artist', None) config.pop('track', None) config.pop('album', None) config.pop('suggested', None) config.pop('year', None) config['isPlaying'] = False saveConfig(config)
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 dontTagMe(bot, update): id = update.effective_user.id config = loadConfig() if 'tagList' not in config and id not in config['tagList']: config['tagList'] = [] bot.sendMessage(id, "You are not subscribed to /tag updates.") else: config['tagList'].remove(id) bot.sendMessage(id, "You are now unsubscribed from /tag updates.") saveConfig(config)
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 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.")
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 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 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.")
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)
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 app_main(): logging.getLogger().setLevel (logging.DEBUG) # Note that this setting only affects app's logs not the app engine system logs # Can also use command line https://cloud.google.com/appengine/docs/python/tools/devserver#Python_Command-line_arguments # eg -dev_appserver.py --log_level=debug Possible values are debug, info, warning, error, and critical. logging.info('####################### startup ###############################') logging.info('####################### ======= ###############################') # def route(C, suffix='', **ka): # n = C.__name__ # s = n[2:].lower() # u = '/' + s + suffix # return wa2.Route (u, C, s, **ka) # def route(n, hm=None, ms=None, **ka): # assert not n.startswith('/') # m = n[:-1] if n[-1].isdigit() else n # m = m.replace('/','-') # C = eval('h.H_'+ m) # u = '/' if n == 'Home' else '/' + n.lower() # logging.debug ('route = %s,%s,%s',u, C, n ) # return wa2.Route (u, C, n, handler_method=hm, methods=ms, **ka) rts = [# url handlerClass name wa2.Route ('/' , h.H_Home , 'Home' ) , wa2.Route ('/nocookie' , h.H_NoCookie , 'NoCookie' ) , wa2.Route ('/signup' , h.H_Signup , 'Signup' ) , wa2.Route ('/signup/msg' , h.H_Signup , handler_method='get2' , methods=['GET' ]) , wa2.Route ('/signup/<token:.+>' , h.H_SignupToken , 'Signup-token' ) , wa2.Route ('/forgot' , h.H_Forgot , 'Forgot' ) , wa2.Route ('/forgot/a' , h.H_Forgot , handler_method='post2', methods=['POST']) , wa2.Route ('/login' , h.H_Login , 'Login' ) , wa2.Route ('/logout' , h.H_Logout , 'Logout' ) , wa2.Route ('/secure' , h.H_Secure , 'Secure' ) , wa2.Route ('/np/<token:.+>' , h.H_NewPassword , 'NewPassword' ) , wa2.Route ('/tqsendemail' , h.H_TQSendEmail , 'TQSendEmail' ) , wa2.Route ('/tqverify' , h.H_TQSendVerifyEmail, 'TQSendVerifyEmail' ) , wa2.Route ('/admin/' , h.H_Admin , 'Admin-users-geochart') , wa2.Route ('/admin/newkeys' , h.H_AdminNewKeys ) , wa2.Route ('/admin/users/' , h.H_AdminUserList , 'Admin-users-list' ) , wa2.Route ('/admin/logout/' , h.H_AdminLogout , 'Admin-logout' ) , wa2.Route ('/admin/users/<user_id>/' , h.H_AdminUserEdit , 'Admin-user-edit', handler_method='edit') , wa2.Route ('/admin/logs/emails/' , h.H_AdminLogsEmails , 'Admin-logs-emails' ) , wa2.Route ('/admin/logs/emails/<email_id>/', h.H_AdminEmailView , 'Admin-logs-email-view' ) , wa2.Route ('/admin/logs/visits/' , h.H_AdminLogsVisits , 'Admin-logs-visits' ) #, wa2.Route ('/crontasks/purgeAuthKeys/' , h.H_PurgeAuthKeys , 'Crontasks-purgeAuthKeys' ) ] # rts = [# urlbase, handler_method, methods # route ('Home' ) # , route ('NoCookie') # , route ('Signup1' , 'get1' ,['GET' ]) # , route ('Signup2' , None ,['POST']) # , route ('Signup3' , 'get2' ,['GET' ]) # , route ('Forgot1' , 'post1',['POST']) # , route ('Forgot2' , 'post2',['POST']) # , route ('Forgot3' , None ,['GET' ]) # , route ('Login' ) # , route ('Logout' ) # , route ('Secure' ) # , route ('TQSendEmail' ) # , route ('TQVerify' ) # , wa2.Route ('/s2/<token:.+>' , h.H_Signup_2 , 'signup_2' ) # , wa2.Route ('/np/<token:.+>' , h.H_NewPassword, 'newpassword' ) # , wa2.Route ('/admin/' , h.H_Admin ,'admin-users-geochart') # , wa2.Route ('/admin/newkeys' , h.H_AdminNewKeys ) # , wa2.Route ('/admin/users/' , h.H_AdminUserList , 'admin-users-list' ) # , wa2.Route ('/admin/logout/' , h.H_AdminLogout , 'admin-logout' ) # , wa2.Route ('/admin/users/<user_id>/' , h.H_AdminUserEdit , 'admin-user-edit', handler_method='edit') # , wa2.Route ('/admin/logs/emails/' , h.H_AdminLogsEmails , 'admin-logs-emails' ) # , wa2.Route ('/admin/logs/emails/<email_id>/', h.H_AdminEmailView , 'admin-logs-email-view' ) # , wa2.Route ('/admin/logs/visits/' , h.H_AdminLogsVisits , 'admin-logs-visits' ) # , wa2.Route ('/crontasks/purgeAuthKeys/' , h.H_PurgeAuthKeys , 'crontasks-purgeAuthKeys' ) # ] # , wa2.Route ('/<ttype:s|p>/<token:.+>',h.H_Verify, 'verify') #, wa2.Route ('/signup2' , h.H_Signup2 ) #, wa2.Route ('/password' , h.H_ResetPassword ) myConfig.cfg['Env'] = 'Dev' if os.environ['SERVER_SOFTWARE'].startswith('Dev') else 'Prod' wa = wa2.WSGIApplication( rts , debug =myConfig.cfg['DebugMode'] , config=myConfig.cfg ) session.loadConfig(wa) # override/add-to session config defaults with myConfig # logging.debug('config = %r', a.config) return wa