-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbot.py
More file actions
62 lines (45 loc) · 1.68 KB
/
bot.py
File metadata and controls
62 lines (45 loc) · 1.68 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
50
51
52
53
54
55
56
57
58
59
60
61
62
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
from pathlib import Path
import nonebot
from tomlkit import parse
# 自定义 Logger
# 这里示范添加一个每日 0 点重新生成的 error.log 日志
#
# from nonebot.log import logger, default_format
#
# logger.add(
# "error.log",
# rotation="00:00",
# diagnose=False,
# level="ERROR",
# format=default_format
# )
# 可以在init函数中添加 .env 配置,优先级高于 .env
nonebot.init(
# var1=True
)
pyproject = parse((Path(__file__).parent / "pyproject.toml").read_text(encoding="u8"))
# 根据 pyproject.toml 注册 Adapter
import importlib
driver = nonebot.get_driver()
for adapter in pyproject["tool"]["nonebot"]["adapters"]: # type: ignore
driver.register_adapter(importlib.import_module(adapter["module_name"]).Adapter)
# 在加载其他插件之前加载前置插件
# 详见 pyproject.toml [tool.nonebot.oneclick] 项的注释
preload_plugins: list[str] = pyproject["tool"]["nonebot"]["oneclick"]["preload_plugins"] # type: ignore
for p in preload_plugins:
nonebot.load_plugin(p)
# 如果你不知道你在干什么,请不要动此文件
# 你可以 使用nb脚手架 或者 修改`pyproject.toml` 来加载插件
# 下面的几行代码会自动加载 pyproject.toml [tool.nonebot] 项里的插件和插件目录
plugins = set(pyproject["tool"]["nonebot"]["plugins"]) # type: ignore
plugin_dirs = set(pyproject["tool"]["nonebot"]["plugin_dirs"]) # type: ignore
plugins.difference_update(preload_plugins)
nonebot.load_all_plugins(plugins, plugin_dirs)
# 在已加载配置的基础上修改配置
#
# config = driver.config
# config.var1 = False
if __name__ == "__main__":
nonebot.run()