Merge branch 'dev' of https://github.com/MaiM-with-u/MaiBot into dev
This commit is contained in:
@@ -3,7 +3,7 @@ from tkinter import ttk, messagebox, filedialog
|
||||
import tomli
|
||||
import tomli_w
|
||||
import os
|
||||
from typing import Any, Dict, List, Union
|
||||
from typing import Any, Dict, List
|
||||
import threading
|
||||
import time
|
||||
import re
|
||||
@@ -244,7 +244,7 @@ class ConfigEditor:
|
||||
}
|
||||
|
||||
item_name_to_display = key # 默认显示原始键名
|
||||
item_desc_to_display = "" # 默认无描述
|
||||
item_desc_to_display = "" # 默认无描述
|
||||
|
||||
# 1. 尝试使用完整路径的特定翻译
|
||||
specific_translation = self.translations.get("items", {}).get(full_config_path_key)
|
||||
@@ -266,13 +266,16 @@ class ConfigEditor:
|
||||
label.grid(row=0, column=0, sticky=tk.W, padx=5, pady=(0, 0))
|
||||
|
||||
# 星星图标快捷设置(与配置名同一行)
|
||||
content_col_offset_for_star = 1 # 星标按钮占一列
|
||||
content_col_offset_for_star = 1 # 星标按钮占一列
|
||||
quick_settings = self.editor_config.get("editor", {}).get("quick_settings", {}).get("items", [])
|
||||
already_in_quick = any(item.get("path") == full_config_path_key for item in quick_settings)
|
||||
icon = "★" if already_in_quick else "☆"
|
||||
icon_fg = "#FFD600" # 始终金色
|
||||
|
||||
def on_star_click():
|
||||
self.toggle_quick_setting(full_config_path_key, widget_type, item_name_to_display, item_desc_to_display, already_in_quick)
|
||||
self.toggle_quick_setting(
|
||||
full_config_path_key, widget_type, item_name_to_display, item_desc_to_display, already_in_quick
|
||||
)
|
||||
# 立即刷新本分组
|
||||
for widget in parent.winfo_children():
|
||||
widget.destroy()
|
||||
@@ -307,7 +310,7 @@ class ConfigEditor:
|
||||
desc_label.grid(row=desc_row, column=0, columnspan=content_col_offset_for_star + 1, sticky=tk.W, padx=5, pady=(0, 4))
|
||||
widget_row = desc_row + 1 # 内容控件在描述下方
|
||||
else:
|
||||
widget_row = desc_row # 内容控件直接在第二行
|
||||
widget_row = desc_row # 内容控件直接在第二行
|
||||
|
||||
# 配置内容控件(第三行或第二行)
|
||||
if path[0] == "inner":
|
||||
@@ -319,7 +322,7 @@ class ConfigEditor:
|
||||
# 布尔值使用复选框
|
||||
var = tk.BooleanVar(value=value)
|
||||
checkbox = ttk.Checkbutton(frame, variable=var, command=lambda: self.on_value_changed())
|
||||
checkbox.grid(row=widget_row, column=0, columnspan=content_col_offset_for_star +1, sticky=tk.W, padx=5)
|
||||
checkbox.grid(row=widget_row, column=0, columnspan=content_col_offset_for_star + 1, sticky=tk.W, padx=5)
|
||||
self.widgets[tuple(path + [key])] = var
|
||||
widget_type = "bool"
|
||||
|
||||
@@ -335,13 +338,17 @@ class ConfigEditor:
|
||||
elif isinstance(value, list):
|
||||
# 列表使用每行一个输入框的形式
|
||||
frame_list = ttk.Frame(frame)
|
||||
frame_list.grid(row=widget_row, column=0, columnspan=content_col_offset_for_star +1, sticky=tk.W+tk.E, padx=5)
|
||||
frame_list.grid(
|
||||
row=widget_row, column=0, columnspan=content_col_offset_for_star + 1, sticky=tk.W + tk.E, padx=5
|
||||
)
|
||||
|
||||
# 创建添加和删除按钮
|
||||
button_frame = ttk.Frame(frame_list)
|
||||
button_frame.pack(side=tk.RIGHT, padx=5)
|
||||
|
||||
add_button = ttk.Button(button_frame, text="+", width=3, command=lambda p=path + [key]: self.add_list_item(frame_list, p))
|
||||
add_button = ttk.Button(
|
||||
button_frame, text="+", width=3, command=lambda p=path + [key]: self.add_list_item(frame_list, p)
|
||||
)
|
||||
add_button.pack(side=tk.TOP, pady=2)
|
||||
|
||||
# 创建列表项框架
|
||||
@@ -548,10 +555,10 @@ class ConfigEditor:
|
||||
if setting_type == "bool":
|
||||
value = bool(value) if value is not None else False
|
||||
var = tk.BooleanVar(value=value)
|
||||
checkbox = ttk.Checkbutton(frame, text="",
|
||||
variable=var,
|
||||
command=lambda p=path, v=var: self.on_quick_setting_changed(p, v))
|
||||
checkbox.pack(anchor=tk.W, padx=5, pady=(0,5))
|
||||
checkbox = ttk.Checkbutton(
|
||||
frame, text="", variable=var, command=lambda p=path, v=var: self.on_quick_setting_changed(p, v)
|
||||
)
|
||||
checkbox.pack(anchor=tk.W, padx=5, pady=(0, 5))
|
||||
|
||||
elif setting_type == "text":
|
||||
value = str(value) if value is not None else ""
|
||||
@@ -569,9 +576,10 @@ class ConfigEditor:
|
||||
|
||||
elif setting_type == "list":
|
||||
# 对于列表类型,创建一个按钮来打开编辑窗口
|
||||
button = ttk.Button(frame, text="编辑列表",
|
||||
command=lambda p=path, s=setting: self.open_list_editor(p, s))
|
||||
button.pack(anchor=tk.W, padx=5, pady=(0,5))
|
||||
button = ttk.Button(
|
||||
frame, text="编辑列表", command=lambda p=path, s=setting: self.open_list_editor(p, s)
|
||||
)
|
||||
button.pack(anchor=tk.W, padx=5, pady=(0, 5))
|
||||
|
||||
def create_list_item(self, parent, value, index, entry_vars, path):
|
||||
"""创建单个列表项的输入框"""
|
||||
@@ -585,8 +593,12 @@ class ConfigEditor:
|
||||
var.trace_add("write", lambda *args: self.on_value_changed())
|
||||
|
||||
# 创建删除按钮
|
||||
del_button = ttk.Button(item_frame, text="-", width=3,
|
||||
command=lambda: self.remove_list_item(parent, item_frame, entry_vars, index, path))
|
||||
del_button = ttk.Button(
|
||||
item_frame,
|
||||
text="-",
|
||||
width=3,
|
||||
command=lambda: self.remove_list_item(parent, item_frame, entry_vars, index, path),
|
||||
)
|
||||
del_button.pack(side=tk.RIGHT, padx=5)
|
||||
|
||||
# 存储变量引用
|
||||
@@ -757,13 +769,13 @@ class ConfigEditor:
|
||||
button_frame.pack(fill=tk.X, pady=10)
|
||||
|
||||
# 添加按钮
|
||||
add_button = ttk.Button(button_frame, text="添加",
|
||||
command=lambda: self.add_list_item(items_frame, path))
|
||||
add_button = ttk.Button(button_frame, text="添加", command=lambda: self.add_list_item(items_frame, path))
|
||||
add_button.pack(side=tk.LEFT, padx=5)
|
||||
|
||||
# 保存按钮
|
||||
save_button = ttk.Button(button_frame, text="保存",
|
||||
command=lambda: self.save_list_editor(dialog, path, entry_vars))
|
||||
save_button = ttk.Button(
|
||||
button_frame, text="保存", command=lambda: self.save_list_editor(dialog, path, entry_vars)
|
||||
)
|
||||
save_button.pack(side=tk.RIGHT, padx=5)
|
||||
|
||||
def save_list_editor(self, dialog, path, entry_vars):
|
||||
@@ -810,20 +822,21 @@ class ConfigEditor:
|
||||
self.on_value_changed()
|
||||
|
||||
def toggle_quick_setting(self, full_path, widget_type, name, desc, already_in_quick):
|
||||
quick_settings = self.editor_config.setdefault("editor", {}).setdefault("quick_settings", {}).setdefault("items", [])
|
||||
quick_settings = (
|
||||
self.editor_config.setdefault("editor", {}).setdefault("quick_settings", {}).setdefault("items", [])
|
||||
)
|
||||
if already_in_quick:
|
||||
# 移除
|
||||
self.editor_config["editor"]["quick_settings"]["items"] = [item for item in quick_settings if item.get("path") != full_path]
|
||||
self.editor_config["editor"]["quick_settings"]["items"] = [
|
||||
item for item in quick_settings if item.get("path") != full_path
|
||||
]
|
||||
else:
|
||||
# 添加
|
||||
quick_settings.append({
|
||||
"name": name,
|
||||
"description": desc,
|
||||
"path": full_path,
|
||||
"type": widget_type
|
||||
})
|
||||
quick_settings.append({"name": name, "description": desc, "path": full_path, "type": widget_type})
|
||||
# 保存到configexe.toml
|
||||
import tomli_w, os
|
||||
import tomli_w
|
||||
import os
|
||||
|
||||
config_path = os.path.join(os.path.dirname(__file__), "configexe.toml")
|
||||
with open(config_path, "wb") as f:
|
||||
tomli_w.dump(self.editor_config, f)
|
||||
@@ -1087,8 +1100,9 @@ class ConfigEditor:
|
||||
|
||||
def main():
|
||||
root = tk.Tk()
|
||||
app = ConfigEditor(root)
|
||||
_app = ConfigEditor(root)
|
||||
root.mainloop()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
||||
@@ -2,7 +2,11 @@ from src.common.logger_manager import get_logger
|
||||
from src.chat.message_receive.message import MessageRecv
|
||||
from src.chat.message_receive.storage import MessageStorage
|
||||
from src.config.config import global_config
|
||||
from src.chat.message_receive.chat_stream import ChatStream
|
||||
|
||||
from maim_message import UserInfo
|
||||
from datetime import datetime
|
||||
import re
|
||||
|
||||
logger = get_logger("pfc")
|
||||
|
||||
@@ -14,7 +18,7 @@ class MessageProcessor:
|
||||
self.storage = MessageStorage()
|
||||
|
||||
@staticmethod
|
||||
def _check_ban_words(text: str, chat, userinfo) -> bool:
|
||||
def _check_ban_words(text: str, chat: ChatStream, userinfo: UserInfo) -> bool:
|
||||
"""检查消息中是否包含过滤词"""
|
||||
for word in global_config.message_receive.ban_words:
|
||||
if word in text:
|
||||
@@ -26,13 +30,12 @@ class MessageProcessor:
|
||||
return False
|
||||
|
||||
@staticmethod
|
||||
def _check_ban_regex(text: str, chat, userinfo) -> bool:
|
||||
def _check_ban_regex(text: str, chat: ChatStream, userinfo: UserInfo) -> bool:
|
||||
"""检查消息是否匹配过滤正则表达式"""
|
||||
for pattern in global_config.chat.ban_msgs_regex:
|
||||
if pattern.search(text):
|
||||
logger.info(
|
||||
f"[{chat.group_info.group_name if chat.group_info else '私聊'}]{userinfo.user_nickname}:{text}"
|
||||
)
|
||||
for pattern in global_config.message_receive.ban_msgs_regex:
|
||||
if re.search(pattern, text):
|
||||
chat_name = chat.group_info.group_name if chat.group_info else "私聊"
|
||||
logger.info(f"[{chat_name}]{userinfo.user_nickname}:{text}")
|
||||
logger.info(f"[正则表达式过滤]消息匹配到{pattern},filtered")
|
||||
return True
|
||||
return False
|
||||
|
||||
Reference in New Issue
Block a user