From 4e6532ff0d7203948ad064cd5efa86cd2c1b0d21 Mon Sep 17 00:00:00 2001 From: Expliyh Date: Thu, 16 May 2024 21:28:18 +0800 Subject: [PATCH] =?UTF-8?q?pacman=E5=92=8Cprofile=E9=80=82=E9=85=8Dsatori?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- liteyuki/plugins/liteyuki_pacman/common.py | 16 +++++++++------- .../plugins/liteyuki_user/profile_manager.py | 8 +++++--- liteyuki/utils/satori_utils/user_info.py | 7 +++++-- 3 files changed, 19 insertions(+), 12 deletions(-) diff --git a/liteyuki/plugins/liteyuki_pacman/common.py b/liteyuki/plugins/liteyuki_pacman/common.py index b416c73d..519a0cf0 100644 --- a/liteyuki/plugins/liteyuki_pacman/common.py +++ b/liteyuki/plugins/liteyuki_pacman/common.py @@ -5,6 +5,7 @@ import aiofiles import nonebot.plugin from nonebot.adapters import satori +from liteyuki.utils import satori_utils from liteyuki.utils.base.data import LiteModel from liteyuki.utils.base.data_manager import GlobalPlugin, Group, User, group_db, plugin_db, user_db from liteyuki.utils.base.ly_typing import T_MessageEvent @@ -139,11 +140,12 @@ def set_plugin_session_enable(event: T_MessageEvent, plugin_name: str, enable: b Returns: """ - if event.message_type == "group": - session = group_db.where_one(Group(), "group_id = ?", str(event.group_id), - default=Group(group_id=str(event.group_id))) + if satori_utils.get_message_type(event) == "group": + session = group_db.where_one(Group(), "group_id = ?", str(satori_utils.get_group_id(event)), + default=Group(group_id=str(satori_utils.get_group_id(event)))) else: - session = user_db.where_one(User(), "user_id = ?", str(event.user_id), default=User(user_id=str(event.user_id))) + session = user_db.where_one(User(), "user_id = ?", str(satori_utils.get_user_id(event)), + default=User(user_id=str(satori_utils.get_user_id(event)))) default_enable = get_plugin_default_enable(plugin_name) if default_enable: if enable: @@ -156,12 +158,12 @@ def set_plugin_session_enable(event: T_MessageEvent, plugin_name: str, enable: b else: session.enabled_plugins.remove(plugin_name) - if event.message_type == "group": - __group_data[str(event.group_id)] = session + if satori_utils.get_message_type(event) == "group": + __group_data[str(satori_utils.get_group_id(event))] = session print(session) group_db.save(session) else: - __user_data[str(event.user_id)] = session + __user_data[str(satori_utils.get_user_id(event))] = session user_db.save(session) diff --git a/liteyuki/plugins/liteyuki_user/profile_manager.py b/liteyuki/plugins/liteyuki_user/profile_manager.py index 1ae69009..bb6c1620 100644 --- a/liteyuki/plugins/liteyuki_user/profile_manager.py +++ b/liteyuki/plugins/liteyuki_user/profile_manager.py @@ -9,6 +9,7 @@ from liteyuki.utils.base.language import Language, change_user_lang, get_all_lan from liteyuki.utils.base.ly_typing import T_Bot, T_MessageEvent from liteyuki.utils.message.message import MarkdownMessage as md from .const import representative_timezones_list +from ...utils import satori_utils require("nonebot_plugin_alconna") from nonebot_plugin_alconna import Alconna, Args, Arparma, Subcommand, on_alconna @@ -41,12 +42,13 @@ class Profile(LiteModel): @profile_alc.handle() async def _(result: Arparma, event: T_MessageEvent, bot: T_Bot): - user: User = user_db.where_one(User(), "user_id = ?", event.user_id, default=User(user_id=str(event.user_id))) - ulang = get_user_lang(str(event.user_id)) + user: User = user_db.where_one(User(), "user_id = ?", satori_utils.get_user_id(event), + default=User(user_id=str(satori_utils.get_user_id(event)))) + ulang = get_user_lang(str(satori_utils.get_user_id(event))) if result.subcommands.get("set"): if result.subcommands["set"].args.get("value"): # 对合法性进行校验后设置 - r = set_profile(result.args["key"], result.args["value"], str(event.user_id)) + r = set_profile(result.args["key"], result.args["value"], str(satori_utils.get_user_id(event))) if r: user.profile[result.args["key"]] = result.args["value"] user_db.save(user) # 数据库保存 diff --git a/liteyuki/utils/satori_utils/user_info.py b/liteyuki/utils/satori_utils/user_info.py index fd97e7d6..f4b9b4b0 100644 --- a/liteyuki/utils/satori_utils/user_info.py +++ b/liteyuki/utils/satori_utils/user_info.py @@ -1,3 +1,5 @@ +import nonebot + from nonebot.adapters import satori from nonebot.adapters.satori.models import User @@ -6,7 +8,7 @@ class UserInfo: user_infos: dict = {} async def load_friends(self, bot: satori.Bot): - print("LoadFriends") + nonebot.logger.info("Update user info from friends") friend_response = await bot.friend_list() while friend_response.next is not None: for i in friend_response.data: @@ -17,7 +19,8 @@ class UserInfo: for i in friend_response.data: i: User = i self.user_infos[str(i.id)] = i - print(i) + + nonebot.logger.info("Finish update user info") async def get(self, uid: int | str) -> User | None: try: