From 41b9bac0f2f1016656f28ea9ca548d87e6046482 Mon Sep 17 00:00:00 2001 From: xtaodada Date: Tue, 29 Nov 2022 21:48:10 +0800 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20get=5Fchat=20support=20show=20can?= =?UTF-8?q?=5Fmanage=5Ftopics?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- plugins/system/get_chat.py | 5 +++-- utils/bot.py | 22 +++++++++++----------- 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/plugins/system/get_chat.py b/plugins/system/get_chat.py index abd6e37..cb4d72d 100644 --- a/plugins/system/get_chat.py +++ b/plugins/system/get_chat.py @@ -12,7 +12,7 @@ from core.sign import SignServices from core.user import UserService from core.user.error import UserNotFoundError from modules.gacha_log.log import GachaLog -from utils.bot import get_all_args +from utils.bot import get_all_args, get_chat as get_chat_with_cache from utils.decorators.admins import bot_admins_rights_check from utils.helpers import get_genshin_client from utils.log import logger @@ -48,6 +48,7 @@ class GetChat(Plugin): text += "D" if admin.can_delete_messages else "_" text += "R" if admin.can_restrict_members else "_" text += "I" if admin.can_invite_users else "_" + text += "T" if admin.can_manage_topics else "_" text += "P" if admin.can_pin_messages else "_" text += "V" if admin.can_manage_video_chats else "_" text += "N" if admin.can_promote_members else "_" @@ -120,7 +121,7 @@ class GetChat(Plugin): await message.reply_text("参数错误,请指定群 id !") return try: - chat = await message.get_bot().get_chat(args[0]) + chat = await get_chat_with_cache(args[0]) if chat_id < 0: admins = await chat.get_administrators() if chat_id < 0 else None text = await self.parse_group_chat(chat, admins) diff --git a/utils/bot.py b/utils/bot.py index f44dbff..bdcef4e 100644 --- a/utils/bot.py +++ b/utils/bot.py @@ -12,17 +12,17 @@ redis_db = cast(RedisDB, redis_db) async def get_chat(chat_id: Union[str, int], ttl: int = 86400) -> Chat: - if redis_db: - qname = f"bot:chat:{chat_id}" - data = await redis_db.client.get(qname) - if data: - json_data = json.loads(data) - return Chat.de_json(json_data, bot.app.bot) - chat_info = await bot.app.bot.get_chat(chat_id) - await redis_db.client.set(qname, chat_info.to_json()) - await redis_db.client.expire(qname, ttl) - return chat_info - return await bot.app.bot.get_chat(chat_id) + if not redis_db: + return await bot.app.bot.get_chat(chat_id) + qname = f"bot:chat:{chat_id}" + data = await redis_db.client.get(qname) + if data: + json_data = json.loads(data) + return Chat.de_json(json_data, bot.app.bot) + chat_info = await bot.app.bot.get_chat(chat_id) + await redis_db.client.set(qname, chat_info.to_json()) + await redis_db.client.expire(qname, ttl) + return chat_info def get_all_args(context: CallbackContext) -> List[str]: