WIP: /language system
This commit is contained in:
@@ -13,7 +13,6 @@ 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 classes.user import PosterUser
|
||||
from modules.database import col_banned, col_submitted
|
||||
from modules.utils import USERS_WITH_CONTEXT
|
||||
|
||||
@@ -35,20 +34,22 @@ async def get_submission(app: PyroClient, msg: Message):
|
||||
if msg.from_user.id in USERS_WITH_CONTEXT:
|
||||
return
|
||||
|
||||
user = await app.find_user(msg.from_user)
|
||||
user_owner = await app.find_user(app.owner)
|
||||
|
||||
try:
|
||||
if col_banned.find_one({"user": msg.from_user.id}) is not None:
|
||||
return
|
||||
|
||||
await app.send_chat_action(msg.chat.id, ChatAction.TYPING)
|
||||
|
||||
user_locale = msg.from_user.language_code
|
||||
save_tmp = True
|
||||
contents = None
|
||||
|
||||
if PosterUser(msg.from_user.id).is_limited():
|
||||
if await user.is_limited():
|
||||
await msg.reply_text(
|
||||
app._("sub_cooldown", "message", locale=user_locale).format(
|
||||
str(app.config["submission"]["timeout"])
|
||||
app._("sub_cooldown", "message", locale=user.locale).format(
|
||||
app.config["submission"]["timeout"]
|
||||
)
|
||||
)
|
||||
return
|
||||
@@ -63,7 +64,7 @@ async def get_submission(app: PyroClient, msg: Message):
|
||||
)
|
||||
if msg.document.mime_type not in app.config["submission"]["mime_types"]:
|
||||
await msg.reply_text(
|
||||
app._("mime_not_allowed", "message", locale=user_locale).format(
|
||||
app._("mime_not_allowed", "message", locale=user.locale).format(
|
||||
", ".join(app.config["submission"]["mime_types"])
|
||||
),
|
||||
quote=True,
|
||||
@@ -71,8 +72,8 @@ async def get_submission(app: PyroClient, msg: Message):
|
||||
return
|
||||
if msg.document.file_size > app.config["submission"]["file_size"]:
|
||||
await msg.reply_text(
|
||||
app._("document_too_large", "message", locale=user_locale).format(
|
||||
str(app.config["submission"]["file_size"] / 1024 / 1024)
|
||||
app._("document_too_large", "message", locale=user.locale).format(
|
||||
app.config["submission"]["file_size"] / 1024 / 1024
|
||||
),
|
||||
quote=True,
|
||||
)
|
||||
@@ -93,8 +94,8 @@ async def get_submission(app: PyroClient, msg: Message):
|
||||
)
|
||||
if msg.video.file_size > app.config["submission"]["file_size"]:
|
||||
await msg.reply_text(
|
||||
app._("document_too_large", "message", locale=user_locale).format(
|
||||
str(app.config["submission"]["file_size"] / 1024 / 1024)
|
||||
app._("document_too_large", "message", locale=user.locale).format(
|
||||
app.config["submission"]["file_size"] / 1024 / 1024
|
||||
),
|
||||
quote=True,
|
||||
)
|
||||
@@ -112,7 +113,7 @@ async def get_submission(app: PyroClient, msg: Message):
|
||||
# )
|
||||
# if msg.animation.file_size > app.config["submission"]["file_size"]:
|
||||
# await msg.reply_text(
|
||||
# app._("document_too_large", "message", locale=user_locale).format(
|
||||
# app._("document_too_large", "message", locale=user.locale).format(
|
||||
# str(app.config["submission"]["file_size"] / 1024 / 1024)
|
||||
# ),
|
||||
# quote=True,
|
||||
@@ -179,7 +180,7 @@ async def get_submission(app: PyroClient, msg: Message):
|
||||
buttons = [
|
||||
[
|
||||
InlineKeyboardButton(
|
||||
text=app._("sub_yes", "button"),
|
||||
text=app._("sub_yes", "button", locale=user_owner.locale),
|
||||
callback_data=f"sub_yes_{str(inserted.inserted_id)}",
|
||||
)
|
||||
]
|
||||
@@ -189,7 +190,7 @@ async def get_submission(app: PyroClient, msg: Message):
|
||||
caption = str(msg.caption)
|
||||
buttons[0].append(
|
||||
InlineKeyboardButton(
|
||||
text=app._("sub_yes_caption", "button"),
|
||||
text=app._("sub_yes_caption", "button", locale=user_owner.locale),
|
||||
callback_data=f"sub_yes_{str(inserted.inserted_id)}_caption",
|
||||
)
|
||||
)
|
||||
@@ -198,11 +199,11 @@ async def get_submission(app: PyroClient, msg: Message):
|
||||
|
||||
buttons[0].append(
|
||||
InlineKeyboardButton(
|
||||
text=app._("sub_no", "button"),
|
||||
text=app._("sub_no", "button", locale=user_owner.locale),
|
||||
callback_data=f"sub_no_{str(inserted.inserted_id)}",
|
||||
)
|
||||
)
|
||||
caption += app._("sub_by", "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}"
|
||||
@@ -220,7 +221,7 @@ async def get_submission(app: PyroClient, msg: Message):
|
||||
try:
|
||||
submitted = await app.submit_media(str(inserted.inserted_id))
|
||||
await msg.reply_text(
|
||||
app._("sub_yes_auto", "message", locale=user_locale),
|
||||
app._("sub_yes_auto", "message", locale=user.locale),
|
||||
disable_notification=True,
|
||||
quote=True,
|
||||
)
|
||||
@@ -230,7 +231,7 @@ async def get_submission(app: PyroClient, msg: Message):
|
||||
return
|
||||
except SubmissionUnsupportedError:
|
||||
await msg.reply_text(
|
||||
app._("mime_not_allowed", "message", locale=user_locale).format(
|
||||
app._("mime_not_allowed", "message", locale=user.locale).format(
|
||||
", ".join(app.config["submission"]["mime_types"]), quote=True
|
||||
),
|
||||
quote=True,
|
||||
@@ -239,7 +240,7 @@ async def get_submission(app: PyroClient, msg: Message):
|
||||
except SubmissionDuplicatesError as exp:
|
||||
await msg.reply_text(
|
||||
app._(
|
||||
"sub_media_duplicates_list", "message", locale=user_locale
|
||||
"sub_media_duplicates_list", "message", locale=user.locale
|
||||
).format("\n • ".join(exp.duplicates)),
|
||||
quote=True,
|
||||
)
|
||||
@@ -254,7 +255,7 @@ async def get_submission(app: PyroClient, msg: Message):
|
||||
try:
|
||||
submitted = await app.submit_photo(str(inserted.inserted_id))
|
||||
await msg.reply_text(
|
||||
app._("sub_yes_auto", "message", locale=user_locale),
|
||||
app._("sub_yes_auto", "message", locale=user.locale),
|
||||
disable_notification=True,
|
||||
quote=True,
|
||||
)
|
||||
@@ -264,22 +265,22 @@ async def get_submission(app: PyroClient, msg: Message):
|
||||
return
|
||||
except SubmissionUnsupportedError:
|
||||
await msg.reply_text(
|
||||
app._("mime_not_allowed", "message", locale=user_locale).format(
|
||||
app._("mime_not_allowed", "message", locale=user.locale).format(
|
||||
", ".join(app.config["submission"]["mime_types"]), quote=True
|
||||
)
|
||||
)
|
||||
return
|
||||
except SubmissionDuplicatesError as exp:
|
||||
await msg.reply_text(
|
||||
app._("sub_dup", "message", locale=user_locale), quote=True
|
||||
app._("sub_dup", "message", locale=user.locale), quote=True
|
||||
)
|
||||
return
|
||||
except Exception as exp:
|
||||
await app.send_message(
|
||||
app.owner,
|
||||
app._("sub_error_admin", "message").format(
|
||||
msg.from_user.id, format_exc()
|
||||
),
|
||||
app._(
|
||||
"sub_error_admin", "message", locale=user_owner.locale
|
||||
).format(msg.from_user.id, format_exc()),
|
||||
)
|
||||
await msg.reply_text("sub_error", quote=True)
|
||||
return
|
||||
@@ -288,17 +289,17 @@ async def get_submission(app: PyroClient, msg: Message):
|
||||
buttons += [
|
||||
[
|
||||
InlineKeyboardButton(
|
||||
text=app._("sub_block", "button"),
|
||||
text=app._("sub_block", "button", locale=user_owner.locale),
|
||||
callback_data=f"sub_block_{msg.from_user.id}",
|
||||
)
|
||||
]
|
||||
]
|
||||
|
||||
PosterUser(msg.from_user.id).limit()
|
||||
await user.update_cooldown()
|
||||
|
||||
if msg.from_user.id != app.owner:
|
||||
await msg.reply_text(
|
||||
app._("sub_sent", "message", locale=user_locale),
|
||||
app._("sub_sent", "message", locale=user.locale),
|
||||
disable_notification=True,
|
||||
quote=True,
|
||||
)
|
||||
|
Reference in New Issue
Block a user