Skip to content

Commit

Permalink
Dev (#19)
Browse files Browse the repository at this point in the history
* 優化前端效果

*修復幾個bug

* 完善日志系统,增加并完善一个api
  • Loading branch information
northgreen authored Feb 2, 2024
1 parent 2c4fa68 commit 9c1cf56
Show file tree
Hide file tree
Showing 17 changed files with 39 additions and 129 deletions.
Binary file removed ictye-live-dm/.coverage
Binary file not shown.
1 change: 0 additions & 1 deletion ictye-live-dm/config/plugin/b_dm_plugin/config.yaml

This file was deleted.

2 changes: 1 addition & 1 deletion ictye-live-dm/config/system/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ plugins:
default_path: "./plugin"

#调试开关,非开发人员勿动(动吧,随便动(bushi)
debug: 1
debug: 0

#日志级别
# DEBUG:调试级别
Expand Down
1 change: 0 additions & 1 deletion ictye-live-dm/depends/configs.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ def read_config(config_family: str) -> 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:
Expand Down
7 changes: 5 additions & 2 deletions ictye-live-dm/depends/logger.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import logging
import datetime

import time

import os


Expand All @@ -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"]])

Expand Down
34 changes: 21 additions & 13 deletions ictye-live-dm/depends/plugin_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = []
Expand All @@ -64,7 +75,6 @@ async def plugin_main(self):

async def message_filter(self, message) -> msgs.msg_box:
"""
消息过滤器,用于自动处理消息,比如翻译或者敏感词过滤
:param message:待处理的消息
:return 消息
Expand All @@ -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):
Expand All @@ -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):
Expand Down
1 change: 0 additions & 1 deletion ictye-live-dm/livewebsocket.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ async def websockets(websocket: server.WebSocketServerProtocol):
websocket消息处理主函数
"""
# 连接检测

try:
async for message in websocket:
loggers.info("receive a message" + message)
Expand Down
10 changes: 4 additions & 6 deletions ictye-live-dm/pluginsystem.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down Expand Up @@ -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)
Expand All @@ -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:
Expand Down
1 change: 0 additions & 1 deletion ictye-live-dm/test/empathy_dir/ignore

This file was deleted.

18 changes: 0 additions & 18 deletions ictye-live-dm/test/test_no_main_error/no_main_plugin-error.py

This file was deleted.

24 changes: 0 additions & 24 deletions ictye-live-dm/test/test_plugin/anaylazer_demo/__init__.py

This file was deleted.

56 changes: 0 additions & 56 deletions ictye-live-dm/test/test_plugin/message_plugin_demo/__init__.py

This file was deleted.

1 change: 1 addition & 0 deletions ictye-live-dm/web/js/lib/dm_writer.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ define(["crypto-js/md5"],
msg = `<div class="danmu">
<div class="dmlaft">
<div class="lbox" >
<img class="face" src="${msgbody.who.face}">
<svg xmlns="http://www.w3.org/2000/svg" version="1.1" width="33" height="31">
<rect width="100%" height="100%" class=${usr} />
</svg>
Expand Down
7 changes: 3 additions & 4 deletions ictye-live-dm/web/js/plugin/default_plugin_mather.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -20,7 +20,6 @@ define(["../lib/dm_writer"],
}
}


// 暴露接口
return {
dm_halder: dm_halder,
Expand Down
3 changes: 3 additions & 0 deletions ictye-live-dm/web/style/default_style.css
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,9 @@ body {
max-width: 80px;
}

div.danmu .face{
display: none;
}

/*动画*/
@keyframes moveLeft {
Expand Down
2 changes: 1 addition & 1 deletion libs/bilibili_dm_plugin
Empty file removed makefile
Empty file.

0 comments on commit 9c1cf56

Please sign in to comment.