qq-botpy-community 2.0.0__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.
- qq_botpy_community-2.0.0/LICENSE +21 -0
- qq_botpy_community-2.0.0/PKG-INFO +213 -0
- qq_botpy_community-2.0.0/README.md +183 -0
- qq_botpy_community-2.0.0/README.rst +158 -0
- qq_botpy_community-2.0.0/botpy/__init__.py +6 -0
- qq_botpy_community-2.0.0/botpy/api.py +1535 -0
- qq_botpy_community-2.0.0/botpy/audio.py +45 -0
- qq_botpy_community-2.0.0/botpy/channel.py +38 -0
- qq_botpy_community-2.0.0/botpy/client.py +292 -0
- qq_botpy_community-2.0.0/botpy/connection.py +307 -0
- qq_botpy_community-2.0.0/botpy/errors.py +60 -0
- qq_botpy_community-2.0.0/botpy/ext/__init__.py +5 -0
- qq_botpy_community-2.0.0/botpy/ext/channel_jump/__init__.py +71 -0
- qq_botpy_community-2.0.0/botpy/ext/cog_apscheduler/__init__.py +13 -0
- qq_botpy_community-2.0.0/botpy/ext/cog_yaml/__init__.py +16 -0
- qq_botpy_community-2.0.0/botpy/ext/command_util.py +30 -0
- qq_botpy_community-2.0.0/botpy/ext/convert_color/__init__.py +39 -0
- qq_botpy_community-2.0.0/botpy/flags.py +370 -0
- qq_botpy_community-2.0.0/botpy/forum.py +172 -0
- qq_botpy_community-2.0.0/botpy/gateway.py +238 -0
- qq_botpy_community-2.0.0/botpy/guild.py +36 -0
- qq_botpy_community-2.0.0/botpy/http.py +207 -0
- qq_botpy_community-2.0.0/botpy/interaction.py +63 -0
- qq_botpy_community-2.0.0/botpy/logging.py +163 -0
- qq_botpy_community-2.0.0/botpy/manage.py +40 -0
- qq_botpy_community-2.0.0/botpy/message.py +285 -0
- qq_botpy_community-2.0.0/botpy/reaction.py +43 -0
- qq_botpy_community-2.0.0/botpy/robot.py +80 -0
- qq_botpy_community-2.0.0/botpy/types/__init__.py +5 -0
- qq_botpy_community-2.0.0/botpy/types/announce.py +24 -0
- qq_botpy_community-2.0.0/botpy/types/audio.py +32 -0
- qq_botpy_community-2.0.0/botpy/types/channel.py +67 -0
- qq_botpy_community-2.0.0/botpy/types/emoji.py +15 -0
- qq_botpy_community-2.0.0/botpy/types/forum.py +75 -0
- qq_botpy_community-2.0.0/botpy/types/gateway.py +81 -0
- qq_botpy_community-2.0.0/botpy/types/guild.py +44 -0
- qq_botpy_community-2.0.0/botpy/types/inline.py +35 -0
- qq_botpy_community-2.0.0/botpy/types/interaction.py +42 -0
- qq_botpy_community-2.0.0/botpy/types/message.py +140 -0
- qq_botpy_community-2.0.0/botpy/types/permission.py +22 -0
- qq_botpy_community-2.0.0/botpy/types/pins_message.py +8 -0
- qq_botpy_community-2.0.0/botpy/types/reaction.py +26 -0
- qq_botpy_community-2.0.0/botpy/types/rich_text.py +128 -0
- qq_botpy_community-2.0.0/botpy/types/robot.py +7 -0
- qq_botpy_community-2.0.0/botpy/types/schedule.py +28 -0
- qq_botpy_community-2.0.0/botpy/types/session.py +17 -0
- qq_botpy_community-2.0.0/botpy/types/user.py +22 -0
- qq_botpy_community-2.0.0/botpy/user.py +31 -0
- qq_botpy_community-2.0.0/pyproject.toml +38 -0
- qq_botpy_community-2.0.0/qq_botpy_community.egg-info/PKG-INFO +213 -0
- qq_botpy_community-2.0.0/qq_botpy_community.egg-info/SOURCES.txt +58 -0
- qq_botpy_community-2.0.0/qq_botpy_community.egg-info/dependency_links.txt +1 -0
- qq_botpy_community-2.0.0/qq_botpy_community.egg-info/requires.txt +3 -0
- qq_botpy_community-2.0.0/qq_botpy_community.egg-info/top_level.txt +1 -0
- qq_botpy_community-2.0.0/setup.cfg +20 -0
- qq_botpy_community-2.0.0/setup.py +37 -0
- qq_botpy_community-2.0.0/tests/test_api.py +239 -0
- qq_botpy_community-2.0.0/tests/test_flags.py +21 -0
- qq_botpy_community-2.0.0/tests/test_token.py +17 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2021 Tencent
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: qq-botpy-community
|
|
3
|
+
Version: 2.0.0
|
|
4
|
+
Summary: Community-maintained QQ Bot SDK, successor to tencent-connect/botpy (upstream dead since 2024-03)
|
|
5
|
+
Home-page: https://github.com/tencent-connect/botpy
|
|
6
|
+
Author: veehou
|
|
7
|
+
Author-email: dawarich <1479821683@qq.com>
|
|
8
|
+
License: MIT
|
|
9
|
+
Project-URL: Homepage, https://github.com/dawarich/botpy-community
|
|
10
|
+
Project-URL: Repository, https://github.com/dawarich/botpy-community
|
|
11
|
+
Project-URL: Issues, https://github.com/dawarich/botpy-community/issues
|
|
12
|
+
Project-URL: Changelog, https://github.com/dawarich/botpy-community/blob/main/CHANGELOG.md
|
|
13
|
+
Classifier: Development Status :: 5 - Production/Stable
|
|
14
|
+
Classifier: Intended Audience :: Developers
|
|
15
|
+
Classifier: Topic :: Software Development
|
|
16
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
17
|
+
Classifier: Programming Language :: Python :: 3
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
22
|
+
Description-Content-Type: text/markdown
|
|
23
|
+
License-File: LICENSE
|
|
24
|
+
Requires-Dist: aiohttp>=3.8
|
|
25
|
+
Requires-Dist: PyYAML>=6.0
|
|
26
|
+
Requires-Dist: typing-extensions>=4.0
|
|
27
|
+
Dynamic: author
|
|
28
|
+
Dynamic: home-page
|
|
29
|
+
Dynamic: license-file
|
|
30
|
+
|
|
31
|
+
<div align="center">
|
|
32
|
+
|
|
33
|
+

