Explorar o código

fix: Several changes to Greetings, Filters, Notes, inline + Added: auto sync Text & keyboard (#228)

* added: Autocorrect Text + Button formattings

* Added: Autocorrect welcome message Text + Button formattings

* Added: save notes without replying to message + autocorrect Text + Buttons (format)

* Added: save filters without replying to message + autocorrect Text + Buttons (format)

* Added: inline command for easy accessibility

* 😐

* Update filters.py

* Update greetings.py

* Update inline.py

* Update notes.py

* Update functions.py

* if rose can why not William

* 🐞

* 🐞

* Update filters.py

* Update greetings.py

* Update inline.py

* Update notes.py

* Update functions.py

* it's already done as a separate feature
SI_NN_ER_LS %!s(int64=2) %!d(string=hai) anos
pai
achega
f434a412ee
Modificáronse 5 ficheiros con 139 adicións e 67 borrados
  1. 28 8
      wbb/modules/filters.py
  2. 42 41
      wbb/modules/greetings.py
  3. 21 2
      wbb/modules/inline.py
  4. 30 16
      wbb/modules/notes.py
  5. 18 0
      wbb/utils/functions.py

+ 28 - 8
wbb/modules/filters.py

@@ -21,6 +21,7 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 SOFTWARE.
 SOFTWARE.
 """
 """
+
 import re
 import re
 
 
 from pyrogram import filters
 from pyrogram import filters
@@ -38,7 +39,7 @@ from wbb.utils.dbfunctions import (
     deleteall_filters,
     deleteall_filters,
 )
 )
 from wbb.utils.filter_groups import chat_filters_group
 from wbb.utils.filter_groups import chat_filters_group
-from wbb.utils.functions import extract_text_and_keyb
+from wbb.utils.functions import extract_text_and_keyb, check_format
 from wbb.modules.admin import member_permissions
 from wbb.modules.admin import member_permissions
 from wbb.modules.notes import extract_urls
 from wbb.modules.notes import extract_urls
 
 
@@ -64,29 +65,38 @@ Checkout /markdownhelp to know more about formattings and other syntax.
 @adminsOnly("can_change_info")
 @adminsOnly("can_change_info")
 async def save_filters(_, message):
 async def save_filters(_, message):
     try:
     try:
-        if len(message.command) < 2 or not message.reply_to_message:
+        if len(message.command) < 2:
             return await message.reply_text(
             return await message.reply_text(
-                "**Usage:**\nReply to a message with /filter [FILTER_NAME] To set a new filter."
+                "**Usage:**\nReply to a message with /filter [FILTER_NAME] [CONTENT] To set a new filter."
             )
             )
-        text = message.text.markdown
+        replied_message = message.reply_to_message
+        if not replied_message:
+            replied_message = message
+        text = message.text.markdown if message.text else message.caption.markdown
         name = text.split(None, 1)[1].strip()
         name = text.split(None, 1)[1].strip()
         if not name:
         if not name:
             return await message.reply_text("**Usage:**\n__/filter [FILTER_NAME]__")
             return await message.reply_text("**Usage:**\n__/filter [FILTER_NAME]__")
         chat_id = message.chat.id
         chat_id = message.chat.id
-        replied_message = message.reply_to_message
         text = name.split(" ", 1)
         text = name.split(" ", 1)
         if len(text) > 1:
         if len(text) > 1:
             name = text[0]
             name = text[0]
             data = text[1].strip()
             data = text[1].strip()
-            if replied_message.sticker or replied_message.video_note:
+            if replied_message and (replied_message.sticker or replied_message.video_note):
                 data = None
                 data = None
         else:
         else:
-            if replied_message.sticker or replied_message.video_note:
+            if replied_message and (replied_message.sticker or replied_message.video_note):
                 data = None
                 data = None
-            elif not replied_message.text and not replied_message.caption:
+            elif replied_message and not replied_message.text and not replied_message.caption:
                 data = None
                 data = None
             else:
             else:
                 data = replied_message.text.markdown if replied_message.text else replied_message.caption.markdown
                 data = replied_message.text.markdown if replied_message.text else replied_message.caption.markdown
