def test_edit_message(): bot = MockBot() chat_id = 42 message_id = 1337 chat = Chat(bot, chat_id) chat.edit_text(message_id, "bye") assert "editMessageText" in bot.calls assert bot.calls["editMessageText"]["text"] == "bye" assert bot.calls["editMessageText"]["message_id"] == message_id
def test_edit_message(): bot = MockBot() chat_id = 42 message_id = 1337 chat = Chat(bot, chat_id) chat.edit_text(message_id, "bye") assert "editMessageText" in bot.calls assert bot.calls["editMessageText"]["text"] == "bye" assert bot.calls["editMessageText"]["message_id"] == message_id
async def subscribe(chat: Chat, match): regex = ".*" if not match.group(1) else match.group(1).strip() queue = Queue() rnd_name = str(uuid4()) hook = get_hook(queue) bot.add_callback(rnd_name + "-(.*)", hook) markup = get_subscribe_markup(["any"] + self.source_types, rnd_name) sended_msg = await chat.send_text("Choose source type", reply_markup=json.dumps(markup)) # print("SENDED", sended_msg) sended_message_id = sended_msg['result']['message_id'] nmatch = await queue.get() choosed_source_type = nmatch.group(1) source_type = ".*" if choosed_source_type == "any" else choosed_source_type subscriber = Subscriber(chat.id, PIN_TYPE, source_type, None, regex) await self.subscribers.add(subscriber) return chat.edit_text(sended_message_id, "You have been subscribed '%s' from source '%s'" % (regex, source_type))
async def subscriptions(chat: Chat, match): subs = await self.subscribers.get_subscriptions(chat.id) # print("(telegram)", subs) if not subs: return chat.send_text("You dont have subscriptions") queue = Queue() rnd_name = str(uuid4()) hook = get_hook(queue) bot.add_callback(rnd_name + "-(.*)", hook) markup = get_subscriptions_markup(subs, rnd_name) sended_msg = await chat.send_text("Subscriptions:", reply_markup=json.dumps(markup)) sended_message_id = sended_msg['result']['message_id'] nmatch = await queue.get() choosed_id = int(nmatch.group(1)) removed_sub = await self.subscribers.remove(chat.id, choosed_id) msg = "Unsubscribed from '%s'" % removed_sub return chat.edit_text(sended_message_id, msg)