Spoilers, major command system improvements #4

Merged
profitroll merged 27 commits from dev into master 2023-01-05 13:45:15 +02:00
20 changed files with 146 additions and 129 deletions
Showing only changes of commit 096a0498f8 - Show all commits

View File

@ -12,7 +12,7 @@ from modules.database import col_applications
from modules import custom_filters from modules import custom_filters
# Applications command ========================================================================================================= # Applications command =========================================================================================================
@app.on_message(~ filters.scheduled & filters.command(["application"], prefixes=["/"]) & custom_filters.admin) @app.on_message(custom_filters.enabled_applications & ~filters.scheduled & filters.command(["application"], prefixes=["/"]) & custom_filters.admin)
async def cmd_application(app: Client, msg: Message): async def cmd_application(app: Client, msg: Message):
try: try:

View File

@ -11,7 +11,7 @@ from modules.database import col_applications
from modules import custom_filters from modules import custom_filters
# Applications command ========================================================================================================= # Applications command =========================================================================================================
@app.on_message(~ filters.scheduled & filters.command(["applications"], prefixes=["/"]) & custom_filters.admin) @app.on_message(custom_filters.enabled_applications & ~filters.scheduled & filters.command(["applications"], prefixes=["/"]) & custom_filters.admin)
async def cmd_applications(app: Client, msg: Message): async def cmd_applications(app: Client, msg: Message):
logWrite(f"Admin {msg.from_user.id} requested export of a database") logWrite(f"Admin {msg.from_user.id} requested export of a database")

View File

@ -4,8 +4,9 @@ from pyrogram.types import Message
from pyrogram.client import Client from pyrogram.client import Client
from modules.utils import should_quote, logWrite, locale from modules.utils import should_quote, logWrite, locale
from modules.database import col_tmp from modules.database import col_tmp
from modules import custom_filters
@app.on_message(~ filters.scheduled & filters.command("cancel", prefixes=["/"])) @app.on_message((custom_filters.enabled_applications | custom_filters.enabled_sponsorships) & ~filters.scheduled & filters.command("cancel", prefixes=["/"]))
async def command_cancel(app: Client, msg: Message): async def command_cancel(app: Client, msg: Message):
col_tmp.delete_many( {"user": msg.from_user.id} ) col_tmp.delete_many( {"user": msg.from_user.id} )
await msg.reply_text(locale("cancel", "message", locale=msg.from_user), quote=should_quote(msg)) await msg.reply_text(locale("cancel", "message", locale=msg.from_user), quote=should_quote(msg))

View File

@ -9,7 +9,7 @@ from classes.holo_user import HoloUser, UserNotFoundError, UserInvalidError
from modules.utils import jsonLoad, should_quote, logWrite, locale, download_tmp, create_tmp from modules.utils import jsonLoad, should_quote, logWrite, locale, download_tmp, create_tmp
from modules import custom_filters from modules import custom_filters
@app.on_message(~ filters.scheduled & filters.command("identify", prefixes=["/"]) & custom_filters.admin) @app.on_message((custom_filters.enabled_applications | custom_filters.enabled_sponsorships) & ~filters.scheduled & filters.command("identify", prefixes=["/"]) & custom_filters.admin)
async def command_identify(app: Client, msg: Message): async def command_identify(app: Client, msg: Message):
if len(msg.command) != 2: if len(msg.command) != 2:

View File

@ -6,7 +6,7 @@ from modules.utils import locale, should_quote, find_user
from classes.holo_user import HoloUser, LabelTooLongError from classes.holo_user import HoloUser, LabelTooLongError
from modules import custom_filters from modules import custom_filters
@app.on_message(~ filters.scheduled & filters.command(["label"], prefixes=["/"]) & custom_filters.admin) @app.on_message(custom_filters.enabled_applications & ~filters.scheduled & filters.command(["label"], prefixes=["/"]) & custom_filters.admin)
async def cmd_label(app: Client, msg: Message): async def cmd_label(app: Client, msg: Message):
if len(msg.command) < 3: if len(msg.command) < 3:

