nonebot-plugin-areusleepy 0.0.2__py3-none-any.whl → 0.1.3__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 +21 -23
- nonebot_plugin_areusleepy/__main__.py +182 -64
- nonebot_plugin_areusleepy/config.py +19 -5
- {nonebot_plugin_areusleepy-0.0.2.dist-info → nonebot_plugin_areusleepy-0.1.3.dist-info}/METADATA +56 -25
- nonebot_plugin_areusleepy-0.1.3.dist-info/RECORD +8 -0
- {nonebot_plugin_areusleepy-0.0.2.dist-info → nonebot_plugin_areusleepy-0.1.3.dist-info}/licenses/LICENSE +1 -1
- nonebot_plugin_areusleepy/getsleepy.py +0 -90
- nonebot_plugin_areusleepy-0.0.2.dist-info/RECORD +0 -9
- {nonebot_plugin_areusleepy-0.0.2.dist-info → nonebot_plugin_areusleepy-0.1.3.dist-info}/WHEEL +0 -0
- {nonebot_plugin_areusleepy-0.0.2.dist-info → nonebot_plugin_areusleepy-0.1.3.dist-info}/entry_points.txt +0 -0
@@ -1,23 +1,21 @@
|
|
1
|
-
from nonebot import get_plugin_config
|
2
|
-
from nonebot.plugin import PluginMetadata, inherit_supported_adapters, require
|
3
|
-
|
4
|
-
require("nonebot_plugin_alconna")
|
5
|
-
|
6
|
-
from . import __main__ as __main__
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
config = get_plugin_config(Config)
|
23
|
-
|
1
|
+
from nonebot import get_plugin_config
|
2
|
+
from nonebot.plugin import PluginMetadata, inherit_supported_adapters, require
|
3
|
+
|
4
|
+
require("nonebot_plugin_alconna")
|
5
|
+
|
6
|
+
from . import __main__ as __main__
|
7
|
+
|
8
|
+
from .config import Config
|
9
|
+
|
10
|
+
__version__ = "0.1.3"
|
11
|
+
__plugin_meta__ = PluginMetadata(
|
12
|
+
name="AreYouSleepy",
|
13
|
+
description="基于 sleepy-project/sleepy 项目的状态查询插件!",
|
14
|
+
usage="/areusleepy [url]",
|
15
|
+
type="application",
|
16
|
+
homepage="https://github.com/Murasame-Dev/nonebot-plugin-areusleepy",
|
17
|
+
supported_adapters=inherit_supported_adapters("nonebot_plugin_alconna"),
|
18
|
+
config=Config,
|
19
|
+
)
|
20
|
+
|
21
|
+
config = get_plugin_config(Config)
|
@@ -1,83 +1,201 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
# --- 导入模块
|
4
|
+
|
1
5
|
from nonebot import on_command
|
2
6
|
from nonebot.matcher import Matcher
|
3
7
|
from nonebot.params import CommandArg
|
4
8
|
from nonebot.adapters import Event as BaseEvent, Message
|
5
9
|
from nonebot import get_plugin_config, get_bot
|
6
|
-
|
7
|
-
import httpx
|
8
|
-
|
9
10
|
from nonebot_plugin_alconna.uniseg import UniMessage
|
10
|
-
from
|
11
|
+
from nonebot_plugin_apscheduler import scheduler
|
12
|
+
from nonebot.log import logger
|
13
|
+
|
14
|
+
import requests
|
15
|
+
from urllib.parse import urljoin
|
11
16
|
|
12
17
|
from .config import Config
|
13
18
|
|
14
|
-
#
|
15
|
-
|
19
|
+
# --- 获取配置
|
20
|
+
|
21
|
+
config: Config = get_plugin_config(Config)
|
22
|
+
|
23
|
+
# --- 处理函数
|
24
|
+
|
25
|
+
|
26
|
+
def get_data(base_url: str, retries: int = config.sleepy_retries) -> tuple[bool, (dict | str)]:
|
27
|
+
'''
|
28
|
+
请求 api 获取数据
|
29
|
+
|
30
|
+
:param base_url: 服务地址
|
31
|
+
:param retries: 重试次数
|
32
|
+
:return bool: 是否成功
|
33
|
+
:return dict | str: 返回数据 (如成功则为返回数据 (dict), 如失败则为错误信息 (str))
|
34
|
+
'''
|
35
|
+
success = False
|
36
|
+
data = '未知错误'
|
37
|
+
query_url = urljoin(base_url, '/query?version=1') # version=1 -> 为未来 (可能) 的 Sleepy /query API 修改提供兼容
|
38
|
+
|
39
|
+
while retries > 0:
|
40
|
+
try:
|
41
|
+
resp: requests.Response = requests.get(
|
42
|
+
url=query_url,
|
43
|
+
timeout=config.sleepy_timeout,
|
44
|
+
allow_redirects=True
|
45
|
+
)
|
46
|
+
data = resp.json()
|
47
|
+
success = True
|
48
|
+
break
|
49
|
+
except Exception as e:
|
50
|
+
data = f'请求 {query_url} 出错: {e}'
|
51
|
+
retries -= 1
|
52
|
+
return success, data
|
53
|
+
|
54
|
+
|
55
|
+
def slice_text(text: str, max_length: int) -> str:
|
56
|
+
'''
|
57
|
+
截取指定长度文本
|
58
|
+
|
59
|
+
:param text: 原文本
|
60
|
+
:param max_length: 最大长度
|
61
|
+
|
62
|
+
:return str: 处理后文本
|
63
|
+
'''
|
64
|
+
if (
|
65
|
+
len(text) <= max_length or # 文本长度小于指定截取长度
|
66
|
+
max_length == 0 # 截取长度设置为 0 (禁用)
|
67
|
+
):
|
68
|
+
return text
|
69
|
+
else:
|
70
|
+
return f'{text[:max_length-3]}...'
|
71
|
+
|
72
|
+
|
73
|
+
def parse_data(url: str, data: dict) -> str:
|
74
|
+
'''
|
75
|
+
处理返回的数据
|
76
|
+
|
77
|
+
:param url: 网站地址
|
78
|
+
:param data: /query 返回数据
|
79
|
+
:return str: 处理后的消息文本
|
80
|
+
'''
|
81
|
+
devices = []
|
82
|
+
n = '\n'
|
83
|
+
if data.get('device'):
|
84
|
+
raw_devices: dict = data.get('device')
|
85
|
+
status_slice: int = data.get('device_status_slice')
|
86
|
+
for i in raw_devices.keys():
|
87
|
+
device: dict = raw_devices[i]
|
88
|
+
devices.append(f'''
|
89
|
+
- {device['show_name']}{f" ({i})" if config.sleepy_show_details else ""}
|
90
|
+
* 状态: {"✅正在线上 Hi~ o(* ̄▽ ̄*)ブ" if device['using'] else "❌离线 /(ㄒoㄒ)/~~"}
|
91
|
+
* 应用: {slice_text(device['app_name'], status_slice)}
|
92
|
+
'''[1:-1])
|
93
|
+
ret = f'''
|
94
|
+
👋你好 {url}
|
95
|
+
|
96
|
+
👀 在线状态
|
97
|
+
状态: {data['info']['name']}{f" ({data['status']})" if config.sleepy_show_details else ""}
|
98
|
+
详细信息: {data['info']['desc']}
|
99
|
+
|
100
|
+
💻 设备状态
|
101
|
+
{n.join(devices) if devices else '无'}
|
102
|
+
|
103
|
+
⏱ 最后更新: {data['last_updated']}{f" ({data['timezone']})" if config.sleepy_show_details else ""}
|
104
|
+
'''[1:-1]
|
105
|
+
return ret
|
16
106
|
|
17
|
-
|
18
|
-
|
19
|
-
|
107
|
+
# --- 定义命令
|
108
|
+
|
109
|
+
|
110
|
+
rusleepy = on_command(
|
111
|
+
cmd=config.sleepy_command
|
20
112
|
)
|
21
113
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
return None
|
30
|
-
except Exception as e:
|
31
|
-
return None
|
32
|
-
|
33
|
-
|
34
|
-
def format_device_info(device_data: dict) -> str:
|
35
|
-
device_lines = []
|
36
|
-
for device_name, info in device_data.items():
|
37
|
-
using_status = "✅ 使用中" if info.get('using', False) else "❌ 未使用"
|
38
|
-
device_lines.append(
|
39
|
-
f" - {info.get('show_name', device_name)}: {using_status}\n"
|
40
|
-
f" 应用: {info.get('app_name')}"
|
41
|
-
)
|
42
|
-
return "\n".join(device_lines)
|
43
|
-
|
44
|
-
async def create_status_message(data: dict) -> UniMessage:
|
45
|
-
msg = UniMessage()
|
46
|
-
|
47
|
-
# info
|
48
|
-
if 'info' in data and isinstance(data['info'], dict):
|
49
|
-
info = data['info']
|
50
|
-
msg += (
|
51
|
-
f"👋你好,{plugin_config.sleepyurl}\n"
|
52
|
-
f"🌐 个人信息:\n"
|
53
|
-
f" 状态: {info.get('name')}\n"
|
54
|
-
f" {info.get('desc')}\n"
|
55
|
-
)
|
56
|
-
|
57
|
-
# device info
|
58
|
-
if 'device' in data and isinstance(data['device'], dict):
|
59
|
-
msg += "\n\n📱 设备使用情况:\n"
|
60
|
-
msg += format_device_info(data['device'])
|
61
|
-
|
62
|
-
# 最后更新时间
|
63
|
-
if 'last_updated' in data:
|
64
|
-
msg += f"\n\n⏱ 最后更新: {data['last_updated']}"
|
114
|
+
|
115
|
+
@rusleepy.handle()
|
116
|
+
async def handle_status(msg: Message = CommandArg()):
|
117
|
+
'''
|
118
|
+
处理 /sleepy (默认) 命令
|
119
|
+
''' # 获取参数
|
120
|
+
query_url = msg.extract_plain_text().strip() or config.sleepy_url
|
65
121
|
|
66
|
-
|
122
|
+
# 提示获取中
|
123
|
+
if config.sleepy_prompt_loading:
|
124
|
+
await rusleepy.send(f'正在从 {query_url} 获取状态, 请稍候...')
|
125
|
+
|
126
|
+
success, data = get_data(query_url)
|
127
|
+
if success:
|
128
|
+
# 成功 -> 处理数据
|
129
|
+
try:
|
130
|
+
# 确保 data 是 dict 类型
|
131
|
+
if isinstance(data, dict):
|
132
|
+
parsed = parse_data(query_url, data)
|
133
|
+
else:
|
134
|
+
parsed = f'数据格式错误: {data}'
|
135
|
+
except Exception as e:
|
136
|
+
parsed = f'处理状态信息失败: {e}'
|
137
|
+
await rusleepy.send(parsed)
|
138
|
+
else:
|
139
|
+
# 失败 -> 返回错误
|
140
|
+
await rusleepy.send(f'获取状态信息失败: {data}')
|
67
141
|
|
68
|
-
@fetch_status.handle()
|
69
|
-
async def _(arg_msg: Message = CommandArg()):
|
70
|
-
"""处理queryFetch命令"""
|
71
|
-
await fetch_status.send("正在获取状态信息,请稍候...")
|
72
142
|
|
143
|
+
# --- 定时任务功能
|
144
|
+
|
145
|
+
async def send_scheduled_status():
|
146
|
+
'''
|
147
|
+
定时发送状态信息
|
148
|
+
'''
|
149
|
+
if not config.sleepy_scheduler_enabled:
|
150
|
+
return
|
151
|
+
|
73
152
|
# 获取状态数据
|
74
|
-
|
153
|
+
query_url = config.sleepy_url
|
154
|
+
success, data = get_data(query_url)
|
155
|
+
|
156
|
+
if not success:
|
157
|
+
logger.error(f'定时任务获取状态失败: {data}')
|
158
|
+
return
|
75
159
|
|
76
|
-
#
|
77
|
-
if data
|
78
|
-
|
160
|
+
# 确保 data 是 dict 类型
|
161
|
+
if not isinstance(data, dict):
|
162
|
+
logger.error(f'定时任务获取到的数据格式错误: {data}')
|
79
163
|
return
|
164
|
+
|
165
|
+
try:
|
166
|
+
parsed = parse_data(query_url, data)
|
167
|
+
message = f'📅 定时状态推送\n\n{parsed}'
|
168
|
+
except Exception as e:
|
169
|
+
logger.error(f'定时任务处理状态信息失败: {e}')
|
170
|
+
return
|
171
|
+
|
172
|
+
# 获取机器人实例
|
173
|
+
try:
|
174
|
+
bot = get_bot()
|
175
|
+
except Exception as e:
|
176
|
+
logger.error(f'获取机器人实例失败: {e}')
|
177
|
+
return
|
178
|
+
|
179
|
+
# 向配置的群组发送消息
|
180
|
+
for group_id in config.sleepy_scheduler_groups:
|
181
|
+
try:
|
182
|
+
await rusleepy.send(group_id=int(group_id), message=message)
|
183
|
+
logger.info(f'定时状态已发送到群组: {group_id}')
|
184
|
+
except Exception as e:
|
185
|
+
logger.error(f'向群组 {group_id} 发送定时状态失败: {e}')
|
186
|
+
|
80
187
|
|
81
|
-
|
82
|
-
|
83
|
-
|
188
|
+
# 注册定时任务
|
189
|
+
if config.sleepy_scheduler_enabled:
|
190
|
+
scheduler.add_job(
|
191
|
+
send_scheduled_status,
|
192
|
+
"cron",
|
193
|
+
id="sleepy_scheduled_status",
|
194
|
+
**{k: v for k, v in zip(
|
195
|
+
["second", "minute", "hour", "day", "month", "day_of_week"],
|
196
|
+
config.sleepy_scheduler_cron.split()
|
197
|
+
) if v != "*"},
|
198
|
+
misfire_grace_time=60,
|
199
|
+
replace_existing=True
|
200
|
+
)
|
201
|
+
logger.info(f'定时任务已启用,Cron 表达式: {config.sleepy_scheduler_cron}')
|
@@ -1,5 +1,19 @@
|
|
1
|
-
from pydantic import BaseModel
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
1
|
+
from pydantic import BaseModel
|
2
|
+
from typing import List, Optional
|
3
|
+
|
4
|
+
|
5
|
+
class Config(BaseModel):
|
6
|
+
# 基本配置
|
7
|
+
sleepy_command: str = 'areusleepy' # 触发命令
|
8
|
+
sleepy_prompt_loading: bool = True # 是否提示获取中
|
9
|
+
sleepy_show_details: bool = True # 是否显示详细信息
|
10
|
+
|
11
|
+
# Sleepy 服务配置
|
12
|
+
sleepy_url: str = 'https://sleepy-preview.wyf9.top' # Sleepy 服务地址
|
13
|
+
sleepy_timeout: float = 5.0 # 请求超时 (秒)
|
14
|
+
sleepy_retries: int = 3 # 请求失败时的重试次数
|
15
|
+
|
16
|
+
# 定时任务配置
|
17
|
+
sleepy_scheduler_enabled: bool = False # 是否启用定时任务
|
18
|
+
sleepy_scheduler_cron: str = '0 9,21 * * *' # Cron 表达式,默认每天 9:00 和 21:00
|
19
|
+
sleepy_scheduler_groups: List[str] = [] # 推送的群组列表
|
{nonebot_plugin_areusleepy-0.0.2.dist-info → nonebot_plugin_areusleepy-0.1.3.dist-info}/METADATA
RENAMED
@@ -1,14 +1,15 @@
|
|
1
1
|
Metadata-Version: 2.1
|
2
2
|
Name: nonebot-plugin-areusleepy
|
3
|
-
Version: 0.
|
3
|
+
Version: 0.1.3
|
4
4
|
Summary: Let bot look!!!
|
5
|
-
Author-Email: Murasame <congyu@sbhfy.cn>
|
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.
|
10
|
-
Requires-Dist: nonebot-plugin-
|
11
|
-
Requires-Dist:
|
9
|
+
Requires-Dist: nonebot2>=2.0.0
|
10
|
+
Requires-Dist: nonebot-plugin-apscheduler>=0.3.0
|
11
|
+
Requires-Dist: nonebot-plugin-alconna>=0.12.0
|
12
|
+
Requires-Dist: requests>=2.32.3
|
12
13
|
Description-Content-Type: text/markdown
|
13
14
|
|
14
15
|
<!-- markdownlint-disable MD031 MD033 MD036 MD041 -->
|
@@ -34,13 +35,11 @@ _✨基于 [sleepy-project/sleepy](https://github.com/sleepy-project/sleepy) 项
|
|
34
35
|
|
35
36
|
## 📖 介绍
|
36
37
|
|
37
|
-
此插件可以发送在 [sleepy-project/sleepy](https://github.com/sleepy-project/sleepy) 目前的状态信息,可以显示用户的设备是否在使用中,正在听的歌曲(支持情况以 sleepy 项目为准),支持多设备状态列表
|
38
|
-
|
39
|
-
|
38
|
+
此插件可以发送在 [sleepy-project/sleepy](https://github.com/sleepy-project/sleepy) 目前的状态信息,可以显示用户的设备是否在使用中,正在听的歌曲 (支持情况以 sleepy 项目为准),支持多设备状态列表
|
40
39
|
|
41
40
|
## 💿 安装
|
42
41
|
|
43
|
-
以下提到的方法
|
42
|
+
以下提到的方法 任选**其一**即可
|
44
43
|
|
45
44
|
<details open>
|
46
45
|
<summary>[推荐] 使用 nb-cli 安装</summary>
|
@@ -111,23 +110,33 @@ plugins = [
|
|
111
110
|
|
112
111
|
## ⚙️ 配置
|
113
112
|
|
114
|
-
|
115
|
-
|
116
|
-
默认: "http://127.0.0.1:9010"
|
113
|
+
env 配置示例,变量后面为默认配置:
|
117
114
|
|
118
|
-
|
119
|
-
|
120
|
-
|
115
|
+
```ini
|
116
|
+
# 基本配置
|
117
|
+
sleepy_command="aresleepy" # 触发命令
|
118
|
+
sleepy_prompt_loading=true # 是否在发送消息前显示 "正在获取, 请稍候"
|
119
|
+
sleepy_show_details=false # 是否显示详细信息 (状态的 id, 设备的 id, 最后更新时间的时区)
|
121
120
|
|
122
|
-
|
121
|
+
# Sleepy 服务配置
|
122
|
+
sleepy_url="https://status.0d000721.xin" # Sleepy 服务地址, 必须以 http:// 或 https:// 开头, 不以 / 结尾
|
123
|
+
sleepy_timeout=5.0 # 请求超时 (秒)
|
124
|
+
sleepy_retries=3 # 重试次数
|
123
125
|
|
124
|
-
|
126
|
+
# sleepy 定时任务配置
|
127
|
+
sleepy_scheduler_enabled=False # 是否启用定时任务
|
128
|
+
sleepy_scheduler_cron="0 9,21 * * *" # Cron 表达式,默认每天 9:00 和 21:00
|
129
|
+
sleepy_scheduler_groups:"" # 推送的群组列表,默认为空,开启定时任务后必须配置此项
|
130
|
+
```
|
125
131
|
|
126
|
-
|
132
|
+
## 🎉 使用
|
127
133
|
|
128
|
-
|
134
|
+
用法:
|
129
135
|
|
130
|
-
|
136
|
+
- `/sleepy` - 查询配置中网站的在线状态
|
137
|
+
- `/sleepy [url]` - 查询其他网站的在线状态
|
138
|
+
* 如: `/sleepy https://sleepy.wyf9.top`
|
139
|
+
* **注意: `url` 必须以 `http://` 或 `https://` 开头**
|
131
140
|
|
132
141
|
### 效果图
|
133
142
|
|
@@ -135,14 +144,36 @@ url 可填写为任意地址,**但需要注意http://或https://**
|
|
135
144
|
|
136
145
|
## 📞 联系
|
137
146
|
|
138
|
-
|
139
|
-
|
140
|
-
|
147
|
+
### Sleepy 项目
|
148
|
+
|
149
|
+
QQ 群组: [点此加群](https://siiway.top/t/qq)
|
150
|
+
Discord: [点此加入服务器](https://siiway.top/t/dc)
|
151
|
+
[更多联系方式](https://siiway.top/about/contact)
|
152
|
+
|
153
|
+
> *人较多, 请注明来意*
|
154
|
+
|
155
|
+
### 本项目
|
156
|
+
|
157
|
+
TG群组:[点此加入](https://t.me/LoveMurasame)
|
158
|
+
QQ群:[1049319982](https://qm.qq.com/q/DfTsIDXuc8)
|
159
|
+
作者邮箱:<congyu@sbhfy.cn>
|
160
|
+
|
161
|
+
> *大概率没人*
|
141
162
|
|
142
163
|
## 💡 鸣谢
|
143
164
|
|
144
|
-
[sleepy-project/sleepy: Are you sleeping?](https://github.com/sleepy-project/sleepy)
|
165
|
+
本项目基于 [sleepy-project/sleepy: Are you sleeping?](https://github.com/sleepy-project/sleepy)
|
166
|
+
|
167
|
+
感谢 Sleepy 开发者 [wyf9](https://github.com/wyf9) 重构插件
|
145
168
|
|
146
169
|
## 📝 更新日志
|
147
170
|
|
148
|
-
|
171
|
+
### 0.1.0
|
172
|
+
|
173
|
+
重构插件
|
174
|
+
|
175
|
+
|
176
|
+
|
177
|
+
### 0.1.2
|
178
|
+
|
179
|
+
添加了定时任务
|
@@ -0,0 +1,8 @@
|
|
1
|
+
nonebot_plugin_areusleepy-0.1.3.dist-info/METADATA,sha256=HSPf9fQEw9vvojOa68ZfZyqbq2wyytTe7qNZQdP7aHY,4519
|
2
|
+
nonebot_plugin_areusleepy-0.1.3.dist-info/WHEEL,sha256=tSfRZzRHthuv7vxpI4aehrdN9scLjk-dCJkPLzkHxGg,90
|
3
|
+
nonebot_plugin_areusleepy-0.1.3.dist-info/entry_points.txt,sha256=6OYgBcLyFCUgeqLgnvMyOJxPCWzgy7se4rLPKtNonMs,34
|
4
|
+
nonebot_plugin_areusleepy-0.1.3.dist-info/licenses/LICENSE,sha256=MVxFMTnhkkb66KBtMXZlHD7D0YbMVX1bSR9Z-jowliM,1086
|
5
|
+
nonebot_plugin_areusleepy/__init__.py,sha256=m5zu4O5-Phez7EXMqcVPFAN4LDRJNeiarK1fkorNLs4,661
|
6
|
+
nonebot_plugin_areusleepy/__main__.py,sha256=cA4aYmlKWc_dvCs0r8yOhETy0faZ-XRtgjfUoiIXE-Y,5982
|
7
|
+
nonebot_plugin_areusleepy/config.py,sha256=WChgbr07OyZrNaTojLUCpzSHiV5mU5XBMAkQysrktgw,796
|
8
|
+
nonebot_plugin_areusleepy-0.1.3.dist-info/RECORD,,
|
@@ -18,4 +18,4 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
18
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
19
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
20
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
-
SOFTWARE.
|
21
|
+
SOFTWARE.
|
@@ -1,90 +0,0 @@
|
|
1
|
-
from nonebot import on_command
|
2
|
-
from nonebot.matcher import Matcher
|
3
|
-
from nonebot.params import CommandArg
|
4
|
-
from nonebot.adapters import Event as BaseEvent, Message
|
5
|
-
from nonebot import get_plugin_config, get_bot
|
6
|
-
|
7
|
-
import httpx
|
8
|
-
|
9
|
-
from nonebot_plugin_alconna.uniseg import UniMessage
|
10
|
-
from typing import Optional
|
11
|
-
|
12
|
-
from .config import Config
|
13
|
-
|
14
|
-
# 获取插件配置
|
15
|
-
plugin_config = get_plugin_config(Config)
|
16
|
-
|
17
|
-
get_other_status = on_command(
|
18
|
-
"getsleepy",
|
19
|
-
aliases={"获取其他Sleepy状态"}
|
20
|
-
)
|
21
|
-
|
22
|
-
async def get_status_data(custom_url: Optional[str] = None) -> Optional[dict]:
|
23
|
-
url = f"{custom_url or plugin_config.sleepyurl}/query"
|
24
|
-
try:
|
25
|
-
async with httpx.AsyncClient(timeout=10.0) as client:
|
26
|
-
response = await client.get(url)
|
27
|
-
if response.status_code == 200:
|
28
|
-
return response.json()
|
29
|
-
return None
|
30
|
-
except Exception as e:
|
31
|
-
return None
|
32
|
-
|
33
|
-
|
34
|
-
def format_device_info(device_data: dict) -> str:
|
35
|
-
device_lines = []
|
36
|
-
for device_name, info in device_data.items():
|
37
|
-
using_status = "✅ 使用中" if info.get('using', False) else "❌ 未使用"
|
38
|
-
device_lines.append(
|
39
|
-
f" - {info.get('show_name', device_name)}: {using_status}\n"
|
40
|
-
f" 应用: {info.get('app_name')}"
|
41
|
-
)
|
42
|
-
return "\n".join(device_lines)
|
43
|
-
|
44
|
-
async def create_status_message(data: dict, url: Optional[str] = None) -> UniMessage:
|
45
|
-
msg = UniMessage()
|
46
|
-
|
47
|
-
# info
|
48
|
-
if 'info' in data and isinstance(data['info'], dict):
|
49
|
-
info = data['info']
|
50
|
-
display_url = url or plugin_config.sleepyurl
|
51
|
-
msg += (
|
52
|
-
f"👋你好 {display_url}\n"
|
53
|
-
f"🌐 个人信息:\n"
|
54
|
-
f" 状态: {info.get('name')}\n"
|
55
|
-
f" {info.get('desc')}\n"
|
56
|
-
)
|
57
|
-
|
58
|
-
# device info
|
59
|
-
if 'device' in data and isinstance(data['device'], dict):
|
60
|
-
msg += "\n\n📱 设备使用情况:\n"
|
61
|
-
msg += format_device_info(data['device'])
|
62
|
-
|
63
|
-
# 最后更新时间
|
64
|
-
if 'last_updated' in data:
|
65
|
-
msg += f"\n\n⏱ 最后更新: {data['last_updated']}"
|
66
|
-
|
67
|
-
return msg
|
68
|
-
|
69
|
-
@get_other_status.handle()
|
70
|
-
async def handle_get_other_status(arg_msg: Message = CommandArg()):
|
71
|
-
"""处理getsleepy命令"""
|
72
|
-
# 获取URL参数
|
73
|
-
url = arg_msg.extract_plain_text().strip()
|
74
|
-
if not url:
|
75
|
-
await get_other_status.send("请提供要查询的URL\n用法: /getsleepy url")
|
76
|
-
return
|
77
|
-
|
78
|
-
await get_other_status.send("正在获取状态信息,请稍候...")
|
79
|
-
|
80
|
-
# 获取状态数据
|
81
|
-
data = await get_status_data(url)
|
82
|
-
|
83
|
-
# 如果获取数据失败,返回错误信息
|
84
|
-
if data is None:
|
85
|
-
await get_other_status.send("获取状态信息失败,请检查URL是否正确")
|
86
|
-
return
|
87
|
-
|
88
|
-
# 生成并发送消息
|
89
|
-
msg = await create_status_message(data, url)
|
90
|
-
await get_other_status.send(str(msg))
|
@@ -1,9 +0,0 @@
|
|
1
|
-
nonebot_plugin_areusleepy-0.0.2.dist-info/METADATA,sha256=NbJ7Nkvkbe5-J173KElNVv8bexuXR0hO-iHCzOaqhEY,3484
|
2
|
-
nonebot_plugin_areusleepy-0.0.2.dist-info/WHEEL,sha256=tSfRZzRHthuv7vxpI4aehrdN9scLjk-dCJkPLzkHxGg,90
|
3
|
-
nonebot_plugin_areusleepy-0.0.2.dist-info/entry_points.txt,sha256=6OYgBcLyFCUgeqLgnvMyOJxPCWzgy7se4rLPKtNonMs,34
|
4
|
-
nonebot_plugin_areusleepy-0.0.2.dist-info/licenses/LICENSE,sha256=DPGO8xTl-MaoRnTMo5L8Wi6X_uC5K3Nedi2EizrgEaY,1085
|
5
|
-
nonebot_plugin_areusleepy/__init__.py,sha256=mgd65Jzn47klTuicOVD4VEOMqyD0qqrOGMRyAQ5Uzks,687
|
6
|
-
nonebot_plugin_areusleepy/__main__.py,sha256=FOXqsR923ARc3n_vK0OM9bL47tkzTvwBXi_F2D6cuKI,2556
|
7
|
-
nonebot_plugin_areusleepy/config.py,sha256=q_GnTRBE8KJZp8LjFIHhcnuOb9ge-3uMVftU4QflfnU,103
|
8
|
-
nonebot_plugin_areusleepy/getsleepy.py,sha256=Tts-Z8hwbZ13BuhJuDCjY9B2iicKaQpLTMh4OF41_v8,2925
|
9
|
-
nonebot_plugin_areusleepy-0.0.2.dist-info/RECORD,,
|
{nonebot_plugin_areusleepy-0.0.2.dist-info → nonebot_plugin_areusleepy-0.1.3.dist-info}/WHEEL
RENAMED
File without changes
|
File without changes
|