Browse Source

fix: Use regex instead of simple .includes (#260)

SI_NN_ER_LS 2 năm trước cách đây
mục cha
commit
d45280d1fb
3 tập tin đã thay đổi với 7 bổ sung và 5 xóa
  1. 1 1
      wbb/__main__.py
  2. 2 1
      wbb/modules/greetings.py
  3. 4 3
      wbb/utils/functions.py

+ 1 - 1
wbb/__main__.py

@@ -215,7 +215,7 @@ async def start(_, message):
                 if "{name}" in text:
                     text = text.replace("{name}", user.mention)
                 keyb = None
-                if "~" in text:
+                if re.findall(r"\[.+\,.+\]", text):
                     text, keyb = extract_text_and_keyb(ikb, text)
                 await app.send_message(user_id, text=text, reply_markup=keyb)
             else:

+ 2 - 1
wbb/modules/greetings.py

@@ -24,6 +24,7 @@ SOFTWARE.
 
 import asyncio
 import os
+from re import findall
 from datetime import datetime, timedelta
 from random import shuffle
 
@@ -256,7 +257,7 @@ async def send_welcome_message(chat: Chat, user_id: int, delete: bool = False):
         return
     text = raw_text
     keyb = None
-    if "~" in raw_text:
+    if findall(r"\[.+\,.+\]", raw_text):
         text, keyb = extract_text_and_keyb(ikb, raw_text)
 
     if "{chat}" in text:

+ 4 - 3
wbb/utils/functions.py

@@ -305,7 +305,11 @@ def extract_text_and_keyb(ikb, text: str, row_width: int = 2):
         if text.endswith("`"):
             text = text[:-1]
 
+        if "~~" in text:
+            text = text.replace("~~", "¤¤")
         text, keyb = text.split("~")
+        if "¤¤" in text:
+            text = text.replace("¤¤", "~~")
 
         keyb = findall(r"\[.+\,.+\]", keyb)
         for btn_str in keyb:
@@ -327,9 +331,6 @@ async def check_format(ikb, raw_text: str):
     if keyb and not "~" in raw_text:
         raw_text = raw_text.replace("button=", "\n~\nbutton=")
         return raw_text
-    if "~" in raw_text and not keyb:
-        raw_text = raw_text.replace("~", "")
-        return raw_text
     if "~" in raw_text and keyb:
         if not extract_text_and_keyb(ikb, raw_text):
             return ""