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.0.0.tar.gz (20.6 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.0.0-py3-none-any.whl (20.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: ncatbot_sync-0.0.0.tar.gz
  • Upload date:
  • Size: 20.6 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.0.0.tar.gz
Algorithm Hash digest
SHA256 58e67eb3906cbba4d1027b27f894ae98ae561027f09b2234e1172c2158bc8814
MD5 74119f2aad044e42635e0c0ebdb9bbd7
BLAKE2b-256 a839ae56c33440d31f0ea3a93fb841eb3a7d48c9149cffed5bf2b6e8b7c5bd6e

See more details on using hashes here.

File details

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

File metadata

  • Download URL: ncatbot_sync-0.0.0-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.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 4cd88e675be8e21538503d993470ca5ee0e6ac801faaf5e4557b4dcc3ef92115
MD5 b91283b7591308981b78777e33d20464
BLAKE2b-256 8623a9832f02f4f1fc48f5a4557f4f16c51cf549f7c56c08f625d11042a87853

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