mirror of
https://github.com/zhenxun-org/zhenxun_bot.git
synced 2026-09-29 00:32:06 +08:00
feat(nickname): 删除昵称系统相关功能 (#2114)
删除了昵称系统的完整实现,包括: - 移除 nickname.py 插件文件及其所有功能代码 - 从 FriendUser 和 GroupInfoUser 模型中删除 nickname 字段 - 移除相关的数据库配置 - 更新 GroupManager 中的操作者名称获取逻辑 - 简化平台处理的数据源代码
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
from tortoise import fields
|
||||
|
||||
from zhenxun.configs.config import Config
|
||||
from zhenxun.services.db_context import Model
|
||||
|
||||
|
||||
@@ -11,8 +10,6 @@ class FriendUser(Model):
|
||||
"""用户id"""
|
||||
user_name = fields.CharField(max_length=255, default="", description="用户名称")
|
||||
"""用户名称"""
|
||||
nickname = fields.CharField(max_length=255, null=True, description="用户自定义昵称")
|
||||
"""私聊下自定义昵称"""
|
||||
platform = fields.CharField(255, null=True, description="平台")
|
||||
"""平台"""
|
||||
|
||||
@@ -31,53 +28,6 @@ class FriendUser(Model):
|
||||
return user.user_name
|
||||
return ""
|
||||
|
||||
@classmethod
|
||||
async def get_user_nickname(cls, user_id: str) -> str:
|
||||
"""获取用户昵称
|
||||
|
||||
参数:
|
||||
user_id: 用户id
|
||||
"""
|
||||
if user := await cls.get_or_none(user_id=user_id):
|
||||
if user.nickname:
|
||||
_tmp = ""
|
||||
if black_word := Config.get_config("nickname", "BLACK_WORD"):
|
||||
for x in user.nickname:
|
||||
_tmp += "*" if x in black_word else x
|
||||
return _tmp
|
||||
return ""
|
||||
|
||||
@classmethod
|
||||
async def set_user_nickname(
|
||||
cls,
|
||||
user_id: str,
|
||||
nickname: str,
|
||||
uname: str | None = None,
|
||||
platform: str | None = None,
|
||||
):
|
||||
"""设置用户昵称
|
||||
|
||||
参数:
|
||||
user_id: 用户id
|
||||
nickname: 昵称
|
||||
uname: 用户昵称
|
||||
platform: 平台
|
||||
"""
|
||||
defaults = {"nickname": nickname}
|
||||
if uname is not None:
|
||||
defaults["user_name"] = uname
|
||||
if platform is not None:
|
||||
defaults["platform"] = platform
|
||||
await cls.update_or_create(
|
||||
user_id=user_id,
|
||||
defaults=defaults,
|
||||
)
|
||||
|
||||
@classmethod
|
||||
def _run_script(cls):
|
||||
return [
|
||||
"ALTER TABLE friend_users "
|
||||
"ALTER COLUMN user_id TYPE character varying(255);",
|
||||
"ALTER TABLE friend_users "
|
||||
"ADD COLUMN platform character varying(255) default 'qq';",
|
||||
]
|
||||
return ["ALTER TABLE friend_users DROP COLUMN nickname;"]
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
from tortoise import fields
|
||||
|
||||
from zhenxun.configs.config import Config
|
||||
from zhenxun.services.db_context import Model
|
||||
|
||||
|
||||
@@ -15,8 +14,6 @@ class GroupInfoUser(Model):
|
||||
"""群聊id"""
|
||||
user_join_time = fields.DatetimeField(null=True)
|
||||
"""用户入群时间"""
|
||||
nickname = fields.CharField(255, null=True)
|
||||
"""群聊昵称"""
|
||||
uid = fields.BigIntField(null=True)
|
||||
"""用户uid"""
|
||||
platform = fields.CharField(255, null=True, description="平台")
|
||||
@@ -28,7 +25,7 @@ class GroupInfoUser(Model):
|
||||
unique_together = ("user_id", "group_id")
|
||||
|
||||
@classmethod
|
||||
async def get_all_uid(cls, group_id: str) -> set[int]:
|
||||
async def get_all_uid(cls, group_id: str) -> set[str]:
|
||||
"""获取该群所有用户id
|
||||
|
||||
参数:
|
||||
@@ -39,78 +36,16 @@ class GroupInfoUser(Model):
|
||||
) # type: ignore
|
||||
|
||||
@classmethod
|
||||
async def set_user_nickname(
|
||||
cls,
|
||||
user_id: str,
|
||||
group_id: str,
|
||||
nickname: str,
|
||||
uname: str | None = None,
|
||||
platform: str | None = None,
|
||||
):
|
||||
"""设置群员在该群内的昵称
|
||||
|
||||
参数:
|
||||
user_id: 用户id
|
||||
group_id: 群号
|
||||
nickname: 昵称
|
||||
uname: 用户昵称
|
||||
platform: 平台
|
||||
"""
|
||||
defaults = {"nickname": nickname}
|
||||
if uname is not None:
|
||||
defaults["user_name"] = uname
|
||||
if platform is not None:
|
||||
defaults["platform"] = platform
|
||||
await cls.update_or_create(
|
||||
user_id=user_id,
|
||||
group_id=group_id,
|
||||
defaults=defaults,
|
||||
)
|
||||
|
||||
@classmethod
|
||||
async def get_user_all_group(cls, user_id: str) -> list[int]:
|
||||
async def get_user_all_group(cls, user_id: str) -> list[str]:
|
||||
"""获取该用户所在的所有群聊
|
||||
|
||||
参数:
|
||||
user_id: 用户id
|
||||
"""
|
||||
return list(
|
||||
await cls.filter(user_id=str(user_id)).values_list("group_id", flat=True)
|
||||
await cls.filter(user_id=user_id).values_list("group_id", flat=True)
|
||||
) # type: ignore
|
||||
|
||||
@classmethod
|
||||
async def get_user_nickname(cls, user_id: str, group_id: str) -> str:
|
||||
"""获取用户在该群的昵称
|
||||
|
||||
参数:
|
||||
user_id: 用户id
|
||||
group_id: 群号
|
||||
"""
|
||||
if user := await cls.get_or_none(user_id=user_id, group_id=group_id):
|
||||
if user.nickname:
|
||||
nickname = ""
|
||||
if black_word := Config.get_config("nickname", "BLACK_WORD"):
|
||||
for x in user.nickname:
|
||||
nickname += "*" if x in black_word else x
|
||||
return nickname
|
||||
return user.nickname
|
||||
return ""
|
||||
|
||||
@classmethod
|
||||
async def _run_script(cls):
|
||||
return [
|
||||
# 允许 user_join_time 为空
|
||||
"alter table group_info_users alter user_join_time drop not null;",
|
||||
"ALTER TABLE group_info_users "
|
||||
"ALTER COLUMN user_join_time TYPE timestamp with time zone "
|
||||
"USING user_join_time::timestamp with time zone;",
|
||||
# 将user_id改为user_id
|
||||
"ALTER TABLE group_info_users RENAME COLUMN user_qq TO user_id;",
|
||||
"ALTER TABLE group_info_users "
|
||||
"ALTER COLUMN user_id TYPE character varying(255);",
|
||||
# 将user_id字段类型改为character varying(255)
|
||||
"ALTER TABLE group_info_users "
|
||||
"ALTER COLUMN group_id TYPE character varying(255);",
|
||||
"ALTER TABLE group_info_users "
|
||||
"ADD COLUMN platform character varying(255) default 'qq';",
|
||||
]
|
||||
return ["ALTER TABLE group_info_users DROP COLUMN nickname;"]
|
||||
|
||||
Reference in New Issue
Block a user