-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.py
More file actions
49 lines (41 loc) · 1.37 KB
/
main.py
File metadata and controls
49 lines (41 loc) · 1.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# main.py v1.0.3
import asyncio
import logging
import os
from pathlib import Path
from meshbot.core.bot import MeshBot
from meshbot.handlers.signal_handlers import setup_signal_handlers
from meshbot.config.config_loader import load_config
from meshbot.config.config_loader import create_example_config
from meshbot.utils.localize import i18n
# 日志配置
logging.basicConfig(
level=logging.INFO,
format='%(asctime)s - %(levelname)s - %(message)s'
)
logger = logging.getLogger(__name__)
def check_config():
"""检查配置文件是否存在,如果不存在则创建示例"""
config_path = Path(__file__).parent / "config.json"
if not os.path.exists(config_path):
logger.warning("⚠️ 未找到 config.json 配置文件")
logger.info("📝 正在创建示例配置文件...")
create_example_config()
logger.info("ℹ️ 请编辑 config.json 文件并重新启动程序")
return False
return True
async def main() -> None:
"""主入口"""
if not check_config():
return
load_config()
bot = MeshBot()
setup_signal_handlers(bot)
try:
await bot.run()
except Exception as e:
logger.error(i18n.gettext('bot_running_error',err = e))
finally:
await bot.shutdown()
if __name__ == "__main__":
asyncio.run(main())