diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..81ddfb6 --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,24 @@ +{ + "version": "0.2.0", + "configurations": [ + { + "name": "运行 Bot 并调试(自动重载)", + "type": "debugpy", + "request": "launch", + "module": "watchfiles", + "args": [ + "bot.main" + ], + "console": "integratedTerminal", + "justMyCode": true, + "env": { + "PYTHONPATH": "${workspaceFolder}" + }, + "cwd": "${workspaceFolder}", + "presentation": { + "hidden": false, + "group": "bot" + } + } + ] +} \ No newline at end of file diff --git a/.vscode/tasks.json b/.vscode/tasks.json index 43918fb..6222a90 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -12,6 +12,19 @@ }, "problemMatcher": [], "detail": "导出生产环境依赖到 requirements.txt" + }, + { + "label": "Bot: Run with Auto-reload", + "type": "shell", + "command": "poetry run watchfiles bot.main", + "group": "build", + "isBackground": true, + "presentation": { + "reveal": "always", + "panel": "new" + }, + "problemMatcher": [], + "detail": "运行 bot 并启用自动重载功能" } ] } \ No newline at end of file diff --git a/bot.py b/bot.py index adcaf86..9d1c0d5 100644 --- a/bot.py +++ b/bot.py @@ -14,7 +14,7 @@ env_enable_qq = os.environ.get("ENABLE_QQ", "none") env_enable_discord = os.environ.get("ENABLE_DISCORD", "none") env_enable_minecraft = os.environ.get("ENABLE_MINECRAFT", "none") -if __name__ == "__main__": +def main(): nonebot.init() driver = nonebot.get_driver() @@ -35,3 +35,6 @@ if __name__ == "__main__": nonebot.load_plugins("konabot/plugins") nonebot.run() + +if __name__ == "__main__": + main()