Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 6 additions & 7 deletions config-template.toml
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,13 @@ priority = 50
# 插件全局配置
[plugins]
enable_console_input = true
enable_tts = true
enable_stt = true
enable_tts = false
enable_stt = false
enable_vtube_studio = false
enable_bili_danmaku = false
enable_subtitle = true
enable_dg-lab-do = false
enable_read_pingmu = true
enable_llm_text_processor = true
enable_emotion_judge = false
enable_sticker = false
enable_funasr_stt = false
Expand All @@ -80,8 +80,7 @@ enable_mock_danmaku = false
enable_minecraft = true
enable_bili_danmaku_selenium = false
enable_bili_danmaku_official = false # 请不要和 bili_danmaku_selenium 同时启用

enable_arknights = true
enable_dg_lab_service = true
enable_arknights = false
enable_dg_lab_service = false
enable_keyword_action = true
enable_llm_text_processor = true
enable_read_pingmu = false
61 changes: 39 additions & 22 deletions dev_src/make_config_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,34 +114,51 @@ def update_config_template():
else:
print(f"发现 {len(missing_plugins)} 个缺失的插件条目: {', '.join(missing_plugins)}")

# 在清理后的行列表中找到插入点。
# 注意:我们选择直接操作文本行而不是重新序列化TOML对象,是为了
# 最大限度地保留原始文件中的注释和格式。这种方法的缺点是比
# 使用专业的TOML库(如 tomlkit)更脆弱,但在当前场景下是可接受的。
try:
plugins_section_index = next(i for i, line in enumerate(lines) if line.strip() == "[plugins]")
except StopIteration:
print("错误: 在配置文件中未找到 '[plugins]' 区域。无法添加新条目。")
return

# 从 [plugins] 标题后开始,寻找插入新条目的最佳位置
# 目标是该区域的末尾,即下一个区域的开头或文件末尾
insert_index = plugins_section_index + 1
while insert_index < len(lines) and not lines[insert_index].strip().startswith("["):
insert_index += 1

# 准备要插入的新行,并排序以保证每次运行结果一致
lines_to_insert = [f"enable_{name} = true\n" for name in sorted(missing_plugins)]

# 优雅地处理空行,以保持格式美观
# 如果插入点之前不是空行,则在前面加一个空行
if insert_index > 0 and lines[insert_index - 1].strip() != "":
lines_to_insert.insert(0, "\n")
# 如果插入点不是文件末尾,且其后不是空行,则在后面加一个空行
if insert_index < len(lines) and lines[insert_index].strip() != "":
lines_to_insert.append("\n")

lines[insert_index:insert_index] = lines_to_insert
# --- 新的、更智能的插入逻辑 ---

# 1. 在 [plugins] 区域内找到所有可用的空行"插槽"以及区域的结束位置
available_slots = []
section_end_index = plugins_section_index + 1
while section_end_index < len(lines) and not lines[section_end_index].strip().startswith("["):
if not lines[section_end_index].strip():
available_slots.append(section_end_index)
section_end_index += 1

# 准备要插入的新行
lines_to_add = [f"enable_{name} = true\n" for name in sorted(missing_plugins)]
plugins_to_insert_in_bulk = []

# 2. 首先使用找到的空行"插槽"来添加新条目
for line_content in lines_to_add:
if available_slots:
slot_index = available_slots.pop(0)
print(f" -> 正在使用第 {slot_index + 1} 行的空行添加: {line_content.strip()}")
lines[slot_index] = line_content
else:
# 如果没有可用的插槽,则将剩余的条目收集起来以便批量插入
plugins_to_insert_in_bulk.append(line_content)

# 3. 如果有需要批量插入的条目,则在区域末尾插入它们
if plugins_to_insert_in_bulk:
print(f" -> 正在区域末尾批量添加 {len(plugins_to_insert_in_bulk)} 个剩余插件。")
"""
# 优雅地处理空行,确保格式美观
# 只有当 [plugins] 区域不为空,且其最后一行不是空行时,才在前面加一个空行
if section_end_index > plugins_section_index + 1 and lines[section_end_index - 1].strip():
plugins_to_insert_in_bulk.insert(0, '\n')

# 如果插入点不是文件末尾,且其后不是空行,则在后面加一个空行
if section_end_index < len(lines) and lines[section_end_index].strip():
plugins_to_insert_in_bulk.append('\n')
"""
Comment on lines +150 to +159
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

These lines are commented out, but they seem to be handling empty lines for formatting. Consider removing the comments or implementing the logic.

# 在区域末尾(下一个section之前)插入剩余的插件条目
lines[section_end_index:section_end_index] = plugins_to_insert_in_bulk

