使用satori时维护一个有昵称的用户列表

get_plugin_session_enable 判断当前使用的适配器
This commit is contained in:
Expliyh
2024-05-16 19:20:54 +08:00
parent 90e7a90bcf
commit 24722447da
11 changed files with 120 additions and 14 deletions

View File

@ -0,0 +1 @@
from .user_info import user_infos

View File

@ -0,0 +1,35 @@
from nonebot.adapters import satori
from nonebot.adapters.satori.models import User
class UserInfo:
user_infos: dict = {}
async def load_friends(self, bot: satori.Bot):
print("LoadFriends")
friend_response = await bot.friend_list()
while friend_response.next is not None:
for i in friend_response.data:
i: User = i
self.user_infos[str(i.id)] = i
friend_response = await bot.friend_list(next_token=friend_response.next)
for i in friend_response.data:
i: User = i
self.user_infos[str(i.id)] = i
print(i)
async def get(self, uid: int | str) -> User | None:
try:
return self.user_infos[str(uid)]
except KeyError:
return None
async def put(self, user: User):
self.user_infos[str(user.id)] = user
def __init__(self):
pass
user_infos = UserInfo()