mirror of
https://github.com/zhenxun-org/zhenxun_bot.git
synced 2026-10-21 12:10:13 +08:00
🧱 Update the 'user_qq' field in the database to 'user_id'
This commit is contained in:
+20
-17
@@ -11,9 +11,9 @@ class ChatHistory(Model):
|
||||
|
||||
id = fields.IntField(pk=True, generated=True, auto_increment=True)
|
||||
"""自增id"""
|
||||
user_qq = fields.BigIntField()
|
||||
user_id = fields.CharField(255)
|
||||
"""用户id"""
|
||||
group_id = fields.BigIntField(null=True)
|
||||
group_id = fields.CharField(255, null=True)
|
||||
"""群聊id"""
|
||||
text = fields.TextField(null=True)
|
||||
"""文本内容"""
|
||||
@@ -29,7 +29,7 @@ class ChatHistory(Model):
|
||||
@classmethod
|
||||
async def get_group_msg_rank(
|
||||
cls,
|
||||
gid: int,
|
||||
gid: str | int,
|
||||
limit: int = 10,
|
||||
order: str = "DESC",
|
||||
date_scope: Optional[Tuple[datetime, datetime]] = None,
|
||||
@@ -44,27 +44,27 @@ class ChatHistory(Model):
|
||||
:param date_scope: 日期范围
|
||||
"""
|
||||
o = "-" if order == "DESC" else ""
|
||||
query = cls.filter(group_id=gid)
|
||||
query = cls.filter(group_id=str(gid))
|
||||
if date_scope:
|
||||
query = query.filter(create_time__range=date_scope)
|
||||
return list(
|
||||
await query.annotate(count=Count("user_qq"))
|
||||
await query.annotate(count=Count("user_id"))
|
||||
.order_by(o + "count")
|
||||
.group_by("user_qq")
|
||||
.group_by("user_id")
|
||||
.limit(limit)
|
||||
.values_list("user_qq", "count")
|
||||
.values_list("user_id", "count")
|
||||
) # type: ignore
|
||||
|
||||
@classmethod
|
||||
async def get_group_first_msg_datetime(cls, group_id: int) -> Optional[datetime]:
|
||||
async def get_group_first_msg_datetime(cls, group_id: str | int) -> Optional[datetime]:
|
||||
"""
|
||||
说明:
|
||||
获取群第一条记录消息时间
|
||||
参数:
|
||||
:param group_id: 群聊id
|
||||
:param group_id: 群组id
|
||||
"""
|
||||
if (
|
||||
message := await cls.filter(group_id=group_id)
|
||||
message := await cls.filter(group_id=str(group_id))
|
||||
.order_by("create_time")
|
||||
.first()
|
||||
):
|
||||
@@ -73,8 +73,8 @@ class ChatHistory(Model):
|
||||
@classmethod
|
||||
async def get_message(
|
||||
cls,
|
||||
uid: Optional[int],
|
||||
gid: Optional[int],
|
||||
uid: Union[int, str],
|
||||
gid: Union[int, str],
|
||||
type_: Literal["user", "group"],
|
||||
msg_type: Optional[Literal["private", "group"]] = None,
|
||||
days: Optional[Union[int, Tuple[datetime, datetime]]] = None,
|
||||
@@ -83,22 +83,22 @@ class ChatHistory(Model):
|
||||
说明:
|
||||
获取消息查询query
|
||||
参数:
|
||||
:param uid: 用户qq
|
||||
:param gid: 群号
|
||||
:param uid: 用户id
|
||||
:param gid: 群聊id
|
||||
:param type_: 类型,私聊或群聊
|
||||
:param msg_type: 消息类型,用户或群聊
|
||||
:param days: 限制日期
|
||||
"""
|
||||
if type_ == "user":
|
||||
query = cls.filter(user_qq=uid)
|
||||
query = cls.filter(user_id=str(uid))
|
||||
if msg_type == "private":
|
||||
query = query.filter(group_id__isnull=True)
|
||||
elif msg_type == "group":
|
||||
query = query.filter(group_id__not_isnull=True)
|
||||
else:
|
||||
query = cls.filter(group_id=gid)
|
||||
query = cls.filter(group_id=str(gid))
|
||||
if uid:
|
||||
query = query.filter(user_qq=uid)
|
||||
query = query.filter(user_id=str(uid))
|
||||
if days:
|
||||
if isinstance(days, int):
|
||||
query = query.filter(
|
||||
@@ -114,4 +114,7 @@ class ChatHistory(Model):
|
||||
"alter table chat_history alter group_id drop not null;", # 允许 group_id 为空
|
||||
"alter table chat_history alter text drop not null;", # 允许 text 为空
|
||||
"alter table chat_history alter plain_text drop not null;", # 允许 plain_text 为空
|
||||
"ALTER TABLE chat_history RENAME COLUMN user_qq TO user_id;", # 将user_id改为user_id
|
||||
"ALTER TABLE chat_history ALTER COLUMN user_id TYPE character varying(255);",
|
||||
"ALTER TABLE chat_history ALTER COLUMN group_id TYPE character varying(255);",
|
||||
]
|
||||
|
||||
Reference in New Issue
Block a user