View File

@ -11,7 +11,7 @@ from modules.database import col_applications, col_users
from classes.errors.geo import PlaceNotFoundError from classes.errors.geo import PlaceNotFoundError
# Nearby command =============================================================================================================== # Nearby command ===============================================================================================================
@app.on_message(~ filters.scheduled & (filters.private | (filters.chat(configGet("admin_group")) | filters.chat(configGet("destination_group")))) & filters.command(["nearby"], prefixes=["/"]) & (custom_filters.allowed | custom_filters.admin)) @app.on_message(custom_filters.enabled_applications & ~filters.scheduled & (filters.private | (filters.chat(configGet("admin_group")) | filters.chat(configGet("destination_group")))) & filters.command(["nearby"], prefixes=["/"]) & (custom_filters.allowed | custom_filters.admin))
async def cmd_nearby(app: Client, msg: Message): async def cmd_nearby(app: Client, msg: Message):
holo_user = HoloUser(msg.from_user) holo_user = HoloUser(msg.from_user)

View File

@ -6,9 +6,10 @@ from classes.holo_user import HoloUser
from modules.utils import configGet, locale, should_quote from modules.utils import configGet, locale, should_quote
from modules.handlers.welcome import welcome_pass from modules.handlers.welcome import welcome_pass
from modules.database import col_tmp from modules.database import col_tmp
from modules import custom_filters
# Reapply command ============================================================================================================== # Reapply command ==============================================================================================================
@app.on_message(~ filters.scheduled & filters.private & filters.command(["reapply"], prefixes=["/"])) @app.on_message(custom_filters.enabled_applications & ~filters.scheduled & filters.private & filters.command(["reapply"], prefixes=["/"]))
async def cmd_reapply(app: Client, msg: Message): async def cmd_reapply(app: Client, msg: Message):
holo_user = HoloUser(msg.from_user) holo_user = HoloUser(msg.from_user)

View File

@ -8,7 +8,7 @@ from modules.utils import locale, should_quote
from modules.database import col_applications from modules.database import col_applications
# Sponsorship command ========================================================================================================== # Sponsorship command ==========================================================================================================
@app.on_message(~ filters.scheduled & filters.command(["sponsorship"], prefixes=["/"]) & (custom_filters.allowed | custom_filters.admin)) @app.on_message(custom_filters.enabled_sponsorships & ~filters.scheduled & filters.command(["sponsorship"], prefixes=["/"]) & (custom_filters.allowed | custom_filters.admin))
async def cmd_sponsorship(app: Client, msg: Message): async def cmd_sponsorship(app: Client, msg: Message):
if HoloUser(msg.from_user).application_state()[0] == "fill": if HoloUser(msg.from_user).application_state()[0] == "fill":
await msg.reply_text(locale("finish_application", "message", locale=msg.from_user), quote=should_quote(msg)) await msg.reply_text(locale("finish_application", "message", locale=msg.from_user), quote=should_quote(msg))

View File

@ -4,9 +4,10 @@ from pyrogram.types import ReplyKeyboardMarkup, Message
from pyrogram.client import Client from pyrogram.client import Client
from modules.utils import locale, logWrite from modules.utils import locale, logWrite
from modules.database import col_users from modules.database import col_users
from modules import custom_filters
# Start command ================================================================================================================ # Start command ================================================================================================================
@app.on_message(~ filters.scheduled & filters.private & filters.command(["start"], prefixes=["/"])) @app.on_message(custom_filters.enabled_applications & ~filters.scheduled & filters.private & filters.command(["start"], prefixes=["/"]))
async def cmd_start(app: Client, msg: Message): async def cmd_start(app: Client, msg: Message):
user = col_users.find_one({"user": msg.from_user.id}) user = col_users.find_one({"user": msg.from_user.id})

View File

