QQ robot webhook server using Python 3
Project description
ymbotpy
ymbotpy 是基于 机器人开放平台API https://bot.q.qq.com/wiki/develop/api/ 实现的机器人框架,目的提供一个易使用、开发效率高的开发框架,同时支持Webhook和WebSocket,非Tencent官方SDK,但用法完全相同。
特性
- 兼容 Python 3.7+
- 简单、易用、快速集成,过滤垃圾消息以及消息鉴权
- 同时支持Webhook和WebSocket,可无缝替换websocket版本qq-botpy
安装
pip install ymbotpy
注意: Webhook由于通信方式的变化, 不再需要在本地注册监听事件,只需要编写具体的事件代码即可,事件开关在平台控制
Webhook 快速上手
-
频道内@自动回复
import ymbotpy from ymbotpy.message import Message class MyClient(ymbotpy.WebHookClient): async def on_at_message_create(self, message: Message): """频道内@""" await message.reply(content=f"机器人{self.robot.name}收到你的@消息了: {message.content}") if __name__ == "__main__": client = MyClient() # 启用沙盒模式 # client = MyClient(is_sandbox=True) client.run(appid='botid',secret='secert',port=8080,system_log=True)
-
在开发平台应配置的回调地址为:example.com/qbot/webhook,您可以通过以下方式来修改回调URL自定义webhook的url
client.run(appid=BOT_APPID,secret=BOT_SECRET,port=8080,system_log=True,hook_route='/your_url')
-
配置SSL以直接实现域名直接访问
client.run(appid=BOT_APPID,secret=BOT_SECRET,port=443,system_log=True, ssl_keyfile='ssl/private.key',ssl_certfile='ssl/public.crt')
WebSocket 快速上手(更多用法请参考官方文档)
- 频道内@自动回复
import ymbotpy from ymbotpy.message import Message class MyClient(ymbotpy.Client): async def on_at_message_create(self, message: Message): """频道内@""" await message.reply(content=f"机器人{self.robot.name}收到你的@消息了: {message.content}") if __name__ == "__main__": intents = ymbotpy.Intents(public_guild_messages=True) client = MyClient(intents=intents) # 启用沙盒模式 # client = MyClient(intents=intents, is_sandbox=True) client.run(appid='botid', secret='secert')
文档
有关此 SDK 更多用法,请查阅qq-botpy https://github.com/tencent-connect/botpy
欢迎访问镜芯科技
- 天狼星框架:https://www.siriusbot.cn/
- 镜芯API:https://api2.wer.plus/
- 林枫云_站长首选云服务器:https://www.dkdun.cn/
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
ymbotpy-1.1.0.dev0.tar.gz
(43.4 kB
view details)
File details
Details for the file ymbotpy-1.1.0.dev0.tar.gz.
File metadata
- Download URL: ymbotpy-1.1.0.dev0.tar.gz
- Upload date:
- Size: 43.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
31ac735e279d7c07a01bd9dd3bc3794dca17016705ed525847e65880f1576495
|
|
| MD5 |
2efe62efed85a2d1f365479d4f3312ab
|
|
| BLAKE2b-256 |
38d3a5640c74fbf166795ef4130425e5226e94ab92b2fa83142770b9fce8ed91
|