+                match = "/filter " + name
+                if not message.reply_to_message and message.text:
+                    if match == data:
+                        return await message.reply_text("**Usage:**\n__/filter [FILTER_NAME] [CONTENT]__\n`-----------OR-----------`\nReply to a message with.\n/filter [FILTER_NAME].")
+                elif not message.reply_to_message and not message.text:
+                    if match == data:
+                        data = None
         if replied_message.text:
         if replied_message.text:
             _type = "text"
             _type = "text"
             file_id = None
             file_id = None
@@ -119,6 +129,10 @@ async def save_filters(_, message):
             if urls:
             if urls:
                 response = "\n".join([f"{name}=[{text}, {url}]" for name, text, url in urls])
                 response = "\n".join([f"{name}=[{text}, {url}]" for name, text, url in urls])
                 data = data + response
                 data = data + response
+        if data:
+            data = await check_format(ikb, data)
+            if not data:
+                return await message.reply_text("**Wrong formatting, check the help section.**")
         name = name.replace("_", " ")
         name = name.replace("_", " ")
         _filter = {
         _filter = {
             "type": _type,
             "type": _type,
@@ -166,6 +180,8 @@ async def del_filter(_, message):
 )
 )
 @capture_err
 @capture_err
 async def filters_re(_, message):
 async def filters_re(_, message):
+    user_id = message.from_user.id
+    chat_id = message.chat.id
     text = message.text.lower().strip()
     text = message.text.lower().strip()
     if not text:
     if not text:
         return
         return
@@ -180,6 +196,10 @@ async def filters_re(_, message):
             file_id = _filter["file_id"]
             file_id = _filter["file_id"]
             keyb = None
             keyb = None
             if data:
             if data:
+                if "{chat}" in data:
+                    data = data.replace("{chat}", (await app.get_chat(chat_id)).title)
+                if "{name}" in data:
+                    data = data.replace("{name}", (await app.get_users(user_id)).mention)
                 if re.findall(r"\[.+\,.+\]", data):
                 if re.findall(r"\[.+\,.+\]", data):
                     keyboard = extract_text_and_keyb(ikb, data)
                     keyboard = extract_text_and_keyb(ikb, data)
                     if keyboard:
                     if keyboard:

+ 42 - 41
wbb/modules/greetings.py

@@ -60,7 +60,8 @@ from wbb.utils.dbfunctions import (
     update_captcha_cache,
     update_captcha_cache,
 )
 )
 from wbb.utils.filter_groups import welcome_captcha_group
 from wbb.utils.filter_groups import welcome_captcha_group
-from wbb.utils.functions import extract_text_and_keyb, generate_captcha
+from wbb.utils.functions import extract_text_and_keyb, generate_captcha, check_format
+from wbb.modules.notes import extract_urls
 
 
 __MODULE__ = "Greetings"
 __MODULE__ = "Greetings"
 __HELP__ = """
 __HELP__ = """
@@ -91,10 +92,6 @@ button2=[Github, https://github.com]
 
 
 **NOTES ->**
 **NOTES ->**
 
 
-for /rules, you can do /filter rules to a message
-containing rules of your groups whenever a user
-sends /rules, he'll get the message
-
 Checkout /markdownhelp to know more about formattings and other syntax.
 Checkout /markdownhelp to know more about formattings and other syntax.
 """
 """
 
 
@@ -230,7 +227,10 @@ async def send_welcome_message(chat: Chat, user_id: int, delete: bool = False):
 
 
     if not raw_text:
     if not raw_text:
         return
         return
-    text, keyb = extract_text_and_keyb(ikb, raw_text)
+    text = raw_text
+    keyb = None
+    if "~" in raw_text:
+        text, keyb = extract_text_and_keyb(ikb, raw_text)
 
 
     if "{chat}" in text:
     if "{chat}" in text:
         text = text.replace("{chat}", chat.title)
         text = text.replace("{chat}", chat.title)
@@ -397,13 +397,6 @@ async def captcha_state(_, message):
 # WELCOME MESSAGE
 # WELCOME MESSAGE
 
 
 
 
-async def check_caption(message, chat_id, welcome, raw_text, file_id):
-    if not extract_text_and_keyb(ikb, raw_text):
-        return await message.reply_text("Wrong formatting, check the help section.")
-    
-    await set_welcome(chat_id, welcome, raw_text, file_id)
-    await message.reply_text("Welcome message has been successfully set.")
-
 @app.on_message(filters.command("set_welcome") & ~filters.private)
 @app.on_message(filters.command("set_welcome") & ~filters.private)
 @adminsOnly("can_change_info")
 @adminsOnly("can_change_info")
 async def set_welcome_func(_, message):
 async def set_welcome_func(_, message):
@@ -420,34 +413,42 @@ async def set_welcome_func(_, message):
     )
     )
     replied_message = message.reply_to_message
     replied_message = message.reply_to_message
     chat_id = message.chat.id
     chat_id = message.chat.id
