Skip to content
Permalink

Comparing changes

This is a direct comparison between two commits made in this repository or its related repositories. View the default comparison for this range or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: MountainDash/nonebot-bison
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: eb8d81291734288b6ba5b3571155dc68257fa8ee
Choose a base ref
..
head repository: MountainDash/nonebot-bison
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: bb9f8256028e8f75ea7719086fc3f47710ac22d0
Choose a head ref
4 changes: 2 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -56,7 +56,7 @@ jobs:
runs-on: ${{ matrix.os }}
strategy:
matrix:
python-version: ["3.10", "3.11"]
python-version: ["3.10", "3.11", "3.12"]
os: [ubuntu-latest, windows-latest, macos-latest]
fail-fast: false
env:
@@ -89,7 +89,7 @@ jobs:
runs-on: ${{ matrix.os }}
strategy:
matrix:
python-version: ["3.10", "3.11"]
python-version: ["3.10", "3.11", "3.12"]
os: [ubuntu-latest, windows-latest, macos-latest]
fail-fast: false
env:
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -2,7 +2,9 @@

## 最近更新

* No changes
### 新功能

- BISON_OUTER_URL配置改进 [@SherkeyXD](https://github.com/SherkeyXD) ([#405](https://github.com/MountainDash/nonebot-bison/pull/405))

## v0.8.2

2 changes: 1 addition & 1 deletion docker/Dockerfile_with_frontend
Original file line number Diff line number Diff line change
@@ -22,7 +22,7 @@ WORKDIR /src

COPY pyproject.toml poetry.lock /src/

RUN poetry add "nonebot2[fastapi]" && \
RUN poetry add "nonebot2[fastapi]" nonebot-adapter-red nonebot-adapter-qq nonebot-adapter-telegram && \
poetry export --without-hashes --no-interaction --no-ansi -f requirements.txt -o requirements.txt
RUN pip install --prefix=/runtime --force-reinstall -r requirements.txt

4 changes: 3 additions & 1 deletion docker/Dockerfile_with_frontend_sentry
Original file line number Diff line number Diff line change
@@ -22,7 +22,9 @@ WORKDIR /src

COPY pyproject.toml poetry.lock /src/

RUN poetry add "nonebot2[fastapi]" nonebot-plugin-sentry && \
RUN poetry add "nonebot2[fastapi]" \
nonebot-adapter-red nonebot-adapter-qq nonebot-adapter-telegram \
nonebot-plugin-sentry && \
poetry export --without-hashes --no-interaction --no-ansi -f requirements.txt -o requirements.txt
RUN pip install --prefix=/runtime --force-reinstall -r requirements.txt

71 changes: 67 additions & 4 deletions docs/usage/README.md
Original file line number Diff line number Diff line change
@@ -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:<Bot运行在的端口>/bison/`
::: warning
请注意,该网址**并不能直接访问**Bison 的后台管理网页,正确的访问方法请参见[私聊机器人获取后台地址](#私聊机器人获取后台地址)
:::
::: tip
如果需要从外网或者 Docker 容器外访问后台页面,请确保`HOST=0.0.0.0`
::: tip 配置建议
请选择你的部署情况:
<div class="outer_url_help">
<input type="checkbox" id="docker" v-model="docker"/>
<label for="docker">使用容器部署</label>
<input type="checkbox" id="server" v-model="server"/>
<label for="server">部署在服务器上</label>
<input type="checkbox" id="reverse-proxy" v-model="reverseProxy"/>
<label for="reverse-proxy">启用反代</label>
</div>
下面是配置建议:
<div class="outer_url_help" v-html="outerUrlHelp"></div>
:::

- `BISON_FILTER_LOG`: 是否过滤来自`nonebot`的 warning 级以下的 log,如果你的 bot 只运行了这个插件可以考虑
开启,默认关
- `BISON_USE_QUEUE`: 是否用队列的方式发送消息,降低发送频率,默认开
@@ -190,3 +200,56 @@ Bison 在处理每条推送时,会按照以下规则检查推送中的 Tag:
- 如果推送中含有任何已记录的**需订阅 Tag**,Bison 会将该推送发送到群中,不管是否有其他 Tag。
- 如果**没有记录**任何需订阅 Tag,Bison 会将所有通过第一条规则检查的推送发送到群中。
- 如果记录了至少一个需订阅 Tag,Bison 会**丢弃所有**不含任何需订阅 Tag 的推送,即使通过了第一条规则检查。

<script setup>
import { ref, computed } from 'vue';

const docker = ref(false);
const server = ref(false);
const reverseProxy = ref(false);

const outerUrlHelp = computed(() => {
let helpText = '';

if ((docker.value || server.value) && !reverseProxy.value)
helpText += '将Bot配置中的 <code>HOST</code> 部分设置为 <code>0.0.0.0</code><br>';

if (docker.value && !server.value && !reverseProxy.value)
helpText += '将 <code>BISON_OUTER_URL</code> 设置为 <code>http://localhost:[Docker映射到主机的端口]/bison/</code><br>';

if (server.value && !reverseProxy.value){
if (docker.value)
helpText += '将 <code>BISON_OUTER_URL</code> 设置为 <code>http://[你的服务器ip]:[Docker映射到主机的端口]/bison/</code><br>';
else
helpText += '将 <code>BISON_OUTER_URL</code> 设置为 <code>http://[你的服务器ip]:[Bot运行的端口]/bison/</code><br>';
}

if (reverseProxy.value){
if (server.value){
helpText += '将 <code>BISON_OUTER_URL</code> 设置为 <code>http://[你的服务器ip]:[反代端口]/bison/</code><br>';
if (docker.value)
helpText += '请注意反代端口应该指向Docker映射到主机的端口<br>';
else
helpText += '请注意反代端口应该指向Bot运行的端口<br>';
}
else
helpText += '谁没事在自己电脑上起反代啊(<br>';
}

if (!docker.value && !server.value && !reverseProxy.value)
helpText += '你无需设置此项<br>';

return helpText;
});
</script>

<style>
.outer_url_help {
margin-top: 10px;
margin-bottom: 10px;
}

.outer_url_help label {
margin-right: 15px;
}
</style>
2 changes: 1 addition & 1 deletion docs/usage/easy-use.md
Original file line number Diff line number Diff line change
@@ -144,7 +144,7 @@ Bison 提供了一个网页管理订阅的功能,你可以在网页上查看
::: tip Bison 给出的链接无效?
Bison 所给的链接中的 ip 和 port 是`BISON_OUTER_URL`配置决定的,也就是说 Bison 本身不能获取服务器的 ip 与自身的 port,所以 Bison 给出的链接可能是无效的。你可以在`BISON_OUTER_URL`中设置你的服务器 ip 与 port,或者直接修改 Bison 给出的链接为正确的`http://<ip>:<port>/bison/...`来进入网页管理订阅的界面。

参见[详细介绍-配置](usage/#配置)`BISON_OUTER_URL`部分
参见[详细介绍-配置](/usage/#配置)`BISON_OUTER_URL`部分
:::
::: tip 认证失败?
:bug:
2 changes: 1 addition & 1 deletion nonebot_bison/admin_page/__init__.py
Original file line number Diff line number Diff line change
@@ -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
8 changes: 6 additions & 2 deletions nonebot_bison/plugin_config.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import nonebot
from pydantic import Field, BaseSettings

global_config = nonebot.get_driver().config
PlatformName = str
ThemeName = str

@@ -11,7 +12,7 @@ class PlugConfig(BaseSettings):
bison_theme_use_browser: bool = Field(default=False, description="是否允许主题使用浏览器")
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
@@ -25,9 +26,12 @@ class PlugConfig(BaseSettings):
bison_show_network_warning: bool = True
bison_platform_theme: dict[PlatformName, ThemeName] = {}

@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())
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -15,6 +15,7 @@ classifiers = [
"Operating System :: MacOS",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Programming Language :: Python :: Implementation :: CPython",
"License :: OSI Approved :: MIT License",
]
4 changes: 2 additions & 2 deletions tests/test_admin_page.py
Original file line number Diff line number Diff line change
@@ -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()