nonebot-plugin-maimaimonitor 26.2.4__tar.gz → 26.2.5__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {nonebot_plugin_maimaimonitor-26.2.4 → nonebot_plugin_maimaimonitor-26.2.5}/PKG-INFO +1 -1
- {nonebot_plugin_maimaimonitor-26.2.4 → nonebot_plugin_maimaimonitor-26.2.5}/README.md +19 -1
- {nonebot_plugin_maimaimonitor-26.2.4 → nonebot_plugin_maimaimonitor-26.2.5}/nonebot_plugin_maimaimonitor/maimai_plugin_v11.py +71 -16
- {nonebot_plugin_maimaimonitor-26.2.4 → nonebot_plugin_maimaimonitor-26.2.5}/nonebot_plugin_maimaimonitor.egg-info/PKG-INFO +1 -1
- {nonebot_plugin_maimaimonitor-26.2.4 → nonebot_plugin_maimaimonitor-26.2.5}/pyproject.toml +1 -1
- {nonebot_plugin_maimaimonitor-26.2.4 → nonebot_plugin_maimaimonitor-26.2.5}/LICENSE +0 -0
- {nonebot_plugin_maimaimonitor-26.2.4 → nonebot_plugin_maimaimonitor-26.2.5}/nonebot_plugin_maimaimonitor/__init__.py +0 -0
- {nonebot_plugin_maimaimonitor-26.2.4 → nonebot_plugin_maimaimonitor-26.2.5}/nonebot_plugin_maimaimonitor/client.py +0 -0
- {nonebot_plugin_maimaimonitor-26.2.4 → nonebot_plugin_maimaimonitor-26.2.5}/nonebot_plugin_maimaimonitor/config.py +0 -0
- {nonebot_plugin_maimaimonitor-26.2.4 → nonebot_plugin_maimaimonitor-26.2.5}/nonebot_plugin_maimaimonitor/constants.py +0 -0
- {nonebot_plugin_maimaimonitor-26.2.4 → nonebot_plugin_maimaimonitor-26.2.5}/nonebot_plugin_maimaimonitor.egg-info/SOURCES.txt +0 -0
- {nonebot_plugin_maimaimonitor-26.2.4 → nonebot_plugin_maimaimonitor-26.2.5}/nonebot_plugin_maimaimonitor.egg-info/dependency_links.txt +0 -0
- {nonebot_plugin_maimaimonitor-26.2.4 → nonebot_plugin_maimaimonitor-26.2.5}/nonebot_plugin_maimaimonitor.egg-info/requires.txt +0 -0
- {nonebot_plugin_maimaimonitor-26.2.4 → nonebot_plugin_maimaimonitor-26.2.5}/nonebot_plugin_maimaimonitor.egg-info/top_level.txt +0 -0
- {nonebot_plugin_maimaimonitor-26.2.4 → nonebot_plugin_maimaimonitor-26.2.5}/setup.cfg +0 -0
|
@@ -44,7 +44,7 @@ pip install nonebot-plugin-maimaimonitor
|
|
|
44
44
|
| `MAIMAI_BOT_PRIVATE_KEY` | `str` | 无 | 与 ClientID 配套的私钥,申请时一并提供 |
|
|
45
45
|
| `MAIMAI_BOT_DISPLAY_NAME` | `str` | `qwq` | Bot显示名称,上报时展示 |
|
|
46
46
|
| `MAIMAI_WORKER_URL` | `str` | `https://maiapi.chongxi.us` | 上报API地址 |
|
|
47
|
-
| `MAIMAI_BROADCAST_GROUP_IDS` | `list[int]` | `[]` |
|
|
47
|
+
| `MAIMAI_BROADCAST_GROUP_IDS` | `list[int]` | `[]` | 广播推送的群组列表(兜底,配了即始终推送,无需管理员命令) |
|
|
48
48
|
| `MAIMAI_BROADCAST_INTERVAL` | `int` | `300` | 广播轮询检测间隔(秒)|
|
|
49
49
|
| `MAIMAI_BROADCAST_ALL_GROUPS` | `bool` | `false` | 向bot所在所有群播报,谨慎使用 |
|
|
50
50
|
| `MAIMAI_BROADCAST_TIME_RANGES` | `str` | 无 | 推送时间白名单,格式如 `8-11,13-20`,空时不限制。左闭右开(`8-11` 包含 8 点不包含 11 点),跨天用 `22-6`(晚上 10 点到早上 6 点)|
|
|
@@ -100,6 +100,24 @@ pip install nonebot-plugin-maimaimonitor
|
|
|
100
100
|
- 返航(正常):「华立冯返航了」「SEGA老冯落地」
|
|
101
101
|
|
|
102
102
|
### 断网播报 (无需私钥)
|
|
103
|
+
|
|
104
|
+
推荐用管理员命令,直接在群里动态开/关(无需改配置重启):
|
|
105
|
+
|
|
106
|
+
- `/广播 开` —— 对当前群开启断网推送
|
|
107
|
+
- `/广播 关` —— 强制关闭当前群断网推送(**优先级高于 env 配置**)
|
|
108
|
+
- `/广播 状态` —— 查看断网推送配置
|
|
109
|
+
- 仅 **SUPERUSER(bot 配置的管理员)** 可用
|
|
110
|
+
|
|
111
|
+
> 管理员命令针对「触发该命令的群」生效、每群独立。env 配置(下面的 `MAIMAI_BROADCAST_*`)会作为**兜底**,与命令启用的群合并播报:兜底群无需管理员在群里手动开启,凡配置的群始终接收推送。
|
|
112
|
+
>
|
|
113
|
+
> **优先级(高 → 低)**:`/广播 关` 黑名单 > 命令「开」+ env 白名单 > `MAIMAI_BROADCAST_ALL_GROUPS` 全员。
|
|
114
|
+
>
|
|
115
|
+
> - env 配了某群、但管理员 `/广播 关` 了它 → 该群**不会**播报(黑名单压制 env)
|
|
116
|
+
> - 即使 `MAIMAI_BROADCAST_ALL_GROUPS=true`,被 `/广播 关` 的群也会被排除
|
|
117
|
+
> - `/广播 开` 会解除该群的黑名单状态
|
|
118
|
+
>
|
|
119
|
+
> **注意**:命令设置保存在内存中,bot 重启后会清空。要长期生效请配合 env 兜底配置,或重启后重新 `/广播 开`。
|
|
120
|
+
|
|
103
121
|
配置 `MAIMAI_BROADCAST_GROUP_IDS` 或开启 `MAIMAI_BROADCAST_ALL_GROUPS` 后,服务器宕机时自动推送(默认全部服务的宕机都会播报,可用 `MAIMAI_BROADCAST_SERVERS` 限定播报范围):
|
|
104
122
|
|
|
105
123
|
```
|
|
@@ -4,6 +4,7 @@ from datetime import datetime, timezone, timedelta
|
|
|
4
4
|
from nonebot import on_command, on_message, require, get_plugin_config
|
|
5
5
|
from nonebot.log import logger
|
|
6
6
|
from nonebot.rule import Rule
|
|
7
|
+
from nonebot.permission import SUPERUSER
|
|
7
8
|
from nonebot.matcher import Matcher
|
|
8
9
|
from nonebot.adapters.onebot.v11 import Bot, Event, Message, GroupMessageEvent
|
|
9
10
|
from nonebot.params import CommandArg
|
|
@@ -17,6 +18,9 @@ from .constants import (
|
|
|
17
18
|
|
|
18
19
|
config = get_plugin_config(Config)
|
|
19
20
|
|
|
21
|
+
broadcast_group_ids: set[int] = set()
|
|
22
|
+
broadcast_blacklist_ids: set[int] = set()
|
|
23
|
+
|
|
20
24
|
keyword_cooldown: dict[int, float] = {}
|
|
21
25
|
KEYWORD_COOLDOWN_SECONDS = 60
|
|
22
26
|
|
|
@@ -99,6 +103,60 @@ cache_lock = Lock()
|
|
|
99
103
|
|
|
100
104
|
report_matcher = on_command("report", aliases={"上报"}, priority=5, block=False)
|
|
101
105
|
net_matcher = on_command("net", priority=5, block=False)
|
|
106
|
+
broadcast_matcher = on_command("广播", aliases={"断网推送", "推送"}, priority=5, block=True, permission=SUPERUSER)
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
@broadcast_matcher.handle()
|
|
110
|
+
async def handle_broadcast(bot: Bot, event: GroupMessageEvent, args: Message = CommandArg()):
|
|
111
|
+
arg_text = args.extract_plain_text().strip()
|
|
112
|
+
group_id = event.group_id
|
|
113
|
+
|
|
114
|
+
if not arg_text:
|
|
115
|
+
await broadcast_matcher.finish(_broadcast_usage())
|
|
116
|
+
|
|
117
|
+
action = arg_text.split()[0].lower()
|
|
118
|
+
|
|
119
|
+
if action in ("开", "on", "启用", "开启"):
|
|
120
|
+
broadcast_blacklist_ids.discard(group_id)
|
|
121
|
+
broadcast_group_ids.add(group_id)
|
|
122
|
+
await broadcast_matcher.finish(
|
|
123
|
+
f"✅ 已对本群开启断网推送(群 {group_id})\n"
|
|
124
|
+
"服务器宕机/恢复时 bot 会自动播报。\n"
|
|
125
|
+
f"可用 /广播 关 关闭当前群推送"
|
|
126
|
+
)
|
|
127
|
+
|
|
128
|
+
if action in ("关", "off", "关闭", "停用"):
|
|
129
|
+
broadcast_group_ids.discard(group_id)
|
|
130
|
+
broadcast_blacklist_ids.add(group_id)
|
|
131
|
+
await broadcast_matcher.finish(
|
|
132
|
+
f"⛔ 已强制关闭当前群({group_id})的断网推送\n"
|
|
133
|
+
"即使 env 配置了该群也不会播报;/广播 开 可重新开启"
|
|
134
|
+
)
|
|
135
|
+
|
|
136
|
+
if action in ("状态", "status", "查看", "list"):
|
|
137
|
+
lines = []
|
|
138
|
+
if broadcast_group_ids:
|
|
139
|
+
lines.append("命令启用的群:" + "、".join(str(g) for g in sorted(broadcast_group_ids)))
|
|
140
|
+
if broadcast_blacklist_ids:
|
|
141
|
+
lines.append("已强制关闭(黑名单):" + "、".join(str(g) for g in sorted(broadcast_blacklist_ids)))
|
|
142
|
+
if config.maimai_broadcast_group_ids:
|
|
143
|
+
lines.append("env 配置(兜底,仍会播报):" + "、".join(str(g) for g in config.maimai_broadcast_group_ids))
|
|
144
|
+
if config.maimai_broadcast_all_groups:
|
|
145
|
+
lines.append("env:向所有群播报")
|
|
146
|
+
if not lines:
|
|
147
|
+
await broadcast_matcher.finish("当前没有任何断网推送配置")
|
|
148
|
+
await broadcast_matcher.finish("\n".join(lines))
|
|
149
|
+
|
|
150
|
+
await broadcast_matcher.finish(_broadcast_usage())
|
|
151
|
+
|
|
152
|
+
|
|
153
|
+
def _broadcast_usage() -> str:
|
|
154
|
+
return (
|
|
155
|
+
"断网推送管理(仅管理员)\n"
|
|
156
|
+
"/广播 开 —— 对当前群开启断网推送\n"
|
|
157
|
+
"/广播 关 —— 强制关闭当前群断网推送(优先级高于 env 配置)\n"
|
|
158
|
+
"/广播 状态 —— 查看断网推送配置"
|
|
159
|
+
)
|
|
102
160
|
|
|
103
161
|
DIRECT_ALIASES = {"网咋样", "华立服务器死了吗", "炸了吗"}
|
|
104
162
|
|
|
@@ -167,23 +225,20 @@ async def broadcast_to_groups(msg: str):
|
|
|
167
225
|
try:
|
|
168
226
|
from nonebot import get_bot
|
|
169
227
|
bot = get_bot()
|
|
228
|
+
targets: set[int] = set(broadcast_group_ids)
|
|
170
229
|
if config.maimai_broadcast_all_groups:
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
except Exception as e:
|
|
177
|
-
logger.warning(f"播报失败 group_id={group['group_id']}: {e}")
|
|
178
|
-
elif config.maimai_broadcast_group_ids:
|
|
179
|
-
for group_id in config.maimai_broadcast_group_ids:
|
|
180
|
-
try:
|
|
181
|
-
await bot.send_group_msg(group_id=group_id, message=msg)
|
|
182
|
-
logger.info(f"播报成功 group_id={group_id}")
|
|
183
|
-
except Exception as e:
|
|
184
|
-
logger.warning(f"播报失败 group_id={group_id}: {e}")
|
|
185
|
-
else:
|
|
230
|
+
targets |= {g['group_id'] for g in (await bot.get_group_list())}
|
|
231
|
+
if config.maimai_broadcast_group_ids:
|
|
232
|
+
targets |= {int(x) for x in config.maimai_broadcast_group_ids}
|
|
233
|
+
targets -= broadcast_blacklist_ids
|
|
234
|
+
if not targets:
|
|
186
235
|
return
|
|
236
|
+
for group_id in targets:
|
|
237
|
+
try:
|
|
238
|
+
await bot.send_group_msg(group_id=group_id, message=msg)
|
|
239
|
+
logger.info(f"播报成功 group_id={group_id}")
|
|
240
|
+
except Exception as e:
|
|
241
|
+
logger.warning(f"播报失败 group_id={group_id}: {e}")
|
|
187
242
|
except Exception as e:
|
|
188
243
|
logger.warning(f"获取bot实例失败: {e}")
|
|
189
244
|
|
|
@@ -230,7 +285,7 @@ def _is_in_broadcast_window() -> bool:
|
|
|
230
285
|
|
|
231
286
|
async def check_server_status():
|
|
232
287
|
global last_status, anomaly_start_time, outage_active
|
|
233
|
-
if not config.maimai_broadcast_group_ids and not config.maimai_broadcast_all_groups:
|
|
288
|
+
if not broadcast_group_ids and not config.maimai_broadcast_group_ids and not config.maimai_broadcast_all_groups:
|
|
234
289
|
return
|
|
235
290
|
if not _is_in_broadcast_window():
|
|
236
291
|
return
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|