|
2 | 2 | MuRainBot2 |
3 | 3 | """ |
4 | 4 |
|
5 | | -# __ __ ____ _ ____ _ _____ |
6 | | -# | \/ |_ _| _ \ __ _(_)_ __ | __ ) ___ | |_|___ \ |
7 | | -# | |\/| | | | | |_) / _` | | '_ \ | _ \ / _ \| __| __) | |
8 | | -# | | | | |_| | _ < (_| | | | | | | |_) | (_) | |_ / __/ |
9 | | -# |_| |_|\__,_|_| \_\__,_|_|_| |_| |____/ \___/ \__|_____| |
10 | | -import atexit |
11 | | -import logging |
12 | | -import random |
13 | | -import threading |
14 | | -import time |
| 5 | +from murainbot.main import start |
15 | 6 |
|
16 | | -BANNER = r""" __ __ ____ _ ____ _ _____ |
17 | | -| \/ |_ _| _ \ __ _(_)_ __ | __ ) ___ | |_|___ \ |
18 | | -| |\/| | | | | |_) / _` | | '_ \ | _ \ / _ \| __| __) | |
19 | | -| | | | |_| | _ < (_| | | | | | | |_) | (_) | |_ / __/ |
20 | | -|_| |_|\__,_|_| \_\__,_|_|_| |_| |____/ \___/ \__|_____|""" |
21 | | -BANNER_LINK = "https://github.com/MuRainBot/MuRainBot2" |
22 | | - |
23 | | - |
24 | | -def color_text(text: str, text_color: tuple[int, int, int] = None, bg_color: tuple[int, int, int] = None): |
25 | | - """ |
26 | | - 富文本生成器 |
27 | | - @param text: 文本 |
28 | | - @param text_color: 文本颜色 |
29 | | - @param bg_color: 背景颜色 |
30 | | - @return: 富文本 |
31 | | - """ |
32 | | - text = text + "\033[0m" if text_color is not None or bg_color is not None else text |
33 | | - if text_color is not None: |
34 | | - text = f"\033[38;2;{text_color[0]};{text_color[1]};{text_color[2]}m" + text |
35 | | - if bg_color is not None: |
36 | | - text = f"\033[48;2;{bg_color[0]};{bg_color[1]};{bg_color[2]}m" + text |
37 | | - return text |
38 | | - |
39 | | - |
40 | | -def get_gradient(start_color: tuple[int, int, int], end_color: tuple[int, int, int], length: float): |
41 | | - """ |
42 | | - 渐变色生成 |
43 | | - @param start_color: 开始颜色 |
44 | | - @param end_color: 结束颜色 |
45 | | - @param length: 0-1的值 |
46 | | - @return: RGB颜色 |
47 | | - """ |
48 | | - return ( |
49 | | - int(start_color[0] + (end_color[0] - start_color[0]) * length), |
50 | | - int(start_color[1] + (end_color[1] - start_color[1]) * length), |
51 | | - int(start_color[2] + (end_color[2] - start_color[2]) * length) |
52 | | - ) |
53 | | - |
54 | | - |
55 | | -def print_loading(wait_str): |
56 | | - """ |
57 | | - 输出加载动画 |
58 | | - """ |
59 | | - loading_string_list = [r"|/-\\", r"▁▂▃▄▅▆▇█▇▆▅▄▃▂", "\u2801\u2808\u2810\u2820\u2880\u2900\u2804\u2802", r"←↖↑↗→↘↓↙"] |
60 | | - loading_string = random.choice(loading_string_list) |
61 | | - i = 0 |
62 | | - while not is_done: |
63 | | - if i == len(loading_string): |
64 | | - i = 0 |
65 | | - print("\r" + wait_str + color_text(loading_string[i], banner_start_color), end="") |
66 | | - time.sleep(0.07) |
67 | | - i += 1 |
68 | | - |
69 | | - |
70 | | -# 主函数 |
71 | | -if __name__ == '__main__': |
72 | | - banner_start_color = (14, 190, 255) |
73 | | - banner_end_color = (255, 66, 179) |
74 | | - banner = BANNER.split("\n") |
75 | | - color_banner = "" |
76 | | - # 输出banner |
77 | | - for i in range(len(banner)): |
78 | | - for j in range(len(banner[i])): |
79 | | - color_banner += color_text( |
80 | | - banner[i][j], |
81 | | - get_gradient( |
82 | | - banner_start_color, |
83 | | - banner_end_color, |
84 | | - ((j / (len(banner[i]) - 1) + i / (len(banner) - 1)) / 2) |
85 | | - ) |
86 | | - ) |
87 | | - color_banner += "\n" |
88 | | - |
89 | | - print(color_banner.strip()) |
90 | | - |
91 | | - # 输出项目链接 |
92 | | - for c in color_text(BANNER_LINK, get_gradient(banner_start_color, banner_end_color, 0.5)): |
93 | | - print(c, end="") |
94 | | - |
95 | | - wait_str = color_text("正在加载 Lib, 首次启动可能需要几秒钟,请稍等...", banner_start_color) |
96 | | - print("\n" + wait_str, end="") |
97 | | - is_done = False |
98 | | - |
99 | | - threading.Thread(target=print_loading, daemon=True, args=(wait_str,)).start() |
100 | | - |
101 | | - # 开始加载 |
102 | | - start_loading = time.time() |
103 | | - |
104 | | - from Lib.utils import Logger |
105 | | - |
106 | | - Logger.init() |
107 | | - |
108 | | - from Lib.core import * |
109 | | - |
110 | | - from Lib import * |
111 | | - |
112 | | - atexit.register(common.finalize_and_cleanup) |
113 | | - |
114 | | - ThreadPool.init() |
115 | | - |
116 | | - Logger.set_logger_level(logging.DEBUG if ConfigManager.GlobalConfig().debug.enable else logging.INFO) |
117 | | - |
118 | | - is_done = True |
119 | | - |
120 | | - print("\r" + color_text( |
121 | | - f"Lib 加载完成!耗时: {round(time.time() - start_loading, 2)}s 正在启动 MuRainBot... ", |
122 | | - banner_end_color |
123 | | - ) |
124 | | - ) |
125 | | - |
126 | | - logger = Logger.get_logger() |
127 | | - |
128 | | - logger.info("日志初始化完成,MuRainBot正在启动...") |
129 | | - |
130 | | - if ConfigManager.GlobalConfig().account.user_id == 0 or not ConfigManager.GlobalConfig().account.nick_name: |
131 | | - logger.info("正在尝试获取用户信息...") |
132 | | - try: |
133 | | - account = OnebotAPI.api.get_login_info() |
134 | | - new_account = ConfigManager.GlobalConfig().config.get("account") |
135 | | - new_account.update({ |
136 | | - "user_id": account['user_id'], |
137 | | - "nick_name": account['nickname'] |
138 | | - }) |
139 | | - |
140 | | - ConfigManager.GlobalConfig().set("account", new_account) |
141 | | - except Exception as e: |
142 | | - logger.warning(f"获取用户信息失败, 可能会导致严重的问题: {repr(e)}") |
143 | | - |
144 | | - logger.info(f"欢迎使用: {ConfigManager.GlobalConfig().account.nick_name}" |
145 | | - f"({ConfigManager.GlobalConfig().account.user_id})") |
146 | | - |
147 | | - logger.debug(f"准备加载插件") |
148 | | - PluginManager.load_plugins() |
149 | | - logger.info(f"插件加载完成!共成功加载了 {len(PluginManager.plugins)} 个插件" |
150 | | - f"{': \n' if len(PluginManager.plugins) >= 1 else ''}" |
151 | | - f"{'\n'.join( |
152 | | - [ |
153 | | - f'{_['name']}: {_['info'].NAME}' if 'info' in _ and _['info'] else _['name'] |
154 | | - for _ in PluginManager.plugins |
155 | | - ] |
156 | | - )}") |
157 | | - |
158 | | - threading.Thread(target=AutoRestartOnebot.check_heartbeat, daemon=True).start() |
159 | | - |
160 | | - logger.info(f"启动监听服务器: {ConfigManager.GlobalConfig().server.server}") |
161 | | - |
162 | | - if ConfigManager.GlobalConfig().server.server == "werkzeug": |
163 | | - # 禁用werkzeug的日志记录 |
164 | | - log = logging.getLogger('werkzeug') |
165 | | - log.disabled = True |
166 | | - |
167 | | - threading.Thread(target=ListenerServer.start_server, daemon=True).start() |
168 | | - |
169 | | - try: |
170 | | - while True: |
171 | | - time.sleep(1) |
172 | | - except KeyboardInterrupt: |
173 | | - logger.info("正在关闭...") |
| 7 | +start() |
0 commit comments