-
-    if not replied_message:
-        return await message.reply_text(usage, reply_markup=key)
-
-    if replied_message.animation:
-        welcome = "Animation"
-        file_id = replied_message.animation.file_id
-        text = replied_message.caption      
-        if not text:
-            return await message.reply_text(usage, reply_markup=key)
-        raw_text = text.markdown
-        return await check_caption(message, chat_id, welcome, raw_text, file_id)
-    if replied_message.photo:
-        welcome = "Photo"
-        file_id = replied_message.photo.file_id
-        text = replied_message.caption
-        if not text:
-            return await message.reply_text(usage, reply_markup=key)
-        raw_text = text.markdown
-        return await check_caption(message, chat_id, welcome, raw_text, file_id)
-    if replied_message.text:
-        welcome = "Text"
-        file_id = None
-        text = replied_message.text
-        raw_text = text.markdown
-        return await check_caption(message, chat_id, welcome, raw_text, file_id)
-    else:
-        await message.reply_text("Only text, gif and photo welcome message are supposed")
+    try:
+        if not replied_message:
+            await message.reply_text(usage, reply_markup=key)
+            return
+        if replied_message.animation:
+            welcome = "Animation"
+            file_id = replied_message.animation.file_id
+            text = replied_message.caption      
+            if not text:
+                return await message.reply_text(usage, reply_markup=key)
+            raw_text = text.markdown
+        if replied_message.photo:
+            welcome = "Photo"
+            file_id = replied_message.photo.file_id
+            text = replied_message.caption
+            if not text:
+                return await message.reply_text(usage, reply_markup=key)
+            raw_text = text.markdown
+        if replied_message.text:
+            welcome = "Text"
+            file_id = None
+            text = replied_message.text
+            raw_text = text.markdown
+        if replied_message.reply_markup and not "~" in raw_text:
+            urls = extract_urls(replied_message.reply_markup)
+            if urls:
+                response = "\n".join([f"{name}=[{text}, {url}]" for name, text, url in urls])
+                raw_text = raw_text + response
+        raw_text = await check_format(ikb, raw_text)
+        if raw_text:
+            await set_welcome(chat_id, welcome, raw_text, file_id)
+            return await message.reply_text("Welcome message has been successfully set.")
+        else:
+            return await message.reply_text("Wrong formatting, check the help section.\n\n**Usage:**\nText: `Text`\nText + Buttons: `Text ~ Buttons`", reply_markup=key)
+    except UnboundLocalError:
+        return await message.reply_text("**Only Text, Gif and Photo welcome message are supported.**")
 
 
 
 
 @app.on_message(filters.command("del_welcome") & ~filters.private)
 @app.on_message(filters.command("del_welcome") & ~filters.private)

+ 21 - 2
wbb/modules/inline.py

@@ -25,12 +25,31 @@ SOFTWARE.
 
 
 import traceback
 import traceback
 
 
-from wbb import app
+from wbb import app, BOT_USERNAME 
 from wbb.utils.inlinefuncs import *
 from wbb.utils.inlinefuncs import *
+from pyrogram import filters
 
 
 __MODULE__ = "Inline"
 __MODULE__ = "Inline"
