Skip to content

Commit

Permalink
🩹 精确webui调用统计
Browse files Browse the repository at this point in the history
  • Loading branch information
HibiKier committed Feb 1, 2025
1 parent e992a85 commit 95e8040
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 33 deletions.
11 changes: 7 additions & 4 deletions zhenxun/builtin_plugins/sign_in/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
from zhenxun.models.sign_user import SignUser
from zhenxun.utils.http_utils import AsyncHttpx
from zhenxun.utils.image_utils import BuildImage
from zhenxun.utils.platform import PlatformUtils

from .config import (
SIGN_BACKGROUND_PATH,
Expand All @@ -27,9 +28,9 @@
lik2relation,
)

assert (
len(level2attitude) == len(lik2level) == len(lik2relation)
), "好感度态度、等级、关系长度不匹配!"
assert len(level2attitude) == len(lik2level) == len(lik2relation), (
"好感度态度、等级、关系长度不匹配!"
)

AVA_URL = "http://q1.qlogo.cn/g?b=qq&nk={}&s=160"

Expand Down Expand Up @@ -430,7 +431,9 @@ async def _generate_html_card(
)
now = datetime.now()
data = {
"ava_url": session.user.avatar,
"ava_url": PlatformUtils.get_user_avatar_url(
user.user_id, PlatformUtils.get_platform(session), session.self_id
),
"name": nickname,
"uid": uid,
"sign_count": f"{user.sign_count}",
Expand Down
26 changes: 22 additions & 4 deletions zhenxun/builtin_plugins/web_ui/api/tabs/main/data_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,13 +248,31 @@ def __get_query(
if bot_id:
query = query.filter(bot_id=bot_id)
if date_type == QueryDateType.DAY:
query = query.filter(create_time__gte=now - timedelta(hours=now.hour))
query = query.filter(
create_time__gte=now
- timedelta(hours=now.hour, minutes=now.minute, seconds=now.second)
)
if date_type == QueryDateType.WEEK:
query = query.filter(create_time__gte=now - timedelta(days=7))
query = query.filter(
create_time__gte=now
- timedelta(
days=7, hours=now.hour, minutes=now.minute, seconds=now.second
)
)
if date_type == QueryDateType.MONTH:
query = query.filter(create_time__gte=now - timedelta(days=30))
query = query.filter(
create_time__gte=now
- timedelta(
days=30, hours=now.hour, minutes=now.minute, seconds=now.second
)
)
if date_type == QueryDateType.YEAR:
query = query.filter(create_time__gte=now - timedelta(days=365))
query = query.filter(
create_time__gte=now
- timedelta(
days=365, hours=now.hour, minutes=now.minute, seconds=now.second
)
)
return query

@classmethod
Expand Down
2 changes: 2 additions & 0 deletions zhenxun/configs/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

from .utils import ConfigsManager

__all__ = ["BotConfig", "Config"]


class BotSetting(BaseModel):
self_nickname: str = ""
Expand Down
16 changes: 16 additions & 0 deletions zhenxun/utils/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
Voice,
)
from pydantic import BaseModel
import ujson as json

from zhenxun.configs.config import BotConfig
from zhenxun.services.log import logger
Expand Down Expand Up @@ -141,6 +142,21 @@ def alc_forward_msg(
)
return UniMessage(Reference(nodes=node_list))

@classmethod
def markdown(cls, content: dict) -> Message:
"""markdown格式消息
参数:
content: 消息内容
返回:
Message: 构造完成的消息
"""
content_data = base64.b64encode(json.dumps(content).encode("utf-8")).decode(
"utf-8"
)
return Message(f"[CQ:markdown,data=base64://{content_data}]")

@classmethod
def custom_forward_msg(
cls,
Expand Down
50 changes: 25 additions & 25 deletions zhenxun/utils/platform.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ def is_qbot(cls, session: Uninfo | Bot) -> bool:
"""
if isinstance(session, Bot):
return bool(BotConfig.get_qbot_uid(session.self_id))
if BotConfig.get_qbot_uid(session.self_id):
return True
return session.scope == SupportScope.qq_api

@classmethod
Expand Down Expand Up @@ -354,32 +356,30 @@ async def get_group_list(
返回:
tuple[list[GroupConsole], str]: 群组列表, 平台
"""
if interface := get_interface(bot):
platform = cls.get_platform(bot)
result_list = []
scenes = await interface.get_scenes(SceneType.GROUP)
for scene in scenes:
group_id = scene.id
result_list.append(
GroupConsole(
group_id=scene.id,
group_name=scene.name,
)
if not (interface := get_interface(bot)):
return [], ""
platform = cls.get_platform(bot)
result_list = []
scenes = await interface.get_scenes(SceneType.GROUP)
for scene in scenes:
group_id = scene.id
result_list.append(
GroupConsole(
group_id=scene.id,
group_name=scene.name,
)
if not only_group and platform != "qq":
if channel_list := await interface.get_scenes(
parent_scene_id=group_id
):
for channel in channel_list:
result_list.append(
GroupConsole(
group_id=scene.id,
group_name=channel.name,
channel_id=channel.id,
)
)
return result_list, platform
return [], ""
)
if not only_group and platform != "qq":
if channel_list := await interface.get_scenes(parent_scene_id=group_id):
result_list.extend(
GroupConsole(
group_id=scene.id,
group_name=channel.name,
channel_id=channel.id,
)
for channel in channel_list
)
return result_list, platform

@classmethod
async def update_friend(cls, bot: Bot) -> int:
Expand Down

0 comments on commit 95e8040

Please sign in to comment.