def button(client: app, callback_query: CallbackQuery): q_data = callback_query.data query_data = q_data.split('_')[0] type_n = q_data.split('_')[1] user_id = int(q_data.split('_')[2]) cuser_id = callback_query.from_user.id if cuser_id == user_id: if query_data == "type": data = jtype[type_n] strong_against = ", ".join(data['strong_against']) weak_against = ", ".join(data['weak_against']) resistant_to = ", ".join(data['resistant_to']) vulnerable_to = ", ".join(data['vulnerable_to']) keyboard = ([[ InlineKeyboardButton('Back',callback_data=f"hexa_back_{user_id}")]]) callback_query.message.edit_text( text=(f"Type : `{type_n}`\n\n" f"Strong Against:\n`{strong_against}`\n\n" f"Weak Against:\n`{weak_against}`\n\n" f"Resistant To:\n`{resistant_to}`\n\n" f"Vulnerable To:\n`{vulnerable_to}`"), reply_markup=InlineKeyboardMarkup(keyboard) ) else: callback_query.answer( text="You can't use this button!", show_alert=True )
def poketypes_callback(client: app, callback_query: CallbackQuery): q_data = callback_query.data query_data = q_data.split('_')[1].lower() pt_name = q_data.split('_')[2] user_id = int(q_data.split('_')[3]) if callback_query.from_user.id == user_id: data = jtype[query_data] strong_against = ", ".join(data['strong_against']) weak_against = ", ".join(data['weak_against']) resistant_to = ", ".join(data['resistant_to']) vulnerable_to = ", ".join(data['vulnerable_to']) keyboard = ([[ InlineKeyboardButton('Back',callback_data=f"pback_{pt_name}_{user_id}")]]) callback_query.message.edit_text( text=(f"Type : `{query_data}`\n\n" f"Strong Against:\n`{strong_against}`\n\n" f"Weak Against:\n`{weak_against}`\n\n" f"Resistant To:\n`{resistant_to}`\n\n" f"Vulnerable To:\n`{vulnerable_to}`"), reply_markup=InlineKeyboardMarkup(keyboard) ) else: callback_query.answer( text="You're not allowed to use this!", show_alert=True )
def CbQryUlFolder(client: pyrogram.Client, cb_qry: pyrogram.CallbackQuery): zip_name = str(pathlib.Path(utils.config["file_manager"]["path"]).name) zip_name = f"./downloads/{zip_name}" cb_qry.answer(text=f"Zipping and uploading {zip_name}") try: shutil.make_archive( zip_name, "zip", root_dir=str(pathlib.Path(sys.argv[0]).parent), base_dir=utils.config["file_manager"]["path"], ) tmpmsg: pyrogram.Message = cb_qry.message.reply_text( text="Uploading " + os.path.join(str(pathlib.Path(sys.argv[0]).parent), zip_name), quote=True, ) cb_qry.message.reply_document( document=f"./{zip_name}.zip", progress=utils.DFromUToTelegramProgress, progress_args=(tmpmsg, tmpmsg.text, time.time()), ) os.remove(zip_name + ".zip") except Exception as e: print(e)
def CbQryPagesMove(client: pyrogram.Client, cb_qry: pyrogram.CallbackQuery): items = os.listdir(utils.config["file_manager"]["path"]) if cb_qry.data.endswith("<<"): utils.config["file_manager"]["page"] = 0 elif cb_qry.data.endswith("-"): utils.config["file_manager"]["page"] -= 1 elif cb_qry.data.endswith("+"): utils.config["file_manager"]["page"] += 1 elif cb_qry.data.endswith(">>"): utils.config["file_manager"]["page"] = ( math.ceil( len(items) / ( utils.config["file_manager"]["max_columns"] * utils.config["file_manager"]["max_rows"] ) ) - 1 ) cb_qry.answer(text="Turning page...") cb_qry.edit_message_reply_markup( reply_markup=pyrogram.InlineKeyboardMarkup( keyboards.BuildItemsKeyboard( path=utils.config["file_manager"]["path"], page=utils.config["file_manager"]["page"], max_columns=utils.config["file_manager"]["max_columns"], max_rows=utils.config["file_manager"]["max_rows"], ) ) ) with open(file="utils.config.json", mode="w", encoding="utf-8") as f: json.dump(utils.config, f, indent=4)
def poketypes_back(client: app, callback_query: CallbackQuery): q_data = callback_query.data query_data = q_data.split('_')[1].lower() user_id = int(q_data.split('_')[2]) if callback_query.from_user.id == user_id: p_type = data[query_data][query_data]['type'] try: get_pt = f"{p_type['type1']}, {p_type['type2']:}" keyboard = ([[ InlineKeyboardButton(p_type['type1'],callback_data=f"poket_{p_type['type1']}_{query_data}_{user_id}"), InlineKeyboardButton(p_type['type2'],callback_data=f"poket_{p_type['type2']}_{query_data}_{user_id}")]]) except KeyError: get_pt = f"{p_type['type1']}" keyboard = ([[ InlineKeyboardButton(p_type['type1'],callback_data=f"poket_{p_type['type1']}_{query_data}_{user_id}")]]) callback_query.message.edit_text( (f"Pokemon: `{query_data}`\n\n" f"Types: `{get_pt}`\n\n" "__Click the button below to get the pokemon's type's/types' effectiveness and weakness!__"), reply_markup=InlineKeyboardMarkup(keyboard) ) else: callback_query.answer( text="You're not allowed to use this!", show_alert=True )
def on_callback(client: Client, cb: CallbackQuery): #print(len(cb.data)) #decode the data to a list of lists paths = callback_decode(cb.data) #root action is None action = None #for every item in the list get the action_id and args for the action for action_id, *args in paths: #get the action by the id and call with the args and previous action as the parent action = actions[action_id](*args, parent=action) try: #finally, call the last/current action with the callback, and get an optionally different action as response action = action.on_click(cb) or action if not isinstance(action, Menu): return cb.answer(action.callback_answer_text or action.title) #TODO handle if the text and/or keyboard are the same as last cb.message.edit(action.text, parse_mode=action.parse_mode, reply_markup=action.get_reply_markup()) try: cb.answer(action.callback_answer_text or action.title) except errors.QueryIdInvalid: pass except Exception as e: #show alert with exception cb.answer(str(e), True) raise
def send_confirm(self, client: Client, msg: CallbackQuery): if msg.data.startswith('close'): self.confirm_dialog(msg, 'close this ticket', 'close',ticket_id = msg.data.split()[-1]) elif msg.data.startswith('block'): self.confirm_dialog(msg, 'block this user', 'block', user_id = int(msg.data.split()[-1])) elif msg.data.startswith('send'): self.confirm_dialog(msg, 'send the link to', 'send', user_id = int(msg.data.split()[-1])) elif msg.data.startswith('reset'): self.confirm_dialog(msg, 'reset retry times for', 'reset', user_id = int(msg.data.split()[-1])) elif msg.data.startswith('del'): msg.answer('Please press again to make sure. If you really want to delete this reply', True) self.bot.send_message( self.help_group, 'Do you want to delete reply message to {}?'.format(build_html_parse.parse_user(msg.data.split()[-2])), 'markdown', reply_markup = self.generate_confirm_keyboard('del', msg.data[4:]) ) elif msg.data.startswith('bypass'): self.confirm_dialog(msg, 'set bypass for', 'bypass', int(msg.data.split()[-1])) elif msg.data.startswith('renew'): self.confirm_dialog(msg, 'reset user status', 'renew', int(msg.data.split()[-1])) elif msg.data.startswith('setpass'): self.confirm_dialog(msg, 'set pass', 'setpass', int(msg.data.split()[-1])) elif msg.data.startswith('unlimited'): self.confirm_dialog(msg, 'set unlimited retries for', 'unlimited', int(msg.data.split()[-1])) msg.answer()
def click_to_join(self, client: Client, msg: CallbackQuery): if msg.data == 'iamready': try: client.edit_message_reply_markup(msg.message.chat.id, msg.message.message_id) self.revoke_tracker_thread.send_link(msg.message.chat.id, True) msg.answer('The invitation link has been sent.') except: traceback.print_exc() return True return False
def CbQryUpdateFolder(client: pyrogram.Client, cb_qry: pyrogram.CallbackQuery): cb_qry.answer(text="Updating folder...") cb_qry.edit_message_text( text="Path: " + utils.config["file_manager"]["path"], reply_markup=pyrogram.InlineKeyboardMarkup( keyboards.BuildItemsKeyboard( path=utils.config["file_manager"]["path"], page=utils.config["file_manager"]["page"], max_columns=utils.config["file_manager"]["max_columns"], max_rows=utils.config["file_manager"]["max_rows"], ) ), )
def callback_query_pyro(bot: Assistant, cb: CallbackQuery): data = cb.data.encode('UTF-8') user_id = cb.from_user.id chat_id = cb.message.chat.id cht = [cb.message.chat.username] dataid = cb.id res = [item for item in TARGET if item in cht] username = cb.message.chat.username data = data.split(b'%') chat = ''.join(str(e) for e in res) chat_id = str(chat_id) action = '' confirmed = False for elem in data: name, *args = elem.split(b'=') if name == b'act': action = args[0] elif name == b'chat_id': chatid = int(args[0]) elif name == b'user_id': userid = int(args[0]) elif name == b'cnf': confirmed = bool(int(args[0])) if action == b"unres": if username == chat: if user_id == int(userid): if not confirmed: bot.restrict_chat_member(chat_id=chat, user_id=int(userid), until_date=0, can_send_messages=True, can_send_media_messages=True, can_send_other_messages=True, can_add_web_page_previews=True, can_send_polls=True) cb.answer("Your restriction were lifted, welcome!") bot.edit_message_text( chat_id=chat, message_id=cb.message.message_id, text=cb.message.text.markdown.split('\n')[0], disable_web_page_preview=True, reply_markup=None) else: cb.answer("That wasn't your button!", show_alert=True)
def answer(self, client: Client, msg: CallbackQuery): msg.data = msg.data.decode(errors = 'ignore') if msg.data.startswith('cancel'): client.edit_message_reply_markup(msg.message.chat.id, msg.message.message_id) msg.answer('Canceled') elif msg.data.startswith('unban'): self.mysqldb.execute("UPDATE `tickets_user` SET `baned` = 0 WHERE `user_id` = {}".format(msg.data.split()[-1])) msg.answer('UNBANED') client.edit_message_reply_markup(msg.message.chat.id, msg.message.message_id) elif msg.data.startswith('refresh'): try: client.edit_message_text( msg.message.chat.id, msg.message.message_id, self.generate_superuser_text(msg.data.split()[-1]), 'markdown', reply_markup = msg.message.reply_markup ) except api.errors.exceptions.bad_request_400.MessageNotModified: pass msg.answer('refreshed') elif 'confirm' in msg.data: try: self.confirm(client, msg) except TimeoutError: msg.answer('Confirmation time out') client.edit_message_reply_markup(msg.message.chat.id, msg.message.message_id) elif any(msg.data.startswith(x) for x in ('close', 'block', 'send', 'bypass', 'reset', 'unlimited', 'del', 'renew', 'setpass')): self.send_confirm(client, msg) else: try: raise ValueError(msg.data) except: client.send_message(self.help_group, traceback.format_exc(), disable_web_page_preview = True)
def button2(client: app, callback_query: CallbackQuery): q_data = callback_query.data query_data = q_data.split('_')[1] user_id = int(q_data.split('_')[2]) cuser_id = callback_query.from_user.id if user_id == cuser_id: if query_data == "back": callback_query.message.edit_text("List of types of Pokemons:", reply_markup=InlineKeyboardMarkup( ptype_buttons(user_id))) elif query_data == "delete": callback_query.message.delete() else: return else: callback_query.answer(text="You can't use this button!", show_alert=True)
def CbQryUlFile(client: pyrogram.Client, cb_qry: pyrogram.CallbackQuery): i = int(cb_qry.data.replace("FMul", "")) file_name = sorted(os.listdir(utils.config["file_manager"]["path"]))[i] cb_qry.answer(text=f"Uploading {file_name}") try: tmpmsg: pyrogram.Message = cb_qry.message.reply_text( text=f"Uploading {file_name}", quote=True ) cb_qry.message.reply_document( document=os.path.abspath( os.path.join(utils.config["file_manager"]["path"], file_name) ), progress=utils.DFromUToTelegramProgress, progress_args=(tmpmsg, tmpmsg.text, time.time()), ) except Exception as e: print(e)
def button2(client: app, callback_query: CallbackQuery): q_data = callback_query.data query_data = q_data.split('_')[1] user_id = int(q_data.split('_')[2]) cuser_id = callback_query.from_user.id if user_id == cuser_id: if query_data == "back": callback_query.message.edit_text( "<b>List of types of Pokemons which are Available here are given below </b>", reply_markup=InlineKeyboardMarkup(ptype_buttons(user_id))) elif query_data == "delete": callback_query.message.delete() else: return else: callback_query.answer( text= "You can't use this button only the user who used /types can use if you want to use the do /types and use", show_alert=True)
def CbQryCdDrive(client: pyrogram.Client, cb_qry: pyrogram.CallbackQuery): utils.config["file_manager"]["path"] = ( utils.GetDrives()[int(cb_qry.data.replace("FMcddrive", ""))] + ":\\" ) utils.config["file_manager"]["page"] = 0 cb_qry.answer(text="Moving to drive " + utils.config["file_manager"]["path"]) cb_qry.edit_message_text( text="Path: " + utils.config["file_manager"]["path"], reply_markup=pyrogram.InlineKeyboardMarkup( keyboards.BuildItemsKeyboard( path=utils.config["file_manager"]["path"], page=utils.config["file_manager"]["page"], max_columns=utils.config["file_manager"]["max_columns"], max_rows=utils.config["file_manager"]["max_rows"], ) ), ) with open(file="utils.config.json", mode="w", encoding="utf-8") as f: json.dump(utils.config, f, indent=4)
def CbQryCdFolder(client: pyrogram.Client, cb_qry: pyrogram.CallbackQuery): i = int(cb_qry.data.replace("FMcd", "")) folder = sorted(os.listdir(utils.config["file_manager"]["path"]))[i] utils.config["file_manager"]["path"] = os.path.abspath( os.path.join(utils.config["file_manager"]["path"], folder) ) utils.config["file_manager"]["page"] = 0 cb_qry.answer(text="Moving to " + utils.config["file_manager"]["path"]) cb_qry.edit_message_text( text="Path: " + utils.config["file_manager"]["path"], reply_markup=pyrogram.InlineKeyboardMarkup( keyboards.BuildItemsKeyboard( path=utils.config["file_manager"]["path"], page=utils.config["file_manager"]["page"], max_columns=utils.config["file_manager"]["max_columns"], max_rows=utils.config["file_manager"]["max_rows"], ) ), ) with open(file="utils.config.json", mode="w", encoding="utf-8") as f: json.dump(utils.config, f, indent=4)
def CbQryPreviousFolder(client: pyrogram.Client, cb_qry: pyrogram.CallbackQuery): if utils.config["file_manager"]["path"][1:].endswith(":\\"): utils.config["file_manager"]["path"] = "/" else: utils.config["file_manager"]["path"] = str( pathlib.Path(utils.config["file_manager"]["path"]).parent ) utils.config["file_manager"]["page"] = 0 cb_qry.answer(text="Moving to " + utils.config["file_manager"]["path"]) cb_qry.edit_message_text( text="Path: " + utils.config["file_manager"]["path"], reply_markup=pyrogram.InlineKeyboardMarkup( keyboards.BuildItemsKeyboard( path=utils.config["file_manager"]["path"], page=utils.config["file_manager"]["page"], max_columns=utils.config["file_manager"]["max_columns"], max_rows=utils.config["file_manager"]["max_rows"], ) ), ) with open(file="utils.config.json", mode="w", encoding="utf-8") as f: json.dump(utils.config, f, indent=4)
def privacy(client: Client, message: CallbackQuery): action = message.data.split()[-1] if action == 'on': privacy = True else: privacy = False mongo = db_tools.use_mongo() query = {'chat.id': message.from_user.id} query_result = mongo.nintendo.find_one(query) if not isinstance(query_result, dict): text = '發生不明錯誤,無法查詢到該筆資料.' message.answer(text, show_alert=True) return if 'privacy' not in query_result.keys(): current = False else: current = query_result['privacy'] if current == privacy: message.answer("你已經設定好了啦 ヾ(⌒(ノシ'ω')ノシ", show_alert=True) return # update settings. # 忍術拖延戰術! message.answer('已更新設定', show_alert=True) query_ = copy.copy(query) query_.update({'privacy': privacy}) update = {'$set': query_} mongo.nintendo.update_one(query, update) text = '目前你的隱私狀態為 `{status}`\n' \ '意思是任何人都 `{visble}` 利用 `/findfc` 指令找到你喔!'.format( status='開啟' if privacy else '關閉', visble='不可以' if privacy else '可以' ) while True: try: message.edit_message_text(text, parse_mode='markdown', reply_markup=keyboard.privacy()) except FloodWait as wait: sleep(wait.x) else: break
def answer(query: CallbackQuery, sleep: bool = True, *args, **kwargs): """Answers a query in a way that never triggers exceptions and logs errors :param query: The pyrogram.CallbackQuery object to call the method for :type query: class: CallbackQuery :param sleep: If True, the default, the function will call time.sleep() in case of a FloodWait exception and return the exception object after the sleep is done, otherwise the ``FloodWait`` exception is returned immediately :returns: Whatever the called pyrogram method returns, or an exception if the method call caused an error """ try: return query.answer(*args, **kwargs) except FloodWait as fw: logging.warning(f"FloodWait! A wait of {fw.x} seconds is required") if sleep: time.sleep(fw.x) return fw except RPCError as generic_error: logging.error(f"An exception occurred: {generic_error}") return generic_error
def acnh(client: Client, inline_query: CallbackQuery): keyboard = inlinekeyboard.bindacnh(inline_query) inline_query.answer(keyboard, cache_time=0)
def handle_callback(self, client: Client, msg: CallbackQuery): msg.data = msg.data.decode(errors='ignore') try: if msg.data.startswith('cancel') or msg.data == 'rm': msg.answer( msg.id, 'Canceled' if not msg.data == 'rm' else 'Button removed') if msg.data.endswith('d'): client.delete_messages(msg.message.chat.id, msg.message.message_id) else: client.edit_message_reply_markup(msg.message.chat.id, msg.message.message_id) if self.join_group_verify is not None and self.join_group_verify.click_to_join( client, msg): return if msg.data.startswith('res'): if time.time() - msg.message.date > 20: raise OperationTimeoutError() _, dur, _type, _user_id = msg.data.split() if client.restrict_chat_member( self.target_group, int(_user_id), int(time.time()) + int(dur), **({ 'write': { 'can_send_messages': True }, 'media': { 'can_send_media_messages': True }, 'stickers': { 'can_send_other_messages': True }, 'link': { 'can_add_web_page_previews': True }, 'read': {} }.get(_type))): msg.answer('The user is restricted successfully.') client.edit_message_text( msg.message.chat.id, msg.message.message_id, 'Restrictions applied to {} Duration: {}'.format( build_html_parse.parse_user(_user_id), '{}s'.format(dur) if int(dur) else 'Forever'), parse_mode='markdown', reply_markup=InlineKeyboardMarkup([[ InlineKeyboardButton( text='UNBAN', callback_data='unban {}'.format( _user_id).encode()) ]])) elif msg.data.startswith('unban'): if client.restrict_chat_member(self.target_group, int(msg.data.split()[-1]), 0, True, True, True, True): msg.answer('Unban successfully') client.edit_message_reply_markup(msg.message.chat.id, msg.message.message_id) elif msg.data.startswith('auth'): if time.time() - msg.message.date > 20: raise OperationTimeoutError() auth_system.add_user(msg.data.split()[1]) msg.answer('{} added to the authorized group'.format( msg.data.split()[1])) client.edit_message_text( msg.message.chat.id, msg.message.message_id, '{} added to the authorized group'.format( msg.data.split()[1])) with open('config.ini', 'w') as fout: config.write(fout) elif msg.data.startswith('fwd'): if time.time() - msg.message.date > 30: raise OperationTimeoutError() if 'original' in msg.data: self.conn.insert_ex( client.forward_messages( self.target_group, msg.message.chat.id, msg. message.reply_to_message.message_id).message_id, msg.message.reply_to_message.message_id) else: self.conn.insert_ex( client.send_message( self.target_group, build_html_parse( msg.message.reply_to_message).split_offset(), 'html').message_id, msg.message.reply_to_message.message_id) msg.answer('Forward successfully') client.delete_messages(msg.message.chat.id, msg.message.message_id) elif msg.data.startswith('kick'): if not msg.data.startswith( 'kickc') and msg.from_user.id != int( msg.data.split()[-2]): raise OperatorError() if 'true' not in msg.data: if not msg.data.startswith( 'kickc') and time.time() - msg.message.date > 15: raise OperationTimeoutError() args = [ msg.message.chat.id, msg.message.message_id, 'Press the button again to kick {}\nThis confirmation message will expire after 10 seconds.' .format( build_html_parse.parse_user(msg.data.split()[-1])), ] if msg.data.startswith('kickc'): args.pop(1) r = msg.data.split() r.insert(1, msg.from_user.id) msg.data = ' '.join(str(x) for x in r) del r kwargs = { 'parse_mode': 'markdown', 'reply_markup': InlineKeyboardMarkup( inline_keyboard=[[ InlineKeyboardButton( text='Yes, please.', callback_data=b' '.join(( b'kick true', ' '.join( msg.data.split()[1:]).encode()))) ], [ InlineKeyboardButton( text='Cancel', callback_data=b'cancel') ]]) } (client.send_message if msg.data.startswith('kickc') else client.edit_message_text)(*args, **kwargs) msg.answer( 'Please press again to make sure. Do you really want to kick {} ?' .format(msg.data.split()[-1]), True) else: if msg.message.edit_date: if time.time() - msg.message.edit_date > 10: raise OperationTimeoutError() else: if time.time() - msg.message.date > 10: raise OperationTimeoutError() client.kick_chat_member(self.target_group, int(msg.data.split()[-1])) msg.answer('Kicked {}'.format(msg.data.split()[-1])) client.edit_message_text( msg.message.chat.id, msg.message.message_id, 'Kicked {}'.format( build_html_parse.parse_user(msg.data.split()[-1]))) #app.send_message(self.fudu_group, 'Kicked {}'.format(msg.message.entities[0].user.id)) #client.delete_messages(msg.message.chat.id, msg.message.message_id) elif msg.data.startswith('promote'): if not msg.data.endswith('undo'): if time.time() - msg.message.date > 10: raise OperationTimeoutError() self.botapp.promote_chat_member(self.target_group, int(msg.data.split()[1]), True, can_delete_messages=True, can_restrict_members=True, can_invite_users=True, can_pin_messages=True, can_promote_members=True) msg.answer('Promote successfully') client.edit_message_text( msg.message.chat.id, msg.message.message_id, 'Promoted {}'.format( build_html_parse.parse_user( int(msg.data.split()[1]))), parse_mode='markdown', reply_markup=InlineKeyboardMarkup(inline_keyboard=[ [ InlineKeyboardButton(text='UNDO', callback_data=' '.join(( msg.data, 'undo')).encode()) ], [ InlineKeyboardButton(text='remove button', callback_data=b'rm') ] ])) else: self.botapp.promote_chat_member(self.target_group, int(msg.data.split()[1]), False, can_delete_messages=False, can_invite_users=False, can_restrict_members=False) msg.answer('Undo Promote successfully') client.edit_message_text( msg.message.chat.id, msg.message.message_id, 'Unpromoted {}'.format( build_html_parse.parse_user( int(msg.data.split()[1]))), parse_mode='markdown') except OperationTimeoutError: msg.answer('Confirmation time out') client.edit_message_reply_markup(msg.message.chat.id, msg.message.message_id) except OperatorError: msg.answer( 'The operator should be {}.'.format(msg.data.split()[-2]), True) except: self.app.send_message(int(config['fuduji']['help_group']), traceback.format_exc().splitlines()[-1]) traceback.print_exc()
def CbQryPages(client: pyrogram.Client, cb_qry: pyrogram.CallbackQuery): cb_qry.answer(text="Useless button.")
def confirm(self, client: Client, msg: CallbackQuery): if time.time() - msg.message.date > 15: raise TimeoutError() if msg.data.startswith('close'): ticket_id = msg.data.split()[-1] q = self.mysqldb.query1("SELECT `user_id`, `status` FROM `tickets` WHERE `hash` = '{}'".format(ticket_id)) if q is None: return msg.answer('TICKET NOT FOUND', True) if q['status'] == 'closed': return msg.answer('TICKET CLOSED') self.mysqldb.execute("UPDATE `tickets` SET `status` = 'closed' WHERE `hash` = '{}'".format(ticket_id)) msg.answer('This ticket is closed.') client.send_message( self.help_group, "UPDATE\n[ #{} ]\nThis ticket is closed by {}.".format( ticket_id, tg_tools.build_html_parse.parse_user( msg.from_user.id, tg_tools.build_html_parse.user_name(msg.from_user).full_name ) ), 'markdown', reply_markup = self.generate_ticket_keyboard(ticket_id, q['user_id'], True) ) client.send_message(q['user_id'], "Your ticket [ #{} ] is closed".format(ticket_id)) elif msg.data.startswith('block'): self.mysqldb.execute("UPDATE `tickets_user` SET `baned` = 1 WHERE `user_id` = {}".format(msg.data.split()[-1])) msg.answer('DONE!') self.bot.send_message( self.help_group, 'blocked {}'.format(build_html_parse.parse_user(msg.data.split()[-1], msg.data.split()[-1])), parse_mode = 'markdown', reply_markup = InlineKeyboardMarkup( inline_keyboard = [ [InlineKeyboardButton(text = 'UNBAN', callback_data = 'unban {}'.format(msg.data.split()[-1]).encode())] ]) ) elif msg.data.startswith('send'): try: self.send_link_callback(int(msg.data.split()[-1]), True) msg.answer('The invitation link is sent successfully.') except: client.send_message(self.help_group, traceback.format_exc(), disable_web_page_preview = True) msg.answer('Failed to send the invitation link. Please check the console.\n{}'.format(traceback.format_exc().splitlines()[-1]), True) elif msg.data.startswith('reset'): self.mysqldb.execute('UPDATE `exam_user_session` SET `retries` = 0 WHERE `user_id` = {}'.format(msg.data.split()[-1])) msg.answer('Retry times has been reset') elif msg.data.startswith('del'): try: client.delete_messages(int(msg.data.split()[-2]), int(msg.data.split()[-1])) msg.answer('message has been deleted') except: client.send_message(self.help_group, traceback.format_exc(), disable_web_page_preview = True) msg.answer('Failed to delete the message. Please check the console.\n{}'.format(traceback.format_exc().splitlines()[-1]), True) elif msg.data.startswith('renew'): self.mysqldb.execute('DELETE FROM `exam_user_session` WHERE `user_id` = {}'.format(msg.data.split()[-1])) msg.answer('User Profile Deleted') elif msg.data.startswith('bypass'): self.mysqldb.execute('UPDATE `exam_user_session` SET `bypass` = 1 WHERE `user_id` = {}'.format(msg.data.split()[-1])) msg.answer('BYPASS SET SUCCESSFULLY') elif msg.data.startswith('setpass'): self.mysqldb.execute('UPDATE `exam_user_session` SET `passed` = 1 WHERE `user_id` = {}'.format(msg.data.split()[-1])) msg.answer('PASS SET SUCCESSFULLY') elif msg.data.startswith('unlimited'): self.mysqldb.execute('UPDATE `exam_user_session` SET `unlimited` = 1 WHERE `user_id` = {}'.format(msg.data.split()[-1])) msg.answer('UNLIMITED RETRIES SET SUCCESSFULLY') self.mysqldb.commit() client.delete_messages(msg.message.chat.id, msg.message.message_id)