mirror of
https://github.com/zhenxun-org/zhenxun_bot.git
synced 2026-10-13 07:50:00 +08:00
🧱 Update the 'user_qq' field in the database to 'user_id'
This commit is contained in:
+35
-28
@@ -9,7 +9,7 @@ from services.log import logger
|
||||
|
||||
class BanUser(Model):
|
||||
|
||||
user_qq = fields.IntField(pk=True)
|
||||
user_id = fields.CharField(255, pk=True)
|
||||
"""用户id"""
|
||||
ban_level = fields.IntField()
|
||||
"""使用ban命令的用户等级"""
|
||||
@@ -23,33 +23,33 @@ class BanUser(Model):
|
||||
table_description = ".ban/b了 封禁人员数据表"
|
||||
|
||||
@classmethod
|
||||
async def check_ban_level(cls, user_qq: int, level: int) -> bool:
|
||||
async def check_ban_level(cls, user_id: str | int, level: int) -> bool:
|
||||
"""
|
||||
说明:
|
||||
检测ban掉目标的用户与unban用户的权限等级大小
|
||||
参数:
|
||||
:param user_qq: unban用户的qq号
|
||||
:param user_id: unban用户的用户id
|
||||
:param level: ban掉目标用户的权限等级
|
||||
"""
|
||||
user = await cls.filter(user_qq=user_qq).first()
|
||||
user = await cls.filter(user_id=str(user_id)).first()
|
||||
if user:
|
||||
logger.debug(
|
||||
f"检测用户被ban等级,user_level: {user.ban_level},level: {level}",
|
||||
target=user_qq,
|
||||
target=str(user_id),
|
||||
)
|
||||
return bool(user and user.ban_level > level)
|
||||
return False
|
||||
|
||||
@classmethod
|
||||
async def check_ban_time(cls, user_qq: int) -> Union[str, int]:
|
||||
async def check_ban_time(cls, user_id: str | int) -> Union[str, int]:
|
||||
"""
|
||||
说明:
|
||||
检测用户被ban时长
|
||||
参数:
|
||||
:param user_qq: qq号
|
||||
:param user_id: 用户id
|
||||
"""
|
||||
logger.debug(f"获取用户ban时长", target=user_qq)
|
||||
if user := await cls.filter(user_qq=user_qq).first():
|
||||
logger.debug(f"获取用户ban时长", target=str(user_id))
|
||||
if user := await cls.filter(user_id=str(user_id)).first():
|
||||
if (
|
||||
time.time() - (user.ban_time + user.duration) > 0
|
||||
and user.duration != -1
|
||||
@@ -61,64 +61,71 @@ class BanUser(Model):
|
||||
return ""
|
||||
|
||||
@classmethod
|
||||
async def is_ban(cls, user_qq: int) -> bool:
|
||||
async def is_ban(cls, user_id: str | int) -> bool:
|
||||
"""
|
||||
说明:
|
||||
判断用户是否被ban
|
||||
参数:
|
||||
:param user_qq: qq号
|
||||
:param user_id: 用户id
|
||||
"""
|
||||
logger.debug(f"检测是否被ban", target=user_qq)
|
||||
if await cls.check_ban_time(user_qq):
|
||||
logger.debug(f"检测是否被ban", target=str(user_id))
|
||||
if await cls.check_ban_time(str(user_id)):
|
||||
return True
|
||||
else:
|
||||
await cls.unban(user_qq)
|
||||
await cls.unban(user_id)
|
||||
return False
|
||||
|
||||
@classmethod
|
||||
async def is_super_ban(cls, user_qq: int) -> bool:
|
||||
async def is_super_ban(cls, user_id: str | int) -> bool:
|
||||
"""
|
||||
说明:
|
||||
判断用户是否被超级用户ban / b了
|
||||
参数:
|
||||
:param user_qq: qq号
|
||||
:param user_id: 用户id
|
||||
"""
|
||||
logger.debug(f"检测是否被超级用户权限封禁", target=user_qq)
|
||||
if user := await cls.filter(user_qq=user_qq).first():
|
||||
logger.debug(f"检测是否被超级用户权限封禁", target=str(user_id))
|
||||
if user := await cls.filter(user_id=str(user_id)).first():
|
||||
if user.ban_level == 10:
|
||||
return True
|
||||
return False
|
||||
|
||||
@classmethod
|
||||
async def ban(cls, user_qq: int, ban_level: int, duration: int):
|
||||
async def ban(cls, user_id: str | int, ban_level: int, duration: int):
|
||||
"""
|
||||
说明:
|
||||
ban掉目标用户
|
||||
参数:
|
||||
:param user_qq: 目标用户qq号
|
||||
:param user_id: 目标用户id
|
||||
:param ban_level: 使用ban命令用户的权限
|
||||
:param duration: ban时长,秒
|
||||
"""
|
||||
logger.debug(f"封禁用户,等级:{ban_level},时长: {duration}", target=user_qq)
|
||||
if await cls.filter(user_qq=user_qq).first():
|
||||
await cls.unban(user_qq)
|
||||
logger.debug(f"封禁用户,等级:{ban_level},时长: {duration}", target=str(user_id))
|
||||
if await cls.filter(user_id=str(user_id)).first():
|
||||
await cls.unban(user_id)
|
||||
await cls.create(
|
||||
user_qq=user_qq,
|
||||
user_id=str(user_id),
|
||||
ban_level=ban_level,
|
||||
ban_time=time.time(),
|
||||
duration=duration,
|
||||
)
|
||||
|
||||
@classmethod
|
||||
async def unban(cls, user_qq: int) -> bool:
|
||||
async def unban(cls, user_id: str | int) -> bool:
|
||||
"""
|
||||
说明:
|
||||
unban用户
|
||||
参数:
|
||||
:param user_qq: qq号
|
||||
:param user_id: 用户id
|
||||
"""
|
||||
if user := await cls.filter(user_qq=user_qq).first():
|
||||
logger.debug("解除封禁", target=user_qq)
|
||||
if user := await cls.filter(user_id=str(user_id)).first():
|
||||
logger.debug("解除封禁", target=str(user_id))
|
||||
await user.delete()
|
||||
return True
|
||||
return False
|
||||
|
||||
@classmethod
|
||||
async def _run_script(cls):
|
||||
return ["ALTER TABLE ban_users RENAME COLUMN user_qq TO user_id;", # 将user_id改为user_id
|
||||
"ALTER TABLE ban_users ALTER COLUMN user_id TYPE character varying(255);",
|
||||
# 将user_id字段类型改为character varying(255)
|
||||
]
|
||||
|
||||
Reference in New Issue
Block a user