def run(self): update = self.update bot = self.bot if isDos(update): return chat_id = getID(update) while status.get(chat_id) == "photo_update": add_query_photo_lock.get(chat_id).acquire() add_query_photo_lock.get(chat_id).release() if status.get(chat_id) == "add_step2": status.pop(chat_id) update.message.reply_text('正在新增店家...') cur_classification = add_query_classification.get(chat_id) cur_shopname = add_query_shopname.get(chat_id) if(chat_id in add_query_photolink): cur_photolink = add_query_photolink.get(chat_id) else: cur_photolink = [getNoMenuLink()] curMD.add(cur_classification, cur_shopname, menus=cur_photolink, pushNow=True) update.message.reply_text('新增店家 {} 於分類 {}, 新增完成。'.format(cur_shopname, cur_classification)) else: add_query_update.update({chat_id:update}) status.update({chat_id:'add_step0'}) update.message.reply_text("請選擇分類", reply_markup = InlineKeyboardMarkup([ [InlineKeyboardButton(s, callback_data = '{} {} {}'.format(s, chat_id, 0)) for s in list(classMap.keys())[0::2]], [InlineKeyboardButton(s, callback_data = '{} {} {}'.format(s, chat_id, 0)) for s in list(classMap.keys())[1::2]] ])) appendlog(getID(update), update.message.from_user.full_name, update.message.text)
def run(self): update = self.update bot = self.bot if isDos(update): return chat_id = getID(update) status.update({chat_id: 'random'}) add_query_update.update({chat_id: update}) classlist = list(classMap.keys()) classlist.append('無') update.message.reply_text( "有什麼要求嗎?", reply_markup=InlineKeyboardMarkup( [[ InlineKeyboardButton(s, callback_data='{} {} {}'.format( s, chat_id, 3)) for s in classlist[0::2] ], [ InlineKeyboardButton(s, callback_data='{} {} {}'.format( s, chat_id, 3)) for s in classlist[1::2] ]])) appendlog(getID(update), update.message.from_user.full_name, update.message.text)
def run(self): update = self.update bot = self.bot chat_id = getID(update) text = update.message.text if chat_id in status: state = status[chat_id] if state == 'search': status.pop(chat_id) findmenu(text, update) elif state == 'add_step1': status.update({chat_id: 'add_step2'}) add_query_shopname.update({chat_id: preprocess(text)}) update.message.reply_text( '新增店家名稱為{}\n請傳送未壓縮照片( /hint ) 或重新輸入名稱'.format( add_query_shopname[chat_id])) update.message.reply_text( '店家無菜單或傳送完畢請輸入 /add 結束傳送。', reply_markup=ForceReply(selective=True)) elif state == 'add_step2': add_query_shopname.update({chat_id: preprocess(text)}) update.message.reply_text( '更改店家名稱為{}\n請傳送未壓縮照片( /hint ) 或重新輸入名稱'.format( add_query_shopname[chat_id])) update.message.reply_text( '店家無菜單或傳送完畢請輸入 /add 結束傳送。', reply_markup=ForceReply(selective=True)) else: print('ignore it') appendlog(getID(update), update.message.from_user.full_name, update.message.text)
def run(self): update = self.update bot = self.bot if isDos(update): return if(not checkpermission(update)): return # print('hi') chat_id = getID(update) text = 'hihi~~' bot.send_message(chat_id, text) # update.message.reply_text(update.toString()) appendlog(getID(update), update.message.from_user.full_name, update.message.text)
def run(self): update = self.update bot = self.bot if isDos(update): return update.message.reply_text(help_zh) appendlog(getID(update), update.message.from_user.full_name, update.message.text)
def run(self): update = self.update bot = self.bot if isDos(update): return DealWithPhotolink(update, update.message.document.file_id) appendlog(getID(update), update.message.from_user.full_name, 'getfile')
def run(self): update = self.update bot = self.bot if isDos(update): return chat_id = update.message.chat_id try: command, shopname, tag = update.message.text.split() except ValueError: update.message.reply_text('輸入格式為 /addtag 店家 標籤') return tag = '`' + tag + '`' list = curMD.getshops() Done = False for i in list: if shopname in i: Done = True tags = curMD.getTag(shopname) print(tags) if tag in tags: update.message.reply_text('重複的標籤') else: update.message.reply_text('正在新增標籤...') tags.append(tag) curMD.editTag(shopname, tags) update.message.reply_text('在{}上新增標籤{},新增完成。'.format(shopname, tag)) break if not Done: update.message.reply_text('無此店家') update.message.reply_text('可先用 /search 查詢正確名稱') appendlog(getID(update), update.message.from_user.full_name, update.message.text)
def run(self): update = self.update bot = self.bot if isDos(update): return chat_id = getID(update) try: command, keyword = update.message.text.split() findmenu(keyword, update) except: status.update({chat_id: 'search'}) update.message.reply_text('請輸入店家名稱', reply_markup=ForceReply(selective=True)) appendlog(getID(update), update.message.from_user.full_name, update.message.text)
def checkpermission(update): chat_id = getID(update) developer_id = os.getenv("DEVELOPER_ID").split(',') if chat_id in developer_id: return True else: update.message.reply_text("你沒有使用此指令的權限") update.message.reply_text("但名豐可以請客") return False
def run(self): update = self.update bot = self.bot if isDos(update): return if(not checkpermission(update)): return update.message.reply_text(xhelp_en) appendlog(getID(update), update.message.from_user.full_name, update.message.text)
def checkLowerPermission(update): chat_id = getID(update) lower_permission_id = os.getenv("LOWER_PERMISSION_ID").split(',') if checkpermission(update): return True elif chat_id in lower_permission_id: return True else: update.message.reply_text("你沒有使用此指令的權限") update.message.reply_text("但名豐可以請客") return False
def run(self): update = self.update bot = self.bot if isDos(update): return chat_id = getID(update) if chat_id in status: status.pop(chat_id) if chat_id in add_query_shopname: add_query_shopname.pop(chat_id) if chat_id in add_query_classification: add_query_classification.pop(chat_id) if chat_id in add_query_photolink: add_query_photolink.pop(chat_id) if chat_id in add_query_update: add_query_update.pop(chat_id) update.message.reply_text("已清除您的所有要求") appendlog(getID(update), update.message.from_user.full_name, update.message.text)
def run(self): update = self.update bot = self.bot if isDos(update): return if (not checkLowerPermission(update)): return update.message.reply_text("菜單修改功能實作中...") appendlog(getID(update), update.message.from_user.full_name, update.message.text)
def run(self): update = self.update bot = self.bot if isDos(update): return update.message.reply_text('為確保資料完整性,請上傳未壓縮照片( /hint )。') update.message.reply_text('店家無菜單或傳送完畢請輸入 /add 結束傳送。', reply_markup=ForceReply(selective=True)) # DealWithPhotolink(update, update.message.photo[0].file_id) appendlog(getID(update), update.message.from_user.full_name, 'getphoto')
def run(self): update = self.update bot = self.bot if isDos(update): return update.message.reply_text('Bot正常運作中') update.message.reply_text('現在顯然有電') appendlog(getID(update), update.message.from_user.full_name, update.message.text)
def run(self): update = self.update bot = self.bot if isDos(update): return update.message.reply_text('Hello.') update.message.reply_text('I am just a Eating Bot.') update.message.reply_text(help_en) appendlog(getID(update), update.message.from_user.full_name, update.message.text)
def run(self): update = self.update bot = self.bot if isDos(update): return if (not checkpermission(update)): return update.message.reply_text("備份中...") curMD.push(manual=True, hackmd=True) update.message.reply_text("手動備份完成") appendlog(getID(update), update.message.from_user.full_name, update.message.text)
def run(self): update = self.update bot = self.bot if isDos(update): return if (not checkpermission(update)): return chat_id = getID(update) text = update.message.text.split() if len(text) > 2: update.message.reply_text('type error.') elif len(text) == 2: if not text[1].isdecimal(): update.message.reply_text('type error.') else: singleReport(update, int(text[1])) else: for i in range(1, 4): singleReport(update, i) appendlog(getID(update), update.message.from_user.full_name, update.message.text)
def findmenu(text, update): text = preprocess(text) chat_id = getID(update) list = curMD.getshops() newlist = [] for i in list: newlist += i list = newlist if text in list: curMenu = curMD.getMenu(text) for photolink in curMenu: update.message.reply_photo(photolink) else: candi_list = [] print('keyword: {}'.format(text)) for shop in list: if (allin(shop, text) or allin(text, shop) or Levenshtein(shop, text) < 2): candi_list.append(shop) if (len(candi_list) > 5): random.shuffle(candi_list) candi_list = candi_list[0:5] if (len(candi_list) == 0): update.message.reply_text('此店家不存在') append('non-exist-shop.txt', '{}\n'.format(text)) else: print('candicate:', candi_list) add_query_update.update({chat_id: update}) status.update({chat_id: 'search_step1'}) update.message.reply_text( "我猜你想查", reply_markup=InlineKeyboardMarkup( [[ InlineKeyboardButton(s, callback_data='{} {} {}'.format( s, chat_id, 1)) for s in candi_list[0::2] ], [ InlineKeyboardButton(s, callback_data='{} {} {}'.format( s, chat_id, 1)) for s in candi_list[1::2] ]]))
def run(self): update = self.update bot = self.bot if isDos(update): return if(not checkpermission(update)): return update.message.reply_text("還原中...") # overwrite('filename_auto_back_up.txt') curData = Concat_Lines(read('filename.txt')) write('filename.txt', Concat_Lines(read('filename_auto_back_up.txt'))) write('filename_auto_back_up.txt', curData) update.message.reply_text("以自動備份檔還原完成") appendlog(getID(update), update.message.from_user.full_name, update.message.text)
def run(self): update = self.update bot = self.bot if isDos(update): return text = update.message.text.split() if len(text) == 1: update.message.reply_text('請使用以下格式回報問題:\n/report 回報內容\n') return name = update.message.from_user.full_name chat_type = update.message.chat.type text = Concat_Lines(text[1:]) append('user_report.txt', '{} as {}: {}\n'.format(name, chat_type, text)) update.message.reply_text('已將您的問題回報給開發者,感謝您的使用') appendlog(getID(update), update.message.from_user.full_name, update.message.text)
def run(self): update = self.update bot = self.bot if isDos(update): return if (not checkLowerPermission(update)): return try: command, shopname = update.message.text.split() except: update.messge.reply_text('格式錯誤,正確格式為:') update.messge.reply_text('/delete 店家名稱') return curMD.delete(curMD.getCategory(shopname), shopname, pushNow=True) update.message.reply_text('店家 {} 已刪除'.format(shopname)) appendlog(getID(update), update.message.from_user.full_name, update.message.text)
def run(self): update = self.update bot = self.bot if isDos(update): return if (not checkpermission(update)): return update.message.reply_text('備份中...') curMD.push(hackmd=True) if curMD.text == requests.get( 'https://hackmd.io/Tz5EFYy-T-Sp9LqpvJkGLg' ).text.split( '<div id="doc" class="markdown-body container-fluid" data-hard-breaks="true">' )[1].split('</div>')[0]: update.message.reply_text('備份成功') else: update.message.reply_text('備份失敗') appendlog(getID(update), update.message.from_user.full_name, update.message.text)
def DealWithPhotolink(update, file_id): chat_id = getID(update) if chat_id in status: state = status.get(chat_id) if state == 'add_step2' or state == 'photo_update': if chat_id not in add_query_photo_lock: status.update({chat_id: 'photo_update'}) add_query_photo_lock.update({chat_id: threading.Lock()}) add_query_photo_num.update({chat_id: 0}) add_query_photo_num.update( {chat_id: add_query_photo_num.get(chat_id) + 1}) add_query_photo_lock.get(chat_id).acquire() update.message.reply_text('正在取得照片...') photolink = uploadAndGetPhoto(file_id) if chat_id in add_query_photolink: # exist add_query_photolink[chat_id].append(photolink) else: # first append add_query_photolink[chat_id] = [photolink] add_query_photo_num.update( {chat_id: add_query_photo_num.get(chat_id) - 1}) if add_query_photo_num.get(chat_id) == 0: status.update({chat_id: 'add_step2'}) update.message.reply_text( '請繼續傳送照片或輸入 /add 結束傳送', reply_markup=ForceReply(selective=True)) add_query_photo_lock.get(chat_id).release() append( 'imagesource.txt', '{}({}): {}, {}\n'.format(chat_id, update.message.from_user.full_name, add_query_shopname.get(chat_id), photolink)) else: print('ignore it')
def run(self): update = self.update bot = self.bot if isDos(update): return if (not checkpermission(update)): return try: correct, wrong = update.message.text[len('/addtypo '):].split() except: update.message.reply_text('格式錯誤,請使用格式') update.message.reply_text('/addtypo 正確詞 錯誤詞') return r = read("typo.json") if correct in r: r[correct].append(wrong) else: r[correct] = [wrong] r = str(r) r = r.replace("\'", "\"") write("typo.json", r) update.message.reply_text("已新增") appendlog(getID(update), update.message.from_user.full_name, update.message.text)
def run(self): update = self.update bot = self.bot reply, chat_id, type = update.callback_query.data.split(" ") update2 = '' if chat_id in add_query_update: update2 = add_query_update.get(chat_id) add_query_update.pop(chat_id) else: update.callback_query.edit_message_text('此要求已過期') return type = int(type) if type == 0 and status.get(chat_id) == 'add_step0': # add update.callback_query.edit_message_text('分類為:{}\n'.format(reply)) update2.message.reply_text('請輸入店家名稱', reply_markup=ForceReply(selective=True)) status.update({chat_id: 'add_step1'}) add_query_classification[chat_id] = reply elif type == 1 and status.get(chat_id) == 'search_step1': # search update.callback_query.edit_message_text(reply) curMenu = curMD.getMenu(reply) status.pop(chat_id) for photolink in curMenu: update2.message.reply_photo(photolink) elif type == 2 and status.get(chat_id) == 'random': # random def random_shop(category): if category == '無': list = [] for i in curMD.getshops(): list += i else: list = curMD.getshops()[classMap[category] - 2] random.shuffle(list) if list == []: return None else: return list[0] def push_menu(curShop, curMenu): if (curMenu == []): update2.message.reply_text('此分類暫時無店家') return update2.message.reply_text(curShop) for link in curMenu: update2.message.reply_photo(link) status.pop(chat_id) update.callback_query.edit_message_text('條件: {}'.format(reply)) curShop = random_shop(reply) push_menu(curShop, curMD.getMenu(curShop)) elif type == 3: #list update.callback_query.edit_message_text( reply) # reply is the category user_reply = reply if user_reply == '無': list = [] for i in curMD.getshops(): list += i else: list = curMD.getshops()[classMap[user_reply] - 2] reply = '' count = 0 max_word = 4 single_line_cnt = 3 for shop in list: reply += shop count += 1 if count % single_line_cnt == 0: reply += '\n' elif len(shop) > max_word: reply += '\n' count = 0 else: for j in range(max_word - len(shop) + 1): reply += '\t\t\t\t' if reply == '': reply = '此分類暫時無店家' update2.message.reply_text(reply, parse_mode=ParseMode.HTML) else: update.callback_query.edit_message_text('此要求已過期') appendlog(getID(update2), update2.message.from_user.full_name, reply)