Improved typing and linting

This commit is contained in:
Profitroll 2022-12-27 13:36:54 +01:00
parent 47896faf06
commit 5e06859b56
26 changed files with 91 additions and 53 deletions

View File

@ -1,9 +1,11 @@
from app import app
from pyrogram import filters
from pyrogram.types import CallbackQuery
from pyrogram.client import Client
from modules.utils import locale
# Callback empty ===============================================================================================================
@app.on_callback_query(filters.regex("nothing"))
async def callback_query_nothing(app, clb):
async def callback_query_nothing(app: Client, clb: CallbackQuery):
await clb.answer(text=locale("nothing", "callback", locale=clb.from_user))
# ==============================================================================================================================

View File

@ -1,6 +1,7 @@
from datetime import datetime
from app import app
from pyrogram.types import InlineKeyboardMarkup, InlineKeyboardButton, ReplyKeyboardRemove
from pyrogram.types import InlineKeyboardMarkup, InlineKeyboardButton, ReplyKeyboardRemove, CallbackQuery
from pyrogram.client import Client
from pyrogram import filters
from classes.holo_user import HoloUser
from modules.utils import configGet, locale, logWrite, should_quote
@ -10,7 +11,7 @@ from modules.database import col_tmp, col_applications
# Callbacks reapply ============================================================================================================
@app.on_callback_query(filters.regex("reapply_yes_[\s\S]*"))
async def callback_reapply_query_accept(app, clb):
async def callback_reapply_query_accept(app: Client, clb: CallbackQuery):
fullclb = clb.data.split("_")
holo_user = HoloUser(int(fullclb[2]))
@ -56,7 +57,7 @@ async def callback_reapply_query_accept(app, clb):
await app.send_message(holo_user.id, locale("approved_joined", "message", locale=holo_user))
@app.on_callback_query(filters.regex("reapply_no_[\s\S]*"))
async def callback_query_reapply_reject(app, clb):
async def callback_query_reapply_reject(app: Client, clb: CallbackQuery):
fullclb = clb.data.split("_")
holo_user = HoloUser(int(fullclb[2]))
@ -74,25 +75,25 @@ async def callback_query_reapply_reject(app, clb):
# Use old application when user reapplies after leaving the chat
@app.on_callback_query(filters.regex("reapply_old_[\s\S]*"))
async def callback_query_reapply_old(app, clb):
async def callback_query_reapply_old(app: Client, clb: CallbackQuery):
fullclb = clb.data.split("_")
if HoloUser(clb.from_user).sponsorship_state()[0] == "fill":
await clb.message.reply_text(locale("finish_sponsorship", "message"), quote=False))
await clb.message.reply_text(locale("finish_sponsorship", "message"), quote=False)
return
message = await app.get_messages(clb.from_user.id, int(fullclb[2]))
await confirm_yes(app, message, kind="application")
await clb.message.edit(clb.message.text, reply_markup=InlineKeyboardMarkup([[InlineKeyboardButton(locale("done", "button", locale=clb.from_user), "nothing")]]))
# Start a new application when user reapplies after leaving the chat
@app.on_callback_query(filters.regex("reapply_new_[\s\S]*"))
async def callback_query_reapply_new(app, clb):
async def callback_query_reapply_new(app: Client, clb: CallbackQuery):
fullclb = clb.data.split("_")
if HoloUser(clb.from_user).sponsorship_state()[0] == "fill":
await clb.message.reply_text(locale("finish_sponsorship", "message"), quote=False))
await clb.message.reply_text(locale("finish_sponsorship", "message"), quote=False)
return
await clb.answer(locale("reapply_stopped", "callback", locale=clb.from_user))
@ -104,7 +105,7 @@ async def callback_query_reapply_new(app, clb):
# Abort application fill in progress and restart it
@app.on_callback_query(filters.regex("reapply_stop_[\s\S]*"))
async def callback_query_reapply_stop(app, clb):
async def callback_query_reapply_stop(app: Client, clb: CallbackQuery):
fullclb = clb.data.split("_")
holo_user = HoloUser(clb.from_user)

View File

