feat: i18n

This commit is contained in:
xtaodada 2024-01-22 21:01:59 +08:00
parent 3a78dbbca1
commit 6c2e9aed56
Signed by: xtaodada
GPG Key ID: 4CBB3F4FA8C85659
5 changed files with 37 additions and 24 deletions

View File

@ -6,20 +6,13 @@ from pyrogram import filters
from pyrogram.enums import ChatMemberStatus from pyrogram.enums import ChatMemberStatus
from pyrogram.types import ChatMemberUpdated from pyrogram.types import ChatMemberUpdated
from plugins.languages import MSG_PUBLIC, ADMIN_MSG, MSG, VERIFY_TIME
from pyromod.utils.errors import TimeoutConversationError from pyromod.utils.errors import TimeoutConversationError
from sticker.scheduler import add_delete_message_job from sticker.scheduler import add_delete_message_job
from sticker.service_message import ServiceMessage from sticker.service_message import ServiceMessage
from sticker.single_utils import Client from sticker.single_utils import Client
from sticker import bot, log from sticker import bot, log
MSG_PUBLIC = """您好,我发现此群组为公开群组,您需要联系创建者打开 `管理员批准后才能入群` 功能,我就能更好地工作。"""
MSG_SUCCESS = """验证成功,您已经成为群组的一员了!"""
MSG_FAILURE = """验证失败,请重试。"""
MSG = """您好 %s ,当前群组开启了验证功能。
您需要在 30 秒内发送任意一个 贴纸 来完成验证"""
ADMIN_MSG = """管理员邀请,自动放行。"""
@bot.on_chat_member_updated() @bot.on_chat_member_updated()
async def invite(client: Client, chat_member_updated: ChatMemberUpdated): async def invite(client: Client, chat_member_updated: ChatMemberUpdated):
@ -81,7 +74,7 @@ async def invite(client: Client, chat_member_updated: ChatMemberUpdated):
try: try:
with contextlib.suppress(Exception): with contextlib.suppress(Exception):
await log(chat, user, "REQUEST") 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): with contextlib.suppress(Exception):
await msg.delete() await msg.delete()
if not msg_.sticker: if not msg_.sticker:

30
plugins/languages.py Normal file
View File

@ -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.
"""

View File

@ -4,6 +4,7 @@ from cashews import cache
from pyrogram.types import ChatJoinRequest from pyrogram.types import ChatJoinRequest
from pyrogram import filters from pyrogram import filters
from plugins.languages import MSG, MSG_SUCCESS, MSG_FAILURE, VERIFY_TIME
from sticker.single_utils import Client from sticker.single_utils import Client
from sticker.scheduler import add_decline_request_job, rem_decline_request_job from sticker.scheduler import add_decline_request_job, rem_decline_request_job
from sticker import bot, log from sticker import bot, log
@ -11,13 +12,6 @@ from sticker import bot, log
from pyromod.utils.errors import TimeoutConversationError from pyromod.utils.errors import TimeoutConversationError
MSG = """您好,群组 %s 开启了验证功能。
您需要在 30 秒内发送任意一个 贴纸 来完成验证"""
MSG_SUCCESS = """验证成功,您已经成为群组的一员了!"""
MSG_FAILURE = """验证失败,请重试。"""
@bot.on_chat_join_request() @bot.on_chat_join_request()
async def new_member(client: Client, chat_join_request: ChatJoinRequest): async def new_member(client: Client, chat_join_request: ChatJoinRequest):
chat = chat_join_request.chat chat = chat_join_request.chat
@ -27,7 +21,7 @@ async def new_member(client: Client, chat_join_request: ChatJoinRequest):
try: try:
with contextlib.suppress(Exception): with contextlib.suppress(Exception):
await log(chat, user, "REQUEST") 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): with contextlib.suppress(Exception):
await client.send_message(user.id, MSG_SUCCESS) await client.send_message(user.id, MSG_SUCCESS)
await chat_join_request.approve() await chat_join_request.approve()

View File

@ -5,15 +5,12 @@ from pyrogram.enums import ChatMemberStatus
from datetime import datetime, timedelta from datetime import datetime, timedelta
from plugins.languages import RE_MSG, VERIFY_TIME
from pyromod.utils.errors import TimeoutConversationError from pyromod.utils.errors import TimeoutConversationError
from sticker.scheduler import add_delete_message_job from sticker.scheduler import add_delete_message_job
from sticker.single_utils import Message, Client from sticker.single_utils import Message, Client
from sticker import bot, log from sticker import bot, log
MSG = """您好 %s ,您被管理员要求重新验证。
您需要在 30 秒内发送任意一个 贴纸 来完成验证"""
@bot.on_message(filters=filters.group & filters.command("reverify")) @bot.on_message(filters=filters.group & filters.command("reverify"))
async def re_verify(client: Client, message: Message): async def re_verify(client: Client, message: Message):
@ -43,11 +40,11 @@ async def re_verify(client: Client, message: Message):
with contextlib.suppress(Exception): with contextlib.suppress(Exception):
await message.delete() await message.delete()
try: 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 _: except Exception as _:
return return
try: 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): with contextlib.suppress(Exception):
await msg.delete() await msg.delete()
if not msg_.sticker: if not msg_.sticker:

View File

@ -32,7 +32,6 @@ class Client(Client): # noqa
def cancel_listener(self, chat_id): def cancel_listener(self, chat_id):
"""Cancel the conversation with the given chat_id.""" """Cancel the conversation with the given chat_id."""
return
class Message(Message): # noqa class Message(Message): # noqa