🚑 语法适配到python3.8以上

This commit is contained in:
yajiwa 2023-04-22 21:14:51 +08:00
parent 03cfeb22d8
commit 8c65caf35f
7 changed files with 35 additions and 35 deletions

View File

@ -1,4 +1,4 @@
from typing import Dict
from typing import Dict, Union
from tortoise import fields
@ -34,7 +34,7 @@ class BagUser(Model):
unique_together = ("user_id", "group_id")
@classmethod
async def get_user_total_gold(cls, user_id: str | int, group_id: str | int) -> str:
async def get_user_total_gold(cls, user_id: Union[int, str], group_id: Union[int, str]) -> str:
"""
说明:
获取金币概况
@ -50,7 +50,7 @@ class BagUser(Model):
)
@classmethod
async def get_gold(cls, user_id: str | int, group_id: str | int) -> int:
async def get_gold(cls, user_id: Union[int, str], group_id: Union[int, str]) -> int:
"""
说明:
获取当前金币
@ -63,7 +63,7 @@ class BagUser(Model):
@classmethod
async def get_property(
cls, user_id: str | int, group_id: str | int, only_active: bool = False
cls, user_id: Union[int, str], group_id: Union[int, str], only_active: bool = False
) -> Dict[str, int]:
"""
说明:
@ -87,7 +87,7 @@ class BagUser(Model):
return user.property
@classmethod
async def add_gold(cls, user_id: str | int, group_id: str | int, num: int):
async def add_gold(cls, user_id: Union[int, str], group_id: Union[int, str], num: int):
"""
说明:
增加金币
@ -103,7 +103,7 @@ class BagUser(Model):
await user.save(update_fields=["gold", "get_today_gold", "get_total_gold"])
@classmethod
async def spend_gold(cls, user_id: str | int, group_id: str | int, num: int):
async def spend_gold(cls, user_id: Union[int, str], group_id: Union[int, str], num: int):
"""
说明:
花费金币
@ -119,7 +119,7 @@ class BagUser(Model):
await user.save(update_fields=["gold", "spend_total_gold", "spend_today_gold"])
@classmethod
async def add_property(cls, user_id: str | int, group_id: str | int, name: str, num: int = 1):
async def add_property(cls, user_id: Union[int, str], group_id: Union[int, str], name: str, num: int = 1):
"""
说明:
增加道具
@ -139,7 +139,7 @@ class BagUser(Model):
@classmethod
async def delete_property(
cls, user_id: str | int, group_id: str | int, name: str, num: int = 1
cls, user_id: Union[int, str], group_id: Union[int, str], name: str, num: int = 1
) -> bool:
"""
说明:

View File

@ -23,7 +23,7 @@ class BanUser(Model):
table_description = ".ban/b了 封禁人员数据表"
@classmethod
async def check_ban_level(cls, user_id: str | int, level: int) -> bool:
async def check_ban_level(cls, user_id: Union[int, str], level: int) -> bool:
"""
说明:
检测ban掉目标的用户与unban用户的权限等级大小
@ -41,7 +41,7 @@ class BanUser(Model):
return False
@classmethod
async def check_ban_time(cls, user_id: str | int) -> Union[str, int]:
async def check_ban_time(cls, user_id: Union[int, str]) -> Union[str, int]:
"""
说明:
检测用户被ban时长
@ -61,7 +61,7 @@ class BanUser(Model):
return ""
@classmethod
async def is_ban(cls, user_id: str | int) -> bool:
async def is_ban(cls, user_id: Union[int, str]) -> bool:
"""
说明:
判断用户是否被ban
@ -76,7 +76,7 @@ class BanUser(Model):
return False
@classmethod
async def is_super_ban(cls, user_id: str | int) -> bool:
async def is_super_ban(cls, user_id: Union[int, str]) -> bool:
"""
说明:
判断用户是否被超级用户ban / b了
@ -90,7 +90,7 @@ class BanUser(Model):
return False
@classmethod
async def ban(cls, user_id: str | int, ban_level: int, duration: int):
async def ban(cls, user_id: Union[int, str], ban_level: int, duration: int):
"""
说明:
ban掉目标用户
@ -110,7 +110,7 @@ class BanUser(Model):
)
@classmethod
async def unban(cls, user_id: str | int) -> bool:
async def unban(cls, user_id: Union[int, str]) -> bool:
"""
说明:
unban用户

View File

@ -29,7 +29,7 @@ class ChatHistory(Model):
@classmethod
async def get_group_msg_rank(
cls,
gid: str | int,
gid: Union[int, str],
limit: int = 10,
order: str = "DESC",
date_scope: Optional[Tuple[datetime, datetime]] = None,
@ -56,7 +56,7 @@ class ChatHistory(Model):
) # type: ignore
@classmethod
async def get_group_first_msg_datetime(cls, group_id: str | int) -> Optional[datetime]:
async def get_group_first_msg_datetime(cls, group_id: Union[int, str]) -> Optional[datetime]:
"""
说明:
获取群第一条记录消息时间

View File

@ -1,5 +1,5 @@
from tortoise import fields
from typing import Union
from configs.config import Config
from services.db_context import Model
@ -20,7 +20,7 @@ class FriendUser(Model):
table_description = "好友信息数据表"
@classmethod
async def get_user_name(cls, user_id: str | int) -> str:
async def get_user_name(cls, user_id: Union[int, str]) -> str:
"""
说明:
获取好友用户名称
@ -32,7 +32,7 @@ class FriendUser(Model):
return ""
@classmethod
async def get_user_nickname(cls, user_id: str | int) -> str:
async def get_user_nickname(cls, user_id: Union[int, str]) -> str:
"""
说明:
获取用户昵称
@ -49,7 +49,7 @@ class FriendUser(Model):
return ""
@classmethod
async def set_user_nickname(cls, user_id: str | int, nickname: str):
async def set_user_nickname(cls, user_id: Union[int, str], nickname: str):
"""
说明:
设置用户昵称

View File

@ -1,4 +1,4 @@
from typing import Dict, List, Optional, Tuple
from typing import Dict, List, Optional, Tuple, Union
from tortoise import fields
@ -145,7 +145,7 @@ class GoodsInfo(Model):
@classmethod
async def add_user_daily_purchase(
cls, goods: "GoodsInfo", user_id_: int, group_id_: int, num: int = 1
cls, goods: "GoodsInfo", user_id_: Union[int, str], group_id_: Union[int, str], num: int = 1
):
"""
说明:
@ -168,7 +168,7 @@ class GoodsInfo(Model):
@classmethod
async def check_user_daily_purchase(
cls, goods: "GoodsInfo", user_id_: int, group_id_: int, num: int = 1
cls, goods: "GoodsInfo", user_id_: Union[int, str], group_id_: Union[int, str], num: int = 1
) -> Tuple[bool, int]:
"""
说明:

View File

@ -1,5 +1,5 @@
from datetime import datetime
from typing import List, Optional, Set
from typing import List, Optional, Set, Union
from tortoise import fields
@ -31,7 +31,7 @@ class GroupInfoUser(Model):
unique_together = ("user_id", "group_id")
@classmethod
async def get_group_member_id_list(cls, group_id: str | int) -> Set[int]:
async def get_group_member_id_list(cls, group_id: Union[int, str]) -> Set[int]:
"""
说明:
获取该群所有用户id
@ -43,7 +43,7 @@ class GroupInfoUser(Model):
) # type: ignore
@classmethod
async def set_user_nickname(cls, user_id: str | int, group_id: str | int, nickname: str):
async def set_user_nickname(cls, user_id: Union[int, str], group_id: Union[int, str], nickname: str):
"""
说明:
设置群员在该群内的昵称
@ -59,7 +59,7 @@ class GroupInfoUser(Model):
)
@classmethod
async def get_user_all_group(cls, user_id: str | int) -> List[int]:
async def get_user_all_group(cls, user_id: Union[int, str]) -> List[int]:
"""
说明:
获取该用户所在的所有群聊
@ -71,7 +71,7 @@ class GroupInfoUser(Model):
) # type: ignore
@classmethod
async def get_user_nickname(cls, user_id: str | int, group_id: str | int) -> str:
async def get_user_nickname(cls, user_id: Union[int, str], group_id: Union[int, str]) -> str:
"""
说明:
获取用户在该群的昵称
@ -90,7 +90,7 @@ class GroupInfoUser(Model):
return ""
@classmethod
async def get_group_member_uid(cls, user_id: str | int, group_id: str | int) -> Optional[int]:
async def get_group_member_uid(cls, user_id: Union[int, str], group_id: Union[int, str]) -> Optional[int]:
logger.debug(
f"GroupInfoUser 尝试获取 用户[<u><e>{user_id}</e></u>] 群聊[<u><e>{group_id}</e></u>] UID"
)

View File

@ -1,7 +1,7 @@
from tortoise import fields
from services.db_context import Model
from typing import Union
class LevelUser(Model):
@ -22,7 +22,7 @@ class LevelUser(Model):
unique_together = ("user_id", "group_id")
@classmethod
async def get_user_level(cls, user_id: str | int, group_id: str | int) -> int:
async def get_user_level(cls, user_id: Union[int, str], group_id: Union[int, str]) -> int:
"""
说明:
获取用户在群内的等级
@ -36,7 +36,7 @@ class LevelUser(Model):
@classmethod
async def set_level(
cls, user_id: str | int, group_id: str | int, level: int, group_flag: int = 0
cls, user_id: Union[int, str], group_id: Union[int, str], level: int, group_flag: int = 0
):
"""
说明:
@ -54,7 +54,7 @@ class LevelUser(Model):
)
@classmethod
async def delete_level(cls, user_id: str | int, group_id: str | int) -> bool:
async def delete_level(cls, user_id: Union[int, str], group_id: Union[int, str]) -> bool:
"""
说明:
删除用户权限
@ -68,7 +68,7 @@ class LevelUser(Model):
return False
@classmethod
async def check_level(cls, user_id: str | int, group_id: str | int, level: int) -> bool:
async def check_level(cls, user_id: Union[int, str], group_id: Union[int, str], level: int) -> bool:
"""
说明:
检查用户权限等级是否大于 level
@ -87,7 +87,7 @@ class LevelUser(Model):
return False
@classmethod
async def is_group_flag(cls, user_id: str | int, group_id: str | int) -> bool:
async def is_group_flag(cls, user_id: Union[int, str], group_id: Union[int, str]) -> bool:
"""
说明:
检测是否会被自动更新刷新权限