nonebot-plugin-areusleepy 0.0.2__tar.gz → 0.1.3__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.
@@ -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,14 +1,15 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: nonebot-plugin-areusleepy
3
- Version: 0.0.2
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.4.1
10
- Requires-Dist: nonebot-plugin-alconna>=0.54.2
11
- Requires-Dist: httpx>=0.28.1
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
- #### `sleepyurl` - /getsleepy 使用的默认地址
115
-
116
- 默认: "http://127.0.0.1:9010"
113
+ env 配置示例,变量后面为默认配置:
117
114
 
118
- ****必须要有http://或https://****
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
- #### `areusleepy` - 查询默认配置的状态信息
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
- #### `getsleepy url` - 查询其他站点的状态信息
134
+ 用法:
129
135
 
130
- url 可填写为任意地址,**但需要注意http://或https://**
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
- TG群组:[点此加入](https://t.me/LoveMurasame)
139
- QQ群:[1049319982](https://qm.qq.com/q/DfTsIDXuc8)
140
- 邮箱:<congyu@sbhfy.cn>
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) - 提供灵感,感谢开发者 [wyf9](https://github.com/wyf9) 的耐心指导
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
- 芝士刚刚发布的插件,还没有更新日志的说 qwq~
171
+ ### 0.1.0
172
+
173
+ 重构插件
174
+
175
+
176
+
177
+ ### 0.1.2
178
+
179
+ 添加了定时任务
@@ -1,135 +1,165 @@
1
- <!-- markdownlint-disable MD031 MD033 MD036 MD041 -->
2
-
3
- <div align="center">
4
-
5
- <a href="https://v2.nonebot.dev/store">
6
- <img src="https://raw.githubusercontent.com/A-kirami/nonebot-plugin-template/resources/nbp_logo.png" width="180" height="180" alt="NoneBotPluginLogo">
7
- </a>
8
-
9
- <p>
10
- <img src="https://raw.githubusercontent.com/lgc-NB2Dev/readme/main/template/plugin.svg" alt="NoneBotPluginText">
11
- </p>
12
-
13
- # NoneBot-Plugin-AreUSleepy
14
-
15
- _✨基于 [sleepy-project/sleepy](https://github.com/sleepy-project/sleepy) 项目的状态查询插件! ✨_
16
-
17
- [![python3](https://img.shields.io/badge/python-3.9+-blue.svg)](https://www.python.org/)
18
- [![License](https://img.shields.io/badge/license-MIT-blue.svg)](https://opensource.org/licenses/MIT)
19
-
20
- </div>
21
-
22
- ## 📖 介绍
23
-
24
- 此插件可以发送在 [sleepy-project/sleepy](https://github.com/sleepy-project/sleepy) 目前的状态信息,可以显示用户的设备是否在使用中,正在听的歌曲(支持情况以 sleepy 项目为准),支持多设备状态列表
25
-
26
-
27
-
28
- ## 💿 安装
29
-
30
- 以下提到的方法 任选**其一** 即可
31
-
32
- <details open>
33
- <summary>[推荐] 使用 nb-cli 安装</summary>
34
- 在 nonebot2 项目的根目录下打开命令行, 输入以下指令即可安装
35
-
36
- ```bash
37
- nb plugin install nonebot-plugin-areusleepy
38
- ```
39
-
40
- </details>
41
-
42
- <details>
43
- <summary>使用包管理器安装</summary>
44
- 在 nonebot2 项目的插件目录下, 打开命令行, 根据你使用的包管理器, 输入相应的安装命令
45
-
46
- <details>
47
- <summary>pip</summary>
48
-
49
- ```bash
50
- pip install nonebot-plugin-areusleepy
51
- ```
52
-
53
- </details>
54
- <details>
55
- <summary>pdm</summary>
56
-
57
- ```bash
58
- pdm add nonebot-nonebot-plugin-areusleepy
59
- ```
60
-
61
- </details>
62
- <details>
63
- <summary>poetry</summary>
64
-
65
- ```bash
66
- poetry add nonebot-plugin-areusleepy
67
- ```
68
-
69
- </details>
70
- <details>
71
- <summary>conda</summary>
72
-
73
- ```bash
74
- conda install nonebot-plugin-areusleepy
75
- ```
76
-
77
- </details>
78
- <details>
79
- <summary>uv</summary>
80
-
81
- ```bash
82
- uv add nonebot-plugin-areusleepy
83
- ```
84
-
85
- </details>
86
-
87
- 打开 nonebot2 项目根目录下的 `pyproject.toml` 文件, 在 `[tool.nonebot]` 部分的 `plugins` 项里追加写入
88
-
89
- ```toml
90
- [tool.nonebot]
91
- plugins = [
92
- # ...
93
- "nonebot_plugin_areusleepy"
94
- ]
95
- ```
96
-
97
- </details>
98
-
99
- ## ⚙️ 配置
100
-
101
- #### `sleepyurl` - /getsleepy 使用的默认地址
102
-
103
- 默认: "http://127.0.0.1:9010"
104
-
105
- ****必须要有http://或https://****
106
-
107
- ## 🎉 使用
108
-
109
- ### 指令表
110
-
111
- #### `areusleepy` - 查询默认配置的状态信息
112
-
113
- 查询配置文件内的网站信息并输出
114
-
115
- #### `getsleepy url` - 查询其他站点的状态信息
116
-
117
- url 可填写为任意地址,**但需要注意http://或https://**
118
-
119
- ### 效果图
120
-
121
- ![兄弟你睡了吗喵!!!!!!](./areisleepyyyyyy.png)
122
-
123
- ## 📞 联系
124
-
125
- TG群组:[点此加入](https://t.me/LoveMurasame)
126
- QQ群:[1049319982](https://qm.qq.com/q/DfTsIDXuc8)
127
- 邮箱:<congyu@sbhfy.cn>
128
-
129
- ## 💡 鸣谢
130
-
131
- [sleepy-project/sleepy: Are you sleeping?](https://github.com/sleepy-project/sleepy) - 提供灵感,感谢开发者 [wyf9](https://github.com/wyf9) 的耐心指导
132
-
133
- ## 📝 更新日志
134
-
135
- 芝士刚刚发布的插件,还没有更新日志的说 qwq~
1
+ <!-- markdownlint-disable MD031 MD033 MD036 MD041 -->
2
+
3
+ <div align="center">
4
+
5
+ <a href="https://v2.nonebot.dev/store">
6
+ <img src="https://raw.githubusercontent.com/A-kirami/nonebot-plugin-template/resources/nbp_logo.png" width="180" height="180" alt="NoneBotPluginLogo">
7
+ </a>
8
+
9
+ <p>
10
+ <img src="https://raw.githubusercontent.com/lgc-NB2Dev/readme/main/template/plugin.svg" alt="NoneBotPluginText">
11
+ </p>
12
+
13
+ # NoneBot-Plugin-AreUSleepy
14
+
15
+ _✨基于 [sleepy-project/sleepy](https://github.com/sleepy-project/sleepy) 项目的状态查询插件! ✨_
16
+
17
+ [![python3](https://img.shields.io/badge/python-3.9+-blue.svg)](https://www.python.org/)
18
+ [![License](https://img.shields.io/badge/license-MIT-blue.svg)](https://opensource.org/licenses/MIT)
19
+
20
+ </div>
21
+
22
+ ## 📖 介绍
23
+
24
+ 此插件可以发送在 [sleepy-project/sleepy](https://github.com/sleepy-project/sleepy) 目前的状态信息,可以显示用户的设备是否在使用中,正在听的歌曲 (支持情况以 sleepy 项目为准),支持多设备状态列表
25
+
26
+ ## 💿 安装
27
+
28
+ 以下提到的方法 任选**其一**即可
29
+
30
+ <details open>
31
+ <summary>[推荐] 使用 nb-cli 安装</summary>
32
+ nonebot2 项目的根目录下打开命令行, 输入以下指令即可安装
33
+
34
+ ```bash
35
+ nb plugin install nonebot-plugin-areusleepy
36
+ ```
37
+
38
+ </details>
39
+
40
+ <details>
41
+ <summary>使用包管理器安装</summary>
42
+ 在 nonebot2 项目的插件目录下, 打开命令行, 根据你使用的包管理器, 输入相应的安装命令
43
+
44
+ <details>
45
+ <summary>pip</summary>
46
+
47
+ ```bash
48
+ pip install nonebot-plugin-areusleepy
49
+ ```
50
+
51
+ </details>
52
+ <details>
53
+ <summary>pdm</summary>
54
+
55
+ ```bash
56
+ pdm add nonebot-nonebot-plugin-areusleepy
57
+ ```
58
+
59
+ </details>
60
+ <details>
61
+ <summary>poetry</summary>
62
+
63
+ ```bash
64
+ poetry add nonebot-plugin-areusleepy
65
+ ```
66
+
67
+ </details>
68
+ <details>
69
+ <summary>conda</summary>
70
+
71
+ ```bash
72
+ conda install nonebot-plugin-areusleepy
73
+ ```
74
+
75
+ </details>
76
+ <details>
77
+ <summary>uv</summary>
78
+
79
+ ```bash
80
+ uv add nonebot-plugin-areusleepy
81
+ ```
82
+
83
+ </details>
84
+
85
+ 打开 nonebot2 项目根目录下的 `pyproject.toml` 文件, 在 `[tool.nonebot]` 部分的 `plugins` 项里追加写入
86
+
87
+ ```toml
88
+ [tool.nonebot]
89
+ plugins = [
90
+ # ...
91
+ "nonebot_plugin_areusleepy"
92
+ ]
93
+ ```
94
+
95
+ </details>
96
+
97
+ ## ⚙️ 配置
98
+
99
+ env 配置示例,变量后面为默认配置:
100
+
101
+ ```ini
102
+ # 基本配置
103
+ sleepy_command="aresleepy" # 触发命令
104
+ sleepy_prompt_loading=true # 是否在发送消息前显示 "正在获取, 请稍候"
105
+ sleepy_show_details=false # 是否显示详细信息 (状态的 id, 设备的 id, 最后更新时间的时区)
106
+
107
+ # Sleepy 服务配置
108
+ sleepy_url="https://status.0d000721.xin" # Sleepy 服务地址, 必须以 http:// 或 https:// 开头, 不以 / 结尾
109
+ sleepy_timeout=5.0 # 请求超时 (秒)
110
+ sleepy_retries=3 # 重试次数
111
+
112
+ # sleepy 定时任务配置
113
+ sleepy_scheduler_enabled=False # 是否启用定时任务
114
+ sleepy_scheduler_cron="0 9,21 * * *" # Cron 表达式,默认每天 9:00 和 21:00
115
+ sleepy_scheduler_groups:"" # 推送的群组列表,默认为空,开启定时任务后必须配置此项
116
+ ```
117
+
118
+ ## 🎉 使用
119
+
120
+ 用法:
121
+
122
+ - `/sleepy` - 查询配置中网站的在线状态
123
+ - `/sleepy [url]` - 查询其他网站的在线状态
124
+ * 如: `/sleepy https://sleepy.wyf9.top`
125
+ * **注意: `url` 必须以 `http://` 或 `https://` 开头**
126
+
127
+ ### 效果图
128
+
129
+ ![兄弟你睡了吗喵!!!!!!](./areisleepyyyyyy.png)
130
+
131
+ ## 📞 联系
132
+
133
+ ### Sleepy 项目
134
+
135
+ QQ 群组: [点此加群](https://siiway.top/t/qq)
136
+ Discord: [点此加入服务器](https://siiway.top/t/dc)
137
+ [更多联系方式](https://siiway.top/about/contact)
138
+
139
+ > *人较多, 请注明来意*
140
+
141
+ ### 本项目
142
+
143
+ TG群组:[点此加入](https://t.me/LoveMurasame)
144
+ QQ群:[1049319982](https://qm.qq.com/q/DfTsIDXuc8)
145
+ 作者邮箱:<congyu@sbhfy.cn>
146
+
147
+ > *大概率没人*
148
+
149
+ ## 💡 鸣谢
150
+
151
+ 本项目基于 [sleepy-project/sleepy: Are you sleeping?](https://github.com/sleepy-project/sleepy)
152
+
153
+ 感谢 Sleepy 开发者 [wyf9](https://github.com/wyf9) 重构插件
154
+
155
+ ## 📝 更新日志
156
+
157
+ ### 0.1.0
158
+
159
+ 重构插件
160
+
161
+
162
+
163
+ ### 0.1.2
164
+
165
+ 添加了定时任务
@@ -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
- from . import getsleepy as getsleepy
8
-
9
- from .config import Config
10
-
11
- __version__ = "0.0.2"
12
- __plugin_meta__ = PluginMetadata(
13
- name="AreYouSleepy",
14
- description="基于 sleepy-project/sleepy 项目的状态查询插件!",
15
- usage="/areusleepy /getsleepy url",
16
- type="application",
17
- homepage="https://github.com/Murasame-Dev/nonebot-plugin-areusleepy",
18
- supported_adapters=inherit_supported_adapters("nonebot_plugin_alconna"),
19
- config=Config,
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)
@@ -0,0 +1,201 @@
1
+ # coding: utf-8
2
+
3
+ # --- 导入模块
4
+
5
+ from nonebot import on_command
6
+ from nonebot.matcher import Matcher
7
+ from nonebot.params import CommandArg
8
+ from nonebot.adapters import Event as BaseEvent, Message
9
+ from nonebot import get_plugin_config, get_bot
10
+ from nonebot_plugin_alconna.uniseg import UniMessage
11
+ from nonebot_plugin_apscheduler import scheduler
12
+ from nonebot.log import logger
13
+
14
+ import requests
15
+ from urllib.parse import urljoin
16
+
17
+ from .config import Config
18
+
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
106
+
107
+ # --- 定义命令
108
+
109
+
110
+ rusleepy = on_command(
111
+ cmd=config.sleepy_command
112
+ )
113
+
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
121
+
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}')
141
+
142
+
143
+ # --- 定时任务功能
144
+
145
+ async def send_scheduled_status():
146
+ '''
147
+ 定时发送状态信息
148
+ '''
149
+ if not config.sleepy_scheduler_enabled:
150
+ return
151
+
152
+ # 获取状态数据
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
159
+
160
+ # 确保 data 是 dict 类型
161
+ if not isinstance(data, dict):
162
+ logger.error(f'定时任务获取到的数据格式错误: {data}')
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
+
187
+
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}')
@@ -0,0 +1,19 @@
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] = [] # 推送的群组列表
@@ -4,15 +4,17 @@ dynamic = []
4
4
  description = "Let bot look!!!"
5
5
  authors = [
6
6
  { name = "Murasame", email = "congyu@sbhfy.cn" },
7
+ { name = "wyf9", email = "wyf9@wyf9.top" },
7
8
  ]
8
9
  requires-python = ">=3.9,<4.0"
9
10
  readme = "README.md"
10
11
  dependencies = [
11
- "nonebot2>=2.4.1",
12
- "nonebot-plugin-alconna>=0.54.2",
13
- "httpx>=0.28.1",
12
+ "nonebot2>=2.0.0",
13
+ "nonebot-plugin-apscheduler>=0.3.0",
14
+ "nonebot-plugin-alconna>=0.12.0",
15
+ "requests>=2.32.3",
14
16
  ]
15
- version = "0.0.2"
17
+ version = "0.1.3"
16
18
 
17
19
  [project.license]
18
20
  text = "MIT"
@@ -1,83 +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
- fetch_status = on_command(
18
- "areusleepy",
19
- aliases={"获取Sleepy状态"}
20
- )
21
-
22
- async def get_status_data() -> Optional[dict]:
23
- url = f"{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) -> 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']}"
65
-
66
- return msg
67
-
68
- @fetch_status.handle()
69
- async def _(arg_msg: Message = CommandArg()):
70
- """处理queryFetch命令"""
71
- await fetch_status.send("正在获取状态信息,请稍候...")
72
-
73
- # 获取状态数据
74
- data = await get_status_data()
75
-
76
- # 如果获取数据失败,返回错误信息
77
- if data is None:
78
- await fetch_status.send("获取状态信息失败,请稍后重试")
79
- return
80
-
81
- # 生成并发送消息
82
- msg = await create_status_message(data)
83
- await fetch_status.send(str(msg))
@@ -1,5 +0,0 @@
1
- from pydantic import BaseModel
2
-
3
-
4
- class Config(BaseModel):
5
- sleepyurl: str = "https://127.0.0.1:9010"
@@ -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))