From 6c2e9aed56c152919ec74c9d7f897c5eb6c64a59 Mon Sep 17 00:00:00 2001 From: xtaodada Date: Mon, 22 Jan 2024 21:01:59 +0800 Subject: [PATCH] feat: i18n --- plugins/chat_member_update.py | 11 ++--------- plugins/languages.py | 30 ++++++++++++++++++++++++++++++ plugins/new_member.py | 10 ++-------- plugins/reverify.py | 9 +++------ sticker/single_utils.py | 1 - 5 files changed, 37 insertions(+), 24 deletions(-) create mode 100644 plugins/languages.py diff --git a/plugins/chat_member_update.py b/plugins/chat_member_update.py index 7d68cb4..ac69722 100644 --- a/plugins/chat_member_update.py +++ b/plugins/chat_member_update.py @@ -6,20 +6,13 @@ from pyrogram import filters from pyrogram.enums import ChatMemberStatus from pyrogram.types import ChatMemberUpdated +from plugins.languages import MSG_PUBLIC, ADMIN_MSG, MSG, VERIFY_TIME from pyromod.utils.errors import TimeoutConversationError from sticker.scheduler import add_delete_message_job from sticker.service_message import ServiceMessage from sticker.single_utils import Client from sticker import bot, log -MSG_PUBLIC = """您好,我发现此群组为公开群组,您需要联系创建者打开 `管理员批准后才能入群` 功能,我就能更好地工作。""" -MSG_SUCCESS = """验证成功,您已经成为群组的一员了!""" -MSG_FAILURE = """验证失败,请重试。""" -MSG = """您好 %s ,当前群组开启了验证功能。 - -您需要在 30 秒内发送任意一个 贴纸 来完成验证。""" -ADMIN_MSG = """管理员邀请,自动放行。""" - @bot.on_chat_member_updated() async def invite(client: Client, chat_member_updated: ChatMemberUpdated): @@ -81,7 +74,7 @@ async def invite(client: Client, chat_member_updated: ChatMemberUpdated): try: with contextlib.suppress(Exception): await log(chat, user, "REQUEST") - msg_ = await client.listen(chat.id, filters=filters.user(user.id), timeout=30) + msg_ = await client.listen(chat.id, filters=filters.user(user.id), timeout=VERIFY_TIME) with contextlib.suppress(Exception): await msg.delete() if not msg_.sticker: diff --git a/plugins/languages.py b/plugins/languages.py new file mode 100644 index 0000000..3252201 --- /dev/null +++ b/plugins/languages.py @@ -0,0 +1,30 @@ +VERIFY_TIME = 60 +MSG_PUBLIC = """您好,我发现此群组为公开群组,您需要联系创建者打开 `管理员批准后才能入群` 功能,我才能更好地工作。""" +MSG_SUCCESS = """验证成功,您已经成为群组的一员了! + +The verification was successful, and you are now a member of the group! +""" +MSG_FAILURE = """验证失败,请重试。 + +Verification failed; please try again. +""" +MSG = f"""您好 %s ,当前群组开启了验证功能。 + +您需要在 {VERIFY_TIME} 秒内发送任意一个 贴纸 来完成验证。 + +Hello, %s . The group's verification is presently enabled. + +You must transmit any sticker within {VERIFY_TIME} seconds to complete the verification. +""" +ADMIN_MSG = """管理员邀请,自动放行。 + +Administrator's invitation for automatic release. +""" +RE_MSG = f"""您好 %s ,您被管理员要求重新验证。 + +您需要在 {VERIFY_TIME} 秒内发送任意一个 贴纸 来完成验证。 + +Hello, %s . The administrator has requested you to re-verify. + +You must transmit any sticker within {VERIFY_TIME} seconds to complete the verification. +""" diff --git a/plugins/new_member.py b/plugins/new_member.py index e3201ee..bd18d0f 100644 --- a/plugins/new_member.py +++ b/plugins/new_member.py @@ -4,6 +4,7 @@ from cashews import cache from pyrogram.types import ChatJoinRequest from pyrogram import filters +from plugins.languages import MSG, MSG_SUCCESS, MSG_FAILURE, VERIFY_TIME from sticker.single_utils import Client from sticker.scheduler import add_decline_request_job, rem_decline_request_job from sticker import bot, log @@ -11,13 +12,6 @@ from sticker import bot, log from pyromod.utils.errors import TimeoutConversationError -MSG = """您好,群组 %s 开启了验证功能。 - -您需要在 30 秒内发送任意一个 贴纸 来完成验证。""" -MSG_SUCCESS = """验证成功,您已经成为群组的一员了!""" -MSG_FAILURE = """验证失败,请重试。""" - - @bot.on_chat_join_request() async def new_member(client: Client, chat_join_request: ChatJoinRequest): chat = chat_join_request.chat @@ -27,7 +21,7 @@ async def new_member(client: Client, chat_join_request: ChatJoinRequest): try: with contextlib.suppress(Exception): await log(chat, user, "REQUEST") - await client.ask(user.id, MSG % chat.title, filters=filters.sticker, timeout=30) + await client.ask(user.id, MSG % chat.title, filters=filters.sticker, timeout=VERIFY_TIME) with contextlib.suppress(Exception): await client.send_message(user.id, MSG_SUCCESS) await chat_join_request.approve() diff --git a/plugins/reverify.py b/plugins/reverify.py index 29b3401..bfd8a21 100644 --- a/plugins/reverify.py +++ b/plugins/reverify.py @@ -5,15 +5,12 @@ from pyrogram.enums import ChatMemberStatus from datetime import datetime, timedelta +from plugins.languages import RE_MSG, VERIFY_TIME from pyromod.utils.errors import TimeoutConversationError from sticker.scheduler import add_delete_message_job from sticker.single_utils import Message, Client from sticker import bot, log -MSG = """您好 %s ,您被管理员要求重新验证。 - -您需要在 30 秒内发送任意一个 贴纸 来完成验证。""" - @bot.on_message(filters=filters.group & filters.command("reverify")) async def re_verify(client: Client, message: Message): @@ -43,11 +40,11 @@ async def re_verify(client: Client, message: Message): with contextlib.suppress(Exception): await message.delete() try: - msg = await message.reply_to_message.reply(MSG % user.mention) + msg = await message.reply_to_message.reply(RE_MSG % user.mention) except Exception as _: return try: - msg_ = await client.listen(chat.id, filters=filters.user(user.id), timeout=30) + msg_ = await client.listen(chat.id, filters=filters.user(user.id), timeout=VERIFY_TIME) with contextlib.suppress(Exception): await msg.delete() if not msg_.sticker: diff --git a/sticker/single_utils.py b/sticker/single_utils.py index 3a0f26a..4580799 100644 --- a/sticker/single_utils.py +++ b/sticker/single_utils.py @@ -32,7 +32,6 @@ class Client(Client): # noqa def cancel_listener(self, chat_id): """Cancel the conversation with the given chat_id.""" - return class Message(Message): # noqa