|
|
34
|
+
|
|
35
|
+
[](https://www.python.org/)
|
|
36
|
+
[](https://github.com/tencent-connect/botpy/blob/master/LICENSE)
|
|
37
|
+

|
|
38
|
+

|
|
39
|
+
[](https://devops.woa.com/process/api-html/user/builds/projects/qq-guild-open/pipelines/p-713959939bdc4adca0eea2d4420eef4b/latestFinished?X-DEVOPS-PROJECT-ID=qq-guild-open)
|
|
40
|
+
|
|
41
|
+
_✨ 基于 [机器人开放平台API](https://bot.q.qq.com/wiki/develop/api/) 实现的机器人框架 ✨_
|
|
42
|
+
|
|
43
|
+
_✨ 为开发者提供一个易使用、开发效率高的开发框架 ✨_
|
|
44
|
+
|
|
45
|
+
[文档](https://bot.q.qq.com/wiki/develop/pythonsdk/)
|
|
46
|
+
·
|
|
47
|
+
[下载](https://github.com/tencent-connect/botpy/tags)
|
|
48
|
+
·
|
|
49
|
+
[安装](https://bot.q.qq.com/wiki/develop/pythonsdk/#sdk-安装)
|
|
50
|
+
|
|
51
|
+
</div>
|
|
52
|
+
|
|
53
|
+
## 准备工作
|
|
54
|
+
|
|
55
|
+
### 安装
|
|
56
|
+
|
|
57
|
+
```bash
|
|
58
|
+
pip install qq-botpy
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
更新包的话需要添加 `--upgrade` `兼容版本:python3.8+`
|
|
62
|
+
|
|
63
|
+
### 使用
|
|
64
|
+
|
|
65
|
+
需要使用的地方`import botpy`
|
|
66
|
+
|
|
67
|
+
```python
|
|
68
|
+
import botpy
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
### 兼容提示
|
|
72
|
+
|
|
73
|
+
> 原机器人的老版本`qq-bot`仍然可以使用,但新接口的支持上会逐渐暂停,此次升级不会影响线上使用的机器人
|
|
74
|
+
|
|
75
|
+
## 版本更新说明
|
|
76
|
+
### v1.1.5
|
|
77
|
+
1. 更新鉴权方式。 新版本通过AppID + AppSecret进行鉴权,需要使用者进行适配。AppSecret见[QQ机器人开发设置页](https://q.qq.com/qqbot/#/developer/developer-setting)中的AppSecret字段。具体适配方式见示例 [鉴权配置示例](./examples/config.example.yaml) [鉴权传参接口变更示例](./examples/demo_at_reply.py)
|
|
78
|
+
2. 增加群和好友内发消息能力。可参考[群内发消息示例](./examples/demo_group_reply_text.py) [好友内发消息示例](./examples/demo_c2c_reply_text.py)
|
|
79
|
+
3. 增加群和好友内发送富媒体消息能力,目前支持图片、视频、语音类型。可参考 [群内发富媒体消息示例](./examples/demo_group_reply_file.py) [好友内发富媒体消息示例](./examples/demo_c2c_reply_file.py)
|
|
80
|
+
|
|
81
|
+
## 使用方式
|
|
82
|
+
|
|
83
|
+
### 快速入门
|
|
84
|
+
|
|
85
|
+
#### 步骤1
|
|
86
|
+
|
|
87
|
+
通过继承实现`bot.Client`, 实现自己的机器人Client
|
|
88
|
+
|
|
89
|
+
#### 步骤2
|
|
90
|
+
|
|
91
|
+
实现机器人相关事件的处理方法,如 `on_at_message_create`, 详细的事件监听列表,请参考 [事件监听.md](./docs/事件监听.md)
|
|
92
|
+
|
|
93
|
+
如下,是定义机器人被@的后自动回复:
|
|
94
|
+
|
|
95
|
+
```python
|
|
96
|
+
import botpy
|
|
97
|
+
from botpy.message import Message
|
|
98
|
+
|
|
99
|
+
class MyClient(botpy.Client):
|
|
100
|
+
async def on_at_message_create(self, message: Message):
|
|
101
|
+
await message.reply(content=f"机器人{self.robot.name}收到你的@消息了: {message.content}")
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
``注意:每个事件会下发具体的数据对象,如`message`相关事件是`message.Message`的对象 (部分事件透传了后台数据,暂未实现对象缓存)``
|
|
105
|
+
|
|
106
|
+
#### 步骤3
|
|
107
|
+
|
|
108
|
+
设置机器人需要监听的事件通道,并启动`client`
|
|
109
|
+
|
|
110
|
+
```python
|
|
111
|
+
import botpy
|
|
112
|
+
from botpy.message import Message
|
|
113
|
+
|
|
114
|
+
class MyClient(botpy.Client):
|
|
115
|
+
async def on_at_message_create(self, message: Message):
|
|
116
|
+
await self.api.post_message(channel_id=message.channel_id, content="content")
|
|
117
|
+
|
|
118
|
+
intents = botpy.Intents(public_guild_messages=True)
|
|
119
|
+
client = MyClient(intents=intents)
|
|
120
|
+
client.run(appid="12345", secret="xxxx")
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
### 备注
|
|
124
|
+
|
|
125
|
+
也可以通过预设置的类型,设置需要监听的事件通道
|
|
126
|
+
|
|
127
|
+
```python
|
|
128
|
+
import botpy
|
|
129
|
+
|
|
130
|
+
intents = botpy.Intents.none()
|
|
131
|
+
intents.public_guild_messages=True
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
### 使用API
|
|
135
|
+
|
|
136
|
+
如果要使用`api`方法,可以参考如下方式:
|
|
137
|
+
|
|
138
|
+
```python
|
|
139
|
+
import botpy
|
|
140
|
+
from botpy.message import Message
|
|
141
|
+
|
|
142
|
+
class MyClient(botpy.Client):
|
|
143
|
+
async def on_at_message_create(self, message: Message):
|
|
144
|
+
await self.api.post_message(channel_id=message.channel_id, content="content")
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
## 示例机器人
|
|
148
|
+
|
|
149
|
+
[`examples`](./examples/) 目录下存放示例机器人,具体使用可参考[`Readme.md`](./examples/README.md)
|
|
150
|
+
|
|
151
|
+
examples/
|
|
152
|
+
.
|
|
153
|
+
├── README.md
|
|
154
|
+
├── config.example.yaml # 示例配置文件(需要修改为config.yaml)
|
|
155
|
+
├── demo_announce.py # 机器人公告API使用示例
|
|
156
|
+
├── demo_api_permission.py # 机器人授权查询API使用示例
|
|
157
|
+
├── demo_at_reply.py # 机器人at被动回复async示例
|
|
158
|
+
├── demo_at_reply_ark.py # 机器人at被动回复ark消息示例
|
|
159
|
+
├── demo_at_reply_embed.py # 机器人at被动回复embed消息示例
|
|
160
|
+
├── demo_at_reply_command.py # 机器人at被动使用Command指令装饰器回复消息示例
|
|
161
|
+
├── demo_at_reply_file_data.py # 机器人at被动回复本地图片消息示例
|
|
162
|
+
├── demo_at_reply_keyboard.py # 机器人at被动回复md带内嵌键盘的示例
|
|
163
|
+
├── demo_at_reply_markdown.py # 机器人at被动回复md消息示例
|
|
164
|
+
├── demo_at_reply_reference.py # 机器人at被动回复消息引用示例
|
|
165
|
+
├── demo_dms_reply.py # 机器人私信被动回复示例
|
|
166
|
+
├── demo_get_reaction_users.py # 机器人获取表情表态成员列表示例
|
|
167
|
+
├── demo_guild_member_event.py # 机器人频道成员变化事件示例
|
|
168
|
+
├── demo_interaction.py # 机器人互动事件示例(未启用)
|
|
169
|
+
├── demo_pins_message.py # 机器人消息置顶示例
|
|
170
|
+
├── demo_recall.py # 机器人消息撤回示例
|
|
171
|
+
├── demo_schedule.py # 机器人日程相关示例
|
|
172
|
+
|
|
173
|
+
# 参与开发
|
|
174
|
+
|
|
175
|
+
## 环境配置
|
|
176
|
+
|
|
177
|
+
```bash
|
|
178
|
+
pip install -r requirements.txt # 安装依赖的pip包
|
|
179
|
+
|
|
180
|
+
pre-commit install # 安装格式化代码的钩子
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
## 单元测试
|
|
184
|
+
|
|
185
|
+
代码库提供API接口测试和 websocket 的单测用例,位于 `tests` 目录中。如果需要自己运行,可以在 `tests` 目录重命名 `.test.yaml` 文件后添加自己的测试参数启动测试:
|
|
186
|
+
|
|
187
|
+
### 单测执行方法
|
|
188
|
+
|
|
189
|
+
先确保已安装 `pytest` :
|
|
190
|
+
|
|
191
|
+
```bash
|
|
192
|
+
pip install pytest
|
|
193
|
+
```
|
|
194
|
+
|
|
195
|
+
然后在项目根目录下执行单测:
|
|
196
|
+
|
|
197
|
+
```bash
|
|
198
|
+
pytest
|
|
199
|
+
```
|
|
200
|
+
|
|
201
|
+
## 致谢
|
|
202
|
+
|
|
203
|
+
感谢感谢以下开发者对 `botpy` 作出的贡献:
|
|
204
|
+
|
|
205
|
+
<a href="https://github.com/tencent-connect/botpy/graphs/contributors">
|
|
206
|
+
<img src="https://contrib.rocks/image?repo=tencent-connect/botpy" />
|
|
207
|
+
</a>
|
|
208
|
+
|
|
209
|
+
# 加入官方社区
|
|
210
|
+
|
|
211
|
+
欢迎扫码加入**QQ 频道开发者社区**。
|
|
212
|
+
|
|
213
|
+

|
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
<div align="center">
|
|
2
|
+
|
|
3
|
+

|
|
4
|
+
|
|
5
|
+
[](https://www.python.org/)
|
|
6
|
+
[](https://github.com/tencent-connect/botpy/blob/master/LICENSE)
|
|
7
|
+

|
|
8
|
+

|
|
9
|
+
[](https://devops.woa.com/process/api-html/user/builds/projects/qq-guild-open/pipelines/p-713959939bdc4adca0eea2d4420eef4b/latestFinished?X-DEVOPS-PROJECT-ID=qq-guild-open)
|
|
10
|
+
|
|
11
|
+
_✨ 基于 [机器人开放平台API](https://bot.q.qq.com/wiki/develop/api/) 实现的机器人框架 ✨_
|
|
12
|
+
|
|
13
|
+
_✨ 为开发者提供一个易使用、开发效率高的开发框架 ✨_
|
|
14
|
+
|
|
15
|
+
[文档](https://bot.q.qq.com/wiki/develop/pythonsdk/)
|
|
16
|
+
·
|
|
17
|
+
[下载](https://github.com/tencent-connect/botpy/tags)
|
|
18
|
+
·
|
|
19
|
+
[安装](https://bot.q.qq.com/wiki/develop/pythonsdk/#sdk-安装)
|
|
20
|
+
|
|
21
|
+
</div>
|
|
22
|
+
|
|
23
|
+
## 准备工作
|
|
24
|
+
|
|
25
|
+
### 安装
|
|
26
|
+
|
|
27
|
+
```bash
|
|
28
|
+
pip install qq-botpy
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
更新包的话需要添加 `--upgrade` `兼容版本:python3.8+`
|
|
32
|
+
|
|
33
|
+
### 使用
|
|
34
|
+
|
|
35
|
+
需要使用的地方`import botpy`
|
|
36
|
+
|
|
37
|
+
```python
|
|
38
|
+
import botpy
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
### 兼容提示
|
|
42
|
+
|
|
43
|
+
> 原机器人的老版本`qq-bot`仍然可以使用,但新接口的支持上会逐渐暂停,此次升级不会影响线上使用的机器人
|
|
44
|
+
|
|
45
|
+
## 版本更新说明
|
|
46
|
+
### v1.1.5
|
|
47
|
+
1. 更新鉴权方式。 新版本通过AppID + AppSecret进行鉴权,需要使用者进行适配。AppSecret见[QQ机器人开发设置页](https://q.qq.com/qqbot/#/developer/developer-setting)中的AppSecret字段。具体适配方式见示例 [鉴权配置示例](./examples/config.example.yaml) [鉴权传参接口变更示例](./examples/demo_at_reply.py)
|
|
48
|
+
2. 增加群和好友内发消息能力。可参考[群内发消息示例](./examples/demo_group_reply_text.py) [好友内发消息示例](./examples/demo_c2c_reply_text.py)
|
|
49
|
+
3. 增加群和好友内发送富媒体消息能力,目前支持图片、视频、语音类型。可参考 [群内发富媒体消息示例](./examples/demo_group_reply_file.py) [好友内发富媒体消息示例](./examples/demo_c2c_reply_file.py)
|
|
50
|
+
|
|
51
|
+
## 使用方式
|
|
52
|
+
|
|
53
|
+
### 快速入门
|
|
54
|
+
|
|
55
|
+
#### 步骤1
|
|
56
|
+
|
|
57
|
+
通过继承实现`bot.Client`, 实现自己的机器人Client
|
|
58
|
+
|
|
59
|
+
#### 步骤2
|
|
60
|
+
|
|
61
|
+
实现机器人相关事件的处理方法,如 `on_at_message_create`, 详细的事件监听列表,请参考 [事件监听.md](./docs/事件监听.md)
|
|
62
|
+
|
|
63
|
+
如下,是定义机器人被@的后自动回复:
|
|
64
|
+
|
|
65
|
+
```python
|
|
66
|
+
import botpy
|
|
67
|
+
from botpy.message import Message
|
|
68
|
+
|
|
69
|
+
class MyClient(botpy.Client):
|
|
70
|
+
async def on_at_message_create(self, message: Message):
|
|
71
|
+
await message.reply(content=f"机器人{self.robot.name}收到你的@消息了: {message.content}")
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
``注意:每个事件会下发具体的数据对象,如`message`相关事件是`message.Message`的对象 (部分事件透传了后台数据,暂未实现对象缓存)``
|
|
75
|
+
|
|
76
|
+
#### 步骤3
|
|
77
|
+
|
|
78
|
+
设置机器人需要监听的事件通道,并启动`client`
|
|
79
|
+
|
|
80
|
+
```python
|
|
81
|
+
import botpy
|
|
82
|
+
from botpy.message import Message
|
|
83
|
+
|
|
84
|
+
class MyClient(botpy.Client):
|
|
85
|
+
async def on_at_message_create(self, message: Message):
|
|
86
|
+
await self.api.post_message(channel_id=message.channel_id, content="content")
|
|
87
|
+
|
|
88
|
+
intents = botpy.Intents(public_guild_messages=True)
|
|
89
|
+
client = MyClient(intents=intents)
|
|
90
|
+
client.run(appid="12345", secret="xxxx")
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
### 备注
|
|
94
|
+
|
|
95
|
+
也可以通过预设置的类型,设置需要监听的事件通道
|
|
96
|
+
|
|
97
|
+
```python
|
|
98
|
+
import botpy
|
|
99
|
+
|
|
100
|
+
intents = botpy.Intents.none()
|
|
101
|
+
intents.public_guild_messages=True
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
### 使用API
|
|
105
|
+
|
|
106
|
+
如果要使用`api`方法,可以参考如下方式:
|
|
107
|
+
|
|
108
|
+
```python
|
|
109
|
+
import botpy
|
|
110
|
+
from botpy.message import Message
|
|
111
|
+
|
|
112
|
+
class MyClient(botpy.Client):
|
|
113
|
+
async def on_at_message_create(self, message: Message):
|
|
114
|
+
await self.api.post_message(channel_id=message.channel_id, content="content")
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
## 示例机器人
|
|
118
|
+
|
|
119
|
+
[`examples`](./examples/) 目录下存放示例机器人,具体使用可参考[`Readme.md`](./examples/README.md)
|
|
120
|
+
|
|
121
|
+
examples/
|
|
122
|
+
.
|
|
123
|
+
├── README.md
|
|
124
|
+
├── config.example.yaml # 示例配置文件(需要修改为config.yaml)
|
|
125
|
+
├── demo_announce.py # 机器人公告API使用示例
|
|
126
|
+
├── demo_api_permission.py # 机器人授权查询API使用示例
|
|
127
|
+
├── demo_at_reply.py # 机器人at被动回复async示例
|
|
128
|
+
├── demo_at_reply_ark.py # 机器人at被动回复ark消息示例
|
|
129
|
+
├── demo_at_reply_embed.py # 机器人at被动回复embed消息示例
|
|
130
|
+
├── demo_at_reply_command.py # 机器人at被动使用Command指令装饰器回复消息示例
|
|
131
|
+
├── demo_at_reply_file_data.py # 机器人at被动回复本地图片消息示例
|
|
132
|
+
├── demo_at_reply_keyboard.py # 机器人at被动回复md带内嵌键盘的示例
|
|
133
|
+
├── demo_at_reply_markdown.py # 机器人at被动回复md消息示例
|
|
134
|
+
├── demo_at_reply_reference.py # 机器人at被动回复消息引用示例
|
|
135
|
+
├── demo_dms_reply.py # 机器人私信被动回复示例
|
|
136
|
+
├── demo_get_reaction_users.py # 机器人获取表情表态成员列表示例
|
|
137
|
+
├── demo_guild_member_event.py # 机器人频道成员变化事件示例
|
|
138
|
+
├── demo_interaction.py # 机器人互动事件示例(未启用)
|
|
139
|
+
├── demo_pins_message.py # 机器人消息置顶示例
|
|
140
|
+
├── demo_recall.py # 机器人消息撤回示例
|
|
141
|
+
├── demo_schedule.py # 机器人日程相关示例
|
|
142
|
+
|
|
143
|
+
# 参与开发
|
|
144
|
+
|
|
145
|
+
## 环境配置
|
|
146
|
+
|
|
147
|
+
```bash
|
|
148
|
+
pip install -r requirements.txt # 安装依赖的pip包
|
|
149
|
+
|
|
150
|
+
pre-commit install # 安装格式化代码的钩子
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
## 单元测试
|
|
154
|
+
|
|
155
|
+
代码库提供API接口测试和 websocket 的单测用例,位于 `tests` 目录中。如果需要自己运行,可以在 `tests` 目录重命名 `.test.yaml` 文件后添加自己的测试参数启动测试:
|
|
156
|
+
|
|
157
|
+
### 单测执行方法
|
|
158
|
+
|
|
159
|
+
先确保已安装 `pytest` :
|
|
160
|
+
|
|
161
|
+
```bash
|
|
162
|
+
pip install pytest
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
然后在项目根目录下执行单测:
|
|
166
|
+
|
|
167
|
+
```bash
|
|
168
|
+
pytest
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
## 致谢
|
|
172
|
+
|
|
173
|
+
感谢感谢以下开发者对 `botpy` 作出的贡献:
|
|
174
|
+
|
|
175
|
+
<a href="https://github.com/tencent-connect/botpy/graphs/contributors">
|
|
176
|
+
<img src="https://contrib.rocks/image?repo=tencent-connect/botpy" />
|
|
177
|
+
</a>
|
|
178
|
+
|
|
179
|
+
# 加入官方社区
|
|
180
|
+
|
|
181
|
+
欢迎扫码加入**QQ 频道开发者社区**。
|
|
182
|
+
|
|
183
|
+

|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
.. role:: raw-html-m2r(raw)
|
|
2
|
+
:format: html
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
botpy
|
|
6
|
+
=====
|
|
7
|
+
|
|
8
|
+
**botpy** 是基于\ `机器人开放平台API <https://bot.q.qq.com/wiki/develop/api/>`_ 实现的机器人框架,目的提供一个易使用、开发效率高的开发框架。
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
.. image:: https://img.shields.io/pypi/v/qq-botpy
|
|
12
|
+
:target: https://img.shields.io/pypi/v/qq-botpy
|
|
13
|
+
:alt: PyPI
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
.. image:: https://api.bkdevops.qq.com/process/api/external/pipelines/projects/qq-guild-open/p-713959939bdc4adca0eea2d4420eef4b/badge?X-DEVOPS-PROJECT-ID=qq-guild-open
|
|
17
|
+
:target: https://devops.woa.com/process/api-html/user/builds/projects/qq-guild-open/pipelines/p-713959939bdc4adca0eea2d4420eef4b/latestFinished?X-DEVOPS-PROJECT-ID=qq-guild-open
|
|
18
|
+
:alt: BK Pipelines Status
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
准备工作
|
|
22
|
+
--------
|
|
23
|
+
|
|
24
|
+
安装
|
|
25
|
+
^^^^
|
|
26
|
+
|
|
27
|
+
.. code-block:: bash
|
|
28
|
+
|
|
29
|
+
pip install qq-botpy
|
|
30
|
+
|
|
31
|
+
更新包的话需要添加 ``--upgrade`` ``注:需要python3.7+``
|
|
32
|
+
|
|
33
|
+
使用
|
|
34
|
+
^^^^
|
|
35
|
+
|
|
36
|
+
需要使用的地方\ ``import botpy``
|
|
37
|
+
|
|
38
|
+
.. code-block:: python
|
|
39
|
+
|
|
40
|
+
import botpy
|
|
41
|
+
|
|
42
|
+
兼容提示
|
|
43
|
+
^^^^^^^^
|
|
44
|
+
|
|
45
|
+
..
|
|
46
|
+
|
|
47
|
+
原机器人的老版本\ ``qq-bot``\ 仍然可以使用,但新接口的支持上会逐渐暂停,此次升级不会影响线上使用的机器人
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
使用方式
|
|
51
|
+
--------
|
|
52
|
+
|
|
53
|
+
快速入门
|
|
54
|
+
^^^^^^^^
|
|
55
|
+
|
|
56
|
+
步骤1
|
|
57
|
+
~~~~~
|
|
58
|
+
|
|
59
|
+
通过继承实现\ ``bot.Client``\ , 实现自己的机器人Client
|
|
60
|
+
|
|
61
|
+
步骤2
|
|
62
|
+
~~~~~
|
|
63
|
+
|
|
64
|
+
实现机器人相关事件的处理方法,如 ``on_at_message_create``\ , 详细的事件监听列表,请参考 `事件监听.md <./docs/事件监听.md>`_
|
|
65
|
+
|
|
66
|
+
如下,是定义机器人被@的后自动回复:
|
|
67
|
+
|
|
68
|
+
.. code-block:: python
|
|
69
|
+
|
|
70
|
+
import botpy
|
|
71
|
+
from botpy.types.message import Message
|
|
72
|
+
|
|
73
|
+
class MyClient(botpy.Client):
|
|
74
|
+
async def on_ready(self):
|
|
75
|
+
print(f"robot 「{self.robot.name}」 on_ready!")
|
|
76
|
+
|
|
77
|
+
async def on_at_message_create(self, message: Message):
|
|
78
|
+
await message.reply(content=f"机器人{self.robot.name}收到你的@消息了: {message.content}")
|
|
79
|
+
|
|
80
|
+
``注意:每个事件会下发具体的数据对象,如`message`相关事件是`message.Message`的对象 (部分事件透传了后台数据,暂未实现对象缓存)``
|
|
81
|
+
|
|
82
|
+
步骤3
|
|
83
|
+
~~~~~
|
|
84
|
+
|
|
85
|
+
设置机器人需要监听的事件通道,并启动\ ``client``
|
|
86
|
+
|
|
87
|
+
.. code-block:: python
|
|
88
|
+
|
|
89
|
+
import botpy
|
|
90
|
+
from botpy.types.message import Message
|
|
91
|
+
|
|
92
|
+
class MyClient(botpy.Client):
|
|
93
|
+
async def on_at_message_create(self, message: Message):
|
|
94
|
+
await self.api.post_message(channel_id=message.channel_id, content="content")
|
|
95
|
+
|
|
96
|
+
intents = botpy.Intents(public_guild_messages=True)
|
|
97
|
+
client = MyClient(intents=intents)
|
|
98
|
+
client.run(appid="12345", token="xxxx")
|
|
99
|
+
|
|
100
|
+
备注
|
|
101
|
+
^^^^
|
|
102
|
+
|
|
103
|
+
也可以通过预设置的类型,设置需要监听的事件通道
|
|
104
|
+
|
|
105
|
+
.. code-block:: python
|
|
106
|
+
|
|
107
|
+
import botpy
|
|
108
|
+
|
|
109
|
+
intents = botpy.Intents.none()
|
|
110
|
+
intents.public_guild_messages=True
|
|
111
|
+
|
|
112
|
+
使用API
|
|
113
|
+
^^^^^^^
|
|
114
|
+
|
|
115
|
+
如果要使用\ ``api``\ 方法,可以参考如下方式:
|
|
116
|
+
|
|
117
|
+
.. code-block:: python
|
|
118
|
+
|
|
119
|
+
import botpy
|
|
120
|
+
from botpy.types.message import Message
|
|
121
|
+
|
|
122
|
+
class MyClient(botpy.Client):
|
|
123
|
+
async def on_at_message_create(self, message: Message):
|
|
124
|
+
await self.api.post_message(channel_id=message.channel_id, content="content")
|
|
125
|
+
|
|
126
|
+
示例机器人
|
|
127
|
+
----------
|
|
128
|
+
|
|
129
|
+
`\ ``examples`` <./examples/>`_ 目录下存放示例机器人,具体使用可参考\ `\ ``Readme.md`` <./examples/README.md>`_
|
|
130
|
+
|
|
131
|
+
.. code-block::
|
|
132
|
+
|
|
133
|
+
examples/
|
|
134
|
+
.
|
|
135
|
+
├── README.md
|
|
136
|
+
├── config.example.yaml # 示例配置文件(需要修改为config.yaml)
|
|
137
|
+
├── demo_announce.py # 机器人公告API使用示例
|
|
138
|
+
├── demo_api_permission.py # 机器人授权查询API使用示例
|
|
139
|
+
├── demo_at_reply.py # 机器人at被动回复async示例
|
|
140
|
+
├── demo_at_reply_ark.py # 机器人at被动回复ark消息示例
|
|
141
|
+
├── demo_at_reply_embed.py # 机器人at被动回复embed消息示例
|
|
142
|
+
├── demo_at_reply_command.py # 机器人at被动使用Command指令装饰器回复消息示例
|
|
143
|
+
├── demo_at_reply_file_data.py # 机器人at被动回复本地图片消息示例
|
|
144
|
+
├── demo_at_reply_keyboard.py # 机器人at被动回复md带内嵌键盘的示例
|
|
145
|
+
├── demo_at_reply_markdown.py # 机器人at被动回复md消息示例
|
|
146
|
+
├── demo_at_reply_reference.py # 机器人at被动回复消息引用示例
|
|
147
|
+
├── demo_dms_reply.py # 机器人私信被动回复示例
|
|
148
|
+
├── demo_get_reaction_users.py # 机器人获取表情表态成员列表示例
|
|
149
|
+
├── demo_guild_member_event.py # 机器人频道成员变化事件示例
|
|
150
|
+
├── demo_interaction.py # 机器人互动事件示例(未启用)
|
|
151
|
+
├── demo_pins_message.py # 机器人消息置顶示例
|
|
152
|
+
├── demo_recall.py # 机器人消息撤回示例
|
|
153
|
+
├── demo_schedule.py # 机器人日程相关示例
|
|
154
|
+
|
|
155
|
+
更多功能
|
|
156
|
+
--------
|
|
157
|
+
更多功能请参考: [https://github.com/tencent-connect/botpy]
|
|
158
|
+
|