简单测试过的产物

This commit is contained in:
unknown 2023-04-09 10:09:01 +08:00
parent bd1589246e
commit 5a3ac8dac0
2 changed files with 21 additions and 22 deletions

View File

@ -119,7 +119,7 @@ async def _group_message(
@ranks.handle() @ranks.handle()
async def _private_message( async def _private_message(
matcher: Matcher, matcher: Matcher,
event: Union[V11Event.GroupMessageEvent, V12Event.GroupMessageEvent], event: Union[V11Event.PrivateMessageEvent, V12Event.PrivateMessageEvent],
state: T_State, state: T_State,
commands: Tuple[str, ...] = Command(), commands: Tuple[str, ...] = Command(),
args: Union[V11Message, V12Message] = CommandArg(), args: Union[V11Message, V12Message] = CommandArg(),
@ -156,7 +156,9 @@ async def handle_message(
plugin_config.dialectlist_excluded_people.append(bot_id["user_id"]) plugin_config.dialectlist_excluded_people.append(bot_id["user_id"])
msg_list = await get_message_records( msg_list = await get_message_records(
bot_ids=[str(bot.self_id)], bot_ids=[str(bot.self_id)],
platforms=[str(bot.platform)], platforms=['qq']
if isinstance(event, V11Event.GroupMessageEvent)
else [str(bot.platform)],
group_ids=[str(event.group_id)] group_ids=[str(event.group_id)]
if isinstance(event, (V11Event.GroupMessageEvent, V12Event.GroupMessageEvent)) if isinstance(event, (V11Event.GroupMessageEvent, V12Event.GroupMessageEvent))
else None, else None,
@ -167,13 +169,15 @@ async def handle_message(
time_start=start.astimezone(ZoneInfo("UTC")), time_start=start.astimezone(ZoneInfo("UTC")),
time_stop=stop.astimezone(ZoneInfo("UTC")), time_stop=stop.astimezone(ZoneInfo("UTC")),
) )
for i in msg_list:
logger.debug(i.plain_text)
if isinstance(event, V11Event.GroupMessageEvent): if isinstance(event, V11Event.GroupMessageEvent):
processer = V11GroupMsgProcesser(bot=bot, gid=str(event.group_id), msg_list=msg_list) # type: ignore processer = V11GroupMsgProcesser(bot=bot, gid=str(event.group_id), msg_list=msg_list) # type: ignore
elif isinstance(event, V12Event.GroupMessageEvent): elif isinstance(event, V12Event.GroupMessageEvent):
processer = V12GroupMsgProcesser(bot=bot, gid=str(event.group_id), msg_list=msg_list) # type: ignore processer = V12GroupMsgProcesser(bot=bot, gid=str(event.group_id), msg_list=msg_list) # type: ignore
elif isinstance(event, V12Event.ChannelMessageEvent): elif isinstance(event, V12Event.ChannelMessageEvent):
pass processer = V12GuildMsgProcesser(bot=bot, gid=str(event.guild_id), msg_list=msg_list) # type: ignore
else: else:
raise NotImplementedError("没支持呢(())") raise NotImplementedError("没支持呢(())")

View File

@ -21,16 +21,6 @@ try:
except ImportError: except ImportError:
from backports.zoneinfo import ZoneInfo # type: ignore from backports.zoneinfo import ZoneInfo # type: ignore
require("nonebot_plugin_htmlrender")
from nonebot_plugin_htmlrender import (
md_to_pic,
html_to_pic,
text_to_pic,
capture_element,
template_to_pic,
template_to_html,
)
require("nonebot_plugin_chatrecorder") require("nonebot_plugin_chatrecorder")
from nonebot_plugin_chatrecorder import get_message_records from nonebot_plugin_chatrecorder import get_message_records
from nonebot_plugin_chatrecorder.model import MessageRecord from nonebot_plugin_chatrecorder.model import MessageRecord
@ -129,6 +119,7 @@ def got_rank(msg_dict: Dict[str, int]) -> List[List[Union[str, int]]]:
try: try:
max_key = max(msg_dict.items(), key=lambda x: x[1]) max_key = max(msg_dict.items(), key=lambda x: x[1])
rank.append(list(max_key)) rank.append(list(max_key))
msg_dict.pop(max_key[0])
except ValueError: except ValueError:
rank.append(["null", 0]) rank.append(["null", 0])
continue continue
@ -167,7 +158,7 @@ class MsgProcesser(abc.ABC):
pic_msg = None pic_msg = None
if plugin_config.dialectlist_visualization: if plugin_config.dialectlist_visualization:
try: try:
pic_msg = self.render_template_pic() pic_msg = await self.render_template_pic()
except OSError: except OSError:
plugin_config.dialectlist_visualization = False plugin_config.dialectlist_visualization = False
str_msg += "\n\n无法发送可视化图片请检查是否安装GTK+详细安装教程可见github\nhttps://github.com/tschoonj/GTK-for-Windows-Runtime-Environment-Installer \n若不想安装这个软件,再次使用这个指令不会显示这个提示" str_msg += "\n\n无法发送可视化图片请检查是否安装GTK+详细安装教程可见github\nhttps://github.com/tschoonj/GTK-for-Windows-Runtime-Environment-Installer \n若不想安装这个软件,再次使用这个指令不会显示这个提示"
@ -180,7 +171,7 @@ class MsgProcesser(abc.ABC):
nicknames: List = await self.get_nickname_list() nicknames: List = await self.get_nickname_list()
for i in range(len(rank)): for i in range(len(rank)):
index = i + 1 index = i + 1
nickname, chatdatanum = nicknames[i], rank[i] nickname, chatdatanum = nicknames[i], rank[i][1]
str_example = plugin_config.dialectlist_string_format.format( str_example = plugin_config.dialectlist_string_format.format(
index=index, nickname=nickname, chatdatanum=chatdatanum index=index, nickname=nickname, chatdatanum=chatdatanum
) )
@ -188,7 +179,7 @@ class MsgProcesser(abc.ABC):
return string return string
def render_template_pic(self) -> bytes: async def render_template_pic(self) -> bytes:
if plugin_config.dialectlist_visualization_type == "圆环图": if plugin_config.dialectlist_visualization_type == "圆环图":
view = pygal.Pie(inner_radius=0.6, style=style) view = pygal.Pie(inner_radius=0.6, style=style)
elif plugin_config.dialectlist_visualization_type == "饼图": elif plugin_config.dialectlist_visualization_type == "饼图":
@ -197,7 +188,7 @@ class MsgProcesser(abc.ABC):
view = pygal.Bar(style=style) view = pygal.Bar(style=style)
view.title = "消息可视化" view.title = "消息可视化"
for i, j in zip(self.rank, self.get_nickname_list()): # type: ignore for i, j in zip(self.rank, await self.get_nickname_list()): # type: ignore
view.add(str(j), int(i[1])) view.add(str(j), int(i[1]))
png: bytes = view.render_to_png() # type: ignore png: bytes = view.render_to_png() # type: ignore
@ -217,13 +208,15 @@ class V11GroupMsgProcesser(MsgProcesser):
member_info = await self.bot.get_group_member_info( member_info = await self.bot.get_group_member_info(
group_id=int(self.gid), user_id=int(self.rank[i][0]), no_cache=True group_id=int(self.gid), user_id=int(self.rank[i][0]), no_cache=True
) )
nicknames.append( nickname=(
member_info["nickname"] member_info["nickname"]
if not member_info["card"] if not member_info["card"]
else member_info["card"] else member_info["card"]
) )
except ActionFailed as e: nicknames.append(remove_control_characters(nickname))
except (ActionFailed,ValueError) as e:
nicknames.append("{}这家伙不在群里了".format(self.rank[i][0])) nicknames.append("{}这家伙不在群里了".format(self.rank[i][0]))
return nicknames return nicknames
def get_head_portrait_urls(self) -> List: def get_head_portrait_urls(self) -> List:
@ -237,7 +230,7 @@ class V11GroupMsgProcesser(MsgProcesser):
msgs: List = await self.get_msg() msgs: List = await self.get_msg()
msg = V11Message() msg = V11Message()
msg += V11MessageSegment.text(msgs[0]) # type: ignore msg += V11MessageSegment.text(msgs[0]) # type: ignore
msg += V12MessageSegment.image(msgs[1]) # type: ignore msg += V11MessageSegment.image(msgs[1]) # type: ignore
return msg return msg
@ -268,11 +261,12 @@ class V12GroupMsgProcesser(V12MsgProcesser):
member_info = await self.bot.get_group_member_info( member_info = await self.bot.get_group_member_info(
group_id=str(self.gid), user_id=str(self.rank[i][0]), no_cache=True group_id=str(self.gid), user_id=str(self.rank[i][0]), no_cache=True
) )
nicknames.append( nickname=(
member_info["user_displayname"] member_info["user_displayname"]
if member_info["user_displayname"] if member_info["user_displayname"]
else member_info["user_name"] else member_info["user_name"]
) )
nicknames.append(remove_control_characters(nickname))
except ActionFailed as e: except ActionFailed as e:
nicknames.append("{}这家伙不在群里了".format(self.rank[i][0])) nicknames.append("{}这家伙不在群里了".format(self.rank[i][0]))
return nicknames return nicknames
@ -289,11 +283,12 @@ class V12GuildMsgProcesser(V12MsgProcesser):
member_info = await self.bot.get_guild_member_info( member_info = await self.bot.get_guild_member_info(
guild_id=str(self.gid), user_id=str(self.rank[i][0]), no_cache=True guild_id=str(self.gid), user_id=str(self.rank[i][0]), no_cache=True
) )
nicknames.append( nickname=(
member_info["user_displayname"] member_info["user_displayname"]
if member_info["user_displayname"] if member_info["user_displayname"]
else member_info["user_name"] else member_info["user_name"]
) )
nicknames.append(remove_control_characters(nickname))
except ActionFailed as e: except ActionFailed as e:
nicknames.append("{}这家伙不在群里了".format(self.rank[i][0])) nicknames.append("{}这家伙不在群里了".format(self.rank[i][0]))
return nicknames return nicknames