Added language_code context
This commit is contained in:
@@ -22,14 +22,14 @@ async def cmd_application(app, msg):
|
||||
try:
|
||||
holo_user = HoloUser((await app.get_users(msg.command[1])).id)
|
||||
except (bad_request_400.UsernameInvalid, bad_request_400.PeerIdInvalid):
|
||||
await msg.reply_text(locale("no_user_application", "message").format(msg.command[1]), quote=should_quote(msg))
|
||||
await msg.reply_text(locale("no_user_application", "message", locale=msg.from_user).format(msg.command[1]), quote=should_quote(msg))
|
||||
return
|
||||
|
||||
application = col_applications.find_one({"user": holo_user.id})
|
||||
|
||||
if application is None:
|
||||
logWrite(f"User {msg.from_user.id} requested application of {holo_user.id} but user does not exists")
|
||||
await msg.reply_text(locale("user_invalid", "message"), quote=should_quote(msg))
|
||||
await msg.reply_text(locale("user_invalid", "message", locale=msg.from_user), quote=should_quote(msg))
|
||||
return
|
||||
|
||||
application_content = []
|
||||
@@ -39,21 +39,21 @@ async def cmd_application(app, msg):
|
||||
|
||||
if i == 2:
|
||||
age = relativedelta(datetime.now(), application['application']['2'])
|
||||
application_content.append(f"{locale(f'question{i}', 'message', 'question_titles')} {application['application']['2'].strftime('%d.%m.%Y')} ({age.years} р.)")
|
||||
application_content.append(f"{locale(f'question{i}', 'message', 'question_titles', locale=msg.from_user)} {application['application']['2'].strftime('%d.%m.%Y')} ({age.years} р.)")
|
||||
elif i == 3:
|
||||
if application['application']['3']['countryCode'] == "UA":
|
||||
application_content.append(f"{locale(f'question{i}', 'message', 'question_titles')} {application['application']['3']['name']}")
|
||||
application_content.append(f"{locale(f'question{i}', 'message', 'question_titles', locale=msg.from_user)} {application['application']['3']['name']}")
|
||||
else:
|
||||
application_content.append(f"{locale(f'question{i}', 'message', 'question_titles')} {application['application']['3']['name']} ({application['application']['3']['adminName1']}, {application['application']['3']['countryName']})")
|
||||
application_content.append(f"{locale(f'question{i}', 'message', 'question_titles', locale=msg.from_user)} {application['application']['3']['name']} ({application['application']['3']['adminName1']}, {application['application']['3']['countryName']})")
|
||||
else:
|
||||
application_content.append(f"{locale(f'question{i}', 'message', 'question_titles')} {application['application'][question]}")
|
||||
application_content.append(f"{locale(f'question{i}', 'message', 'question_titles', locale=msg.from_user)} {application['application'][question]}")
|
||||
|
||||
i += 1
|
||||
|
||||
application_status = locale("application_status_accepted", "message").format((await app.get_users(application["admin"])).first_name, application["date"].strftime("%d.%m.%Y, %H:%M"))
|
||||
application_status = locale("application_status_accepted", "message", locale=msg.from_user).format((await app.get_users(application["admin"])).first_name, application["date"].strftime("%d.%m.%Y, %H:%M"))
|
||||
|
||||
logWrite(f"User {msg.from_user.id} requested application of {holo_user.id}")
|
||||
await msg.reply_text(locale("contact", "message").format(holo_user.id, "\n".join(application_content), application_status), parse_mode=ParseMode.MARKDOWN, quote=should_quote(msg))
|
||||
await msg.reply_text(locale("contact", "message", locale=msg.from_user).format(holo_user.id, "\n".join(application_content), application_status), parse_mode=ParseMode.MARKDOWN, quote=should_quote(msg))
|
||||
|
||||
# if (path.exists(f"{configGet('data', 'locations')}{sep}users{sep}{msg.command[1]}.json") and jsonLoad(f"{configGet('data', 'locations')}{sep}users{sep}{msg.command[1]}.json")["approved"]):
|
||||
# user_id = int(msg.command[1])
|
||||
@@ -92,5 +92,5 @@ async def cmd_application(app, msg):
|
||||
# await msg.reply_text(locale("contact", "message").format(str(user_id), "\n".join(application_content), application_status), quote=should_quote(msg))
|
||||
|
||||
except IndexError:
|
||||
await msg.reply_text(locale("application_invalid_syntax", "message"), quote=should_quote(msg))
|
||||
await msg.reply_text(locale("application_invalid_syntax", "message", locale=msg.from_user), quote=should_quote(msg))
|
||||
# ==============================================================================================================================
|
@@ -24,9 +24,9 @@ async def cmd_message(app, msg):
|
||||
await destination.message(context=msg, text=None, caption=None, photo=msg.photo, video=msg.video, file=msg.document, adm_context=True)
|
||||
|
||||
except IndexError:
|
||||
await msg.reply_text(locale("message_invalid_syntax", "message"), quote=should_quote(msg))
|
||||
await msg.reply_text(locale("message_invalid_syntax", "message", locale=msg.from_user), quote=should_quote(msg))
|
||||
logWrite(f"Admin {msg.from_user.id} tried to send message but 'IndexError'")
|
||||
except ValueError:
|
||||
await msg.reply_text(locale("message_invalid_syntax", "message"), quote=should_quote(msg))
|
||||
await msg.reply_text(locale("message_invalid_syntax", "message", locale=msg.from_user), quote=should_quote(msg))
|
||||
logWrite(f"Admin {msg.from_user.id} tried to send message but 'ValueError'")
|
||||
# ==============================================================================================================================
|
@@ -22,27 +22,27 @@ async def cmd_reapply(app, msg):
|
||||
holo_user.application_restart()
|
||||
await welcome_pass(app, msg, once_again=True)
|
||||
else:
|
||||
await msg.reply_text(locale("reapply_left_chat", "message"), reply_markup=InlineKeyboardMarkup([
|
||||
await msg.reply_text(locale("reapply_left_chat", "message", locale=holo_user), reply_markup=InlineKeyboardMarkup([
|
||||
[
|
||||
InlineKeyboardButton(locale("reapply_old_one", "button"), f"reapply_old_{msg.id}")
|
||||
InlineKeyboardButton(locale("reapply_old_one", "button", locale=holo_user), f"reapply_old_{msg.id}")
|
||||
],
|
||||
[
|
||||
InlineKeyboardButton(locale("reapply_new_one", "button"), f"reapply_new_{msg.id}")
|
||||
InlineKeyboardButton(locale("reapply_new_one", "button", locale=holo_user), f"reapply_new_{msg.id}")
|
||||
]
|
||||
]))
|
||||
else:
|
||||
await msg.reply_text(locale("reapply_in_progress", "message").format(locale("confirm", "keyboard")[1][0]), reply_markup=InlineKeyboardMarkup([
|
||||
await msg.reply_text(locale("reapply_in_progress", "message", locale=holo_user).format(locale("confirm", "keyboard", locale=holo_user)[1][0]), reply_markup=InlineKeyboardMarkup([
|
||||
[
|
||||
InlineKeyboardButton(locale("applying_stop", "button"), f"reapply_stop_{msg.id}")
|
||||
InlineKeyboardButton(locale("applying_stop", "button", locale=holo_user), f"reapply_stop_{msg.id}")
|
||||
]
|
||||
]))
|
||||
else:
|
||||
if (holo_user.application_state()[0] == "fill") and (col_tmp.find_one({"user": holo_user.id, "type": "application"})["sent"] is True):
|
||||
await msg.reply_text(locale("reapply_forbidden", "message"))
|
||||
await msg.reply_text(locale("reapply_forbidden", "message", locale=holo_user))
|
||||
else:
|
||||
await msg.reply_text(locale("reapply_in_progress", "message").format(locale("confirm", "keyboard")[1][0]), reply_markup=InlineKeyboardMarkup([
|
||||
await msg.reply_text(locale("reapply_in_progress", "message", locale=holo_user).format(locale("confirm", "keyboard", locale=holo_user)[1][0]), reply_markup=InlineKeyboardMarkup([
|
||||
[
|
||||
InlineKeyboardButton(locale("applying_stop", "button"), f"reapply_stop_{msg.id}")
|
||||
InlineKeyboardButton(locale("applying_stop", "button", locale=holo_user), f"reapply_stop_{msg.id}")
|
||||
]
|
||||
]))
|
||||
# ==============================================================================================================================
|
@@ -2,7 +2,7 @@ from app import app, isAnAdmin
|
||||
from os import getpid
|
||||
from sys import exit
|
||||
from pyrogram import filters
|
||||
from modules.utils import logWrite, should_quote
|
||||
from modules.utils import locale, logWrite, should_quote
|
||||
from modules.scheduled import scheduler
|
||||
|
||||
pid = getpid()
|
||||
@@ -13,7 +13,7 @@ async def cmd_kill(app, msg):
|
||||
|
||||
if await isAnAdmin(msg.from_user.id) is True:
|
||||
logWrite(f"Shutting down bot with pid {pid}")
|
||||
await msg.reply_text(f"Вимкнення бота з підом `{pid}`", quote=should_quote(msg))
|
||||
await msg.reply_text(locale("shutdown", "message", locale=msg.from_user).format(pid), quote=should_quote(msg))
|
||||
scheduler.shutdown()
|
||||
exit()
|
||||
# ==============================================================================================================================
|
@@ -1,34 +1,40 @@
|
||||
from typing import Union
|
||||
from app import app
|
||||
from pyrogram import filters
|
||||
from pyrogram.types import InlineKeyboardMarkup, InlineKeyboardButton
|
||||
from pyrogram.types import InlineKeyboardMarkup, InlineKeyboardButton, User
|
||||
from modules.utils import locale
|
||||
from classes.holo_user import HoloUser
|
||||
|
||||
class DefaultRulesMarkup(list):
|
||||
def __init__(self, language_code: Union[str, HoloUser, User, None]):
|
||||
super().__init__([])
|
||||
self.keyboard = InlineKeyboardMarkup(
|
||||
[
|
||||
[
|
||||
InlineKeyboardButton(locale("rules_home", "button", locale=language_code), callback_data="rules_home"),
|
||||
InlineKeyboardButton(locale("rules_additional", "button", locale=language_code), callback_data="rules_additional")
|
||||
],
|
||||
[
|
||||
InlineKeyboardButton("1", callback_data="rule_1"),
|
||||
InlineKeyboardButton("2", callback_data="rule_2"),
|
||||
InlineKeyboardButton("3", callback_data="rule_3")
|
||||
],
|
||||
[
|
||||
InlineKeyboardButton("4", callback_data="rule_4"),
|
||||
InlineKeyboardButton("5", callback_data="rule_5"),
|
||||
InlineKeyboardButton("6", callback_data="rule_6")
|
||||
],
|
||||
[
|
||||
InlineKeyboardButton("7", callback_data="rule_7"),
|
||||
InlineKeyboardButton("8", callback_data="rule_8"),
|
||||
InlineKeyboardButton("9", callback_data="rule_9")
|
||||
]
|
||||
]
|
||||
)
|
||||
|
||||
|
||||
# Rules command =============================================================================================================
|
||||
default_rules_markup = InlineKeyboardMarkup(
|
||||
[
|
||||
[
|
||||
InlineKeyboardButton(locale("rules_home", "button"), callback_data="rules_home"),
|
||||
InlineKeyboardButton(locale("rules_additional", "button"), callback_data="rules_additional")
|
||||
],
|
||||
[
|
||||
InlineKeyboardButton("1", callback_data="rule_1"),
|
||||
InlineKeyboardButton("2", callback_data="rule_2"),
|
||||
InlineKeyboardButton("3", callback_data="rule_3")
|
||||
],
|
||||
[
|
||||
InlineKeyboardButton("4", callback_data="rule_4"),
|
||||
InlineKeyboardButton("5", callback_data="rule_5"),
|
||||
InlineKeyboardButton("6", callback_data="rule_6")
|
||||
],
|
||||
[
|
||||
InlineKeyboardButton("7", callback_data="rule_7"),
|
||||
InlineKeyboardButton("8", callback_data="rule_8"),
|
||||
InlineKeyboardButton("9", callback_data="rule_9")
|
||||
]
|
||||
]
|
||||
)
|
||||
|
||||
@app.on_message(~ filters.scheduled & filters.private & filters.command(["rules"], prefixes=["/"]))
|
||||
async def cmd_rules(app, msg):
|
||||
await msg.reply_text(locale("rules_msg"), disable_web_page_preview=True, reply_markup=default_rules_markup)
|
||||
await msg.reply_text(locale("rules_msg", locale=msg.from_user), disable_web_page_preview=True, reply_markup=DefaultRulesMarkup(msg.from_user).keyboard)
|
||||
# ==============================================================================================================================
|
@@ -23,5 +23,5 @@ async def cmd_start(app, msg):
|
||||
})
|
||||
|
||||
logWrite(f"User {msg.from_user.id} started bot interaction")
|
||||
await msg.reply_text(locale("start", "message"), reply_markup=ReplyKeyboardMarkup(locale("welcome", "keyboard"), resize_keyboard=True))
|
||||
await msg.reply_text(locale("start", "message", locale=msg.from_user), reply_markup=ReplyKeyboardMarkup(locale("welcome", "keyboard", locale=msg.from_user), resize_keyboard=True))
|
||||
# ==============================================================================================================================
|
@@ -11,7 +11,8 @@ async def cmd_warnings(app, msg):
|
||||
if await isAnAdmin(msg.from_user.id) is True:
|
||||
|
||||
if len(msg.command) <= 1:
|
||||
await msg.reply_text(locale("syntax_warnings", "message"), quote=should_quote(msg))
|
||||
await msg.reply_text(locale("syntax_warnings", "message", locale=msg.from_user), quote=should_quote(msg))
|
||||
return
|
||||
|
||||
try:
|
||||
user_db = col_users.find_one({"user": int(msg.command[1])})
|
||||
@@ -27,16 +28,16 @@ async def cmd_warnings(app, msg):
|
||||
target_name = target.first_name
|
||||
target_id = str(target.id)
|
||||
else:
|
||||
await msg.reply_text(locale("no_user_warnings", "message").format(msg.command[1]))
|
||||
await msg.reply_text(locale("no_user_warnings", "message", locale=msg.from_user).format(msg.command[1]))
|
||||
return
|
||||
|
||||
warns = len(list(col_warnings.find({"user": target_id})))
|
||||
|
||||
if warns == 0:
|
||||
await msg.reply_text(locale("no_warnings", "message").format(target_name, target_id), quote=should_quote(msg))
|
||||
await msg.reply_text(locale("no_warnings", "message", locale=msg.from_user).format(target_name, target_id), quote=should_quote(msg))
|
||||
else:
|
||||
if warns <= 5:
|
||||
await msg.reply_text(locale("warnings_1", "message").format(target_name, target_id, warns), quote=should_quote(msg))
|
||||
await msg.reply_text(locale("warnings_1", "message", locale=msg.from_user).format(target_name, target_id, warns), quote=should_quote(msg))
|
||||
else:
|
||||
await msg.reply_text(locale("warnings_2", "message").format(target_name, target_id, warns), quote=should_quote(msg))
|
||||
await msg.reply_text(locale("warnings_2", "message", locale=msg.from_user).format(target_name, target_id, warns), quote=should_quote(msg))
|
||||
# ==============================================================================================================================
|
Reference in New Issue
Block a user