Skip to main content

ncatbot精简同步版,基于onebot11协议编写

Project description

🚀 ncatbot_sync

background

Python 3.8+ License: MIT OneBot v11

基于OneBot v11协议的轻量级QQ机器人框架

English Docs | 文档 | 许可证

🌟 核心特性

  • 多协议支持:完整实现OneBot v11规范并支持Napcat,LLonebot,Lagrange多协议
  • 事件驱动架构:支持群聊/私聊消息处理
  • 高效通信:内置高性能WebSocket客户端
  • 模块化设计:可扩展的消息订阅机制
  • 开发者友好:简洁直观的API设计
  • 丰富功能:支持消息发送、群组管理、文件操作等
  • 专业日志:带轮转机制的彩色日志系统

🛠️ 安装指南

使用pip安装(计划实现,暂未实现)

pip install ncatbot-sync

从源码安装

git clone https://gitee.com/li-yihao0328/ncatbot_sync.git
cd ncatbot_sync
pip install -r requirements.txt

⚙️ 配置说明

在项目根目录创建 config.yaml

# 必填配置
url: "ws://your-onebot-server:port"  # 服务地址
token: "your-access-token"          # 访问令牌

🚀 快速开始

基础示例

from ncatbot_sync import BotClient, Intents, GroupMessage
# 初始化机器人
intents = Intents(group_message=True)
bot = BotClient(intents=intents)
@bot.on_message(GroupMessage, group_id=123456)# 监听指定群聊消息
async def handle_group_message(message: GroupMessage):
    """处理群组消息"""
    bot.onebot11.send_msg("收到消息!", group_id=message.group_id)
bot.run()

高级功能示例

# 发送复合消息
diy_message = [
    bot.onebot11.face(id=1),
    bot.onebot11.text("带表情的消息"),
    bot.onebot11.image(file="http://example.com/image.png")
]
bot.onebot11.send_msg(diy_message, group_id=123456)
# 处理好友请求
@bot.on_message(RequestMessage)
def handle_friend_request(message: RequestMessage):
    if message.sub_type == "friend":
        bot.onebot11.set_friend_add_request(flag=message.flag, approve=True)

📚 功能矩阵

功能类别 已实现接口 状态
消息管理 发送消息/图片/表情
群组操作 禁言/踢人/设置管理员
文件管理 上传/下载群文件
系统监控 获取状态/扩展数据
事件处理 加好友/加群请求处理
高级功能 转发消息/在线状态设置

🧩 开发指南

事件监听

@bot.on_message(PrivateMessage)
def handle_private_msg(message: PrivateMessage):
    """处理私聊消息"""
    if message.raw_message == "状态":
        bot.onebot11.send_msg(f"当前温度:1000℃",user_id=message.user_id)

定时任务(待开发,后续实现)

from ncatbot_sync.tools import schedule_task
@schedule_task(hours=1)
def hourly_task():
    """每小时执行的定时任务"""
    bot.onebot11.send_group_msg("整点报时!", group_id=123456)

🤝 参与贡献

欢迎通过 Issue 或 Pull Request 参与项目开发! 请先阅读 贡献指南


访问量统计

木子/ncatbot_sync

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ncatbot_sync-0.1.1.tar.gz (20.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

ncatbot_sync-0.1.1-py3-none-any.whl (20.5 kB view details)

Uploaded Python 3

File details

Details for the file ncatbot_sync-0.1.1.tar.gz.

File metadata

  • Download URL: ncatbot_sync-0.1.1.tar.gz
  • Upload date:
  • Size: 20.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for ncatbot_sync-0.1.1.tar.gz
Algorithm Hash digest
SHA256 c59206f595e1573cdc2092b1ebfc9f2f2074e68188dc4ca30d9222264b2e13b8
MD5 e6a33744222168b15a7eb4a9c7912001
BLAKE2b-256 aaac07daa1c308caf8f481024515e3a0a99805cdfc4360784bcfa545210fa143

See more details on using hashes here.

File details

Details for the file ncatbot_sync-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: ncatbot_sync-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 20.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for ncatbot_sync-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 011be505662ec77c9df3b8ca6bb740f2e94924dd8b14bae702453eabcf9d39c2
MD5 0e4eef74ee7ccee0f5998cf197ae1691
BLAKE2b-256 c00f99ac7c956300ff4aa98fe438d2e763cc87c0d3dde94d4b0fd6e3af7f7b33

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page