diff --git a/core/sign/repositories.py b/core/sign/repositories.py index 995694f0..54c0b133 100644 --- a/core/sign/repositories.py +++ b/core/sign/repositories.py @@ -37,6 +37,14 @@ class SignRepository: results = await session.exec(statement) return sign[0] if (sign := results.first()) else None + async def get_by_chat_id(self, chat_id: int) -> Optional[List[Sign]]: + async with self.mysql.Session() as session: + session = cast(AsyncSession, session) + statement = select(Sign).where(Sign.chat_id == chat_id) + results = await session.exec(statement) + signs = results.all() + return [sign[0] for sign in signs] + async def get_all(self) -> List[Sign]: async with self.mysql.Session() as session: query = select(Sign) diff --git a/core/sign/services.py b/core/sign/services.py index 70603443..9772ea74 100644 --- a/core/sign/services.py +++ b/core/sign/services.py @@ -20,3 +20,6 @@ class SignServices: async def get_by_user_id(self, user_id: int): return await self._repository.get_by_user_id(user_id) + + async def get_by_chat_id(self, chat_id: int): + return await self._repository.get_by_chat_id(chat_id) diff --git a/plugins/system/get_chat.py b/plugins/system/get_chat.py index 6b83f230..b2e275e1 100644 --- a/plugins/system/get_chat.py +++ b/plugins/system/get_chat.py @@ -8,6 +8,7 @@ from telegram.ext import CommandHandler, CallbackContext from core.cookies import CookiesService from core.cookies.error import CookiesNotFoundError from core.plugin import Plugin, handler +from core.sign import SignServices from core.user import UserService from core.user.error import UserNotFoundError from modules.apihelper.gacha_log import GachaLog @@ -19,15 +20,23 @@ from utils.models.base import RegionEnum class GetChat(Plugin): - def __init__(self, user_service: UserService = None, cookies_service: CookiesService = None): + def __init__( + self, + user_service: UserService = None, + cookies_service: CookiesService = None, + sign_service: SignServices = None, + ): self.cookies_service = cookies_service self.user_service = user_service + self.sign_service = sign_service - @staticmethod - def parse_group_chat(chat: Chat, admins: List[ChatMember]) -> str: + async def parse_group_chat(self, chat: Chat, admins: List[ChatMember]) -> str: text = f"群 ID:{chat.id}\n" f"群名称:{chat.title}\n" if chat.username: - text += f"群用户名:{chat.username}\n" + text += f"群用户名:@{chat.username}\n" + sign_info = await self.sign_service.get_by_chat_id(chat.id) + if sign_info: + text += f"自动签到推送人数:{len(sign_info)}\n" if chat.description: text += f"群简介:{chat.description}\n" if admins: @@ -72,6 +81,17 @@ class GetChat(Plugin): except CookiesNotFoundError: temp = "UID 绑定" text += f"{temp}\n" f"游戏 ID:{uid}" + sign_info = await self.sign_service.get_by_user_id(chat.id) + if sign_info is not None: + text += ( + f"\n自动签到:已开启" + f"\n推送会话:{sign_info.chat_id}" + f"\n开启时间:{sign_info.time_created}" + f"\n更新时间:{sign_info.time_updated}" + f"\n签到状态:{sign_info.status.name}" + ) + else: + text += f"\n自动签到:未开启" with contextlib.suppress(Exception): gacha_log, status = await GachaLog.load_history_info(str(chat.id), str(uid)) if status: @@ -102,7 +122,7 @@ class GetChat(Plugin): chat = await message.get_bot().get_chat(args[0]) if chat_id < 0: admins = await chat.get_administrators() if chat_id < 0 else None - text = self.parse_group_chat(chat, admins) + text = await self.parse_group_chat(chat, admins) else: text = await self.parse_private_chat(chat) await message.reply_text(text, parse_mode="HTML")