mirror of
https://github.com/TriM-Organization/LiteyukiBot-TriM.git
synced 2024-12-01 09:44:44 +08:00
📝 将 Satori 用户缓存更新日志的输出时机由原来的每次调用函数调整为每次用户信息发生变更
This commit is contained in:
parent
322ad19889
commit
077658c68d
@ -1,3 +1,5 @@
|
|||||||
|
import nonebot
|
||||||
|
|
||||||
from liteyuki.utils import satori_utils
|
from liteyuki.utils import satori_utils
|
||||||
from nonebot.message import event_preprocessor
|
from nonebot.message import event_preprocessor
|
||||||
# from nonebot_plugin_alconna.typings import Event
|
# from nonebot_plugin_alconna.typings import Event
|
||||||
@ -10,13 +12,11 @@ from liteyuki.plugins.liteyuki_status.counter_for_satori import satori_counter
|
|||||||
|
|
||||||
@event_preprocessor
|
@event_preprocessor
|
||||||
async def pre_handle(event: Event):
|
async def pre_handle(event: Event):
|
||||||
print("UPDATE_USER")
|
|
||||||
print(event.__dict__)
|
|
||||||
if isinstance(event, satori.MessageEvent):
|
if isinstance(event, satori.MessageEvent):
|
||||||
if event.user.id == event.self_id:
|
if event.user.id == event.self_id:
|
||||||
satori_counter.msg_sent += 1
|
satori_counter.msg_sent += 1
|
||||||
else:
|
else:
|
||||||
satori_counter.msg_received += 1
|
satori_counter.msg_received += 1
|
||||||
if event.user.name is not None:
|
if event.user.name is not None:
|
||||||
await satori_utils.user_infos.put(event.user)
|
if await satori_utils.user_infos.put(event.user):
|
||||||
print(event.user)
|
nonebot.logger.info(f"Satori user {event.user.name}<{event.user.id}> updated")
|
||||||
|
@ -28,8 +28,34 @@ class UserInfo:
|
|||||||
except KeyError:
|
except KeyError:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
async def put(self, user: User):
|
async def put(self, user: User) -> bool:
|
||||||
|
"""
|
||||||
|
向用户信息数据库中添加/修改一项,返回值仅代表数据是否变更,不代表操作是否成功
|
||||||
|
Args:
|
||||||
|
user: 要加入数据库的用户
|
||||||
|
|
||||||
|
Returns: 当数据库中用户信息发生变化时返回 True, 否则返回 False
|
||||||
|
|
||||||
|
"""
|
||||||
|
try:
|
||||||
|
old_user: User = self.user_infos[str(user.id)]
|
||||||
|
attr_edited = False
|
||||||
|
if user.name is not None:
|
||||||
|
if old_user.name != user.name:
|
||||||
|
attr_edited = True
|
||||||
|
self.user_infos[str(user.id)].name = user.name
|
||||||
|
if user.nick is not None:
|
||||||
|
if old_user.nick != user.nick:
|
||||||
|
attr_edited = True
|
||||||
|
self.user_infos[str(user.id)].nick = user.nick
|
||||||
|
if user.avatar is not None:
|
||||||
|
if old_user.avatar != user.avatar:
|
||||||
|
attr_edited = True
|
||||||
|
self.user_infos[str(user.id)].avatar = user.avatar
|
||||||
|
return attr_edited
|
||||||
|
except KeyError:
|
||||||
self.user_infos[str(user.id)] = user
|
self.user_infos[str(user.id)] = user
|
||||||
|
return True
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
pass
|
pass
|
||||||
|
Loading…
Reference in New Issue
Block a user