-__HELP__ = """See inline for help related to inline"""
+__HELP__ = f"""
 
 
+Send /inline for help related to inline.
+
+**Example Usage:**
+`@{BOT_USERNAME} google github`
+"""
+
+
+@app.on_message(filters.command("inline"))
+async def inline(_, message):
+    buttons = InlineKeyboard(row_width=4)
+    buttons.add(
+        *[
+            (InlineKeyboardButton(text=i, switch_inline_query_current_chat=i))
+            for i in keywords_list
+        ]
+    )
+    text = "**Here are the commands available for inline**"
+    await message.reply_text(text=text, reply_markup=buttons)
 
 
 @app.on_inline_query()
 @app.on_inline_query()
 async def inline_query_handler(client, query):
 async def inline_query_handler(client, query):

+ 30 - 16
wbb/modules/notes.py

@@ -21,6 +21,7 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 SOFTWARE.
 SOFTWARE.
 """
 """
+
 from re import findall
 from re import findall
 
 
 from pyrogram import filters
 from pyrogram import filters
@@ -32,7 +33,7 @@ from wbb.core.decorators.permissions import adminsOnly
 from wbb.core.keyboard import ikb
 from wbb.core.keyboard import ikb
 from wbb.utils.dbfunctions import delete_note, get_note, get_note_names, save_note, deleteall_notes
 from wbb.utils.dbfunctions import delete_note, get_note, get_note_names, save_note, deleteall_notes
 from wbb.modules.admin import member_permissions
 from wbb.modules.admin import member_permissions
-from wbb.utils.functions import extract_text_and_keyb
+from wbb.utils.functions import extract_text_and_keyb, check_format
 
 
 __MODULE__ = "Notes"
 __MODULE__ = "Notes"
 __HELP__ = """/notes To Get All The Notes In The Chat.
 __HELP__ = """/notes To Get All The Notes In The Chat.
@@ -63,40 +64,44 @@ def extract_urls(reply_markup):
                     urls.append((f"{name}", button.text, button.url))
                     urls.append((f"{name}", button.text, button.url))
     return urls
     return urls
 
 
-@app2.on_message(
-    filters.command("save", prefixes=USERBOT_PREFIX)
-    & ~filters.forwarded
-    & ~filters.via_bot
-    & SUDOERS
-)
+
 @app.on_message(filters.command("save") & ~filters.private)
 @app.on_message(filters.command("save") & ~filters.private)
 @adminsOnly("can_change_info")
 @adminsOnly("can_change_info")
 async def save_notee(_, message):
 async def save_notee(_, message):
     try:
     try:
-        if len(message.command) < 2 or not message.reply_to_message:
+        if len(message.command) < 2:
             await eor(
             await eor(
                 message,
                 message,
                 text="**Usage:**\nReply to a message with /save [NOTE_NAME] to save a new note.",
                 text="**Usage:**\nReply to a message with /save [NOTE_NAME] to save a new note.",
             )
             )
         else:
         else:
-            text = message.text.markdown
+            replied_message = message.reply_to_message
+            if not replied_message:
+                replied_message = message
+            text = message.text.markdown if message.text else message.caption.markdown
             name = text.split(None, 1)[1].strip()
             name = text.split(None, 1)[1].strip()
             if not name:
             if not name:
                 return await eor(message, text="**Usage**\n__/save [NOTE_NAME]__")
                 return await eor(message, text="**Usage**\n__/save [NOTE_NAME]__")
-            replied_message = message.reply_to_message
             text = name.split(" ", 1)
             text = name.split(" ", 1)
             if len(text) > 1:
             if len(text) > 1:
                 name = text[0]
                 name = text[0]
                 data = text[1].strip()
                 data = text[1].strip()
-                if replied_message.sticker or replied_message.video_note:
+                if replied_message and (replied_message.sticker or replied_message.video_note):
                     data = None
                     data = None
             else:
             else:
-                if replied_message.sticker or replied_message.video_note:
+                if replied_message and (replied_message.sticker or replied_message.video_note):
                     data = None
                     data = None
-                elif not replied_message.text and not replied_message.caption:
+                elif replied_message and not replied_message.text and not replied_message.caption:
                     data = None
                     data = None
                 else:
                 else:
                     data = replied_message.text.markdown if replied_message.text else replied_message.caption.markdown
                     data = replied_message.text.markdown if replied_message.text else replied_message.caption.markdown
+                    match = "/save " + name
+                    if not message.reply_to_message and message.text:
+                        if match == data:
+                            return await message.reply_text("**Usage:**\n__/save [NOTE_NAME] [CONTENT]__\n`-----------OR-----------`\nReply to a message with.\n/save [NOTE_NAME]")
+                    elif not message.reply_to_message and not message.text:
+                        if match == data:
+                            data = None
             if replied_message.text:
             if replied_message.text:
                 _type = "text"
                 _type = "text"
                 file_id = None
                 file_id = None
@@ -129,13 +134,16 @@ async def save_notee(_, message):
                 if urls:
                 if urls:
                     response = "\n".join([f"{name}=[{text}, {url}]" for name, text, url in urls])
                     response = "\n".join([f"{name}=[{text}, {url}]" for name, text, url in urls])
                     data = data + response
                     data = data + response
+            if data:
+                data = await check_format(ikb, data)
+                if not data:
+                    return await message.reply_text("**Wrong formatting, check the help section.**")
             note = {
             note = {
                 "type": _type,
                 "type": _type,
                 "data": data,
                 "data": data,
                 "file_id": file_id,
                 "file_id": file_id,
             }
             }
-            prefix = message.text.split()[0][0]
-            chat_id = message.chat.id if prefix != USERBOT_PREFIX else USERBOT_ID
+            chat_id = message.chat.id 
             await save_note(chat_id, name, note)
             await save_note(chat_id, name, note)
             await eor(message, text=f"__**Saved note {name}.**__")
             await eor(message, text=f"__**Saved note {name}.**__")
     except UnboundLocalError:
     except UnboundLocalError:
@@ -196,6 +204,8 @@ async def get_one_note_userbot(_, message):
 @app.on_message(filters.regex(r"^#.+") & filters.text & ~filters.private)
 @app.on_message(filters.regex(r"^#.+") & filters.text & ~filters.private)
 @capture_err
 @capture_err
 async def get_one_note(_, message):
 async def get_one_note(_, message):
+    user_id = message.from_user.id 
+    chat_id = message.chat.id 
     name = message.text.replace("#", "", 1)
     name = message.text.replace("#", "", 1)
     if not name:
     if not name:
         return
         return
@@ -206,7 +216,11 @@ async def get_one_note(_, message):
     data = _note["data"]
     data = _note["data"]
     file_id = _note["file_id"]
     file_id = _note["file_id"]
     keyb = None
     keyb = None
-    if data:       
+    if data:
+        if "{chat}" in data:
+            data = data.replace("{chat}", (await app.get_chat(chat_id)).title)
+        if "{name}" in data:
+            data = data.replace("{name}", (await app.get_users(user_id)).mention)
         if findall(r"\[.+\,.+\]", data):
         if findall(r"\[.+\,.+\]", data):
             keyboard = extract_text_and_keyb(ikb, data)
             keyboard = extract_text_and_keyb(ikb, data)
             if keyboard:
             if keyboard:

+ 18 - 0
wbb/utils/functions.py

@@ -21,6 +21,7 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 SOFTWARE.
 SOFTWARE.
 """
 """
+
 from asyncio import gather
 from asyncio import gather
 from datetime import datetime, timedelta
 from datetime import datetime, timedelta
 from io import BytesIO
 from io import BytesIO
@@ -314,6 +315,23 @@ def extract_text_and_keyb(ikb, text: str, row_width: int = 2):
         return
         return
     return text, keyboard
     return text, keyboard
 
 
+# BUILDING AN AI BY SI_NN_ER_LS
+async def check_format(ikb, raw_text: str):
+    keyb = findall(r"\[.+\,.+\]", raw_text)
+    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 ""
+        else:
+            return raw_text 
+    else:
+        return raw_text
+
 
 
 async def get_user_id_and_usernames(client) -> dict:
 async def get_user_id_and_usernames(client) -> dict:
     with client.storage.conn:
     with client.storage.conn: