🐛 webui 添加bot详情参数 (#1686)

* 🐛 webui 添加bot详情参数

* chore(version): Update version to v0.2.3-ba3a9f1

---------

Co-authored-by: HibiKier <HibiKier@users.noreply.github.com>
This commit is contained in:
HibiKier 2024-10-07 15:37:55 +08:00 committed by GitHub
parent 856976526f
commit 5f92efa658
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 31 additions and 17 deletions

View File

@ -1 +1 @@
__version__: v0.2.3-f3e5c9e __version__: v0.2.3-ba3a9f1

View File

@ -110,17 +110,22 @@ async def _(bot_id: str | None = None) -> Result:
dependencies=[authentication()], dependencies=[authentication()],
deprecated="获取聊天/调用记录的一个月数量", # type: ignore deprecated="获取聊天/调用记录的一个月数量", # type: ignore
) )
async def _() -> Result: async def _(bot_id: str | None = None) -> Result:
now = datetime.now() now = datetime.now()
filter_date = now - timedelta(days=30, hours=now.hour, minutes=now.minute) filter_date = now - timedelta(days=30, hours=now.hour, minutes=now.minute)
chat_query = ChatHistory
call_query = Statistics
if bot_id:
chat_query = chat_query.filter(bot_id=bot_id)
call_query = call_query.filter(bot_id=bot_id)
chat_date_list = ( chat_date_list = (
await ChatHistory.filter(create_time__gte=filter_date) await chat_query.filter(create_time__gte=filter_date)
.annotate(date=RawSQL("DATE(create_time)"), count=Count("id")) .annotate(date=RawSQL("DATE(create_time)"), count=Count("id"))
.group_by("date") .group_by("date")
.values("date", "count") .values("date", "count")
) )
call_date_list = ( call_date_list = (
await Statistics.filter(create_time__gte=filter_date) await call_query.filter(create_time__gte=filter_date)
.annotate(date=RawSQL("DATE(create_time)"), count=Count("id")) .annotate(date=RawSQL("DATE(create_time)"), count=Count("id"))
.group_by("date") .group_by("date")
.values("date", "count") .values("date", "count")

View File

@ -53,7 +53,8 @@ class BotManage:
bot_info.group_count = len(group_list) bot_info.group_count = len(group_list)
bot_info.friend_count = len(friend_list) bot_info.friend_count = len(friend_list)
bot_info.day_call = await Statistics.filter( bot_info.day_call = await Statistics.filter(
create_time__gte=now - timedelta(hours=now.hour, minutes=now.minute) create_time__gte=now - timedelta(hours=now.hour, minutes=now.minute),
bot_id=bot.self_id,
).count() ).count()
bot_info.received_messages = await ChatHistory.filter( bot_info.received_messages = await ChatHistory.filter(
bot_id=bot_info.self_id, bot_id=bot_info.self_id,

View File

@ -11,11 +11,11 @@ from websockets.exceptions import ConnectionClosedOK, ConnectionClosedError
from starlette.websockets import WebSocket, WebSocketState, WebSocketDisconnect from starlette.websockets import WebSocket, WebSocketState, WebSocketDisconnect
from zhenxun.services.log import logger from zhenxun.services.log import logger
from zhenxun.models.group_info import GroupInfo
from zhenxun.models.statistics import Statistics from zhenxun.models.statistics import Statistics
from zhenxun.utils.platform import PlatformUtils from zhenxun.utils.platform import PlatformUtils
from zhenxun.models.plugin_info import PluginInfo from zhenxun.models.plugin_info import PluginInfo
from zhenxun.models.chat_history import ChatHistory from zhenxun.models.chat_history import ChatHistory
from zhenxun.models.group_console import GroupConsole
from ....base_model import Result from ....base_model import Result
from .data_source import bot_live from .data_source import bot_live
@ -236,17 +236,21 @@ async def _() -> Result:
@router.get( @router.get(
"/get_active_group", dependencies=[authentication()], description="获取活跃群聊" "/get_active_group", dependencies=[authentication()], description="获取活跃群聊"
) )
async def _(date_type: QueryDateType | None = None) -> Result: async def _(
date_type: QueryDateType | None = None, bot_id: str | None = None
) -> Result:
query = ChatHistory query = ChatHistory
now = datetime.now() now = datetime.now()
if bot_id:
query = query.filter(bot_id=bot_id)
if date_type == QueryDateType.DAY: if date_type == QueryDateType.DAY:
query = ChatHistory.filter(create_time__gte=now - timedelta(hours=now.hour)) query = query.filter(create_time__gte=now - timedelta(hours=now.hour))
if date_type == QueryDateType.WEEK: if date_type == QueryDateType.WEEK:
query = ChatHistory.filter(create_time__gte=now - timedelta(days=7)) query = query.filter(create_time__gte=now - timedelta(days=7))
if date_type == QueryDateType.MONTH: if date_type == QueryDateType.MONTH:
query = ChatHistory.filter(create_time__gte=now - timedelta(days=30)) query = query.filter(create_time__gte=now - timedelta(days=30))
if date_type == QueryDateType.YEAR: if date_type == QueryDateType.YEAR:
query = ChatHistory.filter(create_time__gte=now - timedelta(days=365)) query = query.filter(create_time__gte=now - timedelta(days=365))
data_list = ( data_list = (
await query.annotate(count=Count("id")) await query.annotate(count=Count("id"))
.filter(group_id__not_isnull=True) .filter(group_id__not_isnull=True)
@ -257,7 +261,7 @@ async def _(date_type: QueryDateType | None = None) -> Result:
) )
id2name = {} id2name = {}
if data_list: if data_list:
if info_list := await GroupInfo.filter( if info_list := await GroupConsole.filter(
group_id__in=[x[0] for x in data_list] group_id__in=[x[0] for x in data_list]
).all(): ).all():
for group_info in info_list: for group_info in info_list:
@ -282,17 +286,21 @@ async def _(date_type: QueryDateType | None = None) -> Result:
@router.get( @router.get(
"/get_hot_plugin", dependencies=[authentication()], description="获取热门插件" "/get_hot_plugin", dependencies=[authentication()], description="获取热门插件"
) )
async def _(date_type: QueryDateType | None = None) -> Result: async def _(
date_type: QueryDateType | None = None, bot_id: str | None = None
) -> Result:
query = Statistics query = Statistics
now = datetime.now() now = datetime.now()
if bot_id:
query = query.filter(bot_id=bot_id)
if date_type == QueryDateType.DAY: if date_type == QueryDateType.DAY:
query = Statistics.filter(create_time__gte=now - timedelta(hours=now.hour)) query = query.filter(create_time__gte=now - timedelta(hours=now.hour))
if date_type == QueryDateType.WEEK: if date_type == QueryDateType.WEEK:
query = Statistics.filter(create_time__gte=now - timedelta(days=7)) query = query.filter(create_time__gte=now - timedelta(days=7))
if date_type == QueryDateType.MONTH: if date_type == QueryDateType.MONTH:
query = Statistics.filter(create_time__gte=now - timedelta(days=30)) query = query.filter(create_time__gte=now - timedelta(days=30))
if date_type == QueryDateType.YEAR: if date_type == QueryDateType.YEAR:
query = Statistics.filter(create_time__gte=now - timedelta(days=365)) query = query.filter(create_time__gte=now - timedelta(days=365))
data_list = ( data_list = (
await query.annotate(count=Count("id")) await query.annotate(count=Count("id"))
.group_by("plugin_name") .group_by("plugin_name")