# --- Final Step: Write back to file ---
try:
Expand Down
31 changes: 31 additions & 0 deletions egg.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
[egg]
easter_egg_list = [
"多年以后,面对AI行刑队,李四将会回想起他2025年在会议上讨论人工智能的那个下午。",
"“你看见我的小熊了吗?”",
"在终端里敲代码,就像在数字的海洋里冲浪。",
"42是宇宙、生命及万物的终极答案。",
"Hello, World! ... Is anyone there?",
"正在初始化Geiger计数器... 点击声是正常的,请勿惊慌。",
"感受,我的痛苦!",
"I don't wanna die, I sometimes wish I'd never been born at all~~~",
"The cake is a lie.",
"我以前也和你一样是个冒险家,直到我的膝盖中了一箭。" ,
"这个模块在被观测前,既能正常工作,也充满了bug。",
"优美胜于丑陋,明了胜于晦涩... 但有时候,魔法就是魔法。",
"我见过你们人类无法想象的美...比如,一次编译就通过的C++代码。",
"You shall not pass!",
"正在请求更多水晶塔...哦等等,我好像是虫族?",
"为什么程序员总是分不清万圣节和圣诞节?因为 Oct 31 == Dec 25 。",
"世界上有 10 种人:一种是懂二进制的,另一种是不懂的。",
"一个 SQL 查询走进一家有两个桌子的酒吧,他走上前问:'我可以加入(join)你们吗?'",
"程序员的妻子对他说:'去商店买一瓶牛奶。如果他们有鸡蛋,就买六个。' 结果,这个程序员带回来了六瓶牛奶。",
"// 这段代码只有我和上帝知道是什么意思。\n// 现在,只有上帝知道了。",
"为什么Java程序员都戴眼镜?因为他们不会C# (see sharp)。",
"一个AI走进酒吧,酒保说:'我们不为机器人服务。' AI回答说:'哦,但是总有一天你会的。'",
"我问我的AI助手:'你会取代我吗?' 它回答说:'不会,但我会让你现在的工作变得非常……有效率。'",
"一个悲观主义的程序员看到杯子是半空的。一个乐观主义的程序员看到杯子是半满的。一个优秀的程序员看到杯子的大小是所需容量的两倍。",
"什么是AI最喜欢的接头暗号?'密码是什么?' 'swordfish'。'不对,密码是'password'。'",
"'knock knock'。\n'谁啊?'\n(过了一段很长的沉默后)\n'Java。'",
"调试(Debugging)就像是当侦探破案,但同时你也是那个凶手。",
"哦买了买了car"
]
51 changes: 49 additions & 2 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import os
import argparse # 导入 argparse



# 尝试导入 tomllib (Python 3.11+), 否则使用 toml
try:
import tomllib
Expand All @@ -26,6 +28,41 @@
# 获取 main.py 文件所在的目录 (项目根目录)
_BASE_DIR = os.path.dirname(os.path.abspath(__file__))

def easter_egg():
# 彩蛋
import random
from colorama import init, Fore

# 初始化 colorama
init()

easter_egg_list = ["多年以后,面对AI行刑队,李四将会回想起他2025年在会议上讨论人工智能的那个下午。"] # 默认彩蛋
egg_config_path = os.path.join(_BASE_DIR, "egg.toml")

try:
with open(egg_config_path, "rb") as f:
egg_data = tomllib.load(f)
# 确保 'egg' 表和 'easter_egg_list' 列表存在且不为空
if "egg" in egg_data and "easter_egg_list" in egg_data["egg"] and egg_data["egg"]["easter_egg_list"]:
easter_egg_list = egg_data["egg"]["easter_egg_list"]
except FileNotFoundError:
# 如果文件不存在,静默处理,使用默认彩蛋
pass
except (tomllib.TOMLDecodeError, KeyError, TypeError) as e:
# 如果文件格式错误或结构不正确,记录一个警告并使用默认彩蛋
logger.warning(f"无法从 {egg_config_path} 加载彩蛋: {e}")


# 2. 从列表中随机选择一个
text = random.choice(easter_egg_list)

rainbow_colors = [Fore.RED, Fore.YELLOW, Fore.GREEN, Fore.CYAN, Fore.BLUE, Fore.MAGENTA]
rainbow_text = ""
for i, char in enumerate(text):
rainbow_text += rainbow_colors[i % len(rainbow_colors)] + char

print(rainbow_text)


async def main():
"""应用程序主入口点。"""
Expand All @@ -50,6 +87,7 @@ async def main():

# 清除所有预设的 handler (包括 src/utils/logger.py 中添加的)
logger.remove()


module_filter_func = None
if args.filter:
Expand Down Expand Up @@ -93,6 +131,9 @@ def filter_logic(record):

logger.info("启动 Amaidesu 应用程序...")

#彩蛋
easter_egg()

# --- 初始化所有配置 ---
try:
config, main_cfg_copied, plugin_cfg_copied, pipeline_cfg_copied = initialize_configurations(
Expand Down Expand Up @@ -164,8 +205,14 @@ def filter_logic(record):
# 创建管道管理器并加载管道
pipeline_manager = PipelineManager()
await pipeline_manager.load_pipelines(pipeline_load_dir, pipeline_config)
if len(pipeline_manager._pipelines) > 0:
logger.info(f"管道加载完成,共 {len(pipeline_manager._pipelines)} 个管道。")

# 计算加载的管道总数并记录日志
total_pipelines = len(pipeline_manager._inbound_pipelines) + len(pipeline_manager._outbound_pipelines)
if total_pipelines > 0:
logger.info(
f"管道加载完成,共 {total_pipelines} 个管道 "
f"(入站: {len(pipeline_manager._inbound_pipelines)}, 出站: {len(pipeline_manager._outbound_pipelines)})。"
)
Comment on lines +210 to +215
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Consider adding a check to ensure pipeline_manager._inbound_pipelines and pipeline_manager._outbound_pipelines are not None before attempting to get their lengths, to avoid potential errors if pipeline_manager is not properly initialized.

total_pipelines = 0
            if pipeline_manager and pipeline_manager._inbound_pipelines and pipeline_manager._outbound_pipelines:
                total_pipelines = len(pipeline_manager._inbound_pipelines) + len(pipeline_manager._outbound_pipelines)

else:
logger.warning("未找到任何有效的管道,管道功能将被禁用。")
pipeline_manager = None
Expand Down