def deleteCat(bot, message): cats = getCats() try: index = int(message.text.split('cat', 1)[1].strip()) print index, type(index) except: return bf.sendText(bot, message.chat_id, 'Couldn\'t parse index') try: cat = cats[index] except: return bf.sendText(bot, message.chat_id, 'index not found') if (permission(message, cat)): cats.pop(index) else: return bf.sendText( bot, message.chat_id, message.from_user.first_name + ', you do not have permission to delete this entry') saveCats(cats) return bf.sendText( bot, message.chat_id, 'Entry number ' + str(index) + ' removed.\nNew catabase saved.')
def checkMotion(bot): with dataset.connect() as db: motion_log = db['motion'] detections = motion_log.find(new=True) if motion_log.find(new=True,return_count=True)!=0: motions = motion_log times = [] new_ids = [] for detection in detections: times.append(detection['mtime']) new_ids.append(detection['id']) text = "MOTION DETECTED:\n"+'\n'.join(times) send_to_user = db['user'].find_one(id=5)['telegram_id'] bf.sendText(bot,send_to_user,text) bf.postImage('img/motion.png',send_to_user,BASE_URL) for new_id in new_ids: db['motion'].update(dict(id=new_id,new=False),['id'])
def regCats(bot, message): text = message.text user = message.from_user tg_id = user.id tg_fname = user.first_name tg_sname = user.last_name spacecats = getCats() catmatch = filter(lambda cat: cat['telegram_id'] == tg_id, spacecats) if catmatch: bf.sendText(bot, message.chat_id, msgs['reg_check'], True) return else: details = text.split('/register', 1)[1] try: details_list = [element.strip() for element in details.split(',')] dota_fname = details_list[0] dota_sname = details_list[1] dota_id = int(details_list[2].split('/players/', 1)[1]) dota_name = ' '.join([dota_fname, dota_sname]) except: bf.sendText(bot, message.chat_id, msgs['reg_help'], True) return cat_dict = { 'dota_name': dota_name, 'dota_id': dota_id, 'first_name': tg_fname, 'last_name': tg_sname, 'telegram_id': tg_id } print cat_dict spacecats.append(cat_dict) saveCats(spacecats) return bf.sendText(bot, message.chat_id, 'New Spacecat added to the space catabase!')
def deleteCat(bot,message): try: # get index from message and validate input index = int(message.text.split('cat',1)[1].strip()) except: return bf.sendText(bot,message.chat_id,'Couldn\'t parse index') with dataset.connect() as db: cat = db['user'].find_one(id=index) if not cat: # check entry exists return bf.sendText(bot,message.chat_id,'index not found') # check user as permission to do this if(permission(message,cat)): db['user'].delete(id=index) else: return bf.sendText(bot,message.chat_id,message.from_user.first_name+', you do not have permission to delete this entry') return bf.sendText(bot,message.chat_id,'Entry number '+str(index)+' removed.\nNew catabase saved.')
def regCats(bot,message): text = message.text user = message.from_user tg_id = user.id tg_fname = user.first_name tg_sname = user.last_name with dataset.connect() as db: # database URL is set as environment variable in bot_setup shell script. users = db['user'] # table of users catmatch = users.find_one(telegram_id=tg_id) # does the user already exist? # only allows users to add new entry and not modify their existing one (must delete it first) if catmatch: bf.sendText(bot,message.chat_id,msgs['reg_check'],True) return else: details = text.split('/register',1)[1] # get registration parameters from message try: details_list = [element.strip() for element in details.split(',')] # put parameters into list dota_fname = details_list[0] dota_sname = details_list[1] dota_id = int(details_list[2].split('/players/',1)[1]) # get dota ID from dotabuff url dota_name = ' '.join([dota_fname,dota_sname]) except: bf.sendText(bot,message.chat_id,msgs['reg_help'],True) # formatting error return # insert entry into user table db['user'].insert(dict( dota_name= dota_name, dota_id= dota_id, first_name= tg_fname, last_name= tg_sname, telegram_id= tg_id )) return bf.sendText(bot,message.chat_id,'New member added to the database!')
def printCats(bot,message): db = dataset.connect() users = db['user'].all() db_size = len(db['user']) bf.sendText(bot,message.chat_id,'There are '+str(db_size)+' database entries:') entry_found = False for cat in users: if permission(message,cat): entry_found = True catdict = dict(cat) catdict.pop('name', None) catdict.pop('admin', None) catdict.pop('unpatched', None) vals = [str(i) for i in catdict.values()] bf.sendText(bot,message.chat_id,', '.join(vals)) if not entry_found: bf.sendText(bot,message.chat_id,'It appears as though you do not have permission to view any entries.')
def printCats(bot, message): cats = getCats() print cats db_size = len(cats) bf.sendText(bot, message.chat_id, 'There are ' + str(db_size) + ' catabase entries:') entry_found = False for index in range(0, len(cats)): cat = cats[index] if permission(message, cat): entry_found = True vals = [str(i) for i in cat.values()] bf.sendText(bot, message.chat_id, str(index) + ', ' + ', '.join(vals)) if not entry_found: bf.sendText( bot, message.chat_id, 'It appears as though you do not have permission to view any entries.' )
def main(): update_id = None global BASE_URL logging.basicConfig(filename="botlog.log", format="%(asctime)s - %(name)s - %(levelname)s - %(message)s") logging.getLogger().addHandler(logging.StreamHandler()) bot = telegram.Bot(token=os.environ.get("TG_BOT_TOKEN")) try: LAST_UPDATE_ID = bot.getUpdates()[-1].update_id except IndexError: LAST_UPDATE_ID = None # keywords dota_words = ["dota", "dotes"] dota_queries = ["when", "happening"] stack_queries = ["5 stack", "5stack", "stacked"] greetings = ["hello", "hi", "hey"] goodbyes = ["goodbye", "bye", "laters", "cya"] thanks = ["thanks", "cheers", "nice one"] gainz_words = ["gainz"] dota_checked = False # long polling skybeard bot while True: # Does a dota event exist? # Get updates from bot. 10s timeout on poll, update on new message try: try: dotes except NameError: dota_exists = False else: dota_exists = True for update in bot.getUpdates(offset=update_id, timeout=10): chat_id = update.message.chat_id message = update.message text = update.message.text.encode("utf-8") user = update.message.from_user if dota_exists and not dota_checked: dota_t_check = dotes.tcheck(message) logging.info("checked", update_id) if dota_t_check: dota_checked = True ############ MESSAGE HANDLING ############ ########################################## # location testing if message.location: bf.locCheck(bot, message) # test photo sending is working if bf.command("/phototest", text): bf.postImage(text.split("/phototest ", 1)[1], chat_id, BASE_URL) # post space cat pics if bf.command("give me spacecats", text) or bf.command("show me spacecats", text): bf.postCats(bot, message) # send help text if bf.command("/help", text): bf.sendText(bot, chat_id, msg_texts.help()) if bf.command("/weather", text): # does not work in python2.6 imgPath = bf.forecast(bot, message) bf.postImage(imgPath, chat_id, BASE_URL) if bf.command("/movie", text): try: title = text.split("/movie ", 1)[1] except: bf.sendText(bot, chat_id, "Please specify a film title") else: bf.movies(bot, message, title) if bf.command("/register", text): reg.regCats(bot, message) if bf.command("/catabase", text): reg.printCats(bot, message) if bf.command("/catdump", text): reg.dumpCats(bot, message) if bf.command("/delete cat", text): reg.deleteCat(bot, message) if bf.command("/echo", text): bf.echocats(bot, message) # send top dota feeders table and graph if bf.command("/topfeeds", text): if "update" in text.lower(): update_feeds = True else: update_feeds = False imgPath = bf.feeding(bot, message, update_feeds) bf.postImage(imgPath, chat_id, BASE_URL) # post last dota match details of user if bf.command("/lastmatch", text): bf.last_match(bot, message) # create or modify time of dota event if bf.command("/dota", text): dota_checked = False time = events.get_time(bot, message) if dota_exists: dotes.set_time(time) bf.sendText(bot, chat_id, "Dota time modified") dotes.time_info(message) else: shotguns = events.get_str_list(bot, message, "with") dotes = events.dota(bot, message, time) logging.info("multi-shotgun:", shotguns) if shotguns: for cat in shotguns: dotes.shotgun(message, cat) # delete dota event if bf.command("/delete dota", text): if dota_exists: bf.sendText(bot, chat_id, "Dota event deleted") del dotes else: events.nodota(bot, message) # shotgun a place in dota if bf.command("shotgun!", text): if dota_exists: dotes.shotgun(message) else: events.nodota(bot, message) # unshotgun your place in dota if bf.command("unshotgun!", text): if dota_exists: dotes.unshotgun(message, "shotgun") else: events.nodota(bot, message) # ready up for dota if bf.command("unrdry!", text): if dota_exists: dotes.unshotgun(message, "rdry") else: events.nodota(bot, message) # un-ready up for dota if bf.command("rdry!", text): if dota_exists: dotes.rdry_up(message) else: events.nodota(bot, message) # post motivational lifting pics if bf.keywords(gainz_words, text.lower()): bf.gainz(bot, chat_id, message) # reply to thank you messages if bf.keywords(thanks, text.lower()) and ("skybeard" in text.lower()): bf.thank(bot, chat_id, message) # reply to greetings messages if bf.keywords(greetings, text.lower()) and ("skybeard" in text.lower()): bf.greet(bot, chat_id, message) # reply to farewell messages if (bf.keywords(goodbyes, text.lower())) and ("skybeard" in text.lower()): bf.goodbye(bot, chat_id, message) # respond to queries on wif dota is 5 stacked or not if bf.keywords(stack_queries, text.lower()): if dota_exists: dotes.stack(message) else: events.nodota(bot, message) # respond to queries about dota event details if bf.keywords(dota_queries, text.lower()) and ("dota" in text.lower()): if dota_exists: dotes.time_info(message) else: events.nodota(bot, message) update_id = update.update_id + 1 except telegram.TelegramError as e: if e.message in ("Bad Gateway", "Timed out"): sleep(1) else: raise e except URLError as e: sleep(1)
def dumpCats(bot, message): cats = getCats() for cat in cats: bf.sendText(bot, message, str(cat)) print cat
def main(): update_id = None motion_on = False global BASE_URL logging.basicConfig(format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',file='botlog.log') # logging.getLogger().addHandler(logging.StreamHandler()) bot = telegram.Bot(token=os.environ.get('TG_BOT_TOKEN')) try: LAST_UPDATE_ID = bot.getUpdates()[-1].update_id except IndexError: LAST_UPDATE_ID = None #keywords dota_words = ['dota','dotes'] dota_queries = ['when','happening'] stack_queries = ['5 stack','5stack','stacked'] greetings = ['hello','hi','hey'] goodbyes = ['goodbye','bye','laters','cya'] thanks = ['thanks','cheers','nice one'] gainz_words = ['gainz'] dota_checked = False patch_check_time = datetime.datetime.now() tags = [] #create Mycroft AI Adapt engine skb_intelligence = af.skyAdapt() dotes = None bf.delDotaTable() #long polling skybeard bot while True: try: #Does a dota event exist? # try: # dotes # except NameError: # dota_exists = False # else: # dota_exists = True ############## TIME CHECKS ############## ######################################### #checks if it's almost time for dota if (dotes and not dota_checked): dota_t_check = dotes.tcheck(message) logging.info("checked",update_id) if (dota_t_check): dota_checked = True #checks for new dota patches hourly # if bf.expiry(patch_check_time,20): # bf.postUpdate(bot,message) #deletes a dota event if it is 6 hours passed the event start time if dotes and bf.expiry(dotes.date_dota,360): #logging.info('dota event expired',dotes.date_dota) dotes = None bf.delDotaTable() #rpi function time checks if rpi and motion_on: rpf.checkMotion(bot) #Get updates from bot. 10s timeout on poll, update on new message for update in bot.getUpdates(offset=update_id, timeout=10): chat_id = update.message.chat_id message = update.message text = update.message.text.encode('utf-8') user = update.message.from_user ####test commands#### #location testing if (message.location): bf.locCheck(bot,message) #test photo sending is working (removed. Potentially dangerous!) # if bf.command('/phototest',text): # bf.postImage(text.split('/phototest ',1)[1],chat_id,BASE_URL) #test command for gym locator if bf.command('/updategains',text): bf.updateGainz(message) if bf.command('/motion',text): if motion_on: motion_on = False bf.sendText(bot, chat_id, 'Motion detection halted') elif not motion_on: # rpf.clearMotion() rpf.resetMotion() motion_on = True bf.sendText(bot, chat_id, 'Motion detection resumed') if bf.command('/myid',text): bf.sendText(bot, chat_id, user.id) ############ MESSAGE HANDLING ############ ########################################## #latest steam news post for game. Currently just Dota if(bf.command('/news',text)): try: title = text.split('/news ',1)[1] except: title = 'dota' if title == 'dota': bf.dotaNews(bot,message) else: bf.sendText(bot,chat_id,title+' is not a recognised steam game') #post space cat pics if bf.command('give me spacecats',text) or bf.command('show me spacecats',text): bf.postCats(bot,message) #post corgi pics if bf.command('give me corgis',text) or bf.command('show me corgis',text): bf.postCorgis(bot,message, BASE_URL) #send help text if bf.command('/help',text): bf.sendText(bot,chat_id,msg_texts.help()) bf.sendText(bot,chat_id,msg_texts.readme()) #weather forecast if bf.command('/weather',text): #does not work in python2.6 bf.forecast(bot,message,BASE_URL) #movie lookup if bf.command('/movie',text): try: title = text.split('/movie ',1)[1] except: bf.sendText(bot,chat_id,'Please specify a film title') else: bf.movies(bot,message,title) #book lookup if bf.command('/book',text): try: title = text.split('/book ',1)[1] except: bf.sendText(bot,chat_id,'Please specify a book title') else: bf.bookSearch(bot,message,title) #display database entries which user has permission to see if bf.command('/catabase',text): reg.printCats(bot,message) #delete catabase entry if bf.command('/delete cat',text): reg.deleteCat(bot,message) #banter command if bf.command('/echo',text): bf.echocats(bot,message) #send top dota feeders table and graph if bf.command('/topfeeds',text): if 'update' in text.lower(): update_feeds = True else: update_feeds = False bf.feeding(bot,message,BASE_URL,update_feeds) #post last dota match details of user if bf.command('/lastmatch',text): bf.last_match(bot,message) if bf.command('/matches',text): bf.matches(bot,message) if bf.command('#m_',text): bf.last_match(bot,message,text.split('#m_',1)[1]) #create or modify time of dota event if bf.command('/dota',text): dota_checked = False time = events.get_time(bot,message) if (dotes): dotes.set_time(time) bf.sendText(bot,chat_id,'Dota time modified') dotes.time_info(message) else: shotguns = events.get_str_list(bot,message,'with') dotes = events.dota(bot,message,time) logging.info('multi-shotgun:',shotguns) if shotguns: for cat in shotguns: dotes.shotgun(message,cat) #delete dota event if bf.command('/delete dota',text): if (dotes): bf.sendText(bot,chat_id,'Dota event deleted') dotes = None bf.delDotaTable() else: events.nodota(bot,message) #shotgun a place in dota if bf.command('shotgun!',text): if (dotes): dotes.shotgun(message) else: events.nodota(bot,message) #unshotgun your place in dota if bf.command('unshotgun!',text): if (dotes): dotes.unshotgun(message,'shotgun') else: events.nodota(bot,message) #ready up for dota if bf.command('unrdry!',text): if (dotes): dotes.unshotgun(message,'rdry') else: events.nodota(bot,message) #un-ready up for dota if bf.command('rdry!',text): if (dotes): dotes.rdry_up(message) else: events.nodota(bot,message) #post motivational lifting pics if bf.keywords(gainz_words,text.lower()): bf.gainz(bot,message) #reply to thank you messages if bf.keywords(thanks,text.lower()) and ('skybeard' in text.lower()): bf.thank(bot,chat_id,message) #reply to greetings messages if bf.keywords(greetings,text.lower()) and ('skybeard' in text.lower()): bf.greet(bot,chat_id,message) #reply to farewell messages if (bf.keywords(goodbyes,text.lower())) and ('skybeard' in text.lower()): bf.goodbye(bot,chat_id,message) #respond to queries on if dota is 5 stacked or not if (bf.keywords(stack_queries,text.lower())): if (dotes): dotes.stack(message) else: events.nodota(bot,message) #respond to queries about dota event details # if bf.keywords(dota_queries,text.lower()) and ('dota' in text.lower()): # if (dotes): # dotes.time_info(message) # else: # events.nodota(bot,message) #AI tests intents = af.intentChecker(skb_intelligence, 0.3, text) try: for intent in intents: if intent['intent_type'] == 'DotaIntent': events.dotaQuery(bot, message, dotes) elif intent['intent_type'] == 'NewDotaIntent': dota_checked = False time = events.get_time(bot,message) if (dotes): dotes.set_time(time) bf.sendText(bot,chat_id,'Dota time modified') dotes.time_info(message) else: shotguns = events.get_str_list(bot,message,'with') dotes = events.dota(bot,message,time) logging.info('multi-shotgun:',shotguns) if shotguns: for cat in shotguns: dotes.shotgun(message,cat) elif intent['intent_type'] == 'StackIntent': if (dotes): dotes.stack(message) else: events.nodota(bot,message) except: print 'no intents detected' pending_tag = btools.keySearch(tags,'name',user.first_name.lower()) if pending_tag and pending_tag['chat_id']==chat_id: bf.tagReply(bot,message,pending_tag) i = next(index for (index, entry) in enumerate(tags) if entry['name'] == pending_tag['name']) tags.pop(i) tag_match = re.search(r'\/tag\s*(\w+)',text) if tag_match: tags.append(bf.msgTag(bot,message,tag_match.group(1))) # print tags update_id= update.update_id + 1 except telegram.TelegramError as e: if e.message in ("Bad Gateway", "Timed out"): sleep(1) else: raise e except URLError as e: sleep(1)
def main(): update_id = None motion_on = False global BASE_URL logging.basicConfig(format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',filename='botlog.log') # logging.getLogger().addHandler(logging.StreamHandler()) bot = telegram.Bot(token=os.environ.get('TG_BOT_TOKEN')) try: LAST_UPDATE_ID = bot.getUpdates()[-1].update_id except IndexError: LAST_UPDATE_ID = None #keywords stack_queries = ['5 stack','5stack','stacked'] greetings = ['hello','hi','hey'] goodbyes = ['goodbye','bye','laters','cya'] thanks = ['thanks','cheers','nice one'] gainz_words = ['gainz'] dota_checked = False patch_check_time = datetime.datetime.now() tags = [] #create Mycroft AI Adapt engine skb_intelligence = af.skyAdapt() dotes = None bf.delDotaTable() #long polling skybeard bot while True: #dirty try: #even dirtier, oh my! ############## TIME CHECKS ############## ######################################### #checks if it's almost time for dota if (dotes and not dota_checked): dota_t_check = dotes.tcheck(message) logging.info("checked",update_id) if (dota_t_check): dota_checked = True #checks for new dota patches if bf.expiry(patch_check_time,10): bf.postUpdate(bot,message) #deletes a dota event if it is 6 hours passed the event start time if dotes and bf.expiry(dotes.date_dota,360): dotes = None bf.delDotaTable() #Get updates from bot. 10s timeout on poll, update on new message for update in bot.getUpdates(offset=update_id, timeout=10): chat_id = update.message.chat_id message = update.message text = update.message.text #.encode('utf-8') user = update.message.from_user if bf.command('/myid',text): bf.sendText(bot, chat_id, user.id) ############ MESSAGE HANDLING ############ ########################################## #latest steam news post for game. Currently just Dota if(bf.command('/news',text)): try: title = text.split('/news ',1)[1] except: title = 'dota' if title == 'dota': bf.dotaNews(bot,message) else: bf.sendText(bot,chat_id,title+' is not a recognised steam game') #more steam games can be added #send help text if bf.command('/help',text): bf.sendText(bot,chat_id,msg_texts.help()) bf.sendText(bot,chat_id,msg_texts.readme()) #display database entries which user has permission to see if bf.command('/database',text): reg.printCats(bot,message) #delete catabase entry if bf.command('/delete cat',text): reg.deleteCat(bot,message) #banter command if bf.command('/echo',text): bf.echocats(bot,message) #send top dota feeders table and graph if bf.command('/topfeeds',text): if 'update' in text.lower(): update_feeds = True else: update_feeds = False bf.feeding(bot,message,BASE_URL,update_feeds) #post last dota match details of user if bf.command('/lastmatch',text): bf.last_match(bot,message) if bf.command('/matches',text): bf.matches(bot,message) if bf.command('#m_',text): bf.last_match(bot,message,text.split('#m_',1)[1]) #create or modify time of dota event if bf.command('/dota',text): dota_checked = False time = events.get_time(bot,message) if (dotes): dotes.set_time(time) bf.sendText(bot,chat_id,'Dota time modified') dotes.time_info(message) else: shotguns = events.get_str_list(bot,message,'with') dotes = events.dota(bot,message,time) logging.info('multi-shotgun:',shotguns) if shotguns: for cat in shotguns: dotes.shotgun(message,cat) #delete dota event if bf.command('/delete dota',text): if (dotes): bf.sendText(bot,chat_id,'Dota event deleted') dotes = None bf.delDotaTable() else: events.nodota(bot,message) #shotgun a place in dota if bf.command('shotgun!',text): if (dotes): dotes.shotgun(message) else: events.nodota(bot,message) #unshotgun your place in dota if bf.command('unshotgun!',text): if (dotes): dotes.unshotgun(message,'shotgun') else: events.nodota(bot,message) #ready up for dota if bf.command('unready!',text): if (dotes): dotes.unshotgun(message,'rdry') else: events.nodota(bot,message) #un-ready up for dota if bf.command('ready!',text): if (dotes): dotes.rdry_up(message) else: events.nodota(bot,message) #reply to thank you messages if bf.keywords(thanks,text.lower()) and ('skybeard' in text.lower()): bf.thank(bot,chat_id,message) #reply to greetings messages if bf.keywords(greetings,text.lower()) and ('skybeard' in text.lower()): bf.greet(bot,chat_id,message) #reply to farewell messages if (bf.keywords(goodbyes,text.lower())) and ('skybeard' in text.lower()): bf.goodbye(bot,chat_id,message) #respond to queries on if dota is 5 stacked or not if (bf.keywords(stack_queries,text.lower())): if (dotes): dotes.stack(message) else: events.nodota(bot,message) #AI tests intents = af.intentChecker(skb_intelligence, 0.3, text) try: for intent in intents: if intent['intent_type'] == 'DotaIntent': events.dotaQuery(bot, message, dotes) elif intent['intent_type'] == 'NewDotaIntent': dota_checked = False time = events.get_time(bot,message) if (dotes): dotes.set_time(time) bf.sendText(bot,chat_id,'Dota time modified') dotes.time_info(message) else: shotguns = events.get_str_list(bot,message,'with') dotes = events.dota(bot,message,time) logging.info('multi-shotgun:',shotguns) if shotguns: for cat in shotguns: dotes.shotgun(message,cat) elif intent['intent_type'] == 'StackIntent': if (dotes): dotes.stack(message) else: events.nodota(bot,message) except: print('no intents detected') #tag someone in a message for the bot to send again when they're active in the chat pending_tag = btools.keySearch(tags,'name',user.first_name.lower()) if pending_tag and pending_tag['chat_id']==chat_id: bf.tagReply(bot,message,pending_tag) i = next(index for (index, entry) in enumerate(tags) if entry['name'] == pending_tag['name']) tags.pop(i) tag_match = re.search(r'\/tag\s*(\w+)',text) if tag_match: tags.append(bf.msgTag(bot,message,tag_match.group(1))) # print(tags) update_id= update.update_id + 1 except telegram.TelegramError as e: if e.message in ("Bad Gateway", "Timed out"): sleep(1) else: raise e except URLError as e: sleep(1) except: # This is terrible, and it's my fault (nasfarley88) pass
async def on_chat_message(self, msg): print(msg) # housekeeping if bf.expiry(patch_check_time,10): bf.postUpdate(bot,message) chat_id = msg['chat']['id'] text = msg['text'] #.encode('utf-8') user = msg['from']['username'] # A little hacking is needed here to make the message object fit the # old api # # TODO phase this out message = Namespace() message.chat_id = chat_id message.text = text message.from_user = Namespace() message.from_user.first_name = msg['from']['first_name'] message.from_user.id = msg['from']['id'] message.user = msg['from']['username'] if(bf.command('/news',text)): try: title = text.split('/news ',1)[1] except: title = 'dota' if title == 'dota': bf.dotaNews(bot,message) else: bf.sendText(bot,chat_id,title+' is not a recognised steam game') #more steam games can be added #send help text if bf.command('/help',text): bf.sendText(bot,chat_id,msg_texts.help()) bf.sendText(bot,chat_id,msg_texts.readme()) #display database entries which user has permission to see if bf.command('/database',text): reg.printCats(bot,message) #delete catabase entry if bf.command('/delete cat',text): reg.deleteCat(bot,message) #banter command if bf.command('/echo',text): bf.echocats(bot,message) #send top dota feeders table and graph if bf.command('/topfeeds',text): if 'update' in text.lower(): update_feeds = True else: update_feeds = False bf.feeding(bot,message,BASE_URL,update_feeds) #post last dota match details of user if bf.command('/lastmatch',text): bf.last_match(bot,message) if bf.command('/matches',text): bf.matches(bot,message) if bf.command('#m_',text): bf.last_match(bot,message,text.split('#m_',1)[1]) #create or modify time of dota event if bf.command('/dota',text): try: await self.create_event(msg) except EventAlreadyPlanned: event = await self.get_future_event() await self.sender.sendMessage( "Event already planned for {}".format( event.start_datetime)) # dota_checked = False # time = events.get_time(bot,message) # if (dotes): # dotes.set_time(time) # bf.sendText(bot,chat_id,'Dota time modified') # dotes.time_info(message) # else: # shotguns = events.get_str_list(bot,message,'with') # dotes = events.dota(bot,message,time) # logging.info('multi-shotgun:',shotguns) # if shotguns: # for cat in shotguns: # dotes.shotgun(message,cat) #shotgun a place in dota if bf.command('shotgun!',text): # assert False, "Sorry, not implemented yet!" event = await self.get_future_event() if event: try: await self.add_person_to_event( event, {"name": msg["from"]["username"]}) await self.sender.sendMessage( "Your interest has been noted.") except PersonAlreadyAttending: await self.sender.sendMessage( "Your interest has already been noted.") else: await self.sender.sendMessage( "I don't know about any Dota happening today.") #unshotgun your place in dota if bf.command('unshotgun!',text): event = await self.get_future_event() if event: try: await self.remove_person_from_event( event, {"name": msg["from"]["username"]}) await self.sender.sendMessage( "Your lack of interest has been noted.") except PersonNotAttending: await self.sender.sendMessage( "You were never going to this event.") else: await self.sender.sendMessage( "I don't know about any Dota happening today.") # TODO #ready up for dota if bf.command('unready!',text): assert False, "Sorry, not implemented yet!" # if (dotes): # dotes.unshotgun(message,'rdry') # else: # events.nodota(bot,message) #un-ready up for dota if bf.command('ready!',text): assert False, "Sorry, not implemented yet!" # if (dotes): # dotes.rdry_up(message) # else: # events.nodota(bot,message) #reply to thank you messages if bf.keywords(thanks,text.lower()) and ('skybeard' in text.lower()): bf.thank(bot,chat_id,message) #reply to greetings messages if bf.keywords(greetings,text.lower()) and ('skybeard' in text.lower()): bf.greet(bot,chat_id,message) #reply to farewell messages if (bf.keywords(goodbyes,text.lower())) and ('skybeard' in text.lower()): bf.goodbye(bot,chat_id,message) #respond to queries on if dota is 5 stacked or not if bf.keywords(stack_queries, text.lower()): # assert False, "Sorry, not implemented!" event = await self.get_future_event() if event: await self.sender.sendMessage( "There are currently {} people shotgunned.".format( len(event.people_attending))) else: await self.sender.sendMessage("No dota scheduled at the moment.")