@ -1,5 +1,6 @@
from app import app
from pyrogram.types import InlineKeyboardMarkup, InlineKeyboardButton
from pyrogram.types import InlineKeyboardMarkup, InlineKeyboardButton, CallbackQuery
from pyrogram.client import Client
from pyrogram.errors import bad_request_400
from pyrogram import filters
from modules.utils import locale, logWrite
@ -7,7 +8,7 @@ from modules.commands.rules import DefaultRulesMarkup
# Callback rule ================================================================================================================
@app.on_callback_query(filters.regex("rule_[\s\S]*"))
async def callback_query_rule(app, clb):
async def callback_query_rule(app: Client, clb: CallbackQuery):
fullclb = clb.data.split("_")
@ -46,7 +47,7 @@ async def callback_query_rule(app, clb):
await clb.answer(text=locale("rules_page", "callback", locale=clb.from_user).format(fullclb[1]))
@app.on_callback_query(filters.regex("rules_home"))
async def callback_query_rules_home(app, clb):
async def callback_query_rules_home(app: Client, clb: CallbackQuery):
logWrite(f"User {clb.from_user.id} requested to check out homepage rules")
@ -58,7 +59,7 @@ async def callback_query_rules_home(app, clb):
await clb.answer(text=locale("rules_home", "callback", locale=clb.from_user))
@app.on_callback_query(filters.regex("rules_additional"))
async def callback_query_rules_additional(app, clb):
async def callback_query_rules_additional(app: Client, clb: CallbackQuery):
logWrite(f"User {clb.from_user.id} requested to check out additional rules")

View File

@ -29,7 +29,7 @@ async def callback_query_sponsor_apply(app: Client, clb: CallbackQuery):
await clb.answer(text=locale("sponsor_started", "callback").format(holo_user.id), show_alert=False)
@app.on_callback_query(filters.regex("sponsor_yes_[\s\S]*"))
async def callback_query_sponsor_yes(app, clb):
async def callback_query_sponsor_yes(app: Client, clb: CallbackQuery):
fullclb = clb.data.split("_")
holo_user = HoloUser(int(fullclb[2]))
@ -75,7 +75,7 @@ async def callback_query_sponsor_yes(app, clb):
await clb.answer(text=locale("sponsor_accepted", "callback").format(fullclb[2]), show_alert=False)
@app.on_callback_query(filters.regex("sponsor_no_[\s\S]*"))
async def callback_query_sponsor_no(app, clb):
async def callback_query_sponsor_no(app: Client, clb: CallbackQuery):
fullclb = clb.data.split("_")
holo_user = HoloUser(int(fullclb[2]))

View File

@ -1,7 +1,8 @@
from datetime import datetime
from app import app
from pyrogram.types import InlineKeyboardMarkup, InlineKeyboardButton
from pyrogram.types import InlineKeyboardMarkup, InlineKeyboardButton, CallbackQuery
from pyrogram import filters
from pyrogram.client import Client
from classes.holo_user import HoloUser
from modules.utils import configGet, locale, logWrite
from modules.database import col_tmp, col_applications
@ -9,7 +10,7 @@ from modules.commands.rules import DefaultRulesMarkup
# Callbacks application ========================================================================================================
@app.on_callback_query(filters.regex("sub_yes_[\s\S]*"))
async def callback_query_accept(app, clb):
async def callback_query_accept(app: Client, clb: CallbackQuery):
fullclb = clb.data.split("_")
holo_user = HoloUser(int(fullclb[2]))
@ -51,7 +52,7 @@ async def callback_query_accept(app, clb):
await clb.answer(text=locale("sub_accepted", "callback", locale=clb.from_user).format(holo_user.id), show_alert=True)
@app.on_callback_query(filters.regex("sub_no_[\s\S]*"))
async def callback_query_reject(app, clb):
async def callback_query_reject(app: Client, clb: CallbackQuery):
fullclb = clb.data.split("_")
holo_user = HoloUser(int(fullclb[2]))
@ -68,7 +69,7 @@ async def callback_query_reject(app, clb):
await clb.answer(text=locale("sub_rejected", "callback", locale=clb.from_user).format(holo_user.id), show_alert=True)
@app.on_callback_query(filters.regex("sub_aggressive_[\s\S]*"))
async def callback_query_reject_aggressive(app, clb):
async def callback_query_reject_aggressive(app: Client, clb: CallbackQuery):
fullclb = clb.data.split("_")
holo_user = HoloUser(int(fullclb[2]))
@ -85,7 +86,7 @@ async def callback_query_reject_aggressive(app, clb):
await clb.answer(text=locale("sub_aggressive", "callback", locale=clb.from_user).format(holo_user.id), show_alert=True)
@app.on_callback_query(filters.regex("sub_russian_[\s\S]*"))
async def callback_query_reject_russian(app, clb):
async def callback_query_reject_russian(app: Client, clb: CallbackQuery):
fullclb = clb.data.split("_")
holo_user = HoloUser(int(fullclb[2]))

View File

