nonebot-plugin-areusleepy 0.1.7__py3-none-any.whl → 0.1.8__py3-none-any.whl
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_areusleepy/__init__.py +1 -1
- nonebot_plugin_areusleepy/__main__.py +36 -33
- nonebot_plugin_areusleepy/config.py +2 -2
- {nonebot_plugin_areusleepy-0.1.7.dist-info → nonebot_plugin_areusleepy-0.1.8.dist-info}/METADATA +25 -15
- nonebot_plugin_areusleepy-0.1.8.dist-info/RECORD +8 -0
- nonebot_plugin_areusleepy-0.1.7.dist-info/RECORD +0 -8
- {nonebot_plugin_areusleepy-0.1.7.dist-info → nonebot_plugin_areusleepy-0.1.8.dist-info}/WHEEL +0 -0
- {nonebot_plugin_areusleepy-0.1.7.dist-info → nonebot_plugin_areusleepy-0.1.8.dist-info}/entry_points.txt +0 -0
- {nonebot_plugin_areusleepy-0.1.7.dist-info → nonebot_plugin_areusleepy-0.1.8.dist-info}/licenses/LICENSE +0 -0
@@ -11,7 +11,7 @@ from nonebot_plugin_alconna.uniseg import UniMessage
|
|
11
11
|
from nonebot_plugin_apscheduler import scheduler
|
12
12
|
from nonebot.log import logger
|
13
13
|
|
14
|
-
import
|
14
|
+
import httpx
|
15
15
|
from urllib.parse import urljoin
|
16
16
|
|
17
17
|
from .config import Config
|
@@ -23,7 +23,7 @@ config: Config = get_plugin_config(Config)
|
|
23
23
|
# --- 处理函数
|
24
24
|
|
25
25
|
|
26
|
-
def get_data(base_url: str, retries: int = config.sleepy_retries) -> tuple[bool, (dict | str)]:
|
26
|
+
async def get_data(base_url: str, retries: int = config.sleepy_retries) -> tuple[bool, (dict | str)]:
|
27
27
|
'''
|
28
28
|
请求 api 获取数据
|
29
29
|
|
@@ -34,25 +34,27 @@ def get_data(base_url: str, retries: int = config.sleepy_retries) -> tuple[bool,
|
|
34
34
|
'''
|
35
35
|
success = False
|
36
36
|
data = '未知错误'
|
37
|
-
query_url = urljoin(base_url, '/query
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
37
|
+
query_url = urljoin(base_url, '/query')
|
38
|
+
|
39
|
+
async with httpx.AsyncClient() as client:
|
40
|
+
while retries > 0:
|
41
|
+
try:
|
42
|
+
resp: httpx.Response = await client.get(
|
43
|
+
url=query_url,
|
44
|
+
params={'version': '1'}, # version=1 -> 为未来 (可能?) 的 Sleepy /query API 修改提供兼容
|
45
|
+
timeout=config.sleepy_timeout,
|
46
|
+
follow_redirects=True
|
47
|
+
)
|
48
|
+
data = resp.json()
|
49
|
+
success = True
|
50
|
+
break
|
51
|
+
except Exception as e:
|
52
|
+
data = f'请求 {query_url} 出错: {e}'
|
53
|
+
retries -= 1
|
52
54
|
return success, data
|
53
55
|
|
54
56
|
|
55
|
-
def slice_text(text: str, max_length: int) -> str:
|
57
|
+
async def slice_text(text: str, max_length: int) -> str:
|
56
58
|
'''
|
57
59
|
截取指定长度文本
|
58
60
|
|
@@ -70,7 +72,7 @@ def slice_text(text: str, max_length: int) -> str:
|
|
70
72
|
return f'{text[:max_length-3]}...'
|
71
73
|
|
72
74
|
|
73
|
-
def parse_data(url: str, data: dict) -> str:
|
75
|
+
async def parse_data(url: str, data: dict) -> str:
|
74
76
|
'''
|
75
77
|
处理返回的数据
|
76
78
|
|
@@ -88,7 +90,7 @@ def parse_data(url: str, data: dict) -> str:
|
|
88
90
|
devices.append(f'''
|
89
91
|
- {device['show_name']}{f" ({i})" if config.sleepy_show_details else ""}
|
90
92
|
* 状态: {"✅正在线上 Hi~ o(* ̄▽ ̄*)ブ" if device['using'] else "❌离线 /(ㄒoㄒ)/~~"}
|
91
|
-
* 应用: {slice_text(device['app_name'], status_slice)}
|
93
|
+
* 应用: {await slice_text(device['app_name'], status_slice)}
|
92
94
|
'''[1:-1])
|
93
95
|
ret = f'''
|
94
96
|
👋你好 {url}
|
@@ -116,20 +118,21 @@ rusleepy = on_command(
|
|
116
118
|
async def handle_status(msg: Message = CommandArg()):
|
117
119
|
'''
|
118
120
|
处理 /sleepy (默认) 命令
|
119
|
-
'''
|
121
|
+
'''
|
122
|
+
# 获取参数
|
120
123
|
query_url = msg.extract_plain_text().strip() or config.sleepy_url
|
121
|
-
|
124
|
+
|
122
125
|
# 提示获取中
|
123
126
|
if config.sleepy_prompt_loading:
|
124
127
|
await rusleepy.send(f'正在从 {query_url} 获取状态, 请稍候...')
|
125
128
|
|
126
|
-
success, data = get_data(query_url)
|
129
|
+
success, data = await get_data(query_url)
|
127
130
|
if success:
|
128
131
|
# 成功 -> 处理数据
|
129
132
|
try:
|
130
133
|
# 确保 data 是 dict 类型
|
131
134
|
if isinstance(data, dict):
|
132
|
-
parsed = parse_data(query_url, data)
|
135
|
+
parsed = await parse_data(query_url, data)
|
133
136
|
else:
|
134
137
|
parsed = f'数据格式错误: {data}'
|
135
138
|
except Exception as e:
|
@@ -148,34 +151,34 @@ async def send_scheduled_status():
|
|
148
151
|
'''
|
149
152
|
if not config.sleepy_scheduler_enabled:
|
150
153
|
return
|
151
|
-
|
154
|
+
|
152
155
|
# 获取状态数据
|
153
156
|
query_url = config.sleepy_url
|
154
|
-
success, data = get_data(query_url)
|
155
|
-
|
157
|
+
success, data = await get_data(query_url)
|
158
|
+
|
156
159
|
if not success:
|
157
160
|
logger.error(f'定时任务获取状态失败: {data}')
|
158
161
|
return
|
159
|
-
|
162
|
+
|
160
163
|
# 确保 data 是 dict 类型
|
161
164
|
if not isinstance(data, dict):
|
162
165
|
logger.error(f'定时任务获取到的数据格式错误: {data}')
|
163
166
|
return
|
164
|
-
|
167
|
+
|
165
168
|
try:
|
166
|
-
parsed = parse_data(query_url, data)
|
169
|
+
parsed = await parse_data(query_url, data)
|
167
170
|
message = f'📅 定时状态推送\n\n{parsed}'
|
168
171
|
except Exception as e:
|
169
172
|
logger.error(f'定时任务处理状态信息失败: {e}')
|
170
173
|
return
|
171
|
-
|
174
|
+
|
172
175
|
# 获取机器人实例
|
173
176
|
try:
|
174
177
|
bot = get_bot()
|
175
178
|
except Exception as e:
|
176
179
|
logger.error(f'获取机器人实例失败: {e}')
|
177
180
|
return
|
178
|
-
|
181
|
+
|
179
182
|
# 向配置的群组发送消息
|
180
183
|
for group_id in config.sleepy_scheduler_groups:
|
181
184
|
try:
|
@@ -198,4 +201,4 @@ if config.sleepy_scheduler_enabled:
|
|
198
201
|
misfire_grace_time=60,
|
199
202
|
replace_existing=True
|
200
203
|
)
|
201
|
-
logger.info(f'
|
204
|
+
logger.info(f'定时任务已启用, Cron 表达式: {config.sleepy_scheduler_cron}')
|
@@ -9,11 +9,11 @@ class Config(BaseModel):
|
|
9
9
|
sleepy_show_details: bool = False # 是否显示详细信息
|
10
10
|
|
11
11
|
# Sleepy 服务配置
|
12
|
-
sleepy_url: str = 'https://sleepy-preview.wyf9.top' # Sleepy 服务地址
|
12
|
+
sleepy_url: str = 'https://sleepy-preview.wyf9.top' # Sleepy 服务地址 (必须以 http:// 或 https:// 开头)
|
13
13
|
sleepy_timeout: float = 5.0 # 请求超时 (秒)
|
14
14
|
sleepy_retries: int = 3 # 请求失败时的重试次数
|
15
15
|
|
16
16
|
# 定时任务配置
|
17
17
|
sleepy_scheduler_enabled: bool = False # 是否启用定时任务
|
18
18
|
sleepy_scheduler_cron: str = '0 9,21 * * *' # Cron 表达式,默认每天 9:00 和 21:00
|
19
|
-
sleepy_scheduler_groups: List[str] = [] # 推送的群组列表
|
19
|
+
sleepy_scheduler_groups: List[str] = [] # 推送的群组列表
|
{nonebot_plugin_areusleepy-0.1.7.dist-info → nonebot_plugin_areusleepy-0.1.8.dist-info}/METADATA
RENAMED
@@ -1,15 +1,14 @@
|
|
1
1
|
Metadata-Version: 2.1
|
2
2
|
Name: nonebot-plugin-areusleepy
|
3
|
-
Version: 0.1.
|
3
|
+
Version: 0.1.8
|
4
4
|
Summary: Let bot look!!!
|
5
5
|
Author-Email: Murasame <congyu@sbhfy.cn>, wyf9 <wyf9@wyf9.top>
|
6
6
|
License: MIT
|
7
7
|
Project-URL: homepage, https://github.com/Murasame-Dev/nonebot-plugin-areusleepy
|
8
8
|
Requires-Python: <4.0,>=3.9
|
9
|
-
Requires-Dist: nonebot2>=2.
|
9
|
+
Requires-Dist: nonebot2[httpx]>=2.4.2
|
10
10
|
Requires-Dist: nonebot-plugin-apscheduler>=0.3.0
|
11
11
|
Requires-Dist: nonebot-plugin-alconna>=0.12.0
|
12
|
-
Requires-Dist: requests>=2.32.3
|
13
12
|
Description-Content-Type: text/markdown
|
14
13
|
|
15
14
|
<!-- markdownlint-disable MD031 MD033 MD036 MD041 -->
|
@@ -114,19 +113,19 @@ env 配置示例,变量后面为默认配置:
|
|
114
113
|
|
115
114
|
```ini
|
116
115
|
# 基本配置
|
117
|
-
sleepy_command="
|
116
|
+
sleepy_command="areusleepy" # 触发命令
|
118
117
|
sleepy_prompt_loading=true # 是否在发送消息前显示 "正在获取, 请稍候"
|
119
118
|
sleepy_show_details=false # 是否显示详细信息 (状态的 id, 设备的 id, 最后更新时间的时区)
|
120
119
|
|
121
120
|
# Sleepy 服务配置
|
122
|
-
sleepy_url="https://status.0d000721.xin" # Sleepy 服务地址, 必须以 http:// 或 https://
|
121
|
+
sleepy_url="https://status.0d000721.xin" # Sleepy 服务地址, 必须以 http:// 或 https:// 开头
|
123
122
|
sleepy_timeout=5.0 # 请求超时 (秒)
|
124
123
|
sleepy_retries=3 # 重试次数
|
125
124
|
|
126
125
|
# sleepy 定时任务配置
|
127
126
|
sleepy_scheduler_enabled=False # 是否启用定时任务
|
128
127
|
sleepy_scheduler_cron="0 9,21 * * *" # Cron 表达式,默认每天 9:00 和 21:00
|
129
|
-
sleepy_scheduler_groups
|
128
|
+
sleepy_scheduler_groups="" # 推送的群组列表,默认为空,开启定时任务后必须配置此项
|
130
129
|
```
|
131
130
|
|
132
131
|
## 🎉 使用
|
@@ -136,7 +135,7 @@ sleepy_scheduler_groups:"" # 推送的群组列表,默认为空,开启定
|
|
136
135
|
- `/sleepy` - 查询配置中网站的在线状态
|
137
136
|
- `/sleepy [url]` - 查询其他网站的在线状态
|
138
137
|
* 如: `/sleepy https://sleepy.wyf9.top`
|
139
|
-
* **注意: `url` 必须以 `http://` 或 `https://`
|
138
|
+
* **注意: `url` 必须以 `http://` 或 `https://` 开头 (与配置中相同)**
|
140
139
|
|
141
140
|
### 效果图
|
142
141
|
|
@@ -146,16 +145,20 @@ sleepy_scheduler_groups:"" # 推送的群组列表,默认为空,开启定
|
|
146
145
|
|
147
146
|
### Sleepy 项目
|
148
147
|
|
149
|
-
QQ 群组: [
|
150
|
-
|
148
|
+
QQ 群组: [点此加入](https://siiway.top/t/qq)
|
149
|
+
|
150
|
+
Discord (推荐): [点此加入](https://siiway.top/t/dc)
|
151
|
+
|
151
152
|
[更多联系方式](https://siiway.top/about/contact)
|
152
153
|
|
153
|
-
> *人较多,
|
154
|
+
> *人较多, 建议注明来意*
|
154
155
|
|
155
156
|
### 本项目
|
156
157
|
|
157
|
-
TG群组:[点此加入](https://t.me/LoveMurasame)
|
158
|
-
|
158
|
+
TG 群组:[点此加入](https://t.me/LoveMurasame)
|
159
|
+
|
160
|
+
QQ 群组:[点此加入](https://qm.qq.com/q/DfTsIDXuc8)
|
161
|
+
|
159
162
|
作者邮箱:<congyu@sbhfy.cn>
|
160
163
|
|
161
164
|
> *大概率没人*
|
@@ -168,12 +171,19 @@ QQ群:[1049319982](https://qm.qq.com/q/DfTsIDXuc8)
|
|
168
171
|
|
169
172
|
## 📝 更新日志
|
170
173
|
|
171
|
-
### 0.1.
|
172
|
-
|
173
|
-
重构插件
|
174
|
+
### 0.1.8
|
174
175
|
|
176
|
+
将同步的 `requests` 替换为异步的 `httpx`, 支持并发使用
|
175
177
|
|
178
|
+
<details>
|
179
|
+
<summary>展开更多</summary>
|
176
180
|
|
177
181
|
### 0.1.2
|
178
182
|
|
179
183
|
添加了定时任务
|
184
|
+
|
185
|
+
### 0.1.0
|
186
|
+
|
187
|
+
重构插件
|
188
|
+
|
189
|
+
</details>
|
@@ -0,0 +1,8 @@
|
|
1
|
+
nonebot_plugin_areusleepy-0.1.8.dist-info/METADATA,sha256=-8nTOTrPAJwNzz6_MHysydNljG_7p7pSNeypPJ4-eIg,4649
|
2
|
+
nonebot_plugin_areusleepy-0.1.8.dist-info/WHEEL,sha256=tSfRZzRHthuv7vxpI4aehrdN9scLjk-dCJkPLzkHxGg,90
|
3
|
+
nonebot_plugin_areusleepy-0.1.8.dist-info/entry_points.txt,sha256=6OYgBcLyFCUgeqLgnvMyOJxPCWzgy7se4rLPKtNonMs,34
|
4
|
+
nonebot_plugin_areusleepy-0.1.8.dist-info/licenses/LICENSE,sha256=MVxFMTnhkkb66KBtMXZlHD7D0YbMVX1bSR9Z-jowliM,1086
|
5
|
+
nonebot_plugin_areusleepy/__init__.py,sha256=Zqqaol2g08WuAb_JIWJ0PxjdISDapIwwOO9XMPbeOOU,747
|
6
|
+
nonebot_plugin_areusleepy/__main__.py,sha256=-FgK46pZmEliPs2e7B6jJpZ-UipNLoMOTnrALRI9FPk,6138
|
7
|
+
nonebot_plugin_areusleepy/config.py,sha256=AbJRRTdPRTHfckhdnOMi8RetoLQF-2mK8zvswDSMDiM,839
|
8
|
+
nonebot_plugin_areusleepy-0.1.8.dist-info/RECORD,,
|
@@ -1,8 +0,0 @@
|
|
1
|
-
nonebot_plugin_areusleepy-0.1.7.dist-info/METADATA,sha256=lGMeCrrlGLlMsKzdlSH0EWR70GL2n1QuvxJh4vviSsY,4519
|
2
|
-
nonebot_plugin_areusleepy-0.1.7.dist-info/WHEEL,sha256=tSfRZzRHthuv7vxpI4aehrdN9scLjk-dCJkPLzkHxGg,90
|
3
|
-
nonebot_plugin_areusleepy-0.1.7.dist-info/entry_points.txt,sha256=6OYgBcLyFCUgeqLgnvMyOJxPCWzgy7se4rLPKtNonMs,34
|
4
|
-
nonebot_plugin_areusleepy-0.1.7.dist-info/licenses/LICENSE,sha256=MVxFMTnhkkb66KBtMXZlHD7D0YbMVX1bSR9Z-jowliM,1086
|
5
|
-
nonebot_plugin_areusleepy/__init__.py,sha256=Gw0NQKuoyjvVOe63V3-UFe9bW2iO8SuAyvMPxcqPIUM,747
|
6
|
-
nonebot_plugin_areusleepy/__main__.py,sha256=cA4aYmlKWc_dvCs0r8yOhETy0faZ-XRtgjfUoiIXE-Y,5982
|
7
|
-
nonebot_plugin_areusleepy/config.py,sha256=Gtd67yVe3NnNzj1v9qELkVUszd-1CG1MY75KdL6_vtw,797
|
8
|
-
nonebot_plugin_areusleepy-0.1.7.dist-info/RECORD,,
|
{nonebot_plugin_areusleepy-0.1.7.dist-info → nonebot_plugin_areusleepy-0.1.8.dist-info}/WHEEL
RENAMED
File without changes
|
File without changes
|
File without changes
|