mirror of
https://github.com/LiteyukiStudio/LiteyukiBot.git
synced 2024-11-11 06:27:23 +08:00
pacman和profile适配satori
This commit is contained in:
parent
eaf57f2c33
commit
4e6532ff0d
@ -5,6 +5,7 @@ import aiofiles
|
|||||||
import nonebot.plugin
|
import nonebot.plugin
|
||||||
from nonebot.adapters import satori
|
from nonebot.adapters import satori
|
||||||
|
|
||||||
|
from liteyuki.utils import satori_utils
|
||||||
from liteyuki.utils.base.data import LiteModel
|
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.data_manager import GlobalPlugin, Group, User, group_db, plugin_db, user_db
|
||||||
from liteyuki.utils.base.ly_typing import T_MessageEvent
|
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:
|
Returns:
|
||||||
|
|
||||||
"""
|
"""
|
||||||
if event.message_type == "group":
|
if satori_utils.get_message_type(event) == "group":
|
||||||
session = group_db.where_one(Group(), "group_id = ?", str(event.group_id),
|
session = group_db.where_one(Group(), "group_id = ?", str(satori_utils.get_group_id(event)),
|
||||||
default=Group(group_id=str(event.group_id)))
|
default=Group(group_id=str(satori_utils.get_group_id(event))))
|
||||||
else:
|
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)
|
default_enable = get_plugin_default_enable(plugin_name)
|
||||||
if default_enable:
|
if default_enable:
|
||||||
if enable:
|
if enable:
|
||||||
@ -156,12 +158,12 @@ def set_plugin_session_enable(event: T_MessageEvent, plugin_name: str, enable: b
|
|||||||
else:
|
else:
|
||||||
session.enabled_plugins.remove(plugin_name)
|
session.enabled_plugins.remove(plugin_name)
|
||||||
|
|
||||||
if event.message_type == "group":
|
if satori_utils.get_message_type(event) == "group":
|
||||||
__group_data[str(event.group_id)] = session
|
__group_data[str(satori_utils.get_group_id(event))] = session
|
||||||
print(session)
|
print(session)
|
||||||
group_db.save(session)
|
group_db.save(session)
|
||||||
else:
|
else:
|
||||||
__user_data[str(event.user_id)] = session
|
__user_data[str(satori_utils.get_user_id(event))] = session
|
||||||
user_db.save(session)
|
user_db.save(session)
|
||||||
|
|
||||||
|
|
||||||
|
@ -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.base.ly_typing import T_Bot, T_MessageEvent
|
||||||
from liteyuki.utils.message.message import MarkdownMessage as md
|
from liteyuki.utils.message.message import MarkdownMessage as md
|
||||||
from .const import representative_timezones_list
|
from .const import representative_timezones_list
|
||||||
|
from ...utils import satori_utils
|
||||||
|
|
||||||
require("nonebot_plugin_alconna")
|
require("nonebot_plugin_alconna")
|
||||||
from nonebot_plugin_alconna import Alconna, Args, Arparma, Subcommand, on_alconna
|
from nonebot_plugin_alconna import Alconna, Args, Arparma, Subcommand, on_alconna
|
||||||
@ -41,12 +42,13 @@ class Profile(LiteModel):
|
|||||||
|
|
||||||
@profile_alc.handle()
|
@profile_alc.handle()
|
||||||
async def _(result: Arparma, event: T_MessageEvent, bot: T_Bot):
|
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)))
|
user: User = user_db.where_one(User(), "user_id = ?", satori_utils.get_user_id(event),
|
||||||
ulang = get_user_lang(str(event.user_id))
|
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.get("set"):
|
||||||
if result.subcommands["set"].args.get("value"):
|
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:
|
if r:
|
||||||
user.profile[result.args["key"]] = result.args["value"]
|
user.profile[result.args["key"]] = result.args["value"]
|
||||||
user_db.save(user) # 数据库保存
|
user_db.save(user) # 数据库保存
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
import nonebot
|
||||||
|
|
||||||
from nonebot.adapters import satori
|
from nonebot.adapters import satori
|
||||||
from nonebot.adapters.satori.models import User
|
from nonebot.adapters.satori.models import User
|
||||||
|
|
||||||
@ -6,7 +8,7 @@ class UserInfo:
|
|||||||
user_infos: dict = {}
|
user_infos: dict = {}
|
||||||
|
|
||||||
async def load_friends(self, bot: satori.Bot):
|
async def load_friends(self, bot: satori.Bot):
|
||||||
print("LoadFriends")
|
nonebot.logger.info("Update user info from friends")
|
||||||
friend_response = await bot.friend_list()
|
friend_response = await bot.friend_list()
|
||||||
while friend_response.next is not None:
|
while friend_response.next is not None:
|
||||||
for i in friend_response.data:
|
for i in friend_response.data:
|
||||||
@ -17,7 +19,8 @@ class UserInfo:
|
|||||||
for i in friend_response.data:
|
for i in friend_response.data:
|
||||||
i: User = i
|
i: User = i
|
||||||
self.user_infos[str(i.id)] = 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:
|
async def get(self, uid: int | str) -> User | None:
|
||||||
try:
|
try:
|
||||||
|
Loading…
Reference in New Issue
Block a user