-
Notifications
You must be signed in to change notification settings - Fork 5
一点小优化 #24
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
一点小优化 #24
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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" | ||
| ] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,6 +4,8 @@ | |
| import os | ||
| import argparse # 导入 argparse | ||
|
|
||
|
|
||
|
|
||
| # 尝试导入 tomllib (Python 3.11+), 否则使用 toml | ||
| try: | ||
| import tomllib | ||
|
|
@@ -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(): | ||
| """应用程序主入口点。""" | ||
|
|
@@ -50,6 +87,7 @@ async def main(): | |
|
|
||
| # 清除所有预设的 handler (包括 src/utils/logger.py 中添加的) | ||
| logger.remove() | ||
|
|
||
|
|
||
| module_filter_func = None | ||
| if args.filter: | ||
|
|
@@ -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( | ||
|
|
@@ -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
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consider adding a check to ensure 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 | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These lines are commented out, but they seem to be handling empty lines for formatting. Consider removing the comments or implementing the logic.