@ -8,7 +8,7 @@ from modules.database import col_warnings
from modules import custom_filters from modules import custom_filters
# Warn command ================================================================================================================= # Warn command =================================================================================================================
@app.on_message(~ filters.scheduled & filters.command(["warn"], prefixes=["/"]) & custom_filters.admin) @app.on_message(custom_filters.enabled_warnings & ~filters.scheduled & filters.command(["warn"], prefixes=["/"]) & custom_filters.admin)
async def cmd_warn(app: Client, msg: Message): async def cmd_warn(app: Client, msg: Message):
if msg.chat.id == configGet("destination_group"): if msg.chat.id == configGet("destination_group"):

View File

@ -8,7 +8,7 @@ from modules.database import col_users, col_warnings
from modules import custom_filters from modules import custom_filters
# Warnings command ============================================================================================================= # Warnings command =============================================================================================================
@app.on_message(~ filters.scheduled & filters.command(["warnings"], prefixes=["/"]) & custom_filters.admin) @app.on_message(custom_filters.enabled_warnings & ~filters.scheduled & filters.command(["warnings"], prefixes=["/"]) & custom_filters.admin)
async def cmd_warnings(app: Client, msg: Message): async def cmd_warnings(app: Client, msg: Message):
if len(msg.command) <= 1: if len(msg.command) <= 1:

View File

@ -12,16 +12,19 @@ from classes.holo_user import HoloUser
from modules.utils import all_locales, configGet, locale, logWrite from modules.utils import all_locales, configGet, locale, logWrite
from modules.handlers.welcome import welcome_pass from modules.handlers.welcome import welcome_pass
from modules.database import col_tmp from modules.database import col_tmp
from modules import custom_filters
# Confirmation ================================================================================================================= # Confirmation =================================================================================================================
confirmation_1 = [] confirmation_1 = []
for pattern in all_locales("confirm", "keyboard"): for pattern in all_locales("confirm", "keyboard"):
confirmation_1.append(pattern[0][0]) confirmation_1.append(pattern[0][0])
@app.on_message(~ filters.scheduled & filters.private & filters.command(confirmation_1, prefixes=[""])) @app.on_message((custom_filters.enabled_applications | custom_filters.enabled_sponsorships) & ~filters.scheduled & filters.private & filters.command(confirmation_1, prefixes=[""]))
async def confirm_yes(app: Client, msg: Message, kind: Literal["application", "sponsorship"] = "unknown"): async def confirm_yes(app: Client, msg: Message, kind: Literal["application", "sponsorship", "unknown"] = "unknown"):
holo_user = HoloUser(msg.from_user) holo_user = HoloUser(msg.from_user)
if configGet("enabled", "features", "applications") is True:
if (kind == "application") or ((holo_user.application_state()[0] == "fill") and (holo_user.application_state()[1] is True)): if (kind == "application") or ((holo_user.application_state()[0] == "fill") and (holo_user.application_state()[1] is True)):
tmp_application = col_tmp.find_one({"user": holo_user.id, "type": "application"}) tmp_application = col_tmp.find_one({"user": holo_user.id, "type": "application"})
@ -93,6 +96,8 @@ async def confirm_yes(app: Client, msg: Message, kind: Literal["application", "s
# configSet(["sent"], True, file=str(holo_user.id)) # configSet(["sent"], True, file=str(holo_user.id))
# configSet(["confirmed"], True, file=str(holo_user.id)) # configSet(["confirmed"], True, file=str(holo_user.id))
if configGet("enabled", "features", "sponsorships") is True:
if (kind == "sponsorship") or ((holo_user.sponsorship_state()[0] == "fill") and (holo_user.sponsorship_state()[1] is True)): if (kind == "sponsorship") or ((holo_user.sponsorship_state()[0] == "fill") and (holo_user.sponsorship_state()[1] is True)):
tmp_sponsorship = col_tmp.find_one({"user": holo_user.id, "type": "sponsorship"}) tmp_sponsorship = col_tmp.find_one({"user": holo_user.id, "type": "sponsorship"})
@ -142,17 +147,19 @@ async def confirm_yes(app: Client, msg: Message, kind: Literal["application", "s
confirmation_2 = [] confirmation_2 = []
for pattern in all_locales("confirm", "keyboard"): for pattern in all_locales("confirm", "keyboard"):
confirmation_2.append(pattern[1][0]) confirmation_2.append(pattern[1][0])
@app.on_message(~ filters.scheduled & filters.private & filters.command(confirmation_2, prefixes=[""])) @app.on_message((custom_filters.enabled_applications | custom_filters.enabled_sponsorships) & ~filters.scheduled & filters.private & filters.command(confirmation_2, prefixes=[""]))
async def confirm_no(app: Client, msg: Message, kind: Literal["application", "sponsorship"] = "unknown"): async def confirm_no(app: Client, msg: Message, kind: Literal["application", "sponsorship", "unknown"] = "unknown"):
holo_user = HoloUser(msg.from_user) holo_user = HoloUser(msg.from_user)
if configGet("enabled", "features", "applications") is True:
if (kind == "application") or ((holo_user.application_state()[0] == "fill") and (holo_user.application_state()[1] is True)): if (kind == "application") or ((holo_user.application_state()[0] == "fill") and (holo_user.application_state()[1] is True)):
holo_user.application_restart() holo_user.application_restart()
await welcome_pass(app, msg, once_again=True) await welcome_pass(app, msg, once_again=True)
logWrite(f"User {msg.from_user.id} restarted the application due to typo in it") logWrite(f"User {msg.from_user.id} restarted the application due to typo in it")
return return
if configGet("enabled", "features", "sponsorships") is True:
if (kind == "sponsorship") or ((holo_user.sponsorship_state()[0] == "fill") and (holo_user.sponsorship_state()[1] is True)): if (kind == "sponsorship") or ((holo_user.sponsorship_state()[0] == "fill") and (holo_user.sponsorship_state()[1] is True)):
holo_user.sponsorship_restart() holo_user.sponsorship_restart()
await app.send_message(holo_user.id, locale(f"sponsor1", "message", locale=holo_user.locale), reply_markup=ForceReply(placeholder=str(locale(f"sponsor1", "force_reply", locale=holo_user.locale)))) await app.send_message(holo_user.id, locale(f"sponsor1", "message", locale=holo_user.locale), reply_markup=ForceReply(placeholder=str(locale(f"sponsor1", "force_reply", locale=holo_user.locale))))

View File

@ -10,7 +10,7 @@ from classes.holo_user import HoloUser
from modules import custom_filters from modules import custom_filters
# Contact getting ============================================================================================================== # Contact getting ==============================================================================================================
@app.on_message(~ filters.scheduled & filters.contact & filters.private & (custom_filters.allowed | custom_filters.admin)) @app.on_message(custom_filters.enabled_applications & ~filters.scheduled & filters.contact & filters.private & (custom_filters.allowed | custom_filters.admin))
async def get_contact(app: Client, msg: Message): async def get_contact(app: Client, msg: Message):
holo_user = HoloUser(msg.from_user) holo_user = HoloUser(msg.from_user)

View File

@ -52,7 +52,11 @@ async def any_stage(app: Client, msg: Message):
return return
if msg.text is not None: if msg.text is not None:
if configGet("enabled", "features", "applications") is True:
await holo_user.application_next(msg.text, msg=msg) await holo_user.application_next(msg.text, msg=msg)
if configGet("enabled", "features", "sponsorships") is True:
await holo_user.sponsorship_next(msg.text, msg=msg) await holo_user.sponsorship_next(msg.text, msg=msg)
# user_stage = configGet("stage", file=str(msg.from_user.id)) # user_stage = configGet("stage", file=str(msg.from_user.id))

View File

@ -4,9 +4,10 @@ from pyrogram.client import Client
from modules.utils import configGet, locale from modules.utils import configGet, locale
from modules.logging import logWrite from modules.logging import logWrite
from classes.holo_user import HoloUser from classes.holo_user import HoloUser
from modules import custom_filters
# Filter users on join ========================================================================================================= # Filter users on join =========================================================================================================
@app.on_chat_member_updated(group=configGet("destination_group")) @app.on_chat_member_updated(custom_filters.enabled_invites_check, group=configGet("destination_group"))
#@app.on_message(filters.new_chat_members, group=configGet("destination_group")) #@app.on_message(filters.new_chat_members, group=configGet("destination_group"))
async def filter_join(app: Client, member: ChatMemberUpdated): async def filter_join(app: Client, member: ChatMemberUpdated):

View File

@ -2,10 +2,10 @@ from app import app
from pyrogram import filters from pyrogram import filters
from pyrogram.types import Message from pyrogram.types import Message
from pyrogram.client import Client from pyrogram.client import Client
from classes.holo_user import HoloUser from classes.holo_user import HoloUser
from modules import custom_filters
@app.on_message(~ filters.scheduled & filters.photo & filters.private) @app.on_message(custom_filters.enabled_sponsorships & ~filters.scheduled & filters.photo & filters.private)
async def sponsor_proof(app: Client, msg: Message): async def sponsor_proof(app: Client, msg: Message):
if msg.via_bot is None: if msg.via_bot is None:

View File

@ -5,8 +5,9 @@ from pyrogram.types import Message
from pyrogram.client import Client from pyrogram.client import Client
from modules.logging import logWrite from modules.logging import logWrite
from modules.utils import configGet, locale from modules.utils import configGet, locale
from modules import custom_filters
@app.on_message(~ filters.scheduled & filters.voice & filters.chat(configGet("destination_group"))) @app.on_message(custom_filters.enabled_dinovoice & ~filters.scheduled & filters.voice & filters.chat(configGet("destination_group")))
async def voice_message(app: Client, msg: Message): async def voice_message(app: Client, msg: Message):
logWrite(f"User {msg.from_user.id} sent voice message in destination group") logWrite(f"User {msg.from_user.id} sent voice message in destination group")
await msg.reply_text(choice(locale("voice_message", "message"))) await msg.reply_text(choice(locale("voice_message", "message")))

View File

@ -4,6 +4,7 @@ from pyrogram.types import ForceReply, ReplyKeyboardMarkup, Message
from pyrogram.client import Client from pyrogram.client import Client
from classes.holo_user import HoloUser from classes.holo_user import HoloUser
from modules.utils import all_locales, locale, logWrite from modules.utils import all_locales, locale, logWrite
from modules import custom_filters
# Welcome check ================================================================================================================ # Welcome check ================================================================================================================
welcome_1 = [] welcome_1 = []
@ -11,7 +12,7 @@ for pattern in all_locales("welcome", "keyboard"):
welcome_1.append(pattern[0][0]) welcome_1.append(pattern[0][0])
for pattern in all_locales("return", "keyboard"): for pattern in all_locales("return", "keyboard"):
welcome_1.append(pattern[0][0]) welcome_1.append(pattern[0][0])
@app.on_message(~ filters.scheduled & filters.private & filters.command(welcome_1, prefixes=[""])) @app.on_message(custom_filters.enabled_applications & ~filters.scheduled & filters.private & filters.command(welcome_1, prefixes=[""]))
async def welcome_pass(app: Client, msg: Message, once_again: bool = True) -> None: async def welcome_pass(app: Client, msg: Message, once_again: bool = True) -> None:
"""Set user's stage to 1 and start a fresh application """Set user's stage to 1 and start a fresh application
@ -36,7 +37,7 @@ async def welcome_pass(app: Client, msg: Message, once_again: bool = True) -> No
welcome_2 = [] welcome_2 = []
for pattern in all_locales("welcome", "keyboard"): for pattern in all_locales("welcome", "keyboard"):
welcome_2.append(pattern[1][0]) welcome_2.append(pattern[1][0])
@app.on_message(~ filters.scheduled & filters.private & filters.command(welcome_2, prefixes=[""])) @app.on_message(custom_filters.enabled_applications & ~filters.scheduled & filters.private & filters.command(welcome_2, prefixes=[""]))
async def welcome_reject(app: Client, msg: Message): async def welcome_reject(app: Client, msg: Message):
logWrite(f"User {msg.from_user.id} rejected to start the application") logWrite(f"User {msg.from_user.id} rejected to start the application")