From 9c1cf5639a1ab6247bcbfaddd1f2f7dd33bd7edb Mon Sep 17 00:00:00 2001 From: ictye <95436661+northgreen@users.noreply.github.com> Date: Fri, 2 Feb 2024 16:20:16 +0800 Subject: [PATCH] Dev (#19) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 優化前端效果 *修復幾個bug * 完善日志系统,增加并完善一个api --- ictye-live-dm/.coverage | Bin 53248 -> 0 bytes .../config/plugin/b_dm_plugin/config.yaml | 1 - ictye-live-dm/config/system/config.yaml | 2 +- ictye-live-dm/depends/configs.py | 1 - ictye-live-dm/depends/logger.py | 7 ++- ictye-live-dm/depends/plugin_main.py | 34 +++++++---- ictye-live-dm/livewebsocket.py | 1 - ictye-live-dm/pluginsystem.py | 10 ++-- ictye-live-dm/test/empathy_dir/ignore | 1 - .../no_main_plugin-error.py | 18 ------ .../test_plugin/anaylazer_demo/__init__.py | 24 -------- .../message_plugin_demo/__init__.py | 56 ------------------ ictye-live-dm/web/js/lib/dm_writer.js | 1 + .../web/js/plugin/default_plugin_mather.js | 7 +-- ictye-live-dm/web/style/default_style.css | 3 + libs/bilibili_dm_plugin | 2 +- makefile | 0 17 files changed, 39 insertions(+), 129 deletions(-) delete mode 100644 ictye-live-dm/.coverage delete mode 100644 ictye-live-dm/config/plugin/b_dm_plugin/config.yaml delete mode 100644 ictye-live-dm/test/empathy_dir/ignore delete mode 100644 ictye-live-dm/test/test_no_main_error/no_main_plugin-error.py delete mode 100644 ictye-live-dm/test/test_plugin/anaylazer_demo/__init__.py delete mode 100644 ictye-live-dm/test/test_plugin/message_plugin_demo/__init__.py delete mode 100644 makefile diff --git a/ictye-live-dm/.coverage b/ictye-live-dm/.coverage deleted file mode 100644 index 016b77f680f1b6f6174da323dd21d672034944d4..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 53248 zcmeI4Uu+yl9mjWX*SGg)*JH<+!7HA=t%0w4eaAaG|B z=q&15Wo%4-{!@`%Z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tww8Yp+K@KyOXu-G=!)p zG!iwr3sGq=2{WMQ^GV{z@+5I$_Y#H4k+_czkhtMK#3hPt@IR`OoY6kyWc-_cgI)(j z8tqp|lH7+RH;j=#oTKt1eUumD^fa%Ae(gCPks^yS3EG{NZWk%;{~P7=l5y5}X7IPh zKL-yp&L#)H%FdO~>)+HLG~)Ldyk#dlC^yfB8wZGj${C=93*nC}1c538Nwe#C9t{|_vvozZ^eWNK~f|J8@o zj@*x=bpNj$RXZd7l;6Ht&r#n^75gCF9opMP;{AVj`f`Exg8&GC00@8p2!H?xfB*=9 z00`XX1Qc133~~QoW>+Qp-~a&-009sH0T2KI5C8!X009sH0T8$i2`GwDjGzB!`z7`U z`xASO{e*p+eVMJZPqT=fU{A55l!OBWKmY_l00ck)1V8`;KmY_l00i!E0tG{ri+c>o zRCJv}@7ARYS0~Tp4;9KHzAT;j!k!X^?xnlzpZ(t2)l2`m^!4>W4i}0dwJ4ooT7g1C zg*`(BO+;y*n;(2B8BQFF!4*9qET=P8rkR^WFi9-#;K-uzvN|@BZS|J+eT5 z;0K2ak|{~5TF9%EKB&HbSRwx& dict: """ 读取插件的配置 """ - print(os.path.abspath(f"./config/plugin/{config_family}/config.yaml")) configs = {} if os.path.exists(f"./config/plugin/{config_family}/config.yaml"): with open(f"./config/plugin/{config_family}/config.yaml", "r", encoding="utf_8") as f: diff --git a/ictye-live-dm/depends/logger.py b/ictye-live-dm/depends/logger.py index a7b9c4e..4ea5c18 100644 --- a/ictye-live-dm/depends/logger.py +++ b/ictye-live-dm/depends/logger.py @@ -1,5 +1,7 @@ import logging -import datetime + +import time + import os @@ -23,7 +25,8 @@ def setup_logging(config: dict): os.makedirs('logs') fh = logging.FileHandler( - os.path.join('logs', config["logfile"]["name"] + datetime.time().strftime("%Y%m%d_%H%M%S") + ".log"), + os.path.join('logs', config["logfile"]["name"] + time.strftime("%Y%m%d_%H%M%S",time.localtime()) + ".log"), + encoding="utf-8") fh.setLevel(level_dic[config["loglevel"]]) diff --git a/ictye-live-dm/depends/plugin_main.py b/ictye-live-dm/depends/plugin_main.py index 9a7490b..d0a0621 100644 --- a/ictye-live-dm/depends/plugin_main.py +++ b/ictye-live-dm/depends/plugin_main.py @@ -26,20 +26,31 @@ def __init__(self): 不要用这个而是用plugin_init来进行插件的初始化,这个仅供内部使用 """ self.stop: bool = False - self.plugin_js_sprit_support: bool = False # js插件支持 - self.plugin_js_sprit: str = "" # js插件 + """停止标志""" - self.type: str = str() # 插件类型 + self.plugin_js_sprit_support: bool = False + """js插件支持""" - self.config: dict = dict() # 配置 + self.plugin_js_sprit: str = "" + """js插件""" - self.sprit_cgi_support = False # 插件cgi支持 + self.type: str = str() + """插件类型""" - self.sprit_cgi_lists: {} = {} # cgi列表 + self.config: dict = dict() + """配置字典""" - self.plugin_name: str = "" # 插件名称 + self.sprit_cgi_support = False + """插件cgi支持""" - self.web: web = web # web模块 + self.sprit_cgi_lists: dict = dict() + """cgi列表""" + + self.plugin_name: str = "" + """插件名称""" + + self.web: web = web + """web前端模块""" if self.plugin_type() == "message": self.message_list = [] @@ -64,7 +75,6 @@ async def plugin_main(self): async def message_filter(self, message) -> msgs.msg_box: """ - 消息过滤器,用于自动处理消息,比如翻译或者敏感词过滤 :param message:待处理的消息 :return 消息 @@ -73,11 +83,9 @@ async def message_filter(self, message) -> msgs.msg_box: return message async def message_anaylazer(self, message): - """ 消息分析 """ - pass async def sprit_cgi(self, request): @@ -100,12 +108,12 @@ def dm_iter(self, params: dict, connect_waper: connects.connect_wrapper) -> obje return self @typing.final - def update_config(self): + def update_config(self, config: dict): """ 更新配置,将自身的配置写入文件并且保存在计算机上 """ assert self.plugin_name != "" - configs.set_config(self.plugin_name, self.config) + configs.set_config(self.plugin_name, config) @typing.final def read_config(self): diff --git a/ictye-live-dm/livewebsocket.py b/ictye-live-dm/livewebsocket.py index 5e5c868..1ef372b 100644 --- a/ictye-live-dm/livewebsocket.py +++ b/ictye-live-dm/livewebsocket.py @@ -17,7 +17,6 @@ async def websockets(websocket: server.WebSocketServerProtocol): websocket消息处理主函数 """ # 连接检测 - try: async for message in websocket: loggers.info("receive a message" + message) diff --git a/ictye-live-dm/pluginsystem.py b/ictye-live-dm/pluginsystem.py index eb6bc82..2228b83 100644 --- a/ictye-live-dm/pluginsystem.py +++ b/ictye-live-dm/pluginsystem.py @@ -49,8 +49,10 @@ def __init__(self): plugin_module = importlib.import_module(f'{pathname}.{plugin_name}') + # 合法性检查 if not hasattr(plugin_module, "Plugin_Main"): raise plugin_errors.NoMainMather("函数未实现主方法或者主方法名称错误") + plugin_class = getattr(plugin_module, "Plugin_Main") plugin_interface: plugin_main.Plugin_Main = plugin_class() @@ -86,20 +88,17 @@ async def get_plugin_message(self, params, connect: WebSocketServerProtocol): """ 弹幕对象迭代器,迭代对应参数的弹幕 """ - - # FIXME:TM死bug,不知道为什么有时候总是会在消息插件加载完毕之前把它存进字典,按道理来说不能啊。。。。。。。。。 - if connect.id in self.connect_id_dict.keys(): + # 已经缓存消息迭代器 for dm_iter in self.connect_id_dict[connect.id]: - async for _dm in dm_iter: self.logger.debug("get a dm:", _dm) yield _dm else: + # 获取未缓存的消息迭代器 self.connect_id_dict[connect.id] = [] for plugin in self.message_plugin_list: dm = plugin.dm_iter(params, connects.connect_wrapper(connect)) - if dm is None: continue self.connect_id_dict[connect.id].append(dm) @@ -120,7 +119,6 @@ async def message_filter(self, message) -> dict: :return: 处理后的消息对象 :rtype: Message_Object """ - # 消息过滤 message_filtered = message for plugins in self.analyzer_plugin_list: if not plugins: diff --git a/ictye-live-dm/test/empathy_dir/ignore b/ictye-live-dm/test/empathy_dir/ignore deleted file mode 100644 index c914302..0000000 --- a/ictye-live-dm/test/empathy_dir/ignore +++ /dev/null @@ -1 +0,0 @@ -你tm就不能忽略我?????????? \ No newline at end of file diff --git a/ictye-live-dm/test/test_no_main_error/no_main_plugin-error.py b/ictye-live-dm/test/test_no_main_error/no_main_plugin-error.py deleted file mode 100644 index 317be84..0000000 --- a/ictye-live-dm/test/test_no_main_error/no_main_plugin-error.py +++ /dev/null @@ -1,18 +0,0 @@ -# Copyright (c) 2023 楚天寻箫(ictye) -# -# 此软件基于楚天寻箫非商业开源软件许可协议 1.0发布. -# 您可以根据该协议的规定,在非商业或商业环境中使用、分发和引用此软件. -# 惟分发此软件副本时,您不得以商业方式获利,并且不得限制用户获取该应用副本的体验. -# 如果您修改或者引用了此软件,请按协议规定发布您的修改源码. -# -# 此软件由版权所有者提供,没有明确的技术支持承诺,使用此软件和源码造成的任何损失, -# 版权所有者概不负责。如需技术支持,请联系版权所有者或社区获取最新版本。 -# -# 更多详情请参阅许可协议文档 - -from depends import plugin_main - - -class No_Plugin_main(plugin_main.Plugin_Main): - def nano(self): - pass diff --git a/ictye-live-dm/test/test_plugin/anaylazer_demo/__init__.py b/ictye-live-dm/test/test_plugin/anaylazer_demo/__init__.py deleted file mode 100644 index 9d4d1d3..0000000 --- a/ictye-live-dm/test/test_plugin/anaylazer_demo/__init__.py +++ /dev/null @@ -1,24 +0,0 @@ -# Copyright (c) 2023 楚天寻箫(ictye) -# -# 此软件基于楚天寻箫非商业开源软件许可协议 1.0发布. -# 您可以根据该协议的规定,在非商业或商业环境中使用、分发和引用此软件. -# 惟分发此软件副本时,您不得以商业方式获利,并且不得限制用户获取该应用副本的体验. -# 如果您修改或者引用了此软件,请按协议规定发布您的修改源码. -# -# 此软件由版权所有者提供,没有明确的技术支持承诺,使用此软件和源码造成的任何损失, -# 版权所有者概不负责。如需技术支持,请联系版权所有者或社区获取最新版本。 -# -# 更多详情请参阅许可协议文档 -from depends import plugin_main - - -class Plugin_Main(plugin_main.Plugin_Main): - def plugin_init(self): - return "analyzer" - - def plugin_main(self): - print("测试插件") - return - - def message_filter(self, message): - return diff --git a/ictye-live-dm/test/test_plugin/message_plugin_demo/__init__.py b/ictye-live-dm/test/test_plugin/message_plugin_demo/__init__.py deleted file mode 100644 index a40c8cf..0000000 --- a/ictye-live-dm/test/test_plugin/message_plugin_demo/__init__.py +++ /dev/null @@ -1,56 +0,0 @@ -# Copyright (c) 2023 楚天寻箫(ictye) -# -# 此软件基于楚天寻箫非商业开源软件许可协议 1.0发布. -# 您可以根据该协议的规定,在非商业或商业环境中使用、分发和引用此软件. -# 惟分发此软件副本时,您不得以商业方式获利,并且不得限制用户获取该应用副本的体验. -# 如果您修改或者引用了此软件,请按协议规定发布您的修改源码. -# -# 此软件由版权所有者提供,没有明确的技术支持承诺,使用此软件和源码造成的任何损失, -# 版权所有者概不负责。如需技术支持,请联系版权所有者或社区获取最新版本。 -# -# 更多详情请参阅许可协议文档 - -from depends import plugin_main -import asyncio -import random - - -class Plugin_Main(plugin_main.Plugin_Main): - def plugin_init(self): - self.sprit_cgi_support = True - self.sprit_cgi_path = "test" - self.dm_list: list[dms] = [] - self.clock = True - return "message" - - async def sprit_cgi(self, request): - return self.web.Response(text="ok") - - async def plugin_main(self): - while True: - await asyncio.sleep(3) - self.clock = not self.clock - await asyncio.sleep(random.randint(1, 3)) - print("(^_^)") - - def plugin_callback(self): - print(f"plugin {__name__} is done") - - def dm_iter(self, params, connect_id): - # 生成一个dm对象 - if self.clock: - return None - dm = dms(fader_class=self, param=params) - self.dm_list.append(dm) - return dm - - -class dms: - def __init__(self, fader_class: Plugin_Main, param: dict): - self.param: dict = param - self.fader_class = fader_class - self.message_list = [] - - def __aiter__(self): - for msg in self.param.items(): - yield msg diff --git a/ictye-live-dm/web/js/lib/dm_writer.js b/ictye-live-dm/web/js/lib/dm_writer.js index 8dcdc42..bc28eaa 100644 --- a/ictye-live-dm/web/js/lib/dm_writer.js +++ b/ictye-live-dm/web/js/lib/dm_writer.js @@ -108,6 +108,7 @@ define(["crypto-js/md5"], msg = `
+ diff --git a/ictye-live-dm/web/js/plugin/default_plugin_mather.js b/ictye-live-dm/web/js/plugin/default_plugin_mather.js index 6ad92d2..2406ed7 100644 --- a/ictye-live-dm/web/js/plugin/default_plugin_mather.js +++ b/ictye-live-dm/web/js/plugin/default_plugin_mather.js @@ -2,11 +2,11 @@ define(["../lib/dm_writer"], function(dm_writer) { console.log("default plugin mather is ready") - var plugin_init = function () { - console.log("debug:default_ok") + let plugin_init = function () { + let a = null } - var dm_halder = function (ms) { + let dm_halder = function (ms) { if(ms.msg_type === "dm"){ dm_writer.create_dm(ms.message_body) console.debug("creating dm"+ms.message_body) @@ -20,7 +20,6 @@ define(["../lib/dm_writer"], } } - // 暴露接口 return { dm_halder: dm_halder, diff --git a/ictye-live-dm/web/style/default_style.css b/ictye-live-dm/web/style/default_style.css index 8b0fb1b..df23c34 100644 --- a/ictye-live-dm/web/style/default_style.css +++ b/ictye-live-dm/web/style/default_style.css @@ -136,6 +136,9 @@ body { max-width: 80px; } +div.danmu .face{ + display: none; +} /*动画*/ @keyframes moveLeft { diff --git a/libs/bilibili_dm_plugin b/libs/bilibili_dm_plugin index dc93a06..a2525b7 160000 --- a/libs/bilibili_dm_plugin +++ b/libs/bilibili_dm_plugin @@ -1 +1 @@ -Subproject commit dc93a06f9c040c5afe6fb18bad48901ee9226a4c +Subproject commit a2525b71039f865553a269eb8b59e68b696b8628 diff --git a/makefile b/makefile deleted file mode 100644 index e69de29..0000000