From 6216bcf96fe330683a2590cb7a26bf5602a42aa7 Mon Sep 17 00:00:00 2001
From: Charlielv04 <carloslv04@gmail.com>
Date: Mon, 7 Aug 2023 18:40:04 +0200
Subject: [PATCH] Move gems to different file this time for real

---
 src/BX-Telegram.py |  6 ++---
 src/Lore/gems.py   | 66 ++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 68 insertions(+), 4 deletions(-)

diff --git a/src/BX-Telegram.py b/src/BX-Telegram.py
index 72967c4..63f3909 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 e69de29..0af5fc5 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
-- 
GitLab