diff --git a/src/BX-Telegram.py b/src/BX-Telegram.py index 72967c4909574401342ea0fa031ba6eee2dc39c6..63f3909462b2a8e82a7b3a6d0ebf53b09ac5fb01 100644 --- a/src/BX-Telegram.py +++ b/src/BX-Telegram.py @@ -126,15 +126,13 @@ def main() -> None: application = Application.builder().token(bot_token).build() members = Lore.Members() - + gemhandler = Lore.GemHandler() conv_handler = ConversationHandler( entry_points=[CommandHandler("start", start), MessageHandler(filters.TEXT, start)], states={ INITIAL: [ #Initial state of the bot in which it can be asked about gems, the lore and committees - MessageHandler( - filters.Regex(re.compile(r'gems', re.IGNORECASE)), gems - ), + gemhandler.handler, MessageHandler( filters.Regex(re.compile(r"l'?ore", re.IGNORECASE)), lore ), diff --git a/src/Lore/gems.py b/src/Lore/gems.py index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..0af5fc58043175e754e9432d819b9161dfd2ca87 100644 --- a/src/Lore/gems.py +++ b/src/Lore/gems.py @@ -0,0 +1,66 @@ +import logging +import re +import time +import json +from utils import db, config + + +with open(config.ROOT + './credentials.json') as f: + bot_token = json.load(f)["SailoreBXBot"] + +with open(config.ROOT + './data/Initial.json', encoding='utf-8') as f: + texts = json.load(f) + +from telegram import __version__ as TG_VER +try: + from telegram import __version_info__ +except ImportError: + __version_info__ = (0, 0, 0, 0, 0) # type: ignore[assignment] + +if __version_info__ < (20, 0, 0, "alpha", 1): + raise RuntimeError( + f"This example is not compatible with your current PTB version {TG_VER}. To view the " + f"{TG_VER} version of this example, " + f"visit https://docs.python-telegram-bot.org/en/v{TG_VER}/examples.html" + ) +from telegram import Update +from telegram.ext import ( + Application, + CommandHandler, + ContextTypes, + ConversationHandler, + MessageHandler, + filters, +) + +# Enable logging +logging.basicConfig( + format="%(asctime)s - %(name)s - %(levelname)s - %(message)s", level=logging.INFO +) +# set higher logging level for httpx to avoid all GET and POST requests being logged +logging.getLogger("httpx").setLevel(logging.WARNING) + +logger = logging.getLogger(__name__) + +class GemHandler: + def __init__(self): + self.EXIT = 0 + self.handler = ConversationHandler( + entry_points=[MessageHandler(filters.Regex(re.compile(r'gems', re.IGNORECASE)), self.gems)], + states={ + + }, + fallbacks=[], + map_to_parent={ + self.EXIT: self.EXIT + } + ) + + + async def gems(self, update: Update, context: ContextTypes.DEFAULT_TYPE): + """Tell them a little bit about gems, in the future it will give more options but for that I'll have to ask Gaia and Adrien about IW""" + for message in texts["gems"]: + await context.bot.send_chat_action(chat_id=update.effective_chat.id, action='typing') + time.sleep(len(message)/140) + await context.bot.send_message(chat_id=update.effective_chat.id, text=message) + return self.EXIT \ No newline at end of file