From 1ff3d6edd4a4efb56ed4751e77559c51dcebd1f2 Mon Sep 17 00:00:00 2001 From: Stefano Pigozzi Date: Wed, 8 Apr 2020 20:21:52 +0200 Subject: [PATCH] Readd legacy keyboard registration --- royalnet/commands/commanddata.py | 8 ++++++++ royalnet/serf/telegram/telegramserf.py | 12 ++++++++++-- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/royalnet/commands/commanddata.py b/royalnet/commands/commanddata.py index bee9d885..f4598f1d 100644 --- a/royalnet/commands/commanddata.py +++ b/royalnet/commands/commanddata.py @@ -80,3 +80,11 @@ class CommandData: async def keyboard(self, text, keys: List["KeyboardKey"]): yield raise UnsupportedError(f"{self.keyboard.__name__} is not supported") + + @classmethod + def register_keyboard_key(cls, identifier: str, key: "KeyboardKey"): + raise UnsupportedError(f"{cls.register_keyboard_key.__name__} is not supported") + + @classmethod + def unregister_keyboard_key(cls, identifier: str): + raise UnsupportedError(f"{cls.unregister_keyboard_key.__name__} is not supported") diff --git a/royalnet/serf/telegram/telegramserf.py b/royalnet/serf/telegram/telegramserf.py index f77415c6..9b956920 100644 --- a/royalnet/serf/telegram/telegramserf.py +++ b/royalnet/serf/telegram/telegramserf.py @@ -147,7 +147,7 @@ class TelegramSerf(Serf): for key in keys: uid: str = str(uuid.uuid4()) key_uids.append(uid) - self.key_callbacks[uid] = key + data.register_keyboard_key(uid, key) tg_button: telegram.InlineKeyboardButton = telegram.InlineKeyboardButton(key.text, callback_data=uid) tg_row: List[telegram.InlineKeyboardButton] = [tg_button] @@ -161,7 +161,15 @@ class TelegramSerf(Serf): yield message await self.api_call(message.edit_reply_markup, reply_markup=None) for uid in key_uids: - del self.key_callbacks[uid] + data.unregister_keyboard_key(uid) + + @classmethod + def register_keyboard_key(cls, identifier: str, key: rc.KeyboardKey): + self.key_callbacks[identifier] = key + + @classmethod + def unregister_keyboard_key(cls, identifier: str): + del self.key_callbacks[identifier] return TelegramMessageData