@ -1,5 +1,6 @@
from app import app
from pyrogram.types import InlineKeyboardMarkup, InlineKeyboardButton, ChatPermissions
from pyrogram.types import InlineKeyboardMarkup, InlineKeyboardButton, ChatPermissions, CallbackQuery
from pyrogram.client import Client
from pyrogram import filters
from classes.holo_user import HoloUser
from modules.utils import configGet, locale, logWrite
@ -7,7 +8,7 @@ from modules.database import col_tmp
# Callbacks sus users ==========================================================================================================
@app.on_callback_query(filters.regex("sus_allow_[\s\S]*"))
async def callback_query_sus_allow(app, clb):
async def callback_query_sus_allow(app: Client, clb: CallbackQuery):
fullclb = clb.data.split("_")
holo_user = HoloUser(int(fullclb[2]))
@ -29,7 +30,7 @@ async def callback_query_sus_allow(app, clb):
)
@app.on_callback_query(filters.regex("sus_reject_[\s\S]*"))
async def callback_query_sus_reject(app, clb):
async def callback_query_sus_reject(app: Client, clb: CallbackQuery):
fullclb = clb.data.split("_")
holo_user = HoloUser(int(fullclb[2]))

View File

@ -2,7 +2,9 @@ from datetime import datetime
from app import app, isAnAdmin
from pyrogram import filters
from pyrogram.enums.parse_mode import ParseMode
from pyrogram.types import Message
from pyrogram.errors import bad_request_400
from pyrogram.client import Client
from classes.holo_user import HoloUser, UserNotFoundError
from modules.utils import logWrite, locale, should_quote
from dateutil.relativedelta import relativedelta
@ -10,7 +12,7 @@ from modules.database import col_applications
# Applications command =========================================================================================================
@app.on_message(~ filters.scheduled & filters.command(["application"], prefixes=["/"]))
async def cmd_application(app, msg):
async def cmd_application(app: Client, msg: Message):
if await isAnAdmin(msg.from_user.id) is True:

View File

@ -2,6 +2,8 @@ from os import sep, makedirs, remove
from uuid import uuid1
from app import app, isAnAdmin
from pyrogram import filters
from pyrogram.types import Message
from pyrogram.client import Client
from pyrogram.enums.chat_action import ChatAction
from modules.logging import logWrite
from modules.utils import should_quote, jsonSave
@ -9,7 +11,7 @@ from modules.database import col_applications
# Applications command =========================================================================================================
@app.on_message(~ filters.scheduled & filters.command(["applications"], prefixes=["/"]))
async def cmd_applications(app, msg):
async def cmd_applications(app: Client, msg: Message):
if await isAnAdmin(msg.from_user.id) is True:
logWrite(f"Admin {msg.from_user.id} requested export of a database")

View File

@ -1,7 +1,9 @@
from app import app
from pyrogram import filters
from pyrogram.types import Message
from pyrogram.client import Client
from modules.utils import should_quote
@app.on_message(~ filters.scheduled & filters.command("cancel", prefixes=["/"]))
async def command_cancel(app, msg):
async def command_cancel(app: Client, msg: Message):
await msg.reply_text("Command exists.", quote=should_quote(msg))

View File

@ -1,10 +1,12 @@
from app import app, isAnAdmin
from pyrogram import filters
from pyrogram.types import Message
from pyrogram.client import Client
from modules.utils import locale, should_quote, find_user
from classes.holo_user import HoloUser, LabelTooLongError
@app.on_message(~ filters.scheduled & filters.private & filters.command(["label"], prefixes=["/"]))
async def cmd_label(app, msg):
async def cmd_label(app: Client, msg: Message):
if await isAnAdmin(msg.from_user.id) is True:

View File

@ -1,11 +1,13 @@
from app import app, isAnAdmin
from pyrogram import filters
from pyrogram.types import Message
from pyrogram.client import Client
from classes.holo_user import HoloUser
from modules.utils import logWrite, locale, should_quote
# Message command ==============================================================================================================
@app.on_message(~ filters.scheduled & filters.command(["message"], prefixes=["/"]))
async def cmd_message(app, msg):
async def cmd_message(app: Client, msg: Message):
if await isAnAdmin(msg.from_user.id) is True:

View File

@ -1,11 +1,13 @@
from app import app, isAnAdmin
from pyrogram import filters
from pyrogram.types import Message
from pyrogram.client import Client
from modules.utils import configGet, should_quote
from modules.database import col_applications
# Nearby command ===============================================================================================================
@app.on_message(~ filters.scheduled & (filters.private | (filters.chat(configGet("admin_group")) | filters.chat(configGet("destination_group")))) & filters.command(["nearby"], prefixes=["/"]))
async def cmd_nearby(app, msg):
async def cmd_nearby(app: Client, msg: Message):
if (await isAnAdmin(msg) is True) or (col_applications.find_one({"user": msg.from_user.id}) is not None):
await msg.reply_text("Yes, I exist.", quote=should_quote(msg))
# if not path.exists(f"{configGet('data', 'locations')}{sep}sponsors{sep}{msg.from_user.id}.json"):

