onebot

package module
v0.0.0-...-dee3670 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 6, 2025 License: AGPL-3.0 Imports: 15 Imported by: 8

README

OneBot的Go SDK

image

这是针对onebot-11编写的Go SDK。

OneBot是一个通用聊天机器人应用接口标准。

开始

请多参阅onebot-11的文档。

[!IMPORTANT] 本项目是基于onebot的正向ws接口,因此你需要开启对应机器人项目的ws监听。

本项目处理消息的格式是消息段数组,因此你需要将onobot中的event.message_format配置为array

引入项目:

go get -u github.com/CuteReimu/onebot

关于如何使用,可以参考examples文件夹下的例子

进度

onebot-11的文档中的所有功能均已完成,包含:

  • 消息链
    • 所有消息类型
    • 所有消息解析
  • 事件
    • 消息事件,包括私聊消息、群消息等
    • 通知事件,包括群成员变动、好友变动等
    • 请求事件,包括加群请求、加好友请求等
    • 元事件,包括 OneBot 生命周期、心跳等
  • 请求
    • 发送、撤回消息
    • 获取消息
    • 发送好友赞
    • 群管理
    • 设置群名片
    • 退出群
    • 处理好友、加群请求
    • 获取账号信息
    • 获取群信息
    • 获取群成员信息
    • 获取群荣誉信息
    • 获取QQ相关信息
    • 图片语音相关
    • 获取OneBot相关信息
  • 其它
    • 连接与认证
    • 请求限流
    • 快速操作
    • 断线重连

Documentation

Index

Constants

View Source
const (
	// WsChannelApi 连接此接口后,向 OneBot 发送如下结构的 JSON 对象,即可调用相应的 API
	WsChannelApi = "api"

	// WsChannelEvent 连接此接口后,OneBot 会在收到事件后推送至客户端
	WsChannelEvent = "event"

	// WsChannelAll 在一条连接上同时提供 api 和 event 的服务
	WsChannelAll = ""
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Anonymous

type Anonymous struct {
	Ignore string `json:"ignore,omitempty"` // 发消息时使用,1和0表示无法匿名时是否继续发送
}

Anonymous 匿名发消息

func (*Anonymous) GetMessageType

func (m *Anonymous) GetMessageType() string

func (*Anonymous) String

func (m *Anonymous) String() string

type AnonymousMember

type AnonymousMember struct {
	Id   int64  `json:"id"`   // 匿名用户 ID
	Name string `json:"name"` // 匿名用户名称
	Flag string `json:"flag"` // 匿名用户 flag,在调用禁言 API 时需要传入
}

func (*AnonymousMember) String

func (a *AnonymousMember) String() string

type At

type At struct {
	QQ string `json:"qq"` // 群员QQ号,或者"all"表示全体成员
}

At @某人

func (*At) GetMessageType

func (m *At) GetMessageType() string

func (*At) String

func (m *At) String() string

type Bot

type Bot struct {
	QQ int64
	// contains filtered or unexported fields
}

func Connect

func Connect(host string, port int, channel WsChannel, accessToken string, qq int64, concurrentEvent bool) (*Bot, error)

Connect 连接onebot

concurrentEvent 参数如果是true,表示采用并发方式处理事件和消息,由调用者自行解决并发问题。 如果是false表示用单线程处理事件和消息,调用者无需关心并发问题。

func (*Bot) CanSendImage

func (b *Bot) CanSendImage() (bool, error)

CanSendImage 检查是否可以发送图片

func (*Bot) CanSendRecord

func (b *Bot) CanSendRecord() (bool, error)

CanSendRecord 检查是否可以发送语音

func (*Bot) CleanCache

func (b *Bot) CleanCache() error

CleanCache 用于清理积攒了太多的缓存文件

func (*Bot) Close

func (b *Bot) Close() error

func (*Bot) DeleteMessage

func (b *Bot) DeleteMessage(messageId int64) error

DeleteMessage 撤回消息,messageId-需要撤回的消息的ID

func (*Bot) GetCookies

func (b *Bot) GetCookies(domain string) (string, error)

GetCookies 获取Cookies,domain-需要获取cookies的域名

func (*Bot) GetCredentials

func (b *Bot) GetCredentials(domain string) (string, int32, error)

GetCredentials 获取QQ相关接口凭证,即上面两个接口的合并

func (*Bot) GetCsrfToken

func (b *Bot) GetCsrfToken() (int32, error)

GetCsrfToken 获取 CSRF Token

func (*Bot) GetForwardMessage

func (b *Bot) GetForwardMessage(id string) ([]any, error)

GetForwardMessage 获取合并转发消息

func (*Bot) GetFriendList

func (b *Bot) GetFriendList() ([]*Friend, error)

GetFriendList 获取陌生人信息,获取好友列表

func (*Bot) GetGroupInfo

func (b *Bot) GetGroupInfo(group int64, noCache bool) (*GroupInfo, error)

GetGroupInfo 获取群信息,group-群号,noCache-是否不使用缓存

func (*Bot) GetGroupList

func (b *Bot) GetGroupList() ([]*GroupInfo, error)

GetGroupList 获取群列表

func (*Bot) GetGroupMemberInfo

func (b *Bot) GetGroupMemberInfo(group, qq int64, noCache bool) (*GroupMemberInfo, error)

GetGroupMemberInfo 获取群成员信息,group-群号,qq-QQ号,noCache-是否不使用缓存

func (*Bot) GetGroupMemberList

func (b *Bot) GetGroupMemberList(group int64) ([]*GroupMemberInfo, error)

GetGroupMemberList 获取群成员列表,group-群号

注意:获取群成员列表时,不保证能获取到每个成员的所有信息,有些信息(例如area、title等)可能无法获得。 想要获取所有信息,请调用 Bot.GetGroupMemberInfo 方法获取单个成员信息。

func (*Bot) GetImage

func (b *Bot) GetImage(file string) (string, error)

GetImage 获取图片,file-收到的图片文件名(消息段的file参数),返回下载后的图片文件路径

func (*Bot) GetLoginInfo

func (b *Bot) GetLoginInfo() (*LoginInfo, error)

GetLoginInfo 获取登录号信息

func (*Bot) GetMessage

func (b *Bot) GetMessage(messageId int32) (*Message, error)

GetMessage 获取消息

func (*Bot) GetRecord

func (b *Bot) GetRecord(file, outFormat string) (string, error)

GetRecord 获取语音,file-收到的语音文件名(消息段的file参数),outFormat-要转换到的格式,返回转换后的语音文件路径

提示:要使用此接口,通常需要安装 ffmpeg,请参考 OneBot 实现的相关说明。 outFormat目前支持mp3、amr、wma、m4a、spx、ogg、wav、flac

func (*Bot) GetStatus

func (b *Bot) GetStatus() (*BotStatus, error)

GetStatus 获取运行状态

func (*Bot) GetStrangerInfo

func (b *Bot) GetStrangerInfo(userId int64, noCache bool) (*Profile, error)

GetStrangerInfo 获取陌生人信息,userId-QQ号,noCache-是否不使用缓存

func (*Bot) GetVersionInfo

func (b *Bot) GetVersionInfo() (*BotVersionInfo, error)

GetVersionInfo 获取版本信息

func (*Bot) ListenFriendAddNotice

func (b *Bot) ListenFriendAddNotice(l func(notice *FriendAddNotice) bool)

ListenFriendAddNotice 监听好友添加

func (*Bot) ListenFriendRecallNotice

func (b *Bot) ListenFriendRecallNotice(l func(notice *FriendRecallNotice) bool)

ListenFriendRecallNotice 监听好友消息撤回

func (*Bot) ListenFriendRequest

func (b *Bot) ListenFriendRequest(l func(request *FriendRequest) bool)

ListenFriendRequest 监听加好友请求

func (*Bot) ListenGroupAdminNotice

func (b *Bot) ListenGroupAdminNotice(l func(notice *GroupAdminNotice) bool)

ListenGroupAdminNotice 监听群管理员变动

func (*Bot) ListenGroupBanNotice

func (b *Bot) ListenGroupBanNotice(l func(notice *GroupBanNotice) bool)

ListenGroupBanNotice 监听群禁言

func (*Bot) ListenGroupDecreaseNotice

func (b *Bot) ListenGroupDecreaseNotice(l func(notice *GroupDecreaseNotice) bool)

ListenGroupDecreaseNotice 监听群成员减少

func (*Bot) ListenGroupIncreaseNotice

func (b *Bot) ListenGroupIncreaseNotice(l func(notice *GroupIncreaseNotice) bool)

ListenGroupIncreaseNotice 监听群成员增加

func (*Bot) ListenGroupMessage

func (b *Bot) ListenGroupMessage(l func(message *GroupMessage) bool)

ListenGroupMessage 监听群消息

func (*Bot) ListenGroupRecallNotice

func (b *Bot) ListenGroupRecallNotice(l func(notice *GroupRecallNotice) bool)

ListenGroupRecallNotice 监听群消息撤回

func (*Bot) ListenGroupRequest

func (b *Bot) ListenGroupRequest(l func(request *GroupRequest) bool)

ListenGroupRequest 监听加群请求 / 邀请

func (*Bot) ListenGroupUploadNotice

func (b *Bot) ListenGroupUploadNotice(l func(notice *GroupUploadNotice) bool)

ListenGroupUploadNotice 监听群文件上传

func (*Bot) ListenHeartbeatMetaEvent

func (b *Bot) ListenHeartbeatMetaEvent(l func(notice *HeartbeatMetaEvent) bool)

ListenHeartbeatMetaEvent 监听心跳事件

func (*Bot) ListenLifecycleMetaEvent

func (b *Bot) ListenLifecycleMetaEvent(l func(notice *LifecycleMetaEvent) bool)

ListenLifecycleMetaEvent 监听生命周期

func (*Bot) ListenNotifyNotice

func (b *Bot) ListenNotifyNotice(l func(notice *NotifyNotice) bool)

ListenNotifyNotice 监听其它通知

func (*Bot) ListenPrivateMessage

func (b *Bot) ListenPrivateMessage(l func(message *PrivateMessage) bool)

ListenPrivateMessage 监听私聊消息

func (*Bot) Run

func (b *Bot) Run(f func())

Run 如果不是并发方式启动,则此方法会将函数放入事件队列。如果是并发方式启动,则此方法等同于go f()。

func (*Bot) SendGroupMessage

func (b *Bot) SendGroupMessage(group int64, message MessageChain) (int64, error)

SendGroupMessage 发送群消息,group-群号,message-发送的内容,返回消息id

func (*Bot) SendLike

func (b *Bot) SendLike(userId int64, times int32) error

SendLike 发送好友赞,userId-对方QQ号,times-赞的次数(每个好友每天最多10次)

func (*Bot) SendMessage

func (b *Bot) SendMessage(messageType MessageType, targetId int64, message MessageChain) (int64, error)

SendMessage 发送消息,返回消息id

func (*Bot) SendPrivateMessage

func (b *Bot) SendPrivateMessage(userId int64, message MessageChain) (int64, error)

SendPrivateMessage 发送私聊消息,消息ID

func (*Bot) SetFriendAddRequest

func (b *Bot) SetFriendAddRequest(flag string, approve bool, remark string) error

SetFriendAddRequest 处理加好友请求,flag-从请求中获取,approve-是否同意,remark-同意好友后的备注

func (*Bot) SetGroupAddRequest

func (b *Bot) SetGroupAddRequest(flag string, subType GroupRequestSubType, approve bool, reason string) error

SetGroupAddRequest 处理加群请求/邀请,flag-从请求中获取,subType-从请求中获取,approve-是否同意,reason-拒绝理由

func (*Bot) SetGroupAdmin

func (b *Bot) SetGroupAdmin(groupId, userId int64, enable bool) error

SetGroupAdmin 群组设置管理员

func (*Bot) SetGroupAnonymous

func (b *Bot) SetGroupAnonymous(groupId int64, enable bool) error

SetGroupAnonymous 群组匿名

func (*Bot) SetGroupAnonymousBan

func (b *Bot) SetGroupAnonymousBan(groupId int64, flag string, duration int32) error

SetGroupAnonymousBan 群组匿名用户禁言,flag-需从群消息上报的 AnonymousMember 中获得,duration-禁言时长,单位秒,无法取消匿名用户禁言

func (*Bot) SetGroupBan

func (b *Bot) SetGroupBan(groupId, userId int64, duration int32) error

SetGroupBan 群组单人禁言,duration-禁言时长,单位秒,0表示取消禁言

func (*Bot) SetGroupCard

func (b *Bot) SetGroupCard(groupId, userId int64, card string) error

SetGroupCard 设置群名片(群备注),card-群名片内容,不填或空字符串表示删除群名片

func (*Bot) SetGroupKick

func (b *Bot) SetGroupKick(groupId, userId int64, rejectAddRequest bool) error

SetGroupKick 群组踢人,rejectAddRequest-拒绝此人的加群请求

func (*Bot) SetGroupLeave

func (b *Bot) SetGroupLeave(group int64, isDismiss bool) error

SetGroupLeave 退出群,group-群号,isDismiss-是否解散

func (*Bot) SetGroupName

func (b *Bot) SetGroupName(groupId int64, groupName string) error

SetGroupName 设置群名

func (*Bot) SetGroupSpecialTitle

func (b *Bot) SetGroupSpecialTitle(groupId, userId int64, specialTitle string, duration int32) error

SetGroupSpecialTitle 设置群组专属头衔,specialTitle-专属头衔,不填或空字符串表示删除专属头衔,duration-专属头衔有效期,单位秒,-1表示永久,不过此项似乎没有效果,可能是只有某些特殊的时间长度有效,有待测试

func (*Bot) SetGroupWholeBan

func (b *Bot) SetGroupWholeBan(groupId int64, enable bool) error

SetGroupWholeBan 群组全员禁言

func (*Bot) SetLimiter

func (b *Bot) SetLimiter(limiterType string, l *rate.Limiter)

SetLimiter 设置限流器,limiterType为"wait"表示等待,为"drop"表示丢弃

func (*Bot) SetRestart

func (b *Bot) SetRestart(delay int32) error

SetRestart 重启OneBot实现,delay-要延迟的毫秒数,如果默认情况下无法重启,可以尝试设置延迟为2000左右。

由于重启 OneBot 实现同时需要重启 API 服务,这意味着当前的 API 请求会被中断,因此需要异步地重启,接口返回的 status 是 async。

type BotStatus

type BotStatus struct {
	Online *bool `json:"online"` // 当前QQ在线,true|false|nil
	Good   bool  `json:"good"`   // 状态符合预期,意味着各模块正常运行、功能正常,且 QQ 在线
}

type BotVersionInfo

type BotVersionInfo struct {
	AppName         string `json:"app_name"`         // 应用标识,如"mirai-native"
	AppVersion      string `json:"app_version"`      // 应用版本,如"1.2.3"
	ProtocolVersion string `json:"protocol_version"` // OneBot标准版本,如"v11"
}

type Contact

type Contact struct {
	Type ContactType `json:"type"` // 类型
	Id   string      `json:"id"`   // QQ号或群号
}

Contact 推荐好友、推荐群

func (*Contact) GetMessageType

func (m *Contact) GetMessageType() string

func (*Contact) String

func (m *Contact) String() string

type ContactType

type ContactType string
const (
	ContactTypeQQ    ContactType = "qq"    // 推荐好友
	ContactTypeGroup ContactType = "group" // 推荐群
)

type Dice

type Dice struct {
}

Dice 掷骰子魔法表情

func (*Dice) GetMessageType

func (m *Dice) GetMessageType() string

func (*Dice) String

func (m *Dice) String() string

type Face

type Face struct {
	Id string `json:"id"` // QQ 表情 ID
}

Face QQ表情

func (*Face) GetMessageType

func (m *Face) GetMessageType() string

func (*Face) String

func (m *Face) String() string

type File

type File struct {
	Id    string `json:"id"`    // 文件 ID
	Name  string `json:"name"`  // 文件名
	Size  int64  `json:"size"`  // 文件大小(字节数)
	Busid int64  `json:"busid"` // busid(目前不清楚有什么作用)
}

type Forward

type Forward struct {
	Id string `json:"id"` // 合并转发 ID,需调用 Bot.GetForwardMessage 方法获取具体内容
}

Forward 合并转发

func (*Forward) GetMessageType

func (m *Forward) GetMessageType() string

func (*Forward) String

func (m *Forward) String() string

type Friend

type Friend struct {
	UserId   int64  `json:"user_id"`  // QQ号
	Nickname string `json:"nickname"` // 昵称
	Remark   string `json:"remark"`   // 备注
}

Friend 好友

func (*Friend) RemarkOrNickname

func (f *Friend) RemarkOrNickname() string

func (*Friend) String

func (f *Friend) String() string

type FriendAddNotice

type FriendAddNotice struct {
	Time       int64  `json:"time"`        // 事件发生的时间戳
	SelfId     int64  `json:"self_id"`     // 收到事件的机器人 QQ 号
	PostType   string `json:"post_type"`   // "notice"
	NoticeType string `json:"notice_type"` // "friend_add"
	UserId     int64  `json:"user_id"`     // 新添加好友 QQ 号
}

FriendAddNotice 好友添加

type FriendRecallNotice

type FriendRecallNotice struct {
	Time       int64  `json:"time"`        // 事件发生的时间戳
	SelfId     int64  `json:"self_id"`     // 收到事件的机器人 QQ 号
	PostType   string `json:"post_type"`   // "notice"
	NoticeType string `json:"notice_type"` // "friend_recall"
	UserId     int64  `json:"user_id"`     // 好友 QQ 号
	MessageId  int64  `json:"message_id"`  // 被撤回的消息 ID
}

FriendRecallNotice 好友消息撤回

type FriendRequest

type FriendRequest struct {
	Time        int64  `json:"time"`         // 事件发生的时间戳
	SelfId      int64  `json:"self_id"`      // 收到事件的机器人 QQ 号
	PostType    string `json:"post_type"`    // "request"
	RequestType string `json:"request_type"` // "friend"
	UserId      int64  `json:"user_id"`      // 发送请求的 QQ 号
	Comment     string `json:"comment"`      // 验证信息
	Flag        string `json:"flag"`         // 请求 flag,在调用处理请求的 API 时需要传入
}

FriendRequest 加好友请求

func (*FriendRequest) Reply

func (r *FriendRequest) Reply(b *Bot, approve bool, remark string) error

Reply 响应加好友请求,approve是是否同意,remark是添加后的好友备注(仅在同意时有效)

type Group

type Group struct {
	Id         int64  `json:"id"`         // 群号
	Name       string `json:"name"`       // 群名称
	Permission Role   `json:"permission"` // Bot在群中的权限
}

Group 群

func (*Group) String

func (g *Group) String() string

type GroupAdminNotice

type GroupAdminNotice struct {
	Time       int64                   `json:"time"`        // 事件发生的时间戳
	SelfId     int64                   `json:"self_id"`     // 收到事件的机器人 QQ 号
	PostType   string                  `json:"post_type"`   // "notice"
	NoticeType string                  `json:"notice_type"` // "group_admin"
	SubType    GroupAdminNoticeSubType `json:"sub_type"`    // 事件子类型
	GroupId    int64                   `json:"group_id"`    // 群号
	UserId     int64                   `json:"user_id"`     // 管理员 QQ 号
}

GroupAdminNotice 群管理员变动

type GroupAdminNoticeSubType

type GroupAdminNoticeSubType string
const (
	GroupAdminNoticeSet   GroupAdminNoticeSubType = "set"   // 设置管理员
	GroupAdminNoticeUnset GroupAdminNoticeSubType = "unset" // 取消管理员
)

type GroupBanNotice

type GroupBanNotice struct {
	Time       int64                 `json:"time"`        // 事件发生的时间戳
	SelfId     int64                 `json:"self_id"`     // 收到事件的机器人 QQ 号
	PostType   string                `json:"post_type"`   // "notice"
	NoticeType string                `json:"notice_type"` // "group_ban"
	SubType    GroupBanNoticeSubType `json:"sub_type"`    // 事件子类型
	GroupId    int64                 `json:"group_id"`    // 群号
	OperatorId int64                 `json:"operator_id"` // 操作者 QQ 号
	UserId     int64                 `json:"user_id"`     // 加入者 QQ 号
	Duration   int64                 `json:"duration"`    // 禁言时长,单位秒
}

GroupBanNotice 群禁言

type GroupBanNoticeSubType

type GroupBanNoticeSubType string
const (
	GroupBanNoticeBan     GroupBanNoticeSubType = "ban"      // 禁言
	GroupBanNoticeLiftBan GroupBanNoticeSubType = "lift_ban" // 解除禁言
)

type GroupDecreaseNotice

type GroupDecreaseNotice struct {
	Time       int64                      `json:"time"`        // 事件发生的时间戳
	SelfId     int64                      `json:"self_id"`     // 收到事件的机器人 QQ 号
	PostType   string                     `json:"post_type"`   // "notice"
	NoticeType string                     `json:"notice_type"` // "group_decrease"
	SubType    GroupDecreaseNoticeSubType `json:"sub_type"`    // 事件子类型
	GroupId    int64                      `json:"group_id"`    // 群号
	OperatorId int64                      `json:"operator_id"` // 操作者 QQ 号(如果是主动退群,则和 user_id 相同)
	UserId     int64                      `json:"user_id"`     // 离开者 QQ 号
}

GroupDecreaseNotice 群成员减少

type GroupDecreaseNoticeSubType

type GroupDecreaseNoticeSubType string
const (
	GroupDecreaseNoticeLeave  GroupDecreaseNoticeSubType = "leave"   // 主动退群
	GroupDecreaseNoticeKick   GroupDecreaseNoticeSubType = "kick"    // 成员被踢
	GroupDecreaseNoticeKickMe GroupDecreaseNoticeSubType = "kick_me" // 机器人被踢
)

type GroupIncreaseNotice

type GroupIncreaseNotice struct {
	Time       int64                      `json:"time"`        // 事件发生的时间戳
	SelfId     int64                      `json:"self_id"`     // 收到事件的机器人 QQ 号
	PostType   string                     `json:"post_type"`   // "notice"
	NoticeType string                     `json:"notice_type"` // "group_increase"
	SubType    GroupIncreaseNoticeSubType `json:"sub_type"`    // 事件子类型
	GroupId    int64                      `json:"group_id"`    // 群号
	OperatorId int64                      `json:"operator_id"` // 操作者 QQ 号(即管理员 QQ 号)
	UserId     int64                      `json:"user_id"`     // 加入者 QQ 号
}

GroupIncreaseNotice 群成员增加

type GroupIncreaseNoticeSubType

type GroupIncreaseNoticeSubType string
const (
	GroupIncreaseNoticeApprove GroupIncreaseNoticeSubType = "approve" // 管理员已同意入群
	GroupIncreaseNoticeInvite  GroupIncreaseNoticeSubType = "invite"  // 管理员已邀请入群
)

type GroupInfo

type GroupInfo struct {
	GroupId        int64  `json:"group_id"`         // 群号
	GroupName      string `json:"group_name"`       // 群名称
	MemberCount    int32  `json:"member_count"`     // 成员数
	MaxMemberCount int32  `json:"max_member_count"` // 最大成员数(群容量)
}

type GroupMemberInfo

type GroupMemberInfo struct {
	GroupId         int64  `json:"group_id"`          // 群号
	UserId          int64  `json:"user_id"`           // QQ 号
	Nickname        string `json:"nickname"`          // 昵称
	Card            string `json:"card"`              // 群名片/备注
	Sex             Sex    `json:"sex"`               // 性别
	Age             int32  `json:"age"`               // 年龄
	Area            string `json:"area"`              // 地区
	JoinTime        int32  `json:"join_time"`         // 加群时间戳
	LastSentTime    int32  `json:"last_sent_time"`    // 最后发言时间戳
	Level           String `json:"level"`             // 成员等级(onebot11标准这里是字符串,但很多框架把它返回了一个整型数值,这里就用这个方式兼容一下)
	Role            Role   `json:"role"`              // 角色
	Unfriendly      bool   `json:"unfriendly"`        // 是否不良记录成员
	Title           string `json:"title"`             // 专属头衔
	TitleExpireTime int32  `json:"title_expire_time"` // 专属头衔过期时间戳
	CardChangeable  bool   `json:"card_changeable"`   // 是否允许修改群名片
}

func (*GroupMemberInfo) CardOrNickname

func (m *GroupMemberInfo) CardOrNickname() string

type GroupMessage

type GroupMessage struct {
	Time        int64               `json:"time"`         // 事件发生的时间戳
	SelfId      int64               `json:"self_id"`      // 收到事件的机器人 QQ 号
	PostType    string              `json:"post_type"`    // "message"
	MessageType string              `json:"message_type"` // "group"
	SubType     GroupMessageSubType `json:"sub_type"`     // 消息子类型
	MessageId   int32               `json:"message_id"`   // 消息 ID
	GroupId     int64               `json:"group_id"`     // 群号
	UserId      int64               `json:"user_id"`      // 发送者 QQ 号
	Anonymous   *AnonymousMember    `json:"anonymous"`    // 匿名信息,如果不是匿名消息则为 nil
	Message     MessageChain        `json:"message"`      // 消息内容
	RawMessage  string              `json:"raw_message"`  // 原始消息内容
	Font        int32               `json:"font"`         // 字体
	Sender      Member              `json:"sender"`       // 发送人信息
}

GroupMessage 群消息

func (*GroupMessage) Ban

func (m *GroupMessage) Ban(b *Bot, duration int32) error

Ban 把发送者禁言,对匿名用户也有效

func (*GroupMessage) Delete

func (m *GroupMessage) Delete(b *Bot) error

Delete 撤回(需要权限),发送者是匿名用户时无效

func (*GroupMessage) Kick

func (m *GroupMessage) Kick(b *Bot) error

Kick 把发送者踢出群组(需要权限),不拒绝此人后续加群请求,发送者是匿名用户时无效

func (*GroupMessage) Reply

func (m *GroupMessage) Reply(b *Bot, reply MessageChain, atSender bool) error

Reply 回复

type GroupMessageSubType

type GroupMessageSubType string
const (
	GroupMessageNormal    GroupMessageSubType = "normal"    // 正常消息
	GroupMessageAnonymous GroupMessageSubType = "anonymous" // 匿名消息
	GroupMessageNotice    GroupMessageSubType = "notice"    // 系统提示
)

type GroupRecallNotice

type GroupRecallNotice struct {
	Time       int64  `json:"time"`        // 事件发生的时间戳
	SelfId     int64  `json:"self_id"`     // 收到事件的机器人 QQ 号
	PostType   string `json:"post_type"`   // "notice"
	NoticeType string `json:"notice_type"` // "group_recall"
	GroupId    int64  `json:"group_id"`    // 群号
	UserId     int64  `json:"user_id"`     // 消息发送者 QQ 号
	OperatorId int64  `json:"operator_id"` // 操作者 QQ 号
	MessageId  int64  `json:"message_id"`  // 被撤回的消息 ID
}

GroupRecallNotice 群消息撤回

type GroupRequest

type GroupRequest struct {
	Time        int64               `json:"time"`         // 事件发生的时间戳
	SelfId      int64               `json:"self_id"`      // 收到事件的机器人 QQ 号
	PostType    string              `json:"post_type"`    // "request"
	RequestType string              `json:"request_type"` // "group"
	SubType     GroupRequestSubType `json:"sub_type"`     // 请求子类型
	GroupId     int64               `json:"group_id"`     // 群号
	UserId      int64               `json:"user_id"`      // 发送请求的 QQ 号
	Comment     string              `json:"comment"`      // 验证信息
	Flag        string              `json:"flag"`         // 请求 flag,在调用处理请求的 API 时需要传入
}

GroupRequest 加群请求/邀请

func (*GroupRequest) Reply

func (r *GroupRequest) Reply(b *Bot, approve bool, reason string) error

Reply 响应加群请求/邀请,approve是是否同意,reason是拒绝理由(仅在拒绝时有效)

type GroupRequestSubType

type GroupRequestSubType string
const (
	GroupRequestAdd    GroupRequestSubType = "add"    // 加群请求
	GroupRequestInvite GroupRequestSubType = "invite" // 邀请入群
)

type GroupUploadNotice

type GroupUploadNotice struct {
	Time       int64  `json:"time"`        // 事件发生的时间戳
	SelfId     int64  `json:"self_id"`     // 收到事件的机器人 QQ 号
	PostType   string `json:"post_type"`   // "notice"
	NoticeType string `json:"notice_type"` // "group_upload"
	GroupId    int64  `json:"group_id"`    // 群号
	UserId     int64  `json:"user_id"`     // 发送者 QQ 号
	File       File   `json:"file"`        // 文件信息
}

GroupUploadNotice 群文件上传

type HeartbeatMetaEvent

type HeartbeatMetaEvent struct {
	Time          int64     `json:"time"`            // 事件发生的时间戳
	SelfId        int64     `json:"self_id"`         // 收到事件的机器人 QQ 号
	PostType      string    `json:"post_type"`       // "meta_event"
	MetaEventType string    `json:"meta_event_type"` // "heartbeat"
	Status        BotStatus `json:"status"`          // 状态信息
	Interval      int64     `json:"interval"`        // 到下次心跳的间隔,单位毫秒
}

HeartbeatMetaEvent 心跳事件

type Image

type Image struct {
	// 图片文件名
	//
	// 当发送图片时,除了可以直接使用收到的文件名直接发送以外,还支持:
	//
	// 绝对路径,格式使用file URI;
	// 网络URL,格式为http://xxx
	// Base64编码,格式为base64://<base64编码>。
	File string `json:"file"`

	// 图片类型,"flash"表示闪照,无此参数表示普通图片
	Type string `json:"type,omitempty"`

	// 图片的URL,只有在收图片时才有这个字段
	Url string `json:"url,omitempty"`

	// 以下字段只在通过网络URL发送时有效
	Cache   string `json:"cache,omitempty"`   // 1和0表示是否使用已缓存的文件,默认是
	Proxy   string `json:"proxy,omitempty"`   // 1和0表示是否通过代理下载文件(需通过环境变量或配置文件配置代理),默认是
	Timeout string `json:"timeout,omitempty"` // 单位秒,表示下载网络文件的超时时间,默认不超时
}

Image 图片

func (*Image) GetMessageType

func (m *Image) GetMessageType() string

func (*Image) String

func (m *Image) String() string

type Json

type Json struct {
	Data string `json:"data"` // Json文本
}

func (*Json) GetMessageType

func (m *Json) GetMessageType() string

func (*Json) String

func (m *Json) String() string

type LifecycleMetaEvent

type LifecycleMetaEvent struct {
	Time          int64                     `json:"time"`            // 事件发生的时间戳
	SelfId        int64                     `json:"self_id"`         // 收到事件的机器人 QQ 号
	PostType      string                    `json:"post_type"`       // "meta_event"
	MetaEventType string                    `json:"meta_event_type"` // "lifecycle"
	SubType       LifecycleMetaEventSubType `json:"sub_type"`        // 请求子类型
}

LifecycleMetaEvent 生命周期事件

type LifecycleMetaEventSubType

type LifecycleMetaEventSubType string
const (
	LifecycleMetaEventEnable  LifecycleMetaEventSubType = "enable"  // OneBot启用
	LifecycleMetaEventDisable LifecycleMetaEventSubType = "disable" // OneBot停用
	LifecycleMetaEventConnect LifecycleMetaEventSubType = "connect" // WebSocket连接成功
)

type Location

type Location struct {
	Lat     string `json:"lat"`               // 纬度
	Lon     string `json:"lon"`               // 经度
	Title   string `json:"title,omitempty"`   // 标题,发送时可不填
	Content string `json:"content,omitempty"` // 内容描述,发送时可不填
}

Location 位置

func (*Location) GetMessageType

func (m *Location) GetMessageType() string

func (*Location) String

func (m *Location) String() string

type LoginInfo

type LoginInfo struct {
	UserId   int64  `json:"user_id"`  // QQ号
	Nickname string `json:"nickname"` // QQ昵称
}

type Member

type Member struct {
	UserId   int64  `json:"user_id"`  // QQ号
	Nickname string `json:"nickname"` // 昵称
	Card     string `json:"card"`     // 群名片/备注
	Sex      Sex    `json:"sex"`      // 性别
	Age      int32  `json:"age"`      // 年龄
	Area     string `json:"area"`     // 地区
	Level    string `json:"level"`    // 成员等级
	Role     Role   `json:"role"`     // 角色
}

Member 群成员

func (*Member) CardOrNickname

func (m *Member) CardOrNickname() string

func (*Member) String

func (m *Member) String() string

type Message

type Message struct {
	Time        int32        `json:"time"`         // 发送时间
	MessageType MessageType  `json:"message_type"` // 消息类型
	MessageId   int32        `json:"message_id"`   // 消息ID
	RealId      int32        `json:"real_id"`      // 消息真实ID
	Sender      Profile      `json:"sender"`       // 发送人信息
	Message     MessageChain `json:"message"`      // 消息内容
}

type MessageChain

type MessageChain []SingleMessage

func (*MessageChain) MarshalJSON

func (c *MessageChain) MarshalJSON() ([]byte, error)

func (*MessageChain) UnmarshalJSON

func (c *MessageChain) UnmarshalJSON(data []byte) error

type MessageType

type MessageType string
const (
	MessageTypePrivate MessageType = "private" // 私聊消息
	MessageTypeGroup   MessageType = "group"   // 群消息
)

type Music

type Music struct {
	// "qq": QQ音乐, "163": 网易云音乐, "xm": 虾米音乐, "custom": 音乐自定义分享
	Type string `json:"type"`

	// 歌曲ID,用于非自定义分享
	Id string `json:"id,omitempty"`

	Url     string `json:"url,omitempty"`     // 点击后跳转目标 URL
	Audio   string `json:"audio,omitempty"`   // 音乐 URL
	Title   string `json:"title,omitempty"`   // 标题
	Content string `json:"content,omitempty"` // 内容描述,发送时可不填
	Image   string `json:"image,omitempty"`   // 图片URL,发送时可不填
}

Music 音乐分享

func (*Music) GetMessageType

func (m *Music) GetMessageType() string

func (*Music) String

func (m *Music) String() string

type Node

type Node struct {
	Id string `json:"id,omitempty"` // 转发的消息 ID

	UserId   string       `json:"user_id,omitempty"`  // 发送者 QQ 号
	Nickname string       `json:"nickname,omitempty"` // 发送者昵称
	Content  MessageChain `json:"content,omitempty"`  // 消息内容
}

Node 合并转发节点

func (*Node) GetMessageType

func (m *Node) GetMessageType() string

func (*Node) String

func (m *Node) String() string

type NotifyNotice

type NotifyNotice struct {
	Time       int64                 `json:"time"`                 // 事件发生的时间戳
	SelfId     int64                 `json:"self_id"`              // 收到事件的机器人 QQ 号
	PostType   string                `json:"post_type"`            // "notice"
	NoticeType string                `json:"notice_type"`          // "notify"
	SubType    NotifyNoticeSubType   `json:"sub_type"`             // 事件子类型
	GroupId    int64                 `json:"group_id"`             // 群号
	HonorType  NotifyNoticeHonorType `json:"honor_type,omitempty"` // (群成员荣誉变更)荣誉类型
	UserId     int64                 `json:"user_id"`              // (戳一戳)发送者/(红包)发送者/(荣誉变更)成员 QQ 号
	TargetId   int64                 `json:"target_id,omitempty"`  // (戳一戳)被戳者/(红包)运气王 QQ 号
}

NotifyNotice 其它通知

type NotifyNoticeHonorType

type NotifyNoticeHonorType string

type NotifyNoticeSubType

type NotifyNoticeSubType string
const (
	NotifyNoticePoke      NotifyNoticeSubType = "poke"       // 群内戳一戳
	NotifyNoticeLuckyKing NotifyNoticeSubType = "lucky_king" // 群红包运气王
	NotifyNoticeHonor     NotifyNoticeSubType = "honor"      // 群成员荣誉变更
)
const (
	NotifyNoticeNone      NotifyNoticeSubType = ""
	NotifyNoticeTalkative NotifyNoticeSubType = "talkative" // 龙王
	NotifyNoticePerformer NotifyNoticeSubType = "performer" // 群聊之火
	NotifyNoticeEmotion   NotifyNoticeSubType = "emotion"   // 快乐源泉
)

type Poke

type Poke struct {
	Type string `json:"type"`
	Id   string `json:"id"`
	Name string `json:"name,omitempty"` // 表情名,发送时无需此字段
}

Poke 戳一戳,字段含义参考文档

https://github.com/botuniverse/onebot-11/blob/master/message/segment.md#%E6%88%B3%E4%B8%80%E6%88%B3

func (*Poke) GetMessageType

func (m *Poke) GetMessageType() string

func (*Poke) String

func (m *Poke) String() string

type PrivateMessage

type PrivateMessage struct {
	Time        int64                 `json:"time"`         // 事件发生的时间戳
	SelfId      int64                 `json:"self_id"`      // 收到事件的机器人 QQ 号
	PostType    string                `json:"post_type"`    // "message"
	MessageType string                `json:"message_type"` // "private"
	SubType     PrivateMessageSubType `json:"sub_type"`     // 消息子类型
	MessageId   int32                 `json:"message_id"`   // 消息 ID
	UserId      int64                 `json:"user_id"`      // 发送者 QQ 号
	Message     MessageChain          `json:"message"`      // 消息内容
	RawMessage  string                `json:"raw_message"`  // 原始消息内容
	Font        int32                 `json:"font"`         // 字体
	Sender      Profile               `json:"sender"`       // 发送人信息
}

PrivateMessage 私聊消息

func (*PrivateMessage) Reply

func (m *PrivateMessage) Reply(b *Bot, reply MessageChain) error

Reply 回复

type PrivateMessageSubType

type PrivateMessageSubType string
const (
	PrivateMessageFriend PrivateMessageSubType = "friend" // 好友私聊
	PrivateMessageGroup  PrivateMessageSubType = "group"  // 群私聊
	PrivateMessageOther  PrivateMessageSubType = "other"  // 其它
)

type Profile

type Profile struct {
	UserId   int64  `json:"user_id"`  // QQ号
	Nickname string `json:"nickname"` // 昵称
	Sex      Sex    `json:"sex"`      // 性别
	Age      int32  `json:"age"`      // 年龄
}

Profile 用户资料

type RPS

type RPS struct {
}

RPS 猜拳魔法表情

func (*RPS) GetMessageType

func (m *RPS) GetMessageType() string

func (*RPS) String

func (m *RPS) String() string

type Record

type Record struct {
	// 语音文件名
	//
	// 当发送语音时,除了可以直接使用收到的文件名直接发送以外,还支持:
	//
	// 绝对路径,格式使用file URI;
	// 网络URL,格式为http://xxx
	// Base64编码,格式为base64://<base64编码>。
	File string `json:"file"`

	// 发送时可选,是否变声
	Magic bool `json:"magic,omitempty"`

	// 语音的URL,只有在收语音时才有这个字段
	Url string `json:"url,omitempty"`

	// 以下字段只在通过网络URL发送时有效
	Cache   string `json:"cache,omitempty"`   // 1和0表示是否使用已缓存的文件,默认是
	Proxy   string `json:"proxy,omitempty"`   // 1和0表示是否通过代理下载文件(需通过环境变量或配置文件配置代理),默认是
	Timeout string `json:"timeout,omitempty"` // 单位秒,表示下载网络文件的超时时间,默认不超时
}

Record 语音

func (*Record) GetMessageType

func (m *Record) GetMessageType() string

func (*Record) String

func (m *Record) String() string

type Reply

type Reply struct {
	Id string `json:"id"` // 回复时引用的消息 ID
}

Reply 回复

func (*Reply) GetMessageType

func (m *Reply) GetMessageType() string

func (*Reply) String

func (m *Reply) String() string

type Role

type Role string
const (
	RoleOwner  Role = "owner"  // 群主
	RoleAdmin  Role = "admin"  // 管理员
	RoleMember Role = "member" // 群成员
)

type Sex

type Sex string
const (
	SexUnknown Sex = "unknown" // 未知
	SexMale    Sex = "male"    // 男
	SexFemale  Sex = "female"  // 女
)

type Shake

type Shake struct {
}

Shake 窗口抖动

func (*Shake) GetMessageType

func (m *Shake) GetMessageType() string

func (*Shake) String

func (m *Shake) String() string

type Share

type Share struct {
	Url     string `json:"url"`               // URL
	Title   string `json:"title"`             // 标题
	Content string `json:"content,omitempty"` // 内容描述,发送时可不填
	Image   string `json:"image,omitempty"`   // 图片URL,发送时可不填
}

Share 链接分享

func (*Share) GetMessageType

func (m *Share) GetMessageType() string

func (*Share) String

func (m *Share) String() string

type SingleMessage

type SingleMessage interface {
	GetMessageType() string
}

type String

type String string

func (*String) String

func (s *String) String() string

func (*String) UnmarshalJSON

func (s *String) UnmarshalJSON(bytes []byte) error

type Text

type Text struct {
	Text string `json:"text"` // 文字消息
}

Text 纯文本

func (*Text) GetMessageType

func (m *Text) GetMessageType() string

func (*Text) String

func (m *Text) String() string

type Video

type Video struct {
	// 短视频文件名
	//
	// 当发送短视频时,除了可以直接使用收到的文件名直接发送以外,还支持:
	//
	// 绝对路径,格式使用file URI;
	// 网络URL,格式为http://xxx
	// Base64编码,格式为base64://<base64编码>。
	File string `json:"file"`

	// 短视频的URL,只有在收短视频时才有这个字段
	Url string `json:"url,omitempty"`

	// 以下字段只在通过网络URL发送时有效
	Cache   string `json:"cache,omitempty"`   // 1和0表示是否使用已缓存的文件,默认是
	Proxy   string `json:"proxy,omitempty"`   // 1和0表示是否通过代理下载文件(需通过环境变量或配置文件配置代理),默认是
	Timeout string `json:"timeout,omitempty"` // 单位秒,表示下载网络文件的超时时间,默认不超时
}

Video 短视频

func (*Video) GetMessageType

func (m *Video) GetMessageType() string

func (*Video) String

func (m *Video) String() string

type WsChannel

type WsChannel string

WsChannel 连接通道

type Xml

type Xml struct {
	Data string `json:"data"` // XML文本
}

func (*Xml) GetMessageType

func (m *Xml) GetMessageType() string

func (*Xml) String

func (m *Xml) String() string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL