This commit is contained in:
ShiXui 2022-10-03 20:21:24 +08:00
parent ffcd7992dd
commit 95c937203d
3 changed files with 18 additions and 15 deletions

View File

@ -167,24 +167,26 @@ async def handle_message(
st = time.time()
if isinstance(event,GroupMessageEvent):
bot_id = await bot.call_api('get_login_info')
bot_id = [str(bot_id['user_id'])]
if plugin_config.dialectlist_excluded_self:
bot_id:str = await bot.call_api('get_login_info')
plugin_config.dialectlist_excluded_people.append(bot_id)
gids:List[str] = [str(event.group_id)]
msg_list = await get_message_records(
group_ids=gids,
exclude_user_ids=bot_id,
exclude_user_ids=plugin_config.dialectlist_excluded_people,
message_type='group',
time_start=start.astimezone(ZoneInfo("UTC")),
time_stop=stop.astimezone(ZoneInfo("UTC"))
)
elif isinstance(event, GuildMessageEvent):
if plugin_config.dialectlist_excluded_self:
bot_id = await bot.call_api('get_guild_service_profile')
bot_id = [str(bot_id['tiny_id'])]
plugin_config.dialectlist_excluded_people.append(bot_id)
guild_ids:List[str] = await get_guild_all_channel(event.guild_id,bot=bot)
msg_list = await get_message_records(
group_ids=guild_ids,
exclude_user_ids=bot_id,
exclude_user_ids=plugin_config.dialectlist_excluded_people,
message_type='group',
time_start=start.astimezone(ZoneInfo("UTC")),
time_stop=stop.astimezone(ZoneInfo("UTC"))
@ -199,5 +201,5 @@ async def handle_message(
await rankings.send(msg)
await asyncio.sleep(1) #让图片先发出来
await rankings.finish(plugin_config.dialectlist_string_suffix_format.format(timecost=time.time()-st-1))
await rankings.finish(plugin_config.dialectlist_string_suffix_format.format(timeCost=time.time()-st-1))

View File

@ -1,4 +1,4 @@
from typing import Optional, Union, Literal
from typing import Optional, Literal, List
from nonebot import get_driver
from pydantic import BaseModel, Extra
@ -6,11 +6,14 @@ from pydantic import BaseModel, Extra
class Config(BaseModel, extra=Extra.ignore):
timezone: Optional[str]
dialectlist_string_format: str = '{index}名:\n{nickname},{chatdatanum}条消息\n' #消息格式
dialectlist_string_suffix_format: str = '你们的职业是水群吗————MYX\n计算花费时间:{timecost}' #消息后缀格式
dialectlist_string_format: str = '{index}名:\n{nickname},{chatDataNum}条消息\n' #消息格式
dialectlist_string_suffix_format: str = '你们的职业是水群吗————MYX\n计算花费时间:{timeCost}' #消息后缀格式
dialectlist_get_num:int = 10 #获取人数数量
dialectlist_visualization:bool = True #是否可视化
dialectlist_visualization_type:Literal['饼图','圆环图','柱状图'] = '圆环图' #可视化方案
dialectlist_font:str = 'SimHei'#字体格式
dialectlist_excluded_people:List[str] = []#排除的人的QQ号(或频道号?(未经测试))
dialectlist_excluded_self:bool = True
global_config = get_driver().config
plugin_config = Config.parse_obj(global_config)
plugin_config = Config(**global_config.dict())

View File

@ -1,4 +1,3 @@
import time
import pygal
import unicodedata
@ -7,7 +6,6 @@ from sqlmodel import select, or_
from typing_extensions import Literal
from typing import Iterable, List, Optional, Dict
from pygal.style import Style
style=Style(font_family="SimHei",)
from nonebot.log import logger
from nonebot.adapters import Bot
@ -18,7 +16,7 @@ from nonebot_plugin_datastore import create_session
from nonebot_plugin_chatrecorder.model import MessageRecord
from .config import plugin_config
style=Style(font_family=plugin_config.dialectlist_font)
def remove_control_characters(string:str) -> str:
@ -185,7 +183,7 @@ async def msg_list2msg(
for i in range(got_num):
index = i+1
nickname,chatdatanum = ranking[i]
str_example = plugin_config.dialectlist_string_format.format(index=index,nickname=nickname,chatdatanum=chatdatanum)
str_example = plugin_config.dialectlist_string_format.format(index=index,nickname=nickname,chatDataNum=chatdatanum)
out = out + str_example
logger.debug(out)