Skip to content

ProtobufBot/cpp-pbbot

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Protobuf C++ SDK

使用C++开发 ProtobufBot QQ机器人,推荐配合 GMC 使用

环境

推荐使用 vcpkg 作为包管理工具

$ git clone https://github.com/microsoft/vcpkg
$ cd vcpkg
$ ./vcpkg/bootstrap-vcpkg.sh
$ ./vcpkg/vcpkg install protobuf
$ ./vcpkg/vcpkg install drogon

Cmake

> cmake -B [build directory] -S . -DCMAKE_TOOLCHAIN_FILE=[path to vcpkg]/scripts/buildsystems/vcpkg.cmake
> cmake --build [build directory]

开发

修改 src/event_handler/event_handler.cpp

如果有问题欢迎提issue和pr

流程介绍

  1. 启动WebSocket Server

  2. 接受binary消息,使用protobuf解析,开新线程,交给event_handler.cpp处理

  3. 发送消息保存promise在map,接收到相同echo的response后 完成promise,继续处理

支持的类型

Event(被动接受)

代码在 event_handler.cpp,建议直接基于这个修改

  • 私聊消息 handlePrivateMessageEvent
  • 群聊消息 handleGroupMessageEvent
  • 群文件上传通知 handleGroupUploadNoticeEvent
  • 管理员变动通知 handleGroupAdminNoticeEvent
  • 群成员减少通知 handleGroupDecreaseNoticeEvent
  • 群成员增加通知 handleGroupIncreaseNoticeEvent
  • 群成员被禁言通知 handleGroupBanNoticeEvent
  • 好友已添加通知 handleFriendAddNoticeEvent
  • 群消息撤回通知 handleGroupRecallNoticeEvent
  • 好友撤回通知 handleFriendRecallNoticeEvent
  • 加好友请求 handleFriendRequestEvent
  • 加群请求 handleGroupRequestEvent

API(主动执行)

代码在 Bot.cpp

  • 发送私聊消息 sendPrivateMsg
  • 发送群消息 sendGroupMsg
  • 撤回消息 deleteMsg
  • 群踢人 setGroupKick
  • 群禁言 setGroupBan
  • 全群禁言 setGroupWholeBan
  • 设置成员名片 setGroupCard
  • 退群 setGroupLeave
  • 处理加好友请求 setFriendAddRequest
  • 处理加群请求 setGroupAddRequest
  • 获取好友列表 getFriendList
  • 获取陌生人信息 getStrangerInfo
  • 获取群列表 getGroupList
  • 获取群信息 getGroupInfo
  • 获取群成员信息 getGroupMemberInfo
  • 获取群成员列表 getGroupMemberList