def add_to_card(call): print('Add to Card') prod_id = call.data.split('_')[1] user_id = call.from_user.id cart = Cart.get_cart(str(user_id)) cart.add_product_to_cart(product_id=prod_id) bot.answer_callback_query(call.id, "Добавлено в корзину", show_alert=True)
def set_button_page(self, call: CallbackQuery, answer="切换到{}界面", alert=None): name = call.data.split(':')[2] answer = answer.format(name) with self._lock: if self._c_name == name: return None, None, True self._c_name = name self._c_page = self.button_pages.get(name) bot.answer_callback_query(call.id, answer, show_alert=alert)
def _listener(call: CallbackQuery): data = call.data.split(':') # type:list # 这里不使用eval是因为避免注入(虽然觉得不会有这种注入发生,但还是有备无患) switch = switch_interpret(data[2]) if flag.set(switch): if answer: # 应答按钮 bot.answer_callback_query( call.id, display_answer.format( *_get_mark(answer_mark, switch.real))) _refresh(switch)
def callbackSettings(call): chatId = call.message.chat.id currentChat = Chats.getChat(chatId) settingsStrings = call.replies.stg.strings # * Toggling setting, if a simple callback for i, callback in enumerate(allSettingsCallbacks): if call.data == callback: Settings.toggleSetting(currentChat, settingsStrings[i][0][3]) # * Upating the message markup = settingsMarkup(chatId) try: bot.edit_message_text( Language(chatId).strs.stg.msgTitle, chatId, call.message.message_id, reply_markup=markup, ) bot.answer_callback_query(call.id, Language(chatId).strs.stg.success) except ApiException as e: print(e)
def field_goto(self): if self.message_text == "111": self.r_print_r("new") else: print(self.call.data) i = 0 print("her_1") while i <= len(self.field): # print(self.field[i]) if self.field[i] == 2: her = i break i += 1 cell = int(self.call.data.split("_")[2]) result = int(self.call.data.split("_")[1]) print(result) print("Игрок %s ходит на %s" % (her, cell)) if result == 1: print("dddd") try: bot.answer_callback_query(callback_query_id=self.call_id, text="Ячейка не доступна") except: pass elif result == 0 or result == 3: print("num_2") # print(self.field) if her - cell == 1 or cell - her == 1 or cell - her == 5 or her - cell == 5: print("rez %s" % result) if result == 3: print(result) print("атака") else: self.field[her] = 0 self.field[cell] = 2 self.r_print_r() else: print("Ошибка")
def callbackInline(call): """Function to control inline buttonsm won't be used anywhere, just in the decorator""" if call.message: chatID = call.message.chat.id if call.data == 'toClearTrue': markup = types.InlineKeyboardMarkup(row_width = 1) keyboardItem1 = types.InlineKeyboardButton(call.replies.skeyboard[1], callback_data = 'deleteMessage') markup.add(keyboardItem1) bot.delete_message(chatID, call.message.message_id - 1) bot.edit_message_text(call.message.text, chatID, call.message.message_id, reply_markup = markup) # * Cleaning the chat Document currentChat = Chats.getChat(call.additionalInfo) currentChat.words = [] currentChat.sentMessages = currentChat.sentWords = 0 currentChat.topWord = Word(text='', sentTimes=0) currentChat.save() bot.send_message(chatID, call.replies.sclrd) if call.data == 'deleteMessage': bot.answer_callback_query(call.id, show_alert=False, text=call.replies.notf[0]) bot.delete_message(chatID, call.message.message_id) if call.data == 'deleteWithCommand': bot.answer_callback_query(call.id, show_alert=False, text=call.replies.notf[1]) bot.delete_message(chatID, call.message.message_id) bot.delete_message(chatID, call.additionalInfo) # * Handles changing language settings if call.data == 'setLangRu': Language(chatID).lang = (call, 'ru') if call.data == 'setLangEng': Language(chatID).lang = (call, 'eng') if call.data == 'setLangEng' or call.data == 'setLangRu': call.replies = Language(chatID).strs bot.answer_callback_query(call.id, show_alert = False, text = call.replies.sectl[1]) bot.delete_message(chatID, call.message.message_id)
def modifyMessage(bot_instance, message): # * Checking if a message id an a chat id match a those which are in the DB. # * Then we assume, that the message it's a new value for a setting, so we # * change it. currentChat = Chats.getChat(message.chat.id) if currentChat is None: return editMessageInfo = currentChat.settings.editMessageInfo if (editMessageInfo and editMessageInfo['requestMessageId'] + 1 == message.message_id and editMessageInfo['requestChatId'] == message.chat.id): try: editArgument = int(message.text.split()[0]) # * Changing setting value and sending user a reponse originalChatId = editMessageInfo['originalChatId'] chatWeToChange = Chats.getChat(originalChatId) strings = Language(originalChatId).strs originalChat = Chats.getChat(originalChatId) # * Checking if new value is not the same as it was before oldValue = Settings.getSettingsValue(originalChat, editMessageInfo['commandName']) print(editArgument, oldValue) if editArgument == oldValue: raise ValueError() except ValueError as e: print(e) bot.send_message(message.chat.id, strings.stg.valueIsWrong) editMessageInfo['requestMessageId'] = message.message_id + 1 currentChat.save() # * Changes setting Settings.setSettingValue( chatWeToChange, editMessageInfo['commandName'], editArgument ) # * Deleting the spare replies, when the number of saved replies # * is higher then the new value of removeAfter idsToRemove = [] if editMessageInfo['commandName'] == 'removeAfter' and oldValue > editArgument: for i, response in enumerate(originalChat.responses.items()): if i >= oldValue - editArgument: break try: bot_instance.delete_message(originalChatId, int(response[0])) if response[1]['connectedIDs']: for chatId, ids in response[1]['connectedIDs'].items(): for id in ids: # pass bot_instance.delete_message(int(chatId), id) except ApiException as e: print(e) idsToRemove.append(response[0]) for toRemove in idsToRemove: del originalChat.responses[toRemove] originalChat.save() # * Updates settings message in the originalChat bot.edit_message_text( strings.stg.msgTitle, originalChatId, originalChat.settings.lastMessageId[0], reply_markup=settingsMarkup(originalChatId) ) # * Answering bot.answer_callback_query( editMessageInfo['callbackId'], strings.stg.changeSuccess )
def set_timeout(self, call): if hasattr(call, 'data'): self.ti.max_download_time = 0 bot.answer_callback_query(call.id, "立即超时种子管理器!")
def _listener(call: CallbackQuery): # print('answer callback') bot.answer_callback_query(call.id, explain, show_alert=alert)