Files
zhenxun_bot/zhenxun/models/friend_user.py
T

34 lines
1.0 KiB
Python
Raw Normal View History

2024-02-04 04:18:54 +08:00
from tortoise import fields
2021-05-20 18:37:51 +08:00
2024-02-04 04:18:54 +08:00
from zhenxun.services.db_context import Model
2021-05-20 18:37:51 +08:00
2024-02-04 04:18:54 +08:00
class FriendUser(Model):
id = fields.IntField(pk=True, generated=True, auto_increment=True)
"""自增id"""
2024-02-04 04:18:54 +08:00
user_id = fields.CharField(255, unique=True, description="用户id")
"""用户id"""
2024-02-04 04:18:54 +08:00
user_name = fields.CharField(max_length=255, default="", description="用户名称")
"""用户名称"""
2024-02-25 03:18:34 +08:00
platform = fields.CharField(255, null=True, description="平台")
"""平台"""
2021-05-20 18:37:51 +08:00
2025-01-07 14:36:22 +08:00
class Meta: # pyright: ignore [reportIncompatibleVariableOverride]
table = "friend_users"
table_description = "好友信息数据表"
2021-05-20 18:37:51 +08:00
@classmethod
2024-02-25 03:18:34 +08:00
async def get_user_name(cls, user_id: str) -> str:
"""获取好友用户名称
2022-07-23 14:09:17 +08:00
参数:
2024-02-25 03:18:34 +08:00
user_id: 用户id
2021-07-30 21:21:51 +08:00
"""
2024-02-25 03:18:34 +08:00
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
2024-02-25 03:18:34 +08:00
def _run_script(cls):
return ["ALTER TABLE friend_users DROP COLUMN nickname;"]