From 6bd1234d3d1b8a315a3b5e96daf144c02e4ad6f0 Mon Sep 17 00:00:00 2001 From: profitroll Date: Sun, 15 Oct 2023 17:40:56 +0200 Subject: [PATCH] This commit closes #45 --- modules/custom_filters.py | 18 ++++++++++++++++++ plugins/commands/mode_submit.py | 11 +++++++++-- plugins/commands/report.py | 4 +++- plugins/handlers/submission.py | 3 ++- 4 files changed, 32 insertions(+), 4 deletions(-) create mode 100644 modules/custom_filters.py diff --git a/modules/custom_filters.py b/modules/custom_filters.py new file mode 100644 index 0000000..8bc458f --- /dev/null +++ b/modules/custom_filters.py @@ -0,0 +1,18 @@ +"""Custom message filters""" + +from pyrogram import filters +from pyrogram.types import Message + +from classes.pyroclient import PyroClient + + +async def _mode_post_func(_, __: PyroClient, message: Message): + return __.config["mode"]["post"] + + +async def _mode_submit_func(_, __: PyroClient, message: Message): + return __.config["mode"]["submit"] + + +mode_post = filters.create(_mode_post_func) +mode_submit = filters.create(_mode_submit_func) diff --git a/plugins/commands/mode_submit.py b/plugins/commands/mode_submit.py index 649e4ac..b91d604 100644 --- a/plugins/commands/mode_submit.py +++ b/plugins/commands/mode_submit.py @@ -3,9 +3,14 @@ from pyrogram.client import Client from pyrogram.types import Message from classes.pyroclient import PyroClient +from modules import custom_filters -@Client.on_message(~filters.scheduled & filters.command(["start"], prefixes="/")) +@Client.on_message( + custom_filters.mode_submit + & ~filters.scheduled + & filters.command(["start"], prefixes="/") +) async def cmd_start(app: PyroClient, msg: Message): user = await app.find_user(msg.from_user) @@ -16,7 +21,9 @@ async def cmd_start(app: PyroClient, msg: Message): @Client.on_message( - ~filters.scheduled & filters.command(["rules", "help"], prefixes="/") + custom_filters.mode_submit + & ~filters.scheduled + & filters.command(["rules", "help"], prefixes="/") ) async def cmd_rules(app: PyroClient, msg: Message): user = await app.find_user(msg.from_user) diff --git a/plugins/commands/report.py b/plugins/commands/report.py index 09f0513..e5072b1 100644 --- a/plugins/commands/report.py +++ b/plugins/commands/report.py @@ -4,10 +4,12 @@ from pyrogram.client import Client from pyrogram.types import Message, User from classes.pyroclient import PyroClient +from modules import custom_filters @Client.on_message( - ~filters.scheduled + custom_filters.mode_post + & ~filters.scheduled & filters.chat(sync.config_get("comments", "posting")) & filters.reply & filters.command(["report"], prefixes=["", "/"]) diff --git a/plugins/handlers/submission.py b/plugins/handlers/submission.py index 9acbfa8..8aee89c 100644 --- a/plugins/handlers/submission.py +++ b/plugins/handlers/submission.py @@ -13,6 +13,7 @@ from pyrogram.types import InlineKeyboardButton, InlineKeyboardMarkup, Message from classes.enums.submission_types import SubmissionType from classes.exceptions import SubmissionDuplicatesError, SubmissionUnsupportedError from classes.pyroclient import PyroClient +from modules import custom_filters from modules.database import col_submitted from modules.utils import USERS_WITH_CONTEXT @@ -20,7 +21,7 @@ logger = logging.getLogger(__name__) @Client.on_message( - ~filters.scheduled & filters.private & filters.photo + custom_filters.mode_submit & ~filters.scheduled & filters.private & filters.photo | filters.video # | filters.animation | filters.document