View File

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

View File

@ -2,6 +2,8 @@ from app import app, isAnAdmin
from os import getpid
from sys import exit
from pyrogram import filters
from pyrogram.types import Message
from pyrogram.client import Client
from modules.utils import locale, logWrite, should_quote
from modules.scheduled import scheduler
@ -9,7 +11,7 @@ pid = getpid()
# Shutdown command =============================================================================================================
@app.on_message(~ filters.scheduled & filters.private & filters.command(["kill", "die", "reboot"], prefixes=["/"]))
async def cmd_kill(app, msg):
async def cmd_kill(app: Client, msg: Message):
if await isAnAdmin(msg.from_user.id) is True:
logWrite(f"Shutting down bot with pid {pid}")

View File

@ -1,7 +1,8 @@
from typing import Union
from app import app
from pyrogram import filters
from pyrogram.types import InlineKeyboardMarkup, InlineKeyboardButton, User
from pyrogram.types import InlineKeyboardMarkup, InlineKeyboardButton, User, Message
from pyrogram.client import Client
from modules.utils import locale
from classes.holo_user import HoloUser
@ -35,6 +36,6 @@ class DefaultRulesMarkup(list):
# Rules command =============================================================================================================
@app.on_message(~ filters.scheduled & filters.private & filters.command(["rules"], prefixes=["/"]))
async def cmd_rules(app, msg):
async def cmd_rules(app: Client, msg: Message):
await msg.reply_text(locale("rules_msg", locale=msg.from_user), disable_web_page_preview=True, reply_markup=DefaultRulesMarkup(msg.from_user).keyboard)
# ==============================================================================================================================

View File

@ -1,13 +1,14 @@
from app import app, isAnAdmin
from pyrogram import filters
from pyrogram.types import InlineKeyboardMarkup, InlineKeyboardButton
from pyrogram.types import InlineKeyboardMarkup, InlineKeyboardButton, Message
from pyrogram.client import Client
from classes.holo_user import HoloUser
from modules.utils import locale, should_quote
from modules.database import col_applications
# Sponsorship command ==========================================================================================================
@app.on_message(~ filters.scheduled & filters.command(["sponsorship"], prefixes=["/"]))
async def cmd_sponsorship(app, msg):
async def cmd_sponsorship(app: Client, msg: Message):
if (await isAnAdmin(msg) is True) or (col_applications.find_one({"user": msg.from_user.id}) is not None):
if HoloUser(msg.from_user).application_state()[0] == "fill":
await msg.reply_text(locale("finish_application", "message"), quote=should_quote(msg))

View File

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

View File

@ -1,12 +1,14 @@
from datetime import datetime
from app import app, isAnAdmin
from pyrogram import filters
from pyrogram.types import Message
from pyrogram.client import Client
from modules.utils import configGet, locale
from modules.database import col_warnings
# Warn command =================================================================================================================
@app.on_message(~ filters.scheduled & filters.command(["warn"], prefixes=["/"]))
async def cmd_warn(app, msg):
async def cmd_warn(app: Client, msg: Message):
if msg.chat.id == configGet("destination_group"):
if msg.reply_to_message_id != None:

View File

@ -1,12 +1,14 @@
from app import app, isAnAdmin
from pyrogram import filters
from pyrogram.types import Message
from pyrogram.client import Client
from pyrogram.enums.chat_members_filter import ChatMembersFilter
from modules.utils import configGet, locale, should_quote
from modules.database import col_users, col_warnings
# Warnings command =============================================================================================================
@app.on_message(~ filters.scheduled & filters.command(["warnings"], prefixes=["/"]))
async def cmd_warnings(app, msg):
async def cmd_warnings(app: Client, msg: Message):
if await isAnAdmin(msg.from_user.id) is True:

View File

