Improved naming

This commit is contained in:
Profitroll 2023-10-15 18:14:22 +02:00
parent c4d31c955f
commit a0616ff285
Signed by: profitroll
GPG Key ID: FA35CAB49DACD3B2
9 changed files with 201 additions and 184 deletions

View File

@ -6,7 +6,7 @@ from classes.pyroclient import PyroClient
@Client.on_callback_query(filters.regex("nothing"))
async def callback_query_nothing(app: PyroClient, clb: CallbackQuery):
user = await app.find_user(clb.from_user)
async def callback_query_nothing(app: PyroClient, callback: CallbackQuery):
user = await app.find_user(callback.from_user)
await clb.answer(text=app._("nothing", "callback", locale=user.locale))
await callback.answer(text=app._("nothing", "callback", locale=user.locale))

View File

@ -10,11 +10,11 @@ from classes.pyroclient import PyroClient
@Client.on_callback_query(filters.regex("shutdown"))
async def callback_query_nothing(app: PyroClient, clb: CallbackQuery):
if clb.from_user.id not in app.admins:
async def callback_query_nothing(app: PyroClient, callback: CallbackQuery):
if callback.from_user.id not in app.admins:
return
await clb.answer()
await callback.answer()
makedirs(await config_get("cache", "locations"), exist_ok=True)
await json_write(

View File

@ -21,22 +21,22 @@ logger = logging.getLogger(__name__)
@Client.on_callback_query(filters.regex("sub_yes_[\s\S]*"))
async def callback_query_yes(app: PyroClient, clb: CallbackQuery):
user = await app.find_user(clb.from_user)
fullclb = str(clb.data).split("_")
async def callback_query_yes(app: PyroClient, callback: CallbackQuery):
user = await app.find_user(callback.from_user)
fullcallback = str(callback.data).split("_")
db_entry = await col_submitted.find_one({"_id": ObjectId(fullclb[2])})
db_entry = await col_submitted.find_one({"_id": ObjectId(fullcallback[2])})
try:
submission = await app.submit_media(fullclb[2])
submission = await app.submit_media(fullcallback[2])
except SubmissionUnavailableError:
await clb.answer(
await callback.answer(
text=app._("sub_msg_unavail", "callback", locale=user.locale),
show_alert=True,
)
return
except SubmissionUnsupportedError:
await clb.answer(
await callback.answer(
text=app._("mime_not_allowed", "message", locale=user.locale).format(
", ".join(app.config["submission"]["mime_types"]), quote=True
),
@ -44,11 +44,11 @@ async def callback_query_yes(app: PyroClient, clb: CallbackQuery):
)
return
except SubmissionDuplicatesError as exc:
await clb.answer(
await callback.answer(
text=app._("sub_duplicates_found", "callback", locale=user.locale),
show_alert=True,
)
await clb.message.reply_text(
await callback.message.reply_text(
app._("sub_media_duplicates_list", "message", locale=user.locale).format(
"\n".join(exc.duplicates)
),
@ -56,7 +56,7 @@ async def callback_query_yes(app: PyroClient, clb: CallbackQuery):
)
logger.info(
"Submission with ID '%s' could not be accepted because of the duplicates: %s",
fullclb[2],
fullcallback[2],
str(exc.duplicates),
)
return
@ -80,8 +80,8 @@ async def callback_query_yes(app: PyroClient, clb: CallbackQuery):
),
)
await clb.answer(
text=app._("sub_yes", "callback", locale=user.locale).format(fullclb[2]),
await callback.answer(
text=app._("sub_yes", "callback", locale=user.locale).format(fullcallback[2]),
show_alert=True,
)
@ -93,9 +93,9 @@ async def callback_query_yes(app: PyroClient, clb: CallbackQuery):
callback_data="nothing",
)
],
clb.message.reply_markup.inline_keyboard[1],
callback.message.reply_markup.inline_keyboard[1],
]
if len(clb.message.reply_markup.inline_keyboard) > 1
if len(callback.message.reply_markup.inline_keyboard) > 1
else [
[
InlineKeyboardButton(
@ -107,27 +107,29 @@ async def callback_query_yes(app: PyroClient, clb: CallbackQuery):
)
if await config_get("send_uploaded_id", "submission"):
await clb.message.edit_caption(
f"{clb.message.caption}\n\nID: `{submission[1]}`"
await callback.message.edit_caption(
f"{callback.message.caption}\n\nID: `{submission[1]}`"
)
await clb.message.edit_reply_markup(
await callback.message.edit_reply_markup(
reply_markup=InlineKeyboardMarkup(edited_markup)
)
logger.info(
"Submission with ID '%s' accepted and uploaded with ID '%s'",
fullclb[2],
fullcallback[2],
submission[1],
)
@Client.on_callback_query(filters.regex("sub_no_[\s\S]*"))
async def callback_query_no(app: PyroClient, clb: CallbackQuery):
user = await app.find_user(clb.from_user)
fullclb = str(clb.data).split("_")
async def callback_query_no(app: PyroClient, callback: CallbackQuery):
user = await app.find_user(callback.from_user)
fullcallback = str(callback.data).split("_")
db_entry = await col_submitted.find_one_and_delete({"_id": ObjectId(fullclb[2])})
db_entry = await col_submitted.find_one_and_delete(
{"_id": ObjectId(fullcallback[2])}
)
if (
db_entry["temp"]["uuid"] is not None
@ -147,7 +149,7 @@ async def callback_query_no(app: PyroClient, clb: CallbackQuery):
db_entry["user"], db_entry["telegram"]["msg_id"]
)
except Exception as exc:
await clb.answer(
await callback.answer(
text=app._("sub_msg_unavail", "message", locale=user.locale),
show_alert=True,
)
@ -161,8 +163,8 @@ async def callback_query_no(app: PyroClient, clb: CallbackQuery):
),
quote=True,
)
await clb.answer(
text=app._("sub_no", "callback", locale=user.locale).format(fullclb[2]),
await callback.answer(
text=app._("sub_no", "callback", locale=user.locale).format(fullcallback[2]),
show_alert=True,
)
@ -174,9 +176,9 @@ async def callback_query_no(app: PyroClient, clb: CallbackQuery):
callback_data="nothing",
)
],
clb.message.reply_markup.inline_keyboard[1],
callback.message.reply_markup.inline_keyboard[1],
]
if len(clb.message.reply_markup.inline_keyboard) > 1
if len(callback.message.reply_markup.inline_keyboard) > 1
else [
[
InlineKeyboardButton(
@ -186,81 +188,83 @@ async def callback_query_no(app: PyroClient, clb: CallbackQuery):
]
]
)
await clb.message.edit_reply_markup(
await callback.message.edit_reply_markup(
reply_markup=InlineKeyboardMarkup(edited_markup)
)
logger.info(
"Submission with ID '%s' rejected",
fullclb[2],
fullcallback[2],
)
@Client.on_callback_query(filters.regex("sub_block_[\s\S]*"))
async def callback_query_block(app: PyroClient, clb: CallbackQuery):
user = await app.find_user(clb.from_user)
fullclb = str(clb.data).split("_")
async def callback_query_block(app: PyroClient, callback: CallbackQuery):
user = await app.find_user(callback.from_user)
fullcallback = str(callback.data).split("_")
await app.send_message(
int(fullclb[2]),
int(fullcallback[2]),
app._(
"sub_blocked",
"message",
locale=(await app.find_user(int(fullclb[2]))).locale,
locale=(await app.find_user(int(fullcallback[2]))).locale,
),
)
await user.block()
await clb.answer(
text=app._("sub_block", "callback", locale=user.locale).format(fullclb[2]),
await callback.answer(
text=app._("sub_block", "callback", locale=user.locale).format(fullcallback[2]),
show_alert=True,
)
edited_markup = [
clb.message.reply_markup.inline_keyboard[0],
callback.message.reply_markup.inline_keyboard[0],
[
InlineKeyboardButton(
text=str(app._("sub_unblock", "button", locale=user.locale)),
callback_data=f"sub_unblock_{fullclb[2]}",
callback_data=f"sub_unblock_{fullcallback[2]}",
)
],
]
await clb.message.edit_reply_markup(
await callback.message.edit_reply_markup(
reply_markup=InlineKeyboardMarkup(edited_markup)
)
logger.info("User %s has been blocked", fullclb[2])
logger.info("User %s has been blocked", fullcallback[2])
@Client.on_callback_query(filters.regex("sub_unblock_[\s\S]*"))
async def callback_query_unblock(app: PyroClient, clb: CallbackQuery):
user = await app.find_user(clb.from_user)
fullclb = str(clb.data).split("_")
async def callback_query_unblock(app: PyroClient, callback: CallbackQuery):
user = await app.find_user(callback.from_user)
fullcallback = str(callback.data).split("_")
await app.send_message(
int(fullclb[2]),
int(fullcallback[2]),
app._(
"sub_unblocked",
"message",
locale=(await app.find_user(int(fullclb[2]))).locale,
locale=(await app.find_user(int(fullcallback[2]))).locale,
),
)
await user.unblock()
await clb.answer(
text=app._("sub_unblock", "callback", locale=user.locale).format(fullclb[2]),
await callback.answer(
text=app._("sub_unblock", "callback", locale=user.locale).format(
fullcallback[2]
),
show_alert=True,
)
edited_markup = [
clb.message.reply_markup.inline_keyboard[0],
callback.message.reply_markup.inline_keyboard[0],
[
InlineKeyboardButton(
text=str(app._("sub_block", "button", locale=user.locale)),
callback_data=f"sub_block_{fullclb[2]}",
callback_data=f"sub_block_{fullcallback[2]}",
)
],
]
await clb.message.edit_reply_markup(
await callback.message.edit_reply_markup(
reply_markup=InlineKeyboardMarkup(edited_markup)
)
logger.info("User %s has been unblocked", fullclb[2])
logger.info("User %s has been unblocked", fullcallback[2])

View File

@ -15,14 +15,14 @@ from modules.utils import USERS_WITH_CONTEXT
@Client.on_message(
~filters.scheduled & filters.command(["shutdown"], prefixes=["", "/"])
)
async def cmd_kill(app: PyroClient, msg: Message):
if msg.from_user.id not in app.admins:
async def cmd_kill(app: PyroClient, message: Message):
if message.from_user.id not in app.admins:
return
user = await app.find_user(msg.from_user)
user = await app.find_user(message.from_user)
if len(USERS_WITH_CONTEXT) > 0:
await msg.reply_text(
await message.reply_text(
app._("shutdown_confirm", "message", locale=user.locale).format(
len(USERS_WITH_CONTEXT)
),

View File

@ -11,13 +11,13 @@ from modules import custom_filters
& ~filters.scheduled
& filters.command(["start"], prefixes="/")
)
async def cmd_start(app: PyroClient, msg: Message):
user = await app.find_user(msg.from_user)
async def cmd_start(app: PyroClient, message: Message):
user = await app.find_user(message.from_user)
if user.banned:
return
await msg.reply_text(app._("start", "message", locale=user.locale))
await message.reply_text(app._("start", "message", locale=user.locale))
@Client.on_message(
@ -25,10 +25,10 @@ async def cmd_start(app: PyroClient, msg: Message):
& ~filters.scheduled
& filters.command(["rules", "help"], prefixes="/")
)
async def cmd_rules(app: PyroClient, msg: Message):
user = await app.find_user(msg.from_user)
async def cmd_rules(app: PyroClient, message: Message):
user = await app.find_user(message.from_user)
if user.banned:
return
await msg.reply_text(app._("rules", "message", locale=user.locale))
await message.reply_text(app._("rules", "message", locale=user.locale))

View File

@ -37,27 +37,27 @@ logger = logging.getLogger(__name__)
@Client.on_message(~filters.scheduled & filters.command(["import"], prefixes=["", "/"]))
async def cmd_import(app: PyroClient, msg: Message):
if msg.from_user.id not in app.admins:
async def cmd_import(app: PyroClient, message: Message):
if message.from_user.id not in app.admins:
return
global USERS_WITH_CONTEXT
if msg.from_user.id not in USERS_WITH_CONTEXT:
USERS_WITH_CONTEXT.append(msg.from_user.id)
if message.from_user.id not in USERS_WITH_CONTEXT:
USERS_WITH_CONTEXT.append(message.from_user.id)
else:
return
user = await app.find_user(msg.from_user)
user = await app.find_user(message.from_user)
await msg.reply_text(app._("import_request", "message", locale=user.locale))
await message.reply_text(app._("import_request", "message", locale=user.locale))
answer = await listen_message(app, msg.chat.id, timeout=600)
answer = await listen_message(app, message.chat.id, timeout=600)
USERS_WITH_CONTEXT.remove(msg.from_user.id)
USERS_WITH_CONTEXT.remove(message.from_user.id)
if answer is None:
await msg.reply_text(
await message.reply_text(
app._("import_ignored", "message", locale=user.locale),
quote=True,
)
@ -86,7 +86,7 @@ async def cmd_import(app: PyroClient, msg: Message):
return
if disk_usage(getcwd())[2] < (answer.document.file_size) * 3:
await msg.reply_text(
await message.reply_text(
app._("import_too_big", "message", locale=user.locale).format(
answer.document.file_size // (2**30),
disk_usage(getcwd())[2] // (2**30),
@ -172,7 +172,7 @@ async def cmd_import(app: PyroClient, msg: Message):
Path(f"{app.config['locations']['tmp']}/{tmp_dir}"),
exc,
)
await msg.reply_text(
await message.reply_text(
app._(
"import_upload_error_other",
"message",
@ -193,7 +193,7 @@ async def cmd_import(app: PyroClient, msg: Message):
)
if len(uploaded_dict["duplicates"]) > 0:
await msg.reply_text(
await message.reply_text(
app._(
"import_upload_error_duplicate",
"message",
@ -202,7 +202,7 @@ async def cmd_import(app: PyroClient, msg: Message):
disable_notification=True,
)
else:
await msg.reply_text(
await message.reply_text(
app._(
"import_upload_error_other",
"message",
@ -235,35 +235,35 @@ async def cmd_import(app: PyroClient, msg: Message):
@Client.on_message(~filters.scheduled & filters.command(["export"], prefixes=["", "/"]))
async def cmd_export(app: PyroClient, msg: Message):
if msg.from_user.id not in app.admins:
async def cmd_export(app: PyroClient, message: Message):
if message.from_user.id not in app.admins:
return
@Client.on_message(~filters.scheduled & filters.command(["remove"], prefixes=["", "/"]))
async def cmd_remove(app: PyroClient, msg: Message):
if msg.from_user.id not in app.admins:
async def cmd_remove(app: PyroClient, message: Message):
if message.from_user.id not in app.admins:
return
global USERS_WITH_CONTEXT
if msg.from_user.id not in USERS_WITH_CONTEXT:
USERS_WITH_CONTEXT.append(msg.from_user.id)
if message.from_user.id not in USERS_WITH_CONTEXT:
USERS_WITH_CONTEXT.append(message.from_user.id)
else:
return
user = await app.find_user(msg.from_user)
user = await app.find_user(message.from_user)
await msg.reply_text(app._("remove_request", "message", locale=user.locale))
await message.reply_text(app._("remove_request", "message", locale=user.locale))
answer_id = await app.listen.Message(
filters.text & ~filters.me, id=filters.user(msg.from_user.id), timeout=600
filters.text & ~filters.me, id=filters.user(message.from_user.id), timeout=600
)
USERS_WITH_CONTEXT.remove(msg.from_user.id)
USERS_WITH_CONTEXT.remove(message.from_user.id)
if answer_id is None:
await msg.reply_text(
await message.reply_text(
app._("remove_ignored", "message", locale=user.locale),
quote=True,
)
@ -273,7 +273,7 @@ async def cmd_remove(app: PyroClient, msg: Message):
await answer_id.reply_text(app._("remove_abort", "message", locale=user.locale))
return
await msg.reply_text(
await message.reply_text(
app._("remove_kind", "message", locale=user.locale),
reply_markup=ReplyKeyboardMarkup(
[
@ -287,16 +287,16 @@ async def cmd_remove(app: PyroClient, msg: Message):
),
)
USERS_WITH_CONTEXT.append(msg.from_user.id)
USERS_WITH_CONTEXT.append(message.from_user.id)
answer_kind = await app.listen.Message(
filters.text & ~filters.me, id=filters.user(msg.from_user.id), timeout=600
filters.text & ~filters.me, id=filters.user(message.from_user.id), timeout=600
)
USERS_WITH_CONTEXT.remove(msg.from_user.id)
USERS_WITH_CONTEXT.remove(message.from_user.id)
if answer_kind is None:
await msg.reply_text(
await message.reply_text(
app._("remove_ignored", "message", locale=user.locale),
quote=True,
reply_markup=ReplyKeyboardRemove(),
@ -355,6 +355,6 @@ async def cmd_remove(app: PyroClient, msg: Message):
@Client.on_message(~filters.scheduled & filters.command(["purge"], prefixes=["", "/"]))
async def cmd_purge(app: PyroClient, msg: Message):
if msg.from_user.id not in app.admins:
async def cmd_purge(app: PyroClient, message: Message):
if message.from_user.id not in app.admins:
return

View File

@ -14,24 +14,25 @@ from modules import custom_filters
& filters.reply
& filters.command(["report"], prefixes=["", "/"])
)
async def command_report(app: PyroClient, msg: Message):
if msg.reply_to_message.forward_from_chat.id != app.config["posting"]["channel"]:
async def command_report(app: PyroClient, message: Message):
if (
message.reply_to_message.forward_from_chat.id
!= app.config["posting"]["channel"]
):
return
user = await app.find_user(msg.from_user)
user = await app.find_user(message.from_user)
await msg.reply_text(
await message.reply_text(
app._(
"report_sent",
"message",
locale=user.locale if msg.from_user is not None else None,
locale=user.locale if message.from_user is not None else None,
)
)
print(msg)
report_sent = await msg.reply_to_message.forward(app.owner)
sender = msg.from_user if msg.from_user is not None else msg.sender_chat
report_sent = await message.reply_to_message.forward(app.owner)
sender = message.from_user if message.from_user is not None else message.sender_chat
sender_name = sender.first_name if isinstance(sender, User) else sender.title

View File

@ -26,115 +26,121 @@ logger = logging.getLogger(__name__)
# | filters.animation
| filters.document
)
async def get_submission(app: PyroClient, msg: Message):
async def get_submission(app: PyroClient, message: Message):
global USERS_WITH_CONTEXT
if not hasattr(msg.from_user, "id"):
if not hasattr(message.from_user, "id"):
return
if msg.from_user.id in USERS_WITH_CONTEXT:
if message.from_user.id in USERS_WITH_CONTEXT:
return
user = await app.find_user(msg.from_user)
user = await app.find_user(message.from_user)
user_owner = await app.find_user(app.owner)
try:
if user.banned:
return
await app.send_chat_action(msg.chat.id, ChatAction.TYPING)
await app.send_chat_action(message.chat.id, ChatAction.TYPING)
save_tmp = True
contents = None
if await user.is_limited():
await msg.reply_text(
await message.reply_text(
app._("sub_cooldown", "message", locale=user.locale).format(
app.config["submission"]["timeout"]
)
)
return
if msg.document is not None:
if message.document is not None:
logger.info(
"User %s is trying to submit a file of type '%s' with name '%s' and size of %s MB",
msg.from_user.id,
msg.document.mime_type,
msg.document.file_name,
msg.document.file_size / 1024 / 1024,
message.from_user.id,
message.document.mime_type,
message.document.file_name,
message.document.file_size / 1024 / 1024,
)
if msg.document.mime_type not in app.config["submission"]["mime_types"]:
await msg.reply_text(
if message.document.mime_type not in app.config["submission"]["mime_types"]:
await message.reply_text(
app._("mime_not_allowed", "message", locale=user.locale).format(
", ".join(app.config["submission"]["mime_types"])
),
quote=True,
)
return
if msg.document.file_size > app.config["submission"]["file_size"]:
await msg.reply_text(
if message.document.file_size > app.config["submission"]["file_size"]:
await message.reply_text(
app._("document_too_large", "message", locale=user.locale).format(
app.config["submission"]["file_size"] / 1024 / 1024
),
quote=True,
)
return
if msg.document.file_size > app.config["submission"]["tmp_size"]:
if message.document.file_size > app.config["submission"]["tmp_size"]:
save_tmp = False
contents = (
msg.document.file_id,
message.document.file_id,
SubmissionType.DOCUMENT,
) # , msg.document.file_name
) # , message.document.file_name
if msg.video is not None:
if message.video is not None:
logger.info(
"User %s is trying to submit a video with name '%s' and size of %s MB",
msg.from_user.id,
msg.video.file_name,
msg.video.file_size / 1024 / 1024,
message.from_user.id,
message.video.file_name,
message.video.file_size / 1024 / 1024,
)
if msg.video.file_size > app.config["submission"]["file_size"]:
await msg.reply_text(
if message.video.file_size > app.config["submission"]["file_size"]:
await message.reply_text(
app._("document_too_large", "message", locale=user.locale).format(
app.config["submission"]["file_size"] / 1024 / 1024
),
quote=True,
)
return
if msg.video.file_size > app.config["submission"]["tmp_size"]:
if message.video.file_size > app.config["submission"]["tmp_size"]:
save_tmp = False
contents = msg.video.file_id, SubmissionType.VIDEO # , msg.video.file_name
contents = (
message.video.file_id,
SubmissionType.VIDEO,
) # , message.video.file_name
# if msg.animation is not None:
# if message.animation is not None:
# logger.info(
# "User %s is trying to submit an animation with name '%s' and size of %s MB",
# msg.from_user.id,
# msg.animation.file_name,
# msg.animation.file_size / 1024 / 1024,
# message.from_user.id,
# message.animation.file_name,
# message.animation.file_size / 1024 / 1024,
# )
# if msg.animation.file_size > app.config["submission"]["file_size"]:
# await msg.reply_text(
# if message.animation.file_size > app.config["submission"]["file_size"]:
# await message.reply_text(
# app._("document_too_large", "message", locale=user.locale).format(
# str(app.config["submission"]["file_size"] / 1024 / 1024)
# ),
# quote=True,
# )
# return
# if msg.animation.file_size > app.config["submission"]["tmp_size"]:
# if message.animation.file_size > app.config["submission"]["tmp_size"]:
# save_tmp = False
# contents = (
# msg.animation.file_id,
# message.animation.file_id,
# SubmissionType.ANIMATION,
# ) # , msg.animation.file_name
# ) # , message.animation.file_name
if msg.photo is not None:
if message.photo is not None:
logger.info(
"User %s is trying to submit a photo with ID '%s' and size of %s MB",
msg.from_user.id,
msg.photo.file_id,
msg.photo.file_size / 1024 / 1024,
message.from_user.id,
message.photo.file_id,
message.photo.file_size / 1024 / 1024,
)
contents = msg.photo.file_id, SubmissionType.PHOTO # , "please_generate"
contents = (
message.photo.file_id,
SubmissionType.PHOTO,
) # , "please_generate"
if contents is None:
return
@ -148,33 +154,37 @@ async def get_submission(app: PyroClient, msg: Message):
exist_ok=True,
)
downloaded = await app.download_media(
msg,
message,
str(Path(f"{app.config['locations']['data']}/submissions/{tmp_id}"))
+ sep,
)
inserted = await col_submitted.insert_one(
{
"user": msg.from_user.id,
"user": message.from_user.id,
"date": datetime.now(),
"done": False,
"type": contents[1].value,
"temp": {"uuid": tmp_id, "file": path.basename(str(downloaded))},
"telegram": {"msg_id": msg.id, "file_id": contents[0]},
"caption": str(msg.caption) if msg.caption is not None else None,
"telegram": {"msg_id": message.id, "file_id": contents[0]},
"caption": str(message.caption)
if message.caption is not None
else None,
}
)
else:
inserted = await col_submitted.insert_one(
{
"user": msg.from_user.id,
"user": message.from_user.id,
"date": datetime.now(),
"done": False,
"type": contents[1].value,
"temp": {"uuid": None, "file": None},
"telegram": {"msg_id": msg.id, "file_id": contents[0]},
"caption": str(msg.caption) if msg.caption is not None else None,
"telegram": {"msg_id": message.id, "file_id": contents[0]},
"caption": str(message.caption)
if message.caption is not None
else None,
}
)
@ -187,8 +197,8 @@ async def get_submission(app: PyroClient, msg: Message):
]
]
if msg.caption is not None:
caption = str(msg.caption)
if message.caption is not None:
caption = str(message.caption)
buttons[0].append(
InlineKeyboardButton(
text=app._("sub_yes_caption", "button", locale=user_owner.locale),
@ -206,32 +216,34 @@ async def get_submission(app: PyroClient, msg: Message):
)
caption += app._("sub_by", "message", locale=user_owner.locale)
if msg.from_user.first_name is not None:
caption += f" {msg.from_user.first_name}"
if msg.from_user.last_name is not None:
caption += f" {msg.from_user.last_name}"
if msg.from_user.username is not None:
caption += f" (@{msg.from_user.username})"
if msg.from_user.phone_number is not None:
caption += f" ({msg.from_user.phone_number})"
if message.from_user.first_name is not None:
caption += f" {message.from_user.first_name}"
if message.from_user.last_name is not None:
caption += f" {message.from_user.last_name}"
if message.from_user.username is not None:
caption += f" (@{message.from_user.username})"
if message.from_user.phone_number is not None:
caption += f" ({message.from_user.phone_number})"
if (
msg.from_user.id in app.admins
message.from_user.id in app.admins
and app.config["submission"]["require_confirmation"]["admins"] is False
):
try:
submitted = await app.submit_media(str(inserted.inserted_id))
await msg.reply_text(
await message.reply_text(
app._("sub_yes_auto", "message", locale=user.locale),
disable_notification=True,
quote=True,
)
if app.config["submission"]["send_uploaded_id"]:
caption += f"\n\nID: `{submitted[1]}`"
await msg.copy(app.owner, caption=caption, disable_notification=True)
await message.copy(
app.owner, caption=caption, disable_notification=True
)
return
except SubmissionUnsupportedError:
await msg.reply_text(
await message.reply_text(
app._("mime_not_allowed", "message", locale=user.locale).format(
", ".join(app.config["submission"]["mime_types"]), quote=True
),
@ -239,7 +251,7 @@ async def get_submission(app: PyroClient, msg: Message):
)
return
except SubmissionDuplicatesError as exc:
await msg.reply_text(
await message.reply_text(
app._(
"sub_media_duplicates_list", "message", locale=user.locale
).format("\n".join(exc.duplicates)),
@ -247,32 +259,32 @@ async def get_submission(app: PyroClient, msg: Message):
)
return
except Exception as exc:
await msg.reply_text(exc, quote=True)
await message.reply_text(exc, quote=True)
return
elif (
msg.from_user.id not in app.admins
message.from_user.id not in app.admins
and app.config["submission"]["require_confirmation"]["users"] is False
):
try:
submitted = await app.submit_photo(str(inserted.inserted_id))
await msg.reply_text(
await message.reply_text(
app._("sub_yes_auto", "message", locale=user.locale),
disable_notification=True,
quote=True,
)
if app.config["submission"]["send_uploaded_id"]:
caption += f"\n\nID: `{submitted[1]}`"
await msg.copy(app.owner, caption=caption)
await message.copy(app.owner, caption=caption)
return
except SubmissionUnsupportedError:
await msg.reply_text(
await message.reply_text(
app._("mime_not_allowed", "message", locale=user.locale).format(
", ".join(app.config["submission"]["mime_types"]), quote=True
)
)
return
except SubmissionDuplicatesError as exc:
await msg.reply_text(
await message.reply_text(
app._("sub_dup", "message", locale=user.locale), quote=True
)
return
@ -281,31 +293,31 @@ async def get_submission(app: PyroClient, msg: Message):
app.owner,
app._(
"sub_error_admin", "message", locale=user_owner.locale
).format(msg.from_user.id, format_exc()),
).format(message.from_user.id, format_exc()),
)
await msg.reply_text("sub_error", quote=True)
await message.reply_text("sub_error", quote=True)
return
if msg.from_user.id not in app.admins:
if message.from_user.id not in app.admins:
buttons += [
[
InlineKeyboardButton(
text=app._("sub_block", "button", locale=user_owner.locale),
callback_data=f"sub_block_{msg.from_user.id}",
callback_data=f"sub_block_{message.from_user.id}",
)
]
]
await user.update_cooldown()
if msg.from_user.id != app.owner:
await msg.reply_text(
if message.from_user.id != app.owner:
await message.reply_text(
app._("sub_sent", "message", locale=user.locale),
disable_notification=True,
quote=True,
)
await msg.copy(
await message.copy(
app.owner, caption=caption, reply_markup=InlineKeyboardMarkup(buttons)
)

View File

@ -8,6 +8,6 @@ from classes.pyroclient import PyroClient
@Client.on_message(
~filters.scheduled & filters.private & filters.command(["remove_commands"], prefixes=["/"]) # type: ignore
)
async def command_remove_commands(app: PyroClient, msg: Message):
await msg.reply_text("Okay.")
async def command_remove_commands(app: PyroClient, message: Message):
await message.reply_text("Okay.")
await app.remove_commands(command_sets=await app.collect_commands())