From 77ee577f7a3fffcbf90bc60e206e4938a7e4e56d Mon Sep 17 00:00:00 2001 From: omg-xtao <100690902+omg-xtao@users.noreply.github.com> Date: Wed, 12 Oct 2022 20:11:54 +0800 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20=E6=94=AF=E6=8C=81BOT=E7=AE=A1?= =?UTF-8?q?=E7=90=86=E5=91=98=E8=8E=B7=E5=8F=96=E7=94=A8=E6=88=B7=E8=87=AA?= =?UTF-8?q?=E5=8A=A8=E7=AD=BE=E5=88=B0=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/sign/repositories.py | 8 ++++++++ core/sign/services.py | 3 +++ plugins/system/get_chat.py | 30 +++++++++++++++++++++++++----- 3 files changed, 36 insertions(+), 5 deletions(-) diff --git a/core/sign/repositories.py b/core/sign/repositories.py index 995694f..54c0b13 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 7060344..9772ea7 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 6b83f23..b2e275e 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")