fix GB18030 to UTF-8.

This commit is contained in:
MangataAkihi 2022-03-26 23:43:06 +08:00 committed by GitHub
parent 2aad517112
commit 0adb66a8bf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -16,68 +16,68 @@ except ModuleNotFoundError:
import json import json
__zx_plugin_name__ = "功能调用统计可视化" __zx_plugin_name__ = "功能调用统计可视化"
__plugin_usage__ = """ __plugin_usage__ = """
usage usage
功能调用统计可视化 功能调用统计可视化
指令 指令
功能调用统计 功能调用统计
日功能调用统计 日功能调用统计
周功能调用统计 ?[功能] 周功能调用统计 ?[功能]
月功能调用统计 ?[功能] 月功能调用统计 ?[功能]
我的功能调用统计 我的功能调用统计
我的日功能调用统计 ?[功能] 我的日功能调用统计 ?[功能]
我的周功能调用统计 ?[功能] 我的周功能调用统计 ?[功能]
我的月功能调用统计 ?[功能] 我的月功能调用统计 ?[功能]
""".strip() """.strip()
__plugin_superuser_usage__ = """ __plugin_superuser_usage__ = """
usage usage
功能调用统计可视化 功能调用统计可视化
指令 指令
全局功能调用统计 全局功能调用统计
全局日功能调用统计 全局日功能调用统计
全局周功能调用统计 ?[功能] 全局周功能调用统计 ?[功能]
全局月功能调用统计 ?[功能] 全局月功能调用统计 ?[功能]
""".strip() """.strip()
__plugin_des__ = "功能调用统计可视化" __plugin_des__ = "功能调用统计可视化"
__plugin_cmd__ = [ __plugin_cmd__ = [
"功能调用统计", "功能调用统计",
"全局功能调用统计 [_superuser]", "全局功能调用统计 [_superuser]",
"全局日功能调用统计 [_superuser]", "全局日功能调用统计 [_superuser]",
"全局周功能调用统计 ?[功能] [_superuser]", "全局周功能调用统计 ?[功能] [_superuser]",
"全局月功能调用统计 ?[功能] [_superuser]", "全局月功能调用统计 ?[功能] [_superuser]",
"周功能调用统计 ?[功能]", "周功能调用统计 ?[功能]",
"月功能调用统计 ?[功能]", "月功能调用统计 ?[功能]",
"我的功能调用统计", "我的功能调用统计",
"我的日功能调用统计 ?[功能]", "我的日功能调用统计 ?[功能]",
"我的周功能调用统计 ?[功能]", "我的周功能调用统计 ?[功能]",
"我的月功能调用统计 ?[功能]", "我的月功能调用统计 ?[功能]",
] ]
__plugin_type__ = ("功能调用统计可视化", 1) __plugin_type__ = ("功能调用统计可视化", 1)
__plugin_version__ = 0.1 __plugin_version__ = 0.1
__plugin_author__ = "HibiKier" __plugin_author__ = "HibiKier"
__plugin_settings__ = { __plugin_settings__ = {
"level": 5, "level": 5,
"default_status": True, "default_status": True,
"limit_superuser": False, "limit_superuser": False,
"cmd": ["功能调用统计"], "cmd": ["功能调用统计"],
} }
statistics = on_command( statistics = on_command(
"功能调用统计", "功能调用统计",
aliases={ aliases={
"全局功能调用统计", "全局功能调用统计",
"全局日功能调用统计", "全局日功能调用统计",
"全局周功能调用统计", "全局周功能调用统计",
"全局月功能调用统计", "全局月功能调用统计",
"日功能调用统计", "日功能调用统计",
"周功能调用统计", "周功能调用统计",
"月功能调用统计", "月功能调用统计",
"我的功能调用统计", "我的功能调用统计",
"我的日功能调用统计", "我的日功能调用统计",
"我的周功能调用统计", "我的周功能调用统计",
"我的月功能调用统计", "我的月功能调用统计",
}, },
priority=5, priority=5,
block=True, block=True,
@ -91,14 +91,14 @@ statistics_user_file = DATA_PATH / "statistics" / "_prefix_user_count.json"
@statistics.handle() @statistics.handle()
async def _(bot: Bot, event: MessageEvent, cmd: Tuple[str, ...] = Command(), arg: Message = CommandArg()): async def _(bot: Bot, event: MessageEvent, cmd: Tuple[str, ...] = Command(), arg: Message = CommandArg()):
msg = arg.extract_plain_text().strip() msg = arg.extract_plain_text().strip()
if cmd[0][:2] == "全局": if cmd[0][:2] == "全局":
if str(event.user_id) in bot.config.superusers: if str(event.user_id) in bot.config.superusers:
data: dict = json.load(open(statistics_group_file, "r", encoding="utf8")) data: dict = json.load(open(statistics_group_file, "r", encoding="utf8"))
if cmd[0][2] == '': if cmd[0][2] == '':
_type = 'day_statistics' _type = 'day_statistics'
elif cmd[0][2] == '': elif cmd[0][2] == '':
_type = 'week_statistics' _type = 'week_statistics'
elif cmd[0][2] == '': elif cmd[0][2] == '':
_type = 'month_statistics' _type = 'month_statistics'
else: else:
_type = 'total_statistics' _type = 'total_statistics'
@ -121,26 +121,26 @@ async def _(bot: Bot, event: MessageEvent, cmd: Tuple[str, ...] = Command(), arg
await asyncio.get_event_loop().run_in_executor(None, bar_graph.gen_graph) await asyncio.get_event_loop().run_in_executor(None, bar_graph.gen_graph)
await statistics.finish(image(b64=bar_graph.pic2bs4())) await statistics.finish(image(b64=bar_graph.pic2bs4()))
return return
if cmd[0][:2] == "我的": if cmd[0][:2] == "我的":
_type = "user" _type = "user"
key = str(event.user_id) key = str(event.user_id)
cmd = list(cmd) cmd = list(cmd)
cmd[0] = cmd[0][2:] cmd[0] = cmd[0][2:]
if not statistics_user_file.exists(): if not statistics_user_file.exists():
await statistics.finish("统计文件不存在...", at_sender=True) await statistics.finish("统计文件不存在...", at_sender=True)
else: else:
if not isinstance(event, GroupMessageEvent): if not isinstance(event, GroupMessageEvent):
await statistics.finish("请在群内调用此功能...") await statistics.finish("请在群内调用此功能...")
_type = "group" _type = "group"
key = str(event.group_id) key = str(event.group_id)
if not statistics_group_file.exists(): if not statistics_group_file.exists():
await statistics.finish("统计文件不存在...", at_sender=True) await statistics.finish("统计文件不存在...", at_sender=True)
plugin = "" plugin = ""
if cmd[0][0] == "": if cmd[0][0] == "":
arg = "day_statistics" arg = "day_statistics"
elif cmd[0][0] == "": elif cmd[0][0] == "":
arg = "week_statistics" arg = "week_statistics"
elif cmd[0][0] == "": elif cmd[0][0] == "":
arg = "month_statistics" arg = "month_statistics"
else: else:
arg = "total_statistics" arg = "total_statistics"
@ -148,15 +148,15 @@ async def _(bot: Bot, event: MessageEvent, cmd: Tuple[str, ...] = Command(), arg
plugin = plugins2settings_manager.get_plugin_module(msg) plugin = plugins2settings_manager.get_plugin_module(msg)
if not plugin: if not plugin:
if arg not in ["day_statistics", "total_statistics"]: if arg not in ["day_statistics", "total_statistics"]:
await statistics.finish("未找到此功能的调用...", at_sender=True) await statistics.finish("未找到此功能的调用...", at_sender=True)
if _type == "group": if _type == "group":
data: dict = json.load(open(statistics_group_file, "r", encoding="utf8")) data: dict = json.load(open(statistics_group_file, "r", encoding="utf8"))
if not data[arg].get(str(event.group_id)): if not data[arg].get(str(event.group_id)):
await statistics.finish("该群统计数据不存在...", at_sender=True) await statistics.finish("该群统计数据不存在...", at_sender=True)
else: else:
data: dict = json.load(open(statistics_user_file, "r", encoding="utf8")) data: dict = json.load(open(statistics_user_file, "r", encoding="utf8"))
if not data[arg].get(str(event.user_id)): if not data[arg].get(str(event.user_id)):
await statistics.finish("该用户统计数据不存在...", at_sender=True) await statistics.finish("该用户统计数据不存在...", at_sender=True)
day_index = data["day_index"] day_index = data["day_index"]
data = data[arg][key] data = data[arg][key]
if _type == "group": if _type == "group":
@ -177,7 +177,7 @@ async def generate_statistics_img(
pass pass
bar_graph = None bar_graph = None
if arg == "day_statistics": if arg == "day_statistics":
bar_graph = await init_bar_graph(data, f"{name} 日功能调用统计") bar_graph = await init_bar_graph(data, f"{name} 日功能调用统计")
elif arg == "week_statistics": elif arg == "week_statistics":
if plugin: if plugin:
current_week = day_index % 7 current_week = day_index % 7
@ -205,7 +205,7 @@ async def generate_statistics_img(
bar_graph = BuildMat( bar_graph = BuildMat(
y=count, y=count,
mat_type="line", mat_type="line",
title=f"{name}{plugin} 功能调用统计【为7天统计】", title=f"{name}{plugin} 功能调用统计【为7天统计】",
x_index=week_lst, x_index=week_lst,
display_num=True, display_num=True,
background=[ background=[
@ -215,7 +215,7 @@ async def generate_statistics_img(
bar_color=["*"], bar_color=["*"],
) )
else: else:
bar_graph = await init_bar_graph(update_data(data), f"{name} 周功能调用统计【为7天统计】") bar_graph = await init_bar_graph(update_data(data), f"{name} 周功能调用统计【为7天统计】")
elif arg == "month_statistics": elif arg == "month_statistics":
if plugin: if plugin:
day_index = day_index % 30 day_index = day_index % 30
@ -229,7 +229,7 @@ async def generate_statistics_img(
bar_graph = BuildMat( bar_graph = BuildMat(
y=count, y=count,
mat_type="line", mat_type="line",
title=f"{name}{plugin} 功能调用统计【为30天统计】", title=f"{name}{plugin} 功能调用统计【为30天统计】",
x_index=day_lst, x_index=day_lst,
display_num=True, display_num=True,
background=[ background=[
@ -239,9 +239,9 @@ async def generate_statistics_img(
bar_color=["*"], bar_color=["*"],
) )
else: else:
bar_graph = await init_bar_graph(update_data(data), f"{name} 月功能调用统计【为30天统计】") bar_graph = await init_bar_graph(update_data(data), f"{name} 月功能调用统计【为30天统计】")
elif arg == "total_statistics": elif arg == "total_statistics":
bar_graph = await init_bar_graph(data, f"{name} 功能调用统计") bar_graph = await init_bar_graph(data, f"{name} 功能调用统计")
await asyncio.get_event_loop().run_in_executor(None, bar_graph.gen_graph) await asyncio.get_event_loop().run_in_executor(None, bar_graph.gen_graph)
return bar_graph.pic2bs4() return bar_graph.pic2bs4()
@ -270,10 +270,10 @@ def update_data(data: dict):
tmp_dict = {} tmp_dict = {}
for day in data.keys(): for day in data.keys():
for plugin_name in data[day].keys(): for plugin_name in data[day].keys():
# print(f'{day}{plugin_name} = {data[day][plugin_name]}') # print(f'{day}{plugin_name} = {data[day][plugin_name]}')
if data[day][plugin_name] is not None: if data[day][plugin_name] is not None:
if tmp_dict.get(plugin_name) is None: if tmp_dict.get(plugin_name) is None:
tmp_dict[plugin_name] = 1 tmp_dict[plugin_name] = 1
else: else:
tmp_dict[plugin_name] += data[day][plugin_name] tmp_dict[plugin_name] += data[day][plugin_name]
return tmp_dict return tmp_dict