Files
zhenxun_bot/models/friend_user.py
T

61 lines
1.7 KiB
Python
Raw Normal View History

from tortoise import fields
2021-12-01 14:03:34 +08:00
from configs.config import Config
from services.db_context import Model
2021-05-20 18:37:51 +08:00
class FriendUser(Model):
2021-05-20 18:37:51 +08:00
id = fields.IntField(pk=True, generated=True, auto_increment=True)
"""自增id"""
user_id = fields.BigIntField(unique=True)
"""用户id"""
user_name = fields.CharField(max_length=255, default="")
"""用户名称"""
nickname = fields.CharField(max_length=255, null=True)
"""私聊下自定义昵称"""
2021-05-20 18:37:51 +08:00
class Meta:
table = "friend_users"
table_description = "好友信息数据表"
2021-05-20 18:37:51 +08:00
@classmethod
async def get_user_name(cls, user_id: int) -> str:
2021-07-30 21:21:51 +08:00
"""
2022-07-23 14:09:17 +08:00
说明:
2021-07-30 21:21:51 +08:00
获取好友用户名称
2022-07-23 14:09:17 +08:00
参数:
2021-07-30 21:21:51 +08:00
:param user_id: qq号
"""
if user := await cls.get_or_none(user_id=user_id):
2021-05-20 18:37:51 +08:00
return user.user_name
return ""
2021-05-20 18:37:51 +08:00
@classmethod
async def get_user_nickname(cls, user_id: int) -> str:
2021-07-30 21:21:51 +08:00
"""
2022-07-23 14:09:17 +08:00
说明:
2021-07-30 21:21:51 +08:00
获取用户昵称
2022-07-23 14:09:17 +08:00
参数:
2021-07-30 21:21:51 +08:00
:param user_id: qq号
"""
if user := await cls.get_or_none(user_id=user_id):
2021-05-20 18:37:51 +08:00
if user.nickname:
2021-12-01 14:03:34 +08:00
_tmp = ""
if black_word := Config.get_config("nickname", "BLACK_WORD"):
2021-12-16 11:16:28 +08:00
for x in user.nickname:
_tmp += "*" if x in black_word else x
2021-12-01 14:03:34 +08:00
return _tmp
2021-07-30 21:21:51 +08:00
return ""
2021-05-20 18:37:51 +08:00
@classmethod
async def set_user_nickname(cls, user_id: int, nickname: str):
2021-07-30 21:21:51 +08:00
"""
2022-07-23 14:09:17 +08:00
说明:
2021-07-30 21:21:51 +08:00
设置用户昵称
2022-07-23 14:09:17 +08:00
参数:
2021-07-30 21:21:51 +08:00
:param user_id: qq号
:param nickname: 昵称
"""
await cls.update_or_create(user_id=user_id, defaults={"nickname": nickname})