From f87e1a306bb2c824440297799df9d60f1a90e7e6 Mon Sep 17 00:00:00 2001 From: Alisson Lauffer <alissonvitortc@gmail.com> Date: Sat, 15 Jun 2024 16:39:36 -0300 Subject: [PATCH] chore: type annotate translation func --- eduu/plugins/admins/bans.py | 10 +++++----- eduu/plugins/admins/misc.py | 6 +++--- eduu/plugins/admins/mutes.py | 8 ++++---- eduu/plugins/admins/pins.py | 4 ++-- eduu/plugins/cats.py | 4 ++-- eduu/plugins/cmds_list.py | 10 +++++----- eduu/plugins/coub.py | 4 ++-- eduu/plugins/custom_filters.py | 8 ++++---- eduu/plugins/dice.py | 4 ++-- eduu/plugins/dogs.py | 4 ++-- eduu/plugins/gif.py | 4 ++-- eduu/plugins/git.py | 4 ++-- eduu/plugins/ids.py | 6 +++--- eduu/plugins/info.py | 4 ++-- eduu/plugins/inline_search.py | 4 ++-- eduu/plugins/inlines.py | 8 ++++---- eduu/plugins/ip.py | 10 +++++----- eduu/plugins/langs.py | 6 +++--- eduu/plugins/misc.py | 18 +++++++++--------- eduu/plugins/notes.py | 8 ++++---- eduu/plugins/pastes.py | 4 ++-- eduu/plugins/prints.py | 4 ++-- eduu/plugins/pypi.py | 4 ++-- eduu/plugins/reddit.py | 4 ++-- eduu/plugins/rules.py | 10 +++++----- eduu/plugins/sed.py | 4 ++-- eduu/plugins/start.py | 8 ++++---- eduu/plugins/stickers.py | 8 ++++---- eduu/plugins/sudos.py | 10 +++++----- eduu/plugins/telegraph.py | 4 ++-- eduu/plugins/tiorunexec.py | 6 +++--- eduu/plugins/translate.py | 6 +++--- eduu/plugins/warns.py | 12 ++++++------ eduu/plugins/weather.py | 4 ++-- eduu/plugins/welcome.py | 18 +++++++++--------- eduu/plugins/youtube.py | 6 +++--- eduu/utils/localization.py | 8 ++++---- 37 files changed, 127 insertions(+), 127 deletions(-) diff --git a/eduu/plugins/admins/bans.py b/eduu/plugins/admins/bans.py index 5e976fe60d..4c64dfc510 100644 --- a/eduu/plugins/admins/bans.py +++ b/eduu/plugins/admins/bans.py @@ -8,13 +8,13 @@ from eduu.utils import commands, extract_time, get_reason_text, get_target_user from eduu.utils.consts import ADMIN_STATUSES from eduu.utils.decorators import require_admin -from eduu.utils.localization import use_chat_lang +from eduu.utils.localization import Strings, use_chat_lang @Client.on_message(filters.command("ban", PREFIXES)) @use_chat_lang @require_admin(ChatPrivileges(can_restrict_members=True)) -async def ban(c: Client, m: Message, s): +async def ban(c: Client, m: Message, s: Strings): target_user = await get_target_user(c, m) reason = get_reason_text(c, m) check_admin = await m.chat.get_member(target_user.id) @@ -36,7 +36,7 @@ async def ban(c: Client, m: Message, s): @Client.on_message(filters.command("kick", PREFIXES)) @use_chat_lang @require_admin(ChatPrivileges(can_restrict_members=True)) -async def kick(c: Client, m: Message, s): +async def kick(c: Client, m: Message, s: Strings): target_user = await get_target_user(c, m) reason = get_reason_text(c, m) check_admin = await m.chat.get_member(target_user.id) @@ -59,7 +59,7 @@ async def kick(c: Client, m: Message, s): @Client.on_message(filters.command("unban", PREFIXES)) @use_chat_lang @require_admin(ChatPrivileges(can_restrict_members=True)) -async def unban(c: Client, m: Message, s): +async def unban(c: Client, m: Message, s: Strings): target_user = await get_target_user(c, m) reason = get_reason_text(c, m) await m.chat.unban_member(target_user.id) @@ -76,7 +76,7 @@ async def unban(c: Client, m: Message, s): @Client.on_message(filters.command("tban", PREFIXES)) @use_chat_lang @require_admin(ChatPrivileges(can_restrict_members=True)) -async def tban(c: Client, m: Message, s): +async def tban(c: Client, m: Message, s: Strings): if len(m.command) == 1: await m.reply_text(s("admins_error_must_specify_time").format(command=m.command[0])) return diff --git a/eduu/plugins/admins/misc.py b/eduu/plugins/admins/misc.py index 289bc33950..d392d9cadc 100644 --- a/eduu/plugins/admins/misc.py +++ b/eduu/plugins/admins/misc.py @@ -10,13 +10,13 @@ from eduu.database.admins import check_if_del_service, toggle_del_service from eduu.utils import commands from eduu.utils.decorators import require_admin -from eduu.utils.localization import use_chat_lang +from eduu.utils.localization import Strings, use_chat_lang @Client.on_message(filters.command("purge", PREFIXES)) @require_admin(ChatPrivileges(can_delete_messages=True), allow_in_private=True) @use_chat_lang -async def purge(c: Client, m: Message, s): +async def purge(c: Client, m: Message, s: Strings): """Purge upto the replied message.""" status_message = await m.reply_text(s("purge_in_progress"), quote=True) await m.delete() @@ -40,7 +40,7 @@ async def purge(c: Client, m: Message, s): @Client.on_message(filters.command("cleanservice", PREFIXES)) @require_admin(ChatPrivileges(can_delete_messages=True)) @use_chat_lang -async def delservice(c: Client, m: Message, s): +async def delservice(c: Client, m: Message, s: Strings): if len(m.text.split()) > 1: if m.command[1] == "on": await toggle_del_service(m.chat.id, True) diff --git a/eduu/plugins/admins/mutes.py b/eduu/plugins/admins/mutes.py index b603390657..be234e6c8d 100644 --- a/eduu/plugins/admins/mutes.py +++ b/eduu/plugins/admins/mutes.py @@ -8,13 +8,13 @@ from eduu.utils import commands, extract_time, get_reason_text, get_target_user from eduu.utils.consts import ADMIN_STATUSES from eduu.utils.decorators import require_admin -from eduu.utils.localization import use_chat_lang +from eduu.utils.localization import Strings, use_chat_lang @Client.on_message(filters.command("mute", PREFIXES)) @use_chat_lang @require_admin(ChatPrivileges(can_restrict_members=True)) -async def mute(c: Client, m: Message, s): +async def mute(c: Client, m: Message, s: Strings): target_user = await get_target_user(c, m) reason = get_reason_text(c, m) check_admin = await m.chat.get_member(target_user.id) @@ -36,7 +36,7 @@ async def mute(c: Client, m: Message, s): @Client.on_message(filters.command("unmute", PREFIXES)) @use_chat_lang @require_admin(ChatPrivileges(can_restrict_members=True)) -async def unmute(c: Client, m: Message, s): +async def unmute(c: Client, m: Message, s: Strings): target_user = await get_target_user(c, m) reason = get_reason_text(c, m) await m.chat.unban_member(target_user.id) @@ -53,7 +53,7 @@ async def unmute(c: Client, m: Message, s): @Client.on_message(filters.command("tmute", PREFIXES)) @use_chat_lang @require_admin(ChatPrivileges(can_restrict_members=True)) -async def tmute(c: Client, m: Message, s): +async def tmute(c: Client, m: Message, s: Strings): if len(m.command) == 1: await m.reply_text(s("admins_error_must_specify_time").format(command=m.command[0])) return diff --git a/eduu/plugins/admins/pins.py b/eduu/plugins/admins/pins.py index c57078fd01..f94be94474 100644 --- a/eduu/plugins/admins/pins.py +++ b/eduu/plugins/admins/pins.py @@ -8,13 +8,13 @@ from eduu.database.admins import check_if_antichannelpin, toggle_antichannelpin from eduu.utils import commands from eduu.utils.decorators import require_admin -from eduu.utils.localization import use_chat_lang +from eduu.utils.localization import Strings, use_chat_lang @Client.on_message(filters.command("antichannelpin", PREFIXES)) @require_admin(ChatPrivileges(can_pin_messages=True)) @use_chat_lang -async def setantichannelpin(c: Client, m: Message, s): +async def setantichannelpin(c: Client, m: Message, s: Strings): if len(m.text.split()) == 1: check_acp = await check_if_antichannelpin(m.chat.id) if not check_acp: diff --git a/eduu/plugins/cats.py b/eduu/plugins/cats.py index 61b18b8511..abe4805cd7 100644 --- a/eduu/plugins/cats.py +++ b/eduu/plugins/cats.py @@ -6,12 +6,12 @@ from config import PREFIXES from eduu.utils import commands, http -from eduu.utils.localization import use_chat_lang +from eduu.utils.localization import Strings, use_chat_lang @Client.on_message(filters.command("cat", PREFIXES)) @use_chat_lang -async def cat(c: Client, m: Message, s): +async def cat(c: Client, m: Message, s: Strings): r = await http.get("https://api.thecatapi.com/v1/images/search") rj = r.json() diff --git a/eduu/plugins/cmds_list.py b/eduu/plugins/cmds_list.py index 5fffe863fe..06804690e7 100644 --- a/eduu/plugins/cmds_list.py +++ b/eduu/plugins/cmds_list.py @@ -13,7 +13,7 @@ from eduu.utils import commands from eduu.utils.decorators import stop_here -from eduu.utils.localization import use_chat_lang +from eduu.utils.localization import Strings, use_chat_lang def gen_categories_kb(strings_manager): @@ -32,7 +32,7 @@ def gen_categories_kb(strings_manager): @Client.on_callback_query(filters.regex("^commands$")) @use_chat_lang -async def cmds_list(c: Client, m: CallbackQuery, s): +async def cmds_list(c: Client, m: CallbackQuery, s: Strings): keyboard = InlineKeyboardMarkup( inline_keyboard=[ *gen_categories_kb(s), @@ -45,7 +45,7 @@ async def cmds_list(c: Client, m: CallbackQuery, s): @Client.on_message(filters.command(["help", "start help"]) & filters.private) @use_chat_lang @stop_here -async def show_private_help(c: Client, m: Message, s): +async def show_private_help(c: Client, m: Message, s: Strings): keyboard = InlineKeyboardMarkup( inline_keyboard=[ *gen_categories_kb(s), @@ -63,7 +63,7 @@ async def show_private_help(c: Client, m: Message, s): @Client.on_message(filters.command(["help", "start help"])) @use_chat_lang @stop_here -async def show_help(c: Client, m: Message, s): +async def show_help(c: Client, m: Message, s: Strings): keyboard = InlineKeyboardMarkup( inline_keyboard=[ [ @@ -79,7 +79,7 @@ async def show_help(c: Client, m: Message, s): @Client.on_callback_query(filters.regex("^view_category .+")) @use_chat_lang -async def get_category(c: Client, m: CallbackQuery, s): +async def get_category(c: Client, m: CallbackQuery, s: Strings): msg = commands.get_commands_message(s, m.data.split(maxsplit=1)[1]) keyboard = InlineKeyboardMarkup( inline_keyboard=[[InlineKeyboardButton(s("general_back_btn"), callback_data="commands")]] diff --git a/eduu/plugins/coub.py b/eduu/plugins/coub.py index 434195e35f..e225f2fdcd 100644 --- a/eduu/plugins/coub.py +++ b/eduu/plugins/coub.py @@ -8,12 +8,12 @@ from config import PREFIXES from eduu.utils import commands, http -from eduu.utils.localization import use_chat_lang +from eduu.utils.localization import Strings, use_chat_lang @Client.on_message(filters.command("coub", PREFIXES)) @use_chat_lang -async def coub(c: Client, m: Message, s): +async def coub(c: Client, m: Message, s: Strings): if len(m.command) == 1: await m.reply_text(s("coub_usage")) return diff --git a/eduu/plugins/custom_filters.py b/eduu/plugins/custom_filters.py index 44aec78ca1..c8f152b775 100644 --- a/eduu/plugins/custom_filters.py +++ b/eduu/plugins/custom_filters.py @@ -16,7 +16,7 @@ ) from eduu.utils import button_parser, commands, split_quotes from eduu.utils.decorators import require_admin -from eduu.utils.localization import use_chat_lang +from eduu.utils.localization import Strings, use_chat_lang async def check_for_filters(chat_id, trigger): @@ -31,7 +31,7 @@ async def check_for_filters(chat_id, trigger): @Client.on_message(filters.command(["filter", "savefilter"], PREFIXES)) @require_admin(allow_in_private=True) @use_chat_lang -async def save_filter(c: Client, m: Message, s): +async def save_filter(c: Client, m: Message, s: Strings): args = m.text.markdown.split(maxsplit=1) split_text = split_quotes(args[1]) trigger = split_text[0].lower() @@ -93,7 +93,7 @@ async def save_filter(c: Client, m: Message, s): @Client.on_message(filters.command(["delfilter", "rmfilter", "stop"], PREFIXES)) @require_admin(allow_in_private=True) @use_chat_lang -async def delete_filter(c: Client, m: Message, s): +async def delete_filter(c: Client, m: Message, s: Strings): args = m.text.markdown.split(maxsplit=1) trigger = args[1].lower() chat_id = m.chat.id @@ -109,7 +109,7 @@ async def delete_filter(c: Client, m: Message, s): @Client.on_message(filters.command("filters", PREFIXES)) @use_chat_lang -async def get_all_filter(c: Client, m: Message, s): +async def get_all_filter(c: Client, m: Message, s: Strings): chat_id = m.chat.id reply_text = s("filters_list") all_filters = await get_all_filters(chat_id) diff --git a/eduu/plugins/dice.py b/eduu/plugins/dice.py index 356bf22da4..dd5cdd0daf 100644 --- a/eduu/plugins/dice.py +++ b/eduu/plugins/dice.py @@ -6,12 +6,12 @@ from config import PREFIXES from eduu.utils import commands -from eduu.utils.localization import use_chat_lang +from eduu.utils.localization import Strings, use_chat_lang @Client.on_message(filters.command(["dice", "dados"], PREFIXES)) @use_chat_lang -async def dice(c: Client, m: Message, s): +async def dice(c: Client, m: Message, s: Strings): dicen = await c.send_dice(m.chat.id, reply_to_message_id=m.id) await dicen.reply_text(s("dice_result").format(number=dicen.dice.value), quote=True) diff --git a/eduu/plugins/dogs.py b/eduu/plugins/dogs.py index 5c2d533407..c34f6607a2 100644 --- a/eduu/plugins/dogs.py +++ b/eduu/plugins/dogs.py @@ -6,12 +6,12 @@ from config import PREFIXES from eduu.utils import commands, http -from eduu.utils.localization import use_chat_lang +from eduu.utils.localization import Strings, use_chat_lang @Client.on_message(filters.command("dog", PREFIXES)) @use_chat_lang -async def dog(c: Client, m: Message, s): +async def dog(c: Client, m: Message, s: Strings): r = await http.get("https://random.dog/woof.json") rj = r.json() diff --git a/eduu/plugins/gif.py b/eduu/plugins/gif.py index 767ccc8882..6da9d6250e 100644 --- a/eduu/plugins/gif.py +++ b/eduu/plugins/gif.py @@ -8,7 +8,7 @@ from config import PREFIXES, TENOR_API_KEY from eduu.utils import commands, http -from eduu.utils.localization import use_chat_lang +from eduu.utils.localization import Strings, use_chat_lang logger = logging.getLogger(__name__) @@ -20,7 +20,7 @@ @Client.on_message(filters.command("gif", PREFIXES)) @use_chat_lang -async def gif(c: Client, m: Message, s): +async def gif(c: Client, m: Message, s: Strings): if len(m.command) == 1: await m.reply_text(s("gif_usage")) return diff --git a/eduu/plugins/git.py b/eduu/plugins/git.py index 29acd6c391..ca4945cb2c 100644 --- a/eduu/plugins/git.py +++ b/eduu/plugins/git.py @@ -8,12 +8,12 @@ from config import PREFIXES from eduu.utils import commands, http -from eduu.utils.localization import use_chat_lang +from eduu.utils.localization import Strings, use_chat_lang @Client.on_message(filters.command("git", PREFIXES)) @use_chat_lang -async def git(c: Client, m: Message, s): +async def git(c: Client, m: Message, s: Strings): if len(m.command) == 1: await m.reply_text(s("git_no_username"), reply_to_message_id=m.id) return diff --git a/eduu/plugins/ids.py b/eduu/plugins/ids.py index 9c55d2449f..ea37846398 100644 --- a/eduu/plugins/ids.py +++ b/eduu/plugins/ids.py @@ -9,12 +9,12 @@ from config import PREFIXES from eduu.utils import commands -from eduu.utils.localization import use_chat_lang +from eduu.utils.localization import Strings, use_chat_lang @Client.on_message(filters.command("id", PREFIXES) & filters.private) @use_chat_lang -async def ids_private(c: Client, m: Message, s): +async def ids_private(c: Client, m: Message, s: Strings): if len(m.command) == 2: try: user_data = await c.get_users( @@ -41,7 +41,7 @@ async def ids_private(c: Client, m: Message, s): @Client.on_message(filters.command("id", PREFIXES) & filters.group) @use_chat_lang -async def ids(c: Client, m: Message, s): +async def ids(c: Client, m: Message, s: Strings): if len(m.command) == 2: try: user_data = await c.get_users( diff --git a/eduu/plugins/info.py b/eduu/plugins/info.py index c78857b6b5..7ff91144ab 100644 --- a/eduu/plugins/info.py +++ b/eduu/plugins/info.py @@ -11,12 +11,12 @@ from config import PREFIXES from eduu.utils import commands -from eduu.utils.localization import use_chat_lang +from eduu.utils.localization import Strings, use_chat_lang @Client.on_message(filters.command("info", PREFIXES)) @use_chat_lang -async def user_info(c: Client, m: Message, s): +async def user_info(c: Client, m: Message, s: Strings): if len(m.command) == 2: try: user = await c.get_users( diff --git a/eduu/plugins/inline_search.py b/eduu/plugins/inline_search.py index 5c7af61af3..54c7c289a4 100644 --- a/eduu/plugins/inline_search.py +++ b/eduu/plugins/inline_search.py @@ -11,12 +11,12 @@ ) from eduu.utils import inline_commands -from eduu.utils.localization import use_chat_lang +from eduu.utils.localization import Strings, use_chat_lang @Client.on_inline_query(group=2) @use_chat_lang -async def inline_search(c: Client, q: InlineQuery, s): +async def inline_search(c: Client, q: InlineQuery, s: Strings): command = q.query.split(maxsplit=1)[0] if q.query else q.query results = inline_commands.search_commands(command) diff --git a/eduu/plugins/inlines.py b/eduu/plugins/inlines.py index 06aeff6059..451398f57a 100644 --- a/eduu/plugins/inlines.py +++ b/eduu/plugins/inlines.py @@ -15,7 +15,7 @@ ) from eduu.utils import button_parser, inline_commands -from eduu.utils.localization import use_chat_lang +from eduu.utils.localization import Strings, use_chat_lang faces_list: Iterable[str] = ( "¯\\_(ツ)_/¯", @@ -69,7 +69,7 @@ async def faces_inline(c: Client, q: InlineQuery): @Client.on_inline_query(filters.regex(r"^markdown .+", re.IGNORECASE)) @use_chat_lang -async def markdown_inline(c: Client, q: InlineQuery, s): +async def markdown_inline(c: Client, q: InlineQuery, s: Strings): queryinputres = q.query.split(None, 1)[1] querytxt, querybuttons = button_parser(queryinputres) await q.answer([ @@ -83,7 +83,7 @@ async def markdown_inline(c: Client, q: InlineQuery, s): @Client.on_inline_query(filters.regex(r"^html .+", re.IGNORECASE)) @use_chat_lang -async def html_inline(c: Client, q: InlineQuery, s): +async def html_inline(c: Client, q: InlineQuery, s: Strings): queryinputres = q.query.split(None, 1)[1] querytxt, querybuttons = button_parser(queryinputres) await q.answer([ @@ -99,7 +99,7 @@ async def html_inline(c: Client, q: InlineQuery, s): @Client.on_inline_query(filters.regex(r"^info .+", re.IGNORECASE)) @use_chat_lang -async def info_inline(c: Client, q: InlineQuery, s): +async def info_inline(c: Client, q: InlineQuery, s: Strings): try: if q.query == "info": user = q.from_user diff --git a/eduu/plugins/ip.py b/eduu/plugins/ip.py index 9f005a4565..58ac332c67 100644 --- a/eduu/plugins/ip.py +++ b/eduu/plugins/ip.py @@ -18,7 +18,7 @@ from config import PREFIXES from eduu.utils import commands, http, inline_commands -from eduu.utils.localization import use_chat_lang +from eduu.utils.localization import Strings, use_chat_lang async def get_api_return(ip: str) -> dict[str, str]: @@ -29,7 +29,7 @@ async def get_api_return(ip: str) -> dict[str, str]: return req -def format_api_return(req: dict[str, str], s) -> str: +def format_api_return(req: dict[str, str], s: Strings) -> str: if req.get("bogon"): return s("ip_err_bogon_ip").format(ip=req["ip"]) @@ -84,7 +84,7 @@ async def get_ips_from_string(hostname: str) -> list[str]: @Client.on_message(filters.command("ip", PREFIXES)) @use_chat_lang -async def ip_cmd(c: Client, m: Message, s): +async def ip_cmd(c: Client, m: Message, s: Strings): if len(m.text.split()) == 1: await m.reply_text(s("ip_err_no_ip")) return @@ -117,7 +117,7 @@ async def ip_cmd(c: Client, m: Message, s): @Client.on_callback_query(filters.regex(r"^ip .+")) @use_chat_lang -async def ip_callback(c: Client, cb: CallbackQuery, s): +async def ip_callback(c: Client, cb: CallbackQuery, s: Strings): ip = cb.data.split(maxsplit=1)[1] await cb.edit_message_text(format_api_return(await get_api_return(ip), s)) @@ -125,7 +125,7 @@ async def ip_callback(c: Client, cb: CallbackQuery, s): @Client.on_inline_query(filters.regex(r"^ip .+", re.IGNORECASE)) @use_chat_lang -async def ip_inline(c: Client, q: InlineQuery, s): +async def ip_inline(c: Client, q: InlineQuery, s: Strings): if len(q.query.split()) == 1: await q.answer([ InlineQueryResultArticle( diff --git a/eduu/plugins/langs.py b/eduu/plugins/langs.py index 9bb2144214..e7a3a15692 100644 --- a/eduu/plugins/langs.py +++ b/eduu/plugins/langs.py @@ -17,7 +17,7 @@ from config import PREFIXES from eduu.database.localization import set_db_lang from eduu.utils.decorators import require_admin -from eduu.utils.localization import langdict, use_chat_lang +from eduu.utils.localization import Strings, langdict, use_chat_lang def gen_langs_kb(): @@ -38,7 +38,7 @@ def gen_langs_kb(): @Client.on_message(filters.command(["setchatlang", "setlang"], PREFIXES) & filters.group) @require_admin(allow_in_private=True) @use_chat_lang -async def chlang(c: Client, m: CallbackQuery | Message, s): +async def chlang(c: Client, m: CallbackQuery | Message, s: Strings): keyboard = InlineKeyboardMarkup( inline_keyboard=[ *gen_langs_kb(), @@ -72,7 +72,7 @@ async def set_chat_lang(c: Client, m: CallbackQuery): @use_chat_lang -async def set_chat_lang_edit(c: Client, m: CallbackQuery, s): +async def set_chat_lang_edit(c: Client, m: CallbackQuery, s: Strings): if m.message.chat.type == ChatType.PRIVATE: keyboard = InlineKeyboardMarkup( inline_keyboard=[ diff --git a/eduu/plugins/misc.py b/eduu/plugins/misc.py index ae7f8249b1..1b1a5b21ac 100644 --- a/eduu/plugins/misc.py +++ b/eduu/plugins/misc.py @@ -13,12 +13,12 @@ from config import LOG_CHAT, PREFIXES from eduu.utils import button_parser, commands, http from eduu.utils.consts import ADMIN_STATUSES -from eduu.utils.localization import use_chat_lang +from eduu.utils.localization import Strings, use_chat_lang @Client.on_message(filters.command("mark", PREFIXES)) @use_chat_lang -async def mark(c: Client, m: Message, s): +async def mark(c: Client, m: Message, s: Strings): if len(m.command) == 1: await m.reply_text(s("mark_usage")) return @@ -34,7 +34,7 @@ async def mark(c: Client, m: Message, s): @Client.on_message(filters.command("html", PREFIXES)) @use_chat_lang -async def html(c: Client, m: Message, s): +async def html(c: Client, m: Message, s: Strings): if len(m.command) == 1: await m.reply_text(s("html_usage")) return @@ -50,7 +50,7 @@ async def html(c: Client, m: Message, s): @Client.on_message(filters.command("admins", PREFIXES) & filters.group) @use_chat_lang -async def mentionadmins(c: Client, m: Message, s): +async def mentionadmins(c: Client, m: Message, s: Strings): mention = "" async for i in m.chat.get_members(m.chat.id, filter=ChatMembersFilter.ADMINISTRATORS): if not (i.user.is_deleted or i.privileges.is_anonymous): @@ -67,7 +67,7 @@ async def mentionadmins(c: Client, m: Message, s): & filters.reply ) @use_chat_lang -async def reportadmins(c: Client, m: Message, s): +async def reportadmins(c: Client, m: Message, s: Strings): if not m.reply_to_message.from_user: return @@ -89,7 +89,7 @@ async def reportadmins(c: Client, m: Message, s): @Client.on_message(filters.command("token")) @use_chat_lang -async def getbotinfo(c: Client, m: Message, s): +async def getbotinfo(c: Client, m: Message, s: Strings): if len(m.command) == 1: await m.reply_text(s("token_no_bot_token"), reply_to_message_id=m.id) return @@ -141,7 +141,7 @@ async def urldecodecmd(c: Client, m: Message): @Client.on_message(filters.command("bug", PREFIXES)) @use_chat_lang -async def bug_report_cmd(c: Client, m: Message, s): +async def bug_report_cmd(c: Client, m: Message, s: Strings): if len(m.text.split()) == 1: await m.reply_text(s("bug_report_empty")) return @@ -186,7 +186,7 @@ async def request_cmd(c: Client, m: Message): @Client.on_message(filters.command("parsebutton")) @use_chat_lang -async def button_parse_helper(c: Client, m: Message, s): +async def button_parse_helper(c: Client, m: Message, s: Strings): if len(m.text.split()) > 2: await m.reply_text( f"[{m.text.split(None, 2)[2]}](buttonurl:{m.command[1]})", @@ -198,7 +198,7 @@ async def button_parse_helper(c: Client, m: Message, s): @Client.on_message(filters.command("donate", PREFIXES)) @use_chat_lang -async def donatecmd(c: Client, m: Message, s): +async def donatecmd(c: Client, m: Message, s: Strings): await m.reply_text(s("donate_info")) diff --git a/eduu/plugins/notes.py b/eduu/plugins/notes.py index a7af768dc2..73ad5af8c1 100644 --- a/eduu/plugins/notes.py +++ b/eduu/plugins/notes.py @@ -11,7 +11,7 @@ from eduu.database.notes import add_note, get_all_notes, rm_note, update_note from eduu.utils import button_parser, commands, split_quotes from eduu.utils.decorators import require_admin -from eduu.utils.localization import use_chat_lang +from eduu.utils.localization import Strings, use_chat_lang async def check_for_notes(chat_id, trigger): @@ -26,7 +26,7 @@ async def check_for_notes(chat_id, trigger): @Client.on_message(filters.command(["note", "savenote", "nota", "salvarnota"], PREFIXES)) @require_admin(allow_in_private=True) @use_chat_lang -async def save_note(c: Client, m: Message, s): +async def save_note(c: Client, m: Message, s: Strings): args = m.text.html.split(maxsplit=1) split_text = split_quotes(args[1]) trigger = split_text[0].lower() @@ -86,7 +86,7 @@ async def save_note(c: Client, m: Message, s): @Client.on_message(filters.command(["delnote", "rmnote", "delnota", "rmnota"], PREFIXES)) @require_admin(allow_in_private=True) @use_chat_lang -async def delete_note(c: Client, m: Message, s): +async def delete_note(c: Client, m: Message, s: Strings): args = m.text.html.split(maxsplit=1) trigger = args[1].lower() chat_id = m.chat.id @@ -100,7 +100,7 @@ async def delete_note(c: Client, m: Message, s): @Client.on_message(filters.command(["notes", "notas"], PREFIXES)) @use_chat_lang -async def get_all_chat_note(c: Client, m: Message, s): +async def get_all_chat_note(c: Client, m: Message, s: Strings): chat_id = m.chat.id reply_text = s("notes_list") all_notes = await get_all_notes(chat_id) diff --git a/eduu/plugins/pastes.py b/eduu/plugins/pastes.py index 8ab9747f3c..514b3f43a6 100644 --- a/eduu/plugins/pastes.py +++ b/eduu/plugins/pastes.py @@ -8,7 +8,7 @@ from config import PREFIXES from eduu.utils import commands, http -from eduu.utils.localization import use_chat_lang +from eduu.utils.localization import Strings, use_chat_lang if TYPE_CHECKING: from io import BytesIO @@ -16,7 +16,7 @@ @Client.on_message(filters.command("paste", PREFIXES)) @use_chat_lang -async def paste(c: Client, m: Message, s): +async def paste(c: Client, m: Message, s: Strings): if not m.reply_to_message: await m.reply_text(s("pastes_reply_to_document_or_text")) return diff --git a/eduu/plugins/prints.py b/eduu/plugins/prints.py index b1bd6c59f6..d077a31ae2 100644 --- a/eduu/plugins/prints.py +++ b/eduu/plugins/prints.py @@ -11,12 +11,12 @@ from config import PREFIXES from eduu.utils import commands, http -from eduu.utils.localization import use_chat_lang +from eduu.utils.localization import Strings, use_chat_lang @Client.on_message(filters.command("print", PREFIXES)) @use_chat_lang -async def prints(c: Client, m: Message, s): +async def prints(c: Client, m: Message, s: Strings): # Get the target URl from the message using Telegram entities. # If there is no URL, try to get an URL from the replied message. # If there is no URL in the replied message, fail. diff --git a/eduu/plugins/pypi.py b/eduu/plugins/pypi.py index 122f76fee1..d55d9fa329 100644 --- a/eduu/plugins/pypi.py +++ b/eduu/plugins/pypi.py @@ -9,7 +9,7 @@ from config import PREFIXES from eduu.utils import commands, http -from eduu.utils.localization import use_chat_lang +from eduu.utils.localization import Strings, use_chat_lang def cleanhtml(raw_html): @@ -26,7 +26,7 @@ def escape_definition(definition): @Client.on_message(filters.command("pypi", PREFIXES)) @use_chat_lang -async def pypi(c: Client, m: Message, s): +async def pypi(c: Client, m: Message, s: Strings): if len(m.command) == 1: await m.reply_text(s("pypi_usage")) return diff --git a/eduu/plugins/reddit.py b/eduu/plugins/reddit.py index 7ec0635eb9..c8d59d58a2 100644 --- a/eduu/plugins/reddit.py +++ b/eduu/plugins/reddit.py @@ -8,7 +8,7 @@ from config import PREFIXES from eduu.utils import commands, http -from eduu.utils.localization import use_chat_lang +from eduu.utils.localization import Strings, use_chat_lang CHARACTER_LIMIT = 25 @@ -22,7 +22,7 @@ def limit_length(title: str): @Client.on_message(filters.command(["reddit", "r"], PREFIXES)) @use_chat_lang -async def reddit(c: Client, m: Message, s): +async def reddit(c: Client, m: Message, s: Strings): if len(m.command) == 1: await m.reply_text(s("reddit_usage")) return diff --git a/eduu/plugins/rules.py b/eduu/plugins/rules.py index 6054820741..01eab220cb 100644 --- a/eduu/plugins/rules.py +++ b/eduu/plugins/rules.py @@ -8,13 +8,13 @@ from eduu.database.rules import get_rules, set_rules from eduu.utils import button_parser, commands from eduu.utils.decorators import require_admin, stop_here -from eduu.utils.localization import use_chat_lang +from eduu.utils.localization import Strings, use_chat_lang @Client.on_message(filters.command(["setrules", "defregras"], PREFIXES) & filters.group) @require_admin(ChatPrivileges(can_change_info=True)) @use_chat_lang -async def settherules(c: Client, m: Message, s): +async def settherules(c: Client, m: Message, s: Strings): if len(m.text.split()) == 1: await m.reply_text(s("rules_set_empty")) return @@ -26,14 +26,14 @@ async def settherules(c: Client, m: Message, s): @Client.on_message(filters.command(["resetrules", "resetarregras"], PREFIXES) & filters.group) @require_admin(ChatPrivileges(can_change_info=True)) @use_chat_lang -async def delete_rules(c: Client, m: Message, s): +async def delete_rules(c: Client, m: Message, s: Strings): await set_rules(m.chat.id, None) await m.reply_text(s("rules_deleted")) @Client.on_message(filters.command(["rules", "regras"], PREFIXES) & filters.group) @use_chat_lang -async def show_rules(c: Client, m: Message, s): +async def show_rules(c: Client, m: Message, s: Strings): rules = await get_rules(m.chat.id) rulestxt, rules_buttons = button_parser(rules) @@ -50,7 +50,7 @@ async def show_rules(c: Client, m: Message, s): @Client.on_message(filters.regex("^/start rules_") & filters.private) @use_chat_lang @stop_here -async def show_rules_pvt(c: Client, m: Message, s): +async def show_rules_pvt(c: Client, m: Message, s: Strings): cid_one = m.text.split("_")[1] rules = await get_rules(cid_one if cid_one.startswith("-") else f"-{cid_one}") rulestxt, rules_buttons = button_parser(rules) diff --git a/eduu/plugins/sed.py b/eduu/plugins/sed.py index fb0f29d118..8ac3d2c01f 100644 --- a/eduu/plugins/sed.py +++ b/eduu/plugins/sed.py @@ -7,12 +7,12 @@ from hydrogram import Client, filters from hydrogram.types import Message -from eduu.utils.localization import use_chat_lang +from eduu.utils.localization import Strings, use_chat_lang @Client.on_message(filters.regex(r"^s/(.+)?/(.+)?(/.+)?") & filters.reply) @use_chat_lang -async def sed(c: Client, m: Message, s): +async def sed(c: Client, m: Message, s: Strings): exp = regex.split(r"(?<![^\\]\\)/", m.text) pattern = exp[1] replace_with = exp[2].replace(r"\/", "/") diff --git a/eduu/plugins/start.py b/eduu/plugins/start.py index 24a3840d0b..7cb75decdc 100644 --- a/eduu/plugins/start.py +++ b/eduu/plugins/start.py @@ -14,14 +14,14 @@ from config import PREFIXES from eduu import __commit__, __version_number__ from eduu.utils import commands, linkify_commit -from eduu.utils.localization import use_chat_lang +from eduu.utils.localization import Strings, use_chat_lang # Using a low priority group so deeplinks will run before this and stop the propagation. @Client.on_message(filters.command("start", PREFIXES) & filters.private, group=2) @Client.on_callback_query(filters.regex("^start_back$")) @use_chat_lang -async def start_pvt(c: Client, m: Message | CallbackQuery, s): +async def start_pvt(c: Client, m: Message | CallbackQuery, s: Strings): if isinstance(m, CallbackQuery): msg = m.message send = msg.edit_text @@ -49,7 +49,7 @@ async def start_pvt(c: Client, m: Message | CallbackQuery, s): @Client.on_message(filters.command("start", PREFIXES) & filters.group, group=2) @use_chat_lang -async def start_grp(c: Client, m: Message | CallbackQuery, s): +async def start_grp(c: Client, m: Message | CallbackQuery, s: Strings): keyboard = InlineKeyboardMarkup( inline_keyboard=[ [ @@ -65,7 +65,7 @@ async def start_grp(c: Client, m: Message | CallbackQuery, s): @Client.on_callback_query(filters.regex("^infos$")) @use_chat_lang -async def infos(c: Client, m: CallbackQuery, s): +async def infos(c: Client, m: CallbackQuery, s: Strings): res = s("start_info_page").format( version_number=f"r{__version_number__}", commit_hash=linkify_commit(__commit__), diff --git a/eduu/plugins/stickers.py b/eduu/plugins/stickers.py index 88cab7b580..845f4c06c7 100644 --- a/eduu/plugins/stickers.py +++ b/eduu/plugins/stickers.py @@ -21,12 +21,12 @@ from config import LOG_CHAT, PREFIXES from eduu.utils import http -from eduu.utils.localization import use_chat_lang +from eduu.utils.localization import Strings, use_chat_lang @Client.on_message(filters.command(["kang", "kibe", "steal"], PREFIXES)) @use_chat_lang -async def kang_sticker(c: Client, m: Message, s): +async def kang_sticker(c: Client, m: Message, s: Strings): prog_msg = await m.reply_text(s("kang_kanging_sticker_msg")) bot_username = c.me.username sticker_emoji = "🤔" @@ -222,7 +222,7 @@ def resize_image(file: str) -> BytesIO: @Client.on_message(filters.command("stickerid", PREFIXES) & filters.reply) @use_chat_lang -async def getstickerid(c: Client, m: Message, s): +async def getstickerid(c: Client, m: Message, s: Strings): if m.reply_to_message.sticker: await m.reply_text( s("stickerid_string").format(stickerid=m.reply_to_message.sticker.file_id) @@ -231,7 +231,7 @@ async def getstickerid(c: Client, m: Message, s): @Client.on_message(filters.command("getsticker", PREFIXES) & filters.reply) @use_chat_lang -async def getstickeraspng(c: Client, m: Message, s): +async def getstickeraspng(c: Client, m: Message, s: Strings): sticker = m.reply_to_message.sticker if not sticker: await m.reply_text(s("getsticker_not_sticker")) diff --git a/eduu/plugins/sudos.py b/eduu/plugins/sudos.py index 2504aa4ffa..5b560fc72f 100644 --- a/eduu/plugins/sudos.py +++ b/eduu/plugins/sudos.py @@ -26,7 +26,7 @@ from eduu.database import database from eduu.database.restarted import set_restarted from eduu.utils import sudofilter -from eduu.utils.localization import use_chat_lang +from eduu.utils.localization import Strings, use_chat_lang from eduu.utils.utils import shell_exec if TYPE_CHECKING: @@ -44,7 +44,7 @@ async def sudos(c: Client, m: Message): @Client.on_message(filters.command("cmd", prefix) & sudofilter) @use_chat_lang -async def run_cmd(c: Client, m: Message, s): +async def run_cmd(c: Client, m: Message, s: Strings): cmd = m.text.split(maxsplit=1)[1] if re.match("(?i)poweroff|halt|shutdown|reboot", cmd): await m.reply_text(s("sudos_forbidden_command")) @@ -59,7 +59,7 @@ async def run_cmd(c: Client, m: Message, s): @Client.on_message(filters.command("upgrade", prefix) & sudofilter) @use_chat_lang -async def upgrade(c: Client, m: Message, s): +async def upgrade(c: Client, m: Message, s: Strings): sm = await m.reply_text("Upgrading sources…") stdout, proc = await shell_exec("git pull --no-edit") if proc.returncode != 0: @@ -116,7 +116,7 @@ async def execs(c: Client, m: Message): @Client.on_message(filters.command("sudos_speedtest", prefix) & sudofilter) @use_chat_lang -async def test_speed(c: Client, m: Message, s): +async def test_speed(c: Client, m: Message, s: Strings): string = s("sudos_speedtest") sent = await m.reply_text(string.format(host="", ping="", download="", upload="")) s = speedtest.Speedtest() @@ -168,7 +168,7 @@ async def execsql(c: Client, m: Message): @Client.on_message(filters.command("restart", prefix) & sudofilter) @use_chat_lang -async def restart(c: Client, m: Message, s): +async def restart(c: Client, m: Message, s: Strings): sent = await m.reply_text(s("sudos_restarting")) await set_restarted(sent.chat.id, sent.id) await conn.commit() diff --git a/eduu/plugins/telegraph.py b/eduu/plugins/telegraph.py index b3b5915c8d..fce23b273e 100644 --- a/eduu/plugins/telegraph.py +++ b/eduu/plugins/telegraph.py @@ -8,12 +8,12 @@ from config import PREFIXES from eduu.utils import http -from eduu.utils.localization import use_chat_lang +from eduu.utils.localization import Strings, use_chat_lang @Client.on_message(filters.command("telegraph", PREFIXES)) @use_chat_lang -async def telegraph(c: Client, m: Message, s): +async def telegraph(c: Client, m: Message, s: Strings): if not m.reply_to_message: await m.reply_text(s("telegraph_err_no_reply")) return diff --git a/eduu/plugins/tiorunexec.py b/eduu/plugins/tiorunexec.py index 9997a18f9f..a9e41452cc 100644 --- a/eduu/plugins/tiorunexec.py +++ b/eduu/plugins/tiorunexec.py @@ -16,7 +16,7 @@ from config import PREFIXES from eduu.utils import commands, inline_commands -from eduu.utils.localization import use_chat_lang +from eduu.utils.localization import Strings, use_chat_lang tio = Tio() @@ -27,7 +27,7 @@ @Client.on_message(filters.command(["run", "exec_code"], PREFIXES)) @use_chat_lang -async def exec_tio_run_code(c: Client, m: Message, s): +async def exec_tio_run_code(c: Client, m: Message, s: Strings): execlanguage = m.command[1] if execlanguage not in langslist: await m.reply_text( @@ -66,7 +66,7 @@ async def exec_tio_run_code(c: Client, m: Message, s): @Client.on_inline_query(filters.regex(r"^(run|exec)", re.IGNORECASE)) @use_chat_lang -async def exec_tio_run_code_inline(c: Client, q: InlineQuery, s): +async def exec_tio_run_code_inline(c: Client, q: InlineQuery, s: Strings): execlanguage = q.query.lower().split()[1] if execlanguage not in langslist: await q.answer([ diff --git a/eduu/plugins/translate.py b/eduu/plugins/translate.py index d1b6aec5f6..374769c2d8 100644 --- a/eduu/plugins/translate.py +++ b/eduu/plugins/translate.py @@ -15,7 +15,7 @@ from config import PREFIXES from eduu.utils import commands, inline_commands -from eduu.utils.localization import use_chat_lang +from eduu.utils.localization import Strings, use_chat_lang tr = Translator() @@ -67,7 +67,7 @@ def get_tr_lang(text): @Client.on_message(filters.command("tr", PREFIXES)) @use_chat_lang -async def translate(c: Client, m: Message, s): +async def translate(c: Client, m: Message, s: Strings): text = m.text[4:] lang = get_tr_lang(text) @@ -102,7 +102,7 @@ async def translate(c: Client, m: Message, s): @Client.on_inline_query(filters.regex(r"^tr .+", re.IGNORECASE)) @use_chat_lang -async def tr_inline(c: Client, q: InlineQuery, s): +async def tr_inline(c: Client, q: InlineQuery, s: Strings): to_tr = q.query.split(None, 2)[2] source_language = await tr.detect(q.query.split(None, 2)[2]) to_language = q.query.lower().split()[1] diff --git a/eduu/plugins/warns.py b/eduu/plugins/warns.py index 2767211246..898935ae08 100644 --- a/eduu/plugins/warns.py +++ b/eduu/plugins/warns.py @@ -17,7 +17,7 @@ from eduu.utils import commands, get_target_user from eduu.utils.consts import ADMIN_STATUSES from eduu.utils.decorators import require_admin -from eduu.utils.localization import use_chat_lang +from eduu.utils.localization import Strings, use_chat_lang def get_warn_reason_text(c: Client, m: Message) -> Message: @@ -35,7 +35,7 @@ def get_warn_reason_text(c: Client, m: Message) -> Message: @Client.on_message(filters.command("warn", PREFIXES) & filters.group) @require_admin(ChatPrivileges(can_restrict_members=True)) @use_chat_lang -async def warn_user(c: Client, m: Message, s): +async def warn_user(c: Client, m: Message, s: Strings): target_user = await get_target_user(c, m) warns_limit = await get_warns_limit(m.chat.id) check_admin = await m.chat.get_member(target_user.id) @@ -79,7 +79,7 @@ async def warn_user(c: Client, m: Message, s): @Client.on_message(filters.command("setwarnslimit", PREFIXES) & filters.group) @require_admin(ChatPrivileges(can_restrict_members=True, can_change_info=True)) @use_chat_lang -async def on_set_warns_limit(c: Client, m: Message, s): +async def on_set_warns_limit(c: Client, m: Message, s: Strings): if len(m.command) == 1: await m.reply_text(s("warn_limit_help")) return @@ -96,7 +96,7 @@ async def on_set_warns_limit(c: Client, m: Message, s): @Client.on_message(filters.command(["resetwarns", "unwarn"], PREFIXES) & filters.group) @require_admin(ChatPrivileges(can_restrict_members=True)) @use_chat_lang -async def unwarn_user(c: Client, m: Message, s): +async def unwarn_user(c: Client, m: Message, s: Strings): target_user = await get_target_user(c, m) await reset_warns(m.chat.id, target_user.id) await m.reply_text(s("warn_reset").format(target_user=target_user.mention)) @@ -105,7 +105,7 @@ async def unwarn_user(c: Client, m: Message, s): @Client.on_message(filters.command("warns", PREFIXES) & filters.group) @require_admin() @use_chat_lang -async def get_user_warns_cmd(c: Client, m: Message, s): +async def get_user_warns_cmd(c: Client, m: Message, s: Strings): target_user = await get_target_user(c, m) user_warns = await get_warns(m.chat.id, target_user.id) await m.reply_text( @@ -116,7 +116,7 @@ async def get_user_warns_cmd(c: Client, m: Message, s): @Client.on_message(filters.command(["setwarnsaction", "warnsaction"], PREFIXES) & filters.group) @require_admin(ChatPrivileges(can_restrict_members=True)) @use_chat_lang -async def set_warns_action_cmd(c: Client, m: Message, s): +async def set_warns_action_cmd(c: Client, m: Message, s: Strings): if len(m.text.split()) == 1: warn_act = await get_warn_action(m.chat.id) await m.reply_text(s("warn_action_status").format(action=warn_act)) diff --git a/eduu/plugins/weather.py b/eduu/plugins/weather.py index 863a20bdc6..f42360e757 100644 --- a/eduu/plugins/weather.py +++ b/eduu/plugins/weather.py @@ -15,7 +15,7 @@ from config import PREFIXES from eduu.utils import commands, http, inline_commands -from eduu.utils.localization import use_chat_lang +from eduu.utils.localization import Strings, use_chat_lang # Api key used in weather.com's mobile app. weather_apikey = "8de2d8b3a93542c9a2d8b3a935a2c909" @@ -84,7 +84,7 @@ def get_status_emoji(status_code: int) -> str: @Client.on_message(filters.command(["clima", "weather"], PREFIXES)) @Client.on_inline_query(filters.regex(r"^(clima|weather) .+", re.IGNORECASE)) @use_chat_lang -async def weather(c: Client, m: InlineQuery | Message, s): +async def weather(c: Client, m: InlineQuery | Message, s: Strings): text = m.text if isinstance(m, Message) else m.query if len(text.split(maxsplit=1)) == 1: if isinstance(m, Message): diff --git a/eduu/plugins/welcome.py b/eduu/plugins/welcome.py index b54b9091fc..13ee469047 100644 --- a/eduu/plugins/welcome.py +++ b/eduu/plugins/welcome.py @@ -10,20 +10,20 @@ from eduu.database.welcome import get_welcome, set_welcome, toggle_welcome from eduu.utils import button_parser, commands, get_format_keys from eduu.utils.decorators import require_admin, stop_here -from eduu.utils.localization import use_chat_lang +from eduu.utils.localization import Strings, use_chat_lang @Client.on_message(filters.command(["welcomeformat", "start welcome_format_help"], PREFIXES)) @use_chat_lang @stop_here -async def welcome_format_message_help(c: Client, m: Message, s): +async def welcome_format_message_help(c: Client, m: Message, s: Strings): await m.reply_text(s("welcome_format_help_msg")) @Client.on_message(filters.command("setwelcome", PREFIXES) & filters.group) @require_admin(ChatPrivileges(can_change_info=True)) @use_chat_lang -async def set_welcome_message(c: Client, m: Message, s): +async def set_welcome_message(c: Client, m: Message, s: Strings): if len(m.text.split()) == 1: await m.reply_text( s("welcome_set_empty").format(bot_username=c.me.username), @@ -61,14 +61,14 @@ async def set_welcome_message(c: Client, m: Message, s): ) @require_admin(ChatPrivileges(can_change_info=True)) @use_chat_lang -async def invlaid_welcome_status_arg(c: Client, m: Message, s): +async def invlaid_welcome_status_arg(c: Client, m: Message, s: Strings): await m.reply_text(s("welcome_mode_invalid")) @Client.on_message(filters.command("getwelcome", PREFIXES) & filters.group) @require_admin(ChatPrivileges(can_change_info=True)) @use_chat_lang -async def getwelcomemsg(c: Client, m: Message, s): +async def getwelcomemsg(c: Client, m: Message, s: Strings): welcome, welcome_enabled = await get_welcome(m.chat.id) if welcome_enabled: await m.reply_text( @@ -82,7 +82,7 @@ async def getwelcomemsg(c: Client, m: Message, s): @Client.on_message(filters.command("welcome on", PREFIXES) & filters.group) @require_admin(ChatPrivileges(can_change_info=True)) @use_chat_lang -async def enable_welcome_message(c: Client, m: Message, s): +async def enable_welcome_message(c: Client, m: Message, s: Strings): await toggle_welcome(m.chat.id, True) await m.reply_text(s("welcome_mode_enable").format(chat_title=m.chat.title)) @@ -90,7 +90,7 @@ async def enable_welcome_message(c: Client, m: Message, s): @Client.on_message(filters.command("welcome off", PREFIXES) & filters.group) @require_admin(ChatPrivileges(can_change_info=True)) @use_chat_lang -async def disable_welcome_message(c: Client, m: Message, s): +async def disable_welcome_message(c: Client, m: Message, s: Strings): await toggle_welcome(m.chat.id, False) await m.reply_text(s("welcome_mode_disable").format(chat_title=m.chat.title)) @@ -98,14 +98,14 @@ async def disable_welcome_message(c: Client, m: Message, s): @Client.on_message(filters.command(["resetwelcome", "clearwelcome"], PREFIXES) & filters.group) @require_admin(ChatPrivileges(can_change_info=True)) @use_chat_lang -async def reset_welcome_message(c: Client, m: Message, s): +async def reset_welcome_message(c: Client, m: Message, s: Strings): await set_welcome(m.chat.id, None) await m.reply_text(s("welcome_reset").format(chat_title=m.chat.title)) @Client.on_message(filters.new_chat_members & filters.group) @use_chat_lang -async def greet_new_members(c: Client, m: Message, s): +async def greet_new_members(c: Client, m: Message, s: Strings): if m.new_chat_members[0].is_bot: return diff --git a/eduu/plugins/youtube.py b/eduu/plugins/youtube.py index 000057dca2..112dd520c5 100644 --- a/eduu/plugins/youtube.py +++ b/eduu/plugins/youtube.py @@ -17,7 +17,7 @@ from config import PREFIXES from eduu.utils import commands, http, pretty_size from eduu.utils.decorators import aiowrap -from eduu.utils.localization import use_chat_lang +from eduu.utils.localization import Strings, use_chat_lang YOUTUBE_REGEX = re.compile( r"(?m)http(?:s?):\/\/(?:www\.)?(?:music\.)?youtu(?:be\.com\/(watch\?v=|shorts/)|\.be\/|)([\w\-\_]*)(&(amp;)?[\w\?=]*)?" @@ -69,7 +69,7 @@ async def yt_search_cmd(c: Client, m: Message): @Client.on_message(filters.command("ytdl", PREFIXES)) @use_chat_lang -async def ytdlcmd(c: Client, m: Message, s): +async def ytdlcmd(c: Client, m: Message, s: Strings): user = m.from_user.id afsize = 0 @@ -130,7 +130,7 @@ async def ytdlcmd(c: Client, m: Message, s): @Client.on_callback_query(filters.regex("^(_(vid|aud))")) @use_chat_lang -async def cli_ytdl(c: Client, cq: CallbackQuery, s): +async def cli_ytdl(c: Client, cq: CallbackQuery, s: Strings): data, fsize, temp, cid, userid, mid = cq.data.split("|") if cq.from_user.id != int(userid): await cq.answer(s("ytdl_button_denied"), cache_time=60) diff --git a/eduu/utils/localization.py b/eduu/utils/localization.py index 09e637cc69..dac0201232 100644 --- a/eduu/utils/localization.py +++ b/eduu/utils/localization.py @@ -5,18 +5,15 @@ import json import logging +from collections.abc import Callable from functools import partial from pathlib import Path -from typing import TYPE_CHECKING from hydrogram.enums import ChatType from hydrogram.types import CallbackQuery, InlineQuery, Message from eduu.database.localization import get_db_lang -if TYPE_CHECKING: - from collections.abc import Callable - enabled_locales: list[str] = [ "en-GB", # English (United Kingdom) "en-US", # English (United States) @@ -78,6 +75,9 @@ def get_locale_string( return res +Strings = Callable[[str], str] + + async def get_lang(message: CallbackQuery | Message | InlineQuery) -> str: if isinstance(message, CallbackQuery): chat = message.message.chat if message.message else message.from_user