@ -5,7 +5,8 @@ from dateutil.relativedelta import relativedelta
from datetime import datetime
from app import app
from pyrogram import filters
from pyrogram.types import ReplyKeyboardRemove, InlineKeyboardMarkup, InlineKeyboardButton, ForceReply
from pyrogram.types import ReplyKeyboardRemove, InlineKeyboardMarkup, InlineKeyboardButton, ForceReply, Message
from pyrogram.client import Client
from pyrogram.enums.parse_mode import ParseMode
from classes.holo_user import HoloUser
from modules.utils import all_locales, configGet, locale, logWrite
@ -17,7 +18,7 @@ confirmation_1 = []
for pattern in all_locales("confirm", "keyboard"):
confirmation_1.append(pattern[0][0])
@app.on_message(~ filters.scheduled & filters.private & filters.command(confirmation_1, prefixes=[""]))
async def confirm_yes(app, msg, kind: Literal["application", "sponsorship"] = "unknown"):
async def confirm_yes(app: Client, msg: Message, kind: Literal["application", "sponsorship"] = "unknown"):
holo_user = HoloUser(msg.from_user)
@ -142,7 +143,7 @@ confirmation_2 = []
for pattern in all_locales("confirm", "keyboard"):
confirmation_2.append(pattern[1][0])
@app.on_message(~ filters.scheduled & filters.private & filters.command(confirmation_2, prefixes=[""]))
async def confirm_no(app, msg, kind: Literal["application", "sponsorship"] = "unknown"):
async def confirm_no(app: Client, msg: Message, kind: Literal["application", "sponsorship"] = "unknown"):
holo_user = HoloUser(msg.from_user)

View File

@ -2,13 +2,15 @@ from dateutil.relativedelta import relativedelta
from datetime import datetime
from app import app, isAnAdmin
from pyrogram import filters
from pyrogram.types import Message
from pyrogram.client import Client
from modules.utils import locale, logWrite
from modules.database import col_applications
from classes.holo_user import HoloUser
# Contact getting ==============================================================================================================
@app.on_message(~ filters.scheduled & filters.contact & filters.private)
async def get_contact(app, msg):
async def get_contact(app: Client, msg: Message):
holo_user = HoloUser(msg.from_user)

View File

@ -2,6 +2,7 @@ from app import app, isAnAdmin
import asyncio
from pyrogram import filters
from pyrogram.types import Message
from pyrogram.client import Client
from classes.holo_user import HoloUser
from modules.utils import configGet, logWrite
from modules.database import col_messages
@ -20,7 +21,7 @@ async def message_context(msg: Message) -> tuple:
# Any other input ==============================================================================================================
@app.on_message(~ filters.scheduled & filters.private)
async def any_stage(app, msg):
async def any_stage(app: Client, msg: Message):
if msg.via_bot is None:
@ -113,7 +114,7 @@ async def any_stage(app, msg):
# await msg.reply_text(locale("already_sent", "message"))
@app.on_message(~ filters.scheduled & filters.group)
async def message_in_group(app, msg):
async def message_in_group(app: Client, msg: Message):
if (msg.chat is not None) and (msg.via_bot is not None):
if (msg.via_bot.id == configGet("bot_id")) and (msg.chat.id == configGet("destination_group")):
if configGet("remove_application_time") > 0:

View File

@ -1,5 +1,6 @@
from app import app, isAnAdmin
from pyrogram.types import ChatPermissions, InlineKeyboardMarkup, InlineKeyboardButton
from pyrogram.types import ChatPermissions, InlineKeyboardMarkup, InlineKeyboardButton, ChatMemberUpdated
from pyrogram.client import Client
from modules.utils import configGet, locale
from modules.logging import logWrite
from classes.holo_user import HoloUser
@ -7,7 +8,7 @@ from classes.holo_user import HoloUser
# Filter users on join =========================================================================================================
@app.on_chat_member_updated(group=configGet("destination_group"))
#@app.on_message(filters.new_chat_members, group=configGet("destination_group"))
async def filter_join(app, member):
async def filter_join(app: Client, member: ChatMemberUpdated):
if member.invite_link != None:

View File

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

View File

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

View File

@ -1,6 +1,7 @@
from app import app
from pyrogram import filters
from pyrogram.types import ForceReply, ReplyKeyboardMarkup
from pyrogram.types import ForceReply, ReplyKeyboardMarkup, Message
from pyrogram.client import Client
from modules.utils import all_locales, locale, logWrite
# Welcome check ================================================================================================================
@ -31,7 +32,7 @@ welcome_2 = []
for pattern in all_locales("welcome", "keyboard"):
welcome_2.append(pattern[1][0])
@app.on_message(~ filters.scheduled & filters.private & filters.command(welcome_2, prefixes=[""]))
async def welcome_reject(app, msg):
async def welcome_reject(app: Client, msg: Message):
logWrite(f"User {msg.from_user.id} rejected to start the application")
await msg.reply_text(locale("goodbye", "message", locale=msg.from_user), reply_markup=ReplyKeyboardMarkup(locale("return", "keyboard", locale=msg.from_user), resize_keyboard=True))