diff --git a/docs/usage/README.md b/docs/usage/README.md index 33d407d..3b1da44 100644 --- a/docs/usage/README.md +++ b/docs/usage/README.md @@ -31,14 +31,24 @@ next: /usage/easy-use ::: - `BISON_SKIP_BROWSER_CHECK`: 是否在启动时自动下载浏览器,如果选择`False`会在用到浏览器时自动下载, 默认`True` -- `BISON_OUTER_URL`: 从外部访问服务器的地址,默认为`http://localhost:8080/bison/`,如果你的插件部署 - 在服务器上,建议配置为`http://<你的服务器ip>:8080/bison/` +- `BISON_OUTER_URL`: 从外部访问服务器的地址,不设置或为空时默认值为 `http://localhost:/bison/` ::: warning 请注意,该网址**并不能直接访问**Bison 的后台管理网页,正确的访问方法请参见[私聊机器人获取后台地址](#私聊机器人获取后台地址) ::: - ::: tip - 如果需要从外网或者 Docker 容器外访问后台页面,请确保`HOST=0.0.0.0` + ::: tip 配置建议 + 请选择你的部署情况: +
+ + + + + + +
+ 下面是配置建议: +
::: + - `BISON_FILTER_LOG`: 是否过滤来自`nonebot`的 warning 级以下的 log,如果你的 bot 只运行了这个插件可以考虑 开启,默认关 - `BISON_USE_QUEUE`: 是否用队列的方式发送消息,降低发送频率,默认开 @@ -190,3 +200,56 @@ Bison 在处理每条推送时,会按照以下规则检查推送中的 Tag: - 如果推送中含有任何已记录的**需订阅 Tag**,Bison 会将该推送发送到群中,不管是否有其他 Tag。 - 如果**没有记录**任何需订阅 Tag,Bison 会将所有通过第一条规则检查的推送发送到群中。 - 如果记录了至少一个需订阅 Tag,Bison 会**丢弃所有**不含任何需订阅 Tag 的推送,即使通过了第一条规则检查。 + + + + diff --git a/docs/usage/easy-use.md b/docs/usage/easy-use.md index 94256c5..a6b6c3d 100644 --- a/docs/usage/easy-use.md +++ b/docs/usage/easy-use.md @@ -144,7 +144,7 @@ Bison 提供了一个网页管理订阅的功能,你可以在网页上查看 ::: tip Bison 给出的链接无效? Bison 所给的链接中的 ip 和 port 是`BISON_OUTER_URL`配置决定的,也就是说 Bison 本身不能获取服务器的 ip 与自身的 port,所以 Bison 给出的链接可能是无效的。你可以在`BISON_OUTER_URL`中设置你的服务器 ip 与 port,或者直接修改 Bison 给出的链接为正确的`http://:/bison/...`来进入网页管理订阅的界面。 -参见[详细介绍-配置](usage/#配置)的`BISON_OUTER_URL`部分 +参见[详细介绍-配置](/usage/#配置)的`BISON_OUTER_URL`部分 ::: ::: tip 认证失败? :bug: diff --git a/nonebot_bison/admin_page/__init__.py b/nonebot_bison/admin_page/__init__.py index b14b81b..cb5f29c 100644 --- a/nonebot_bison/admin_page/__init__.py +++ b/nonebot_bison/admin_page/__init__.py @@ -66,7 +66,7 @@ def register_get_token_handler(): @get_token.handle() async def send_token(bot: "Bot", event: PrivateMessageEvent, state: T_State): token = tm.get_user_token((event.get_user_id(), event.sender.nickname)) - await get_token.finish(f"请访问: {plugin_config.bison_outer_url}auth/{token}") + await get_token.finish(f"请访问: {plugin_config.outer_url}auth/{token}") get_token.__help__name__ = "获取后台管理地址" # type: ignore get_token.__help__info__ = "获取管理bot后台的地址,该地址会在一段时间过后过期,请不要泄漏该地址" # type: ignore diff --git a/nonebot_bison/plugin_config.py b/nonebot_bison/plugin_config.py index 842bf40..8d52d3b 100644 --- a/nonebot_bison/plugin_config.py +++ b/nonebot_bison/plugin_config.py @@ -1,13 +1,15 @@ import nonebot from pydantic import BaseSettings +global_config = nonebot.get_driver().config + class PlugConfig(BaseSettings): bison_config_path: str = "" bison_use_pic: bool = False bison_init_filter: bool = True bison_use_queue: bool = True - bison_outer_url: str = "http://localhost:8080/bison/" + bison_outer_url: str = "" bison_filter_log: bool = False bison_to_me: bool = True bison_skip_browser_check: bool = False @@ -20,9 +22,12 @@ class PlugConfig(BaseSettings): ) bison_show_network_warning: bool = True + @property + def outer_url(self) -> str: + return self.bison_outer_url or f"http://localhost:{global_config.port}/bison/" + class Config: extra = "ignore" -global_config = nonebot.get_driver().config plugin_config = PlugConfig(**global_config.dict()) diff --git a/tests/test_admin_page.py b/tests/test_admin_page.py index 150861c..81f35b0 100644 --- a/tests/test_admin_page.py +++ b/tests/test_admin_page.py @@ -28,12 +28,12 @@ async def test_command(app: App): to_me=True, ) ctx.receive_event(bot, event_1) - ctx.should_call_send(event_1, f"请访问: {plugin_config.bison_outer_url}auth/test_token", True) + ctx.should_call_send(event_1, f"请访问: {plugin_config.outer_url}auth/test_token", True) ctx.should_finished() event_2 = fake_private_message_event(message=Message("管理后台"), sender=fake_admin_user, to_me=True) ctx.receive_event(bot, event_2) - ctx.should_call_send(event_2, f"请访问: {plugin_config.bison_outer_url}auth/test_token", True) + ctx.should_call_send(event_2, f"请访问: {plugin_config.outer_url}auth/test_token", True) ctx.should_finished()