Documentation ¶
Index ¶
- Constants
- type Anonymous
- type AnonymousMember
- type At
- type Bot
- func (b *Bot) Close() error
- func (b *Bot) DeleteMessage(messageId int64) error
- func (b *Bot) GetGroupInfo(group int64, noCache bool) (*GroupInfo, error)
- func (b *Bot) GetGroupList() ([]*GroupInfo, error)
- func (b *Bot) GetGroupMemberInfo(group, qq int64, noCache bool) (*GroupMemberInfo, error)
- func (b *Bot) GetGroupMemberList(group int64) ([]*GroupMemberInfo, error)
- func (b *Bot) ListenFriendRequest(l func(request *FriendRequest) bool)
- func (b *Bot) ListenGroupMessage(l func(message *GroupMessage) bool)
- func (b *Bot) ListenGroupRequest(l func(request *GroupRequest) bool)
- func (b *Bot) ListenPrivateMessage(l func(message *PrivateMessage) bool)
- func (b *Bot) Run(f func())
- func (b *Bot) SendGroupMessage(group int64, message MessageChain) (int64, error)
- func (b *Bot) SendMessage(messageType MessageType, targetId int64, message MessageChain) (int64, error)
- func (b *Bot) SendPrivateMessage(userId int64, message MessageChain) (int64, error)
- func (b *Bot) SetGroupLeave(group int64, isDismiss bool) error
- func (b *Bot) SetLimiter(limiterType string, l *rate.Limiter)
- type Contact
- type ContactType
- type Dice
- type Face
- type Forward
- type Friend
- type FriendRequest
- type Group
- type GroupInfo
- type GroupMemberInfo
- type GroupMessage
- type GroupMessageSubType
- type GroupRequest
- type GroupRequestSubType
- type Image
- type Json
- type Location
- type Member
- type MessageChain
- type MessageType
- type Music
- type Node
- type Poke
- type PrivateMessage
- type PrivateMessageSubType
- type Profile
- type RPS
- type Record
- type Reply
- type Role
- type Sex
- type Shake
- type Share
- type SingleMessage
- type Text
- type Video
- type WsChannel
- type Xml
Constants ¶
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 ¶
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 ¶
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) DeleteMessage ¶
DeleteMessage 撤回消息,messageId-需要撤回的消息的ID
func (*Bot) GetGroupInfo ¶
GetGroupInfo 获取群信息,group-群号,noCache-是否不使用缓存
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) ListenFriendRequest ¶
func (b *Bot) ListenFriendRequest(l func(request *FriendRequest) bool)
ListenFriendRequest 监听加好友请求
func (*Bot) ListenGroupMessage ¶
func (b *Bot) ListenGroupMessage(l func(message *GroupMessage) bool)
ListenGroupMessage 监听群消息
func (*Bot) ListenGroupRequest ¶
func (b *Bot) ListenGroupRequest(l func(request *GroupRequest) bool)
ListenGroupRequest 监听加群请求 / 邀请
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) 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) SetGroupLeave ¶
SetGroupLeave 退出群,group-群号,isDismiss-是否解散
type Contact ¶
type Contact struct { Type ContactType `json:"type"` // 类型 Id string `json:"id"` // QQ号或群号 }
Contact 推荐好友、推荐群
func (*Contact) GetMessageType ¶
type ContactType ¶
type ContactType string
const ( ContactTypeQQ ContactType = "qq" // 推荐好友 ContactTypeGroup ContactType = "group" // 推荐群 )
type Face ¶
type Face struct {
Id string `json:"id"` // QQ 表情 ID
}
Face QQ表情
func (*Face) GetMessageType ¶
type Forward ¶
type Forward struct {
Id string `json:"id"` // 合并转发 ID,需调用 Bot.GetForwardMsg 方法获取具体内容
}
Forward 合并转发
func (*Forward) GetMessageType ¶
type Friend ¶
type Friend struct { UserId int64 `json:"user_id"` // QQ号 Nickname string `json:"nickname"` // 昵称 Remark string `json:"remark"` // 备注 }
Friend 好友
func (*Friend) RemarkOrNickname ¶
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 加好友请求
type Group ¶
type Group struct { Id int64 `json:"id"` // 群号 Name string `json:"name"` // 群名称 Permission Role `json:"permission"` // Bot在群中的权限 }
Group 群
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"` // 成员等级 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) 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 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 加群请求/邀请
type GroupRequestSubType ¶
type GroupRequestSubType string
const ( GroupRequestAdd GroupRequestSubType = "add" // 加群请求 GroupRequestInvite GroupRequestSubType = "invite" // 邀请入群 )
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 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 ¶
type Reply ¶
type Reply struct {
Id string `json:"id"` // 回复时引用的消息 ID
}
Reply 回复
func (*Reply) GetMessageType ¶
type SingleMessage ¶
type SingleMessage interface {
GetMessageType() string
}
type Text ¶
type Text struct {
Text string `json:"text"` // 文字消息
}
Text 纯文本
func (*Text) GetMessageType ¶
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 短视频