Documentation ¶
Index ¶
- Constants
- Variables
- func Escape(s string, escapeComma bool) (res string)
- func GetPluginConfig(plugin Plugin) interface{}
- func LoadCustomConfig(path string, cfgPtr Config)
- func RegisterPlugin(plugin Plugin, pluginConfig interface{})
- func RegisterProvider(name string, provider Provider)
- func Unescape(s string) (res string)
- type Anonymous
- type ApiParams
- type ApiResponse_GetMsg
- type BaseConfig
- type Bot
- func (bot *Bot) CallApi(action string, params ApiParams) (*gjson.Result, error)
- func (bot *Bot) CanSendImage() (bool, error)
- func (bot *Bot) CanSendRecord() (bool, error)
- func (bot *Bot) ClearCache() error
- func (bot *Bot) DeleteMsg(messageId int32) error
- func (bot *Bot) GetCookies(domain string) (string, error)
- func (bot *Bot) GetCredentials(domain string) (*QQCredential, error)
- func (bot *Bot) GetCsrfToken() (int32, error)
- func (bot *Bot) GetForwardMsg(messageId int32) (*Message, error)
- func (bot *Bot) GetFriendList() (*[]FriendInfo, error)
- func (bot *Bot) GetGroupHonorInfo(groupId int64, type_ string) (*GroupHonorInfo, error)
- func (bot *Bot) GetGroupInfo(groupId int64) (*GroupInfo, error)
- func (bot *Bot) GetGroupList() (*[]GroupInfo, error)
- func (bot *Bot) GetGroupMemberInfo(groupId int64, userId int64) (*GroupMemberInfo, error)
- func (bot *Bot) GetGroupMemberList(groupId int64) (*[]GroupMemberInfo, error)
- func (bot *Bot) GetImage(file string) (string, error)
- func (bot *Bot) GetLoginInfo() (*LoginInfo, error)
- func (bot *Bot) GetMsg(messageId int32) (*ApiResponse_GetMsg, error)
- func (bot *Bot) GetRecord(file string, outFormat string) (string, error)
- func (bot *Bot) GetSelfId() int64
- func (bot *Bot) GetStatus() (*Status, error)
- func (bot *Bot) GetStrangerInfo(userId int64) (*StrangerInfo, error)
- func (bot *Bot) GetVersionInfo() (*VesionInfo, error)
- func (bot *Bot) Init(provider Provider)
- func (bot *Bot) SendGroupMsg(groupId int64, message Message, autoEscape bool) (int32, error)
- func (bot *Bot) SendLike(userId int64, times int) error
- func (bot *Bot) SendMsg(messageType string, userId, groupId int64, message Message, autoEscape bool) (int32, error)
- func (bot *Bot) SendPrivateMsg(userId int64, message Message, autoEscape bool) (int32, error)
- func (bot *Bot) SetFriendAddRequest(flag string, approve bool, remark string) error
- func (bot *Bot) SetGroupAddRequest(flag string, subType int, approve bool, reason string) error
- func (bot *Bot) SetGroupAdmin(groupId int64, userId int64, enable bool) error
- func (bot *Bot) SetGroupAnonymous(groupId int64, enable bool) error
- func (bot *Bot) SetGroupAnonymousBan(groupId int64, anonymous *Anonymous, anonymousFlag string, duration int) error
- func (bot *Bot) SetGroupBan(groupId int64, userId int64, duration int) error
- func (bot *Bot) SetGroupCard(groupId int64, userId int64, card string) error
- func (bot *Bot) SetGroupDismiss(groupId int64) error
- func (bot *Bot) SetGroupKick(groupId int64, userId int64, rejectAddRequest bool) error
- func (bot *Bot) SetGroupLeave(groupId int64) error
- func (bot *Bot) SetGroupName(groupId int64, groupName string) error
- func (bot *Bot) SetGroupSpecialTitle(groupId int64, userId int64, specialTitle string, duration int) error
- func (bot *Bot) SetGroupWholeBan(groupId int64, enable bool) error
- func (bot *Bot) SetRestart(delay int) error
- type ClientStatusNoticeEvent
- type Config
- type Context
- func (a *Context) Abort()
- func (ctx *Context) ApproveFriendRequest() (err error)
- func (ctx *Context) ApproveGroupRequest() (err error)
- func (ctx *Context) AtSender(b bool) *Context
- func (ctx *Context) Ban(duration int) (err error)
- func (ctx *Context) Delete() (err error)
- func (ctx *Context) Get(key string) (v interface{}, exist bool)
- func (ctx *Context) GetCommandMatchResult() *commandMatchResult
- func (ctx *Context) GetInt(key string) (i int)
- func (ctx *Context) GetInt64(key string) (i64 int64)
- func (ctx *Context) GetKeywordMatchResult() string
- func (ctx *Context) GetMap(key string) (m map[string]interface{})
- func (ctx *Context) GetPrefixMatchResult() *prefixMatchResult
- func (ctx *Context) GetRegexMatchResult() *regexpMatchResult
- func (ctx *Context) GetShellLikeCommandResult() *parseResult
- func (ctx *Context) GetSlice(key string) (s []interface{})
- func (ctx *Context) GetString(key string) (s string)
- func (ctx *Context) GetSuffixMatchResult() *suffixMatchResult
- func (ctx *Context) Kick() (err error)
- func (ctx *Context) MustGet(key string) interface{}
- func (a *Context) Next() bool
- func (ctx *Context) Prompt(message Message, timeout int) *Message
- func (ctx *Context) RejectFriendRequest() (err error)
- func (ctx *Context) RejectGroupRequest(reason string) (err error)
- func (ctx *Context) Reply(args ...interface{}) (err error)
- func (ctx *Context) ReplyMsg(msg Message) (err error)
- func (ctx *Context) ReplyRaw(msg Message) (err error)
- func (ctx *Context) ReplyText(text string) (err error)
- func (ctx *Context) Replyf(tmpl string, args ...interface{}) (err error)
- func (ctx *Context) Set(key string, value interface{})
- func (ctx *Context) WaitForNextEvent(timeout int, middlewares ...Middleware) I_Event
- func (ctx *Context) WaitForNextEventInSameSession(timeout int, middlewares ...Middleware) I_Event
- type CurrentTalkative
- type Engine
- type EngineHookCallback
- type EssenceNoticeEvent
- type Event
- func (e *Event) ExtractPlainText() string
- func (e *Event) GetEventDescription() string
- func (e *Event) GetEventName() EventName
- func (e *Event) GetMessage() *Message
- func (e *Event) GetPostType() string
- func (e *Event) GetSecondType() string
- func (e *Event) GetSessionId() string
- func (e *Event) GetSubType() string
- func (e *Event) IsMessageEvent() bool
- func (e *Event) IsToMe() bool
- type EventHookCallback
- type EventName
- type FriendAddNoticeEvent
- type FriendInfo
- type FriendRecallNoticeEvent
- type FriendRequestEvent
- type GroupAdminNoticeEvent
- type GroupBanNoticeEvent
- type GroupCardNoticeEvent
- type GroupDecreaseNoticeEvent
- type GroupHonorInfo
- type GroupIncreaseNoticeEvent
- type GroupInfo
- type GroupMemberInfo
- type GroupMessageEvent
- type GroupMessageEventSender
- type GroupRecallNoticeEvent
- type GroupRequestEvent
- type GroupUploadNoticeEvent
- type Handler
- type HandlerFunc
- type HeartbeatMetaEvent
- type HonorListItem
- type HonorNoticeEvent
- type I_Event
- type LifeCycleMetaEvent
- type LoginInfo
- type LuckyKingNoticeEvent
- type Message
- func (m *Message) Append(t t_StringOrSegment)
- func (m *Message) AppendSegment(seg MessageSegment)
- func (m *Message) AppendText(t string)
- func (m *Message) Extend(msg t_MessageOrSegmentArray) (err error)
- func (m *Message) ExtendMessage(msg Message)
- func (m *Message) ExtendSegmentArray(segs []MessageSegment)
- func (m Message) ExtractPlainText() (text string)
- func (m Message) FilterByType(segmentType string) []MessageSegment
- func (m Message) Len() int
- func (m Message) String() string
- type MessageEvent
- type MessageEventSender
- type MessageSegment
- type Middleware
- func Command(cmd ...string) Middleware
- func EndsWith(suffix ...string) Middleware
- func FromAdmin() Middleware
- func FromAdminOrHigher() Middleware
- func FromGroup(groupIds ...int64) Middleware
- func FromOwner() Middleware
- func FromOwnerOrHigher() Middleware
- func FromPrivate(userIds ...int64) Middleware
- func FromSession(sessionId string) Middleware
- func FromSuperuser() Middleware
- func FromUser(userIds ...int64) Middleware
- func FullMatch(text ...string) Middleware
- func Keyword(keywords ...string) Middleware
- func OnEvent(eventName EventName) Middleware
- func OnlyToMe() Middleware
- func Regex(regex regexp.Regexp) Middleware
- func ShellLikeCommand(cmd string, args interface{}, whenFailed ParseFailedAction) Middleware
- func StartsWith(prefix ...string) Middleware
- type NoticeEvent
- type OfflineFileNoticeEvent
- type ParseFailedAction
- type Plugin
- type PluginConfigMap
- type PluginHookCallback
- type PluginHub
- func (p *PluginHub) GetBot() *Bot
- func (p *PluginHub) GetEngineConfig() *BaseConfig
- func (p *PluginHub) GetPluginConfig(plugin Plugin) interface{}
- func (p *PluginHub) GetPluginId() string
- func (p *PluginHub) NewHandler(eventTypes ...EventName) *Handler
- func (p *PluginHub) Use(middlewares ...Middleware)
- type PluginInfo
- type PokeNoticeEvent
- type PrivateMessageEvent
- type Provider
- type ProviderConfigMap
- type QQCredential
- type Status
- type StrangerInfo
- type VesionInfo
Constants ¶
const ( PostType_MetaEvent = "meta_event" PostType_MessageEvent = "message" PostType_NoticeEvent = "notice" PostType_RequestEvent = "request" )
const ( MusicType_QQ = "qq" // QQ 音乐 MusicType_163 = "163" // 网易云音乐 MusicType_XiaMi = "xm" // 虾米音乐 )
Variables ¶
var ( ErrInvalidMessageType = errors.New("不正确的message type") ErrMissingAnonymous = errors.New("缺少anonymous对象") )
var GlobalHooks globalHookManager = globalHookManager{ // contains filtered or unexported fields }
全局钩子,不隶属于特定的Engine实例。Engine的生命周期钩子也会在这里触发
var MsgFactory = messageSegmentFactory{}
Functions ¶
func LoadCustomConfig ¶
载入自定义配置文件,文件为YAML。自定义配置的结构体必须继承BaseConfig
func RegisterPlugin ¶ added in v0.1.4
func RegisterPlugin(plugin Plugin, pluginConfig interface{})
注册插件。插件配置结构体pluginConfig可选,使用反射映射到字段,无则传nil
func RegisterProvider ¶ added in v0.2.1
注册一个Provider
Types ¶
type ApiResponse_GetMsg ¶
type ApiResponse_GetMsg struct { Time int32 MessageType string MessageId int32 RealId int32 Message Message // contains filtered or unexported fields }
func (*ApiResponse_GetMsg) GetGroupSender ¶
func (r *ApiResponse_GetMsg) GetGroupSender() *GroupMessageEventSender
func (*ApiResponse_GetMsg) GetPrivateSender ¶
func (r *ApiResponse_GetMsg) GetPrivateSender() *MessageEventSender
type BaseConfig ¶
type BaseConfig struct { // Websocket WebsocketConfig `yaml:"websocket"` CmdPrefix []string `yaml:"cmd_prefix"` // 命令前缀 Superuser []int64 `yaml:"superuser"` // 超级用户 ApiCallTimeout int `yaml:"apicall_timeout"` // API调用超时时间,单位:秒 Plugin struct { Enable map[string]bool `yaml:"enable"` Config map[string]PluginConfigMap `yaml:"config"` } `yaml:"plugin"` Provider string `yaml:"provider"` ProviderConfig map[string]ProviderConfigMap `yaml:"provider_config"` }
func (*BaseConfig) GetBaseConfig ¶
func (cfg *BaseConfig) GetBaseConfig() *BaseConfig
type Bot ¶
type Bot struct {
// contains filtered or unexported fields
}
func (*Bot) GetCredentials ¶
func (bot *Bot) GetCredentials(domain string) (*QQCredential, error)
获取 QQ 相关接口凭证
func (*Bot) GetForwardMsg ¶
获取合并转发消息
func (*Bot) GetGroupHonorInfo ¶
func (bot *Bot) GetGroupHonorInfo(groupId int64, type_ string) (*GroupHonorInfo, error)
获取群荣誉信息
func (*Bot) GetGroupMemberInfo ¶
func (bot *Bot) GetGroupMemberInfo(groupId int64, userId int64) (*GroupMemberInfo, error)
获取群成员信息
func (*Bot) GetGroupMemberList ¶
func (bot *Bot) GetGroupMemberList(groupId int64) (*[]GroupMemberInfo, error)
获取群成员列表
func (*Bot) GetStrangerInfo ¶
func (bot *Bot) GetStrangerInfo(userId int64) (*StrangerInfo, error)
获取陌生人信息
func (*Bot) SendGroupMsg ¶
发送群消息
func (*Bot) SendMsg ¶
func (bot *Bot) SendMsg(messageType string, userId, groupId int64, message Message, autoEscape bool) (int32, error)
发送消息
func (*Bot) SendPrivateMsg ¶
发送私聊消息
func (*Bot) SetFriendAddRequest ¶
处理加好友请求
func (*Bot) SetGroupAddRequest ¶
处理加群请求/邀请
func (*Bot) SetGroupAdmin ¶
群组设置管理员
func (*Bot) SetGroupAnonymous ¶
群组开关匿名
func (*Bot) SetGroupAnonymousBan ¶
func (bot *Bot) SetGroupAnonymousBan(groupId int64, anonymous *Anonymous, anonymousFlag string, duration int) error
群组匿名用户禁言
func (*Bot) SetGroupBan ¶
群组单人禁言
func (*Bot) SetGroupCard ¶
设置群名片(群备注)
func (*Bot) SetGroupKick ¶
群组踢人
func (*Bot) SetGroupSpecialTitle ¶
func (bot *Bot) SetGroupSpecialTitle(groupId int64, userId int64, specialTitle string, duration int) error
设置群组专属头衔
func (*Bot) SetGroupWholeBan ¶
群组全员禁言
type ClientStatusNoticeEvent ¶
type ClientStatusNoticeEvent struct { NoticeEvent Client struct { AppId int64 `json:"app_id"` // 客户端 ID DeviceName string `json:"device_name"` // 设备名称 DeviceKind string `json:"device_kind"` // 设备类型 } `json:"client"` Online bool `json:"online"` // 在线状态 }
其他客户端在线状态变更
type Config ¶
type Config interface {
GetBaseConfig() *BaseConfig
}
type Context ¶
type Context struct { Event I_Event // 事件(实际上是个指针) Keys map[string]interface{} // 存放一些提取出来的数据 Bot *Bot // Bot实例 Engine *Engine // Engine实例 Handler *Handler // contains filtered or unexported fields }
func (*Context) ApproveFriendRequest ¶
同意加好友请求
func (*Context) ApproveGroupRequest ¶
同意加群请求、或被邀请入群请求
func (*Context) GetCommandMatchResult ¶ added in v0.2.0
func (ctx *Context) GetCommandMatchResult() *commandMatchResult
获取Command的匹配结果
func (*Context) GetKeywordMatchResult ¶ added in v0.2.0
获取Keyword的匹配结果
func (*Context) GetPrefixMatchResult ¶ added in v0.2.0
func (ctx *Context) GetPrefixMatchResult() *prefixMatchResult
获取StartsWith匹配结果
func (*Context) GetRegexMatchResult ¶ added in v0.2.0
func (ctx *Context) GetRegexMatchResult() *regexpMatchResult
func (*Context) GetShellLikeCommandResult ¶ added in v0.2.0
func (ctx *Context) GetShellLikeCommandResult() *parseResult
获取ShellLikeCommand的解析结果
func (*Context) GetSuffixMatchResult ¶ added in v0.2.0
func (ctx *Context) GetSuffixMatchResult() *suffixMatchResult
获取EndsWith的匹配结果
func (*Context) Next ¶ added in v0.1.4
func (a *Context) Next() bool
继续后续执行(后续执行完毕后才返回),返回值代表是否事件被Handler处理过
func (*Context) RejectGroupRequest ¶
拒绝加群请求、或被邀请入群请求
func (*Context) WaitForNextEvent ¶
func (ctx *Context) WaitForNextEvent(timeout int, middlewares ...Middleware) I_Event
获取下一个符合条件的事件,如果没有则阻塞本事件的处理流程。
timeout为超时时间(单位为秒),超时返回nil。 middlewares为事件处理中间件,可以添加筛选条件。
func (*Context) WaitForNextEventInSameSession ¶
func (ctx *Context) WaitForNextEventInSameSession(timeout int, middlewares ...Middleware) I_Event
获取同一个Session的下一个符合条件的事件。
type CurrentTalkative ¶
type Engine ¶
type Engine struct { Handler Config Config Hooks engineHookManager // contains filtered or unexported fields }
func NewEngineWithProvider ¶ added in v0.2.1
直接指定Provider,忽略配置文件
type EngineHookCallback ¶ added in v0.2.0
type EngineHookCallback func(*Engine)
type EssenceNoticeEvent ¶
type EssenceNoticeEvent struct { NoticeEvent SubType string `json:"sub_type"` // 通知子类型,essence SenderId int64 `json:"sender_id"` OperatorId int64 `json:"operator_id"` MessageId int32 `json:"message_id"` }
精华消息
type Event ¶
type Event struct { Time int64 `json:"time"` // 事件发生的时间戳 SelfId int64 `json:"self_id"` // 收到事件的机器人的QQ号 PostType string `json:"post_type"` // 事件的类型,message, notice, request, meta_event EventName EventName `json:"-"` // 事件的名称,形如:notice.group.set ToMe bool `json:"-"` // 是否与我(bot)有关(即私聊我、或群聊At我、我被踢了、等等) }
func (*Event) ExtractPlainText ¶
func (*Event) GetMessage ¶
func (*Event) GetPostType ¶
获取事件的上报类型,有message, notice, request, meta_event
func (*Event) GetSecondType ¶
func (*Event) GetSessionId ¶
func (*Event) GetSubType ¶
func (*Event) IsMessageEvent ¶
type EventHookCallback ¶ added in v0.2.1
type EventHookCallback func(I_Event)
type EventName ¶
type EventName string
const ( EventName_AllEvent EventName = "all" EventName_Message EventName = "message" EventName_PrivateMessage EventName = "message.private" EventName_GroupMessage EventName = "message.group" EventName_Notice EventName = "notice" EventName_GroupUpload EventName = "notice.group_upload" EventName_GroupAdmin EventName = "notice.group_admin" EventName_GroupDecrease EventName = "notice.group_decrease" EventName_GroupIncrease EventName = "notice.group_increase" EventName_GroupBan EventName = "notice.group_ban" EventName_FriendAdd EventName = "notice.friend_add" EventName_GroupRecall EventName = "notice.group_recall" EventName_FriendRecall EventName = "notice.friend_recall" EventName_Notify EventName = "notice.notify" EventName_NotifyPoke EventName = "notice.notify.poke" EventName_NotifyLuckyKing EventName = "notice.notify.lucky_king" EventName_NotifyHonor EventName = "notice.notify.honor" EventName_Request EventName = "request" EventName_RequestFriend EventName = "request.friend" EventName_RequestGroup EventName = "request.group" EventName_Meta EventName = "meta_event" EventName_MetaLifecycle EventName = "meta_event.lifecycle" EventName_MetaHeartbeat EventName = "meta_event.heartbeat" )
type FriendAddNoticeEvent ¶
type FriendAddNoticeEvent struct { NoticeEvent UserId int64 `json:"user_id"` // 好友 QQ 号 }
好友添加通知
func (*FriendAddNoticeEvent) GetSessionId ¶
func (e *FriendAddNoticeEvent) GetSessionId() string
type FriendInfo ¶
type FriendRecallNoticeEvent ¶
type FriendRecallNoticeEvent struct { NoticeEvent UserId int64 `json:"user_id"` // 撤回者 QQ 号 MessageId int64 `json:"message_id"` // 消息 ID }
好友消息撤回通知
func (*FriendRecallNoticeEvent) GetSessionId ¶
func (e *FriendRecallNoticeEvent) GetSessionId() string
type FriendRequestEvent ¶
type FriendRequestEvent struct { Event RequestType string `json:"request_type"` // 请求类型,friend UserId int64 `json:"user_id"` // 发送请求的QQ号 Comment string `json:"comment"` // 验证消息 Flag string `json:"flag"` // 请求 flag,在调用处理请求的 API 时需要传入 }
加好友请求事件
func (*FriendRequestEvent) GetSecondType ¶
func (e *FriendRequestEvent) GetSecondType() string
func (*FriendRequestEvent) GetSessionId ¶
func (e *FriendRequestEvent) GetSessionId() string
type GroupAdminNoticeEvent ¶
type GroupAdminNoticeEvent struct { NoticeEvent SubType string `json:"sub_type"` // 通知子类型,set unset GroupId int64 `json:"group_id"` // 群号 UserId int64 `json:"user_id"` // 管理员 QQ 号 }
群管理员变动通知
func (*GroupAdminNoticeEvent) GetSessionId ¶
func (e *GroupAdminNoticeEvent) GetSessionId() string
func (*GroupAdminNoticeEvent) GetSubType ¶
func (e *GroupAdminNoticeEvent) GetSubType() string
type GroupBanNoticeEvent ¶
type GroupBanNoticeEvent struct { NoticeEvent SubType string `json:"sub_type"` // 通知子类型,ban, lift_ban GroupId int64 `json:"group_id"` // 群号 UserId int64 `json:"user_id"` // 被禁言 QQ 号 OperatorId int64 `json:"operator_id"` // 操作者 QQ 号 Duration int64 `json:"duration"` // 禁言时长,单位秒 }
群禁言通知
func (*GroupBanNoticeEvent) GetSessionId ¶
func (e *GroupBanNoticeEvent) GetSessionId() string
func (*GroupBanNoticeEvent) GetSubType ¶
func (e *GroupBanNoticeEvent) GetSubType() string
type GroupCardNoticeEvent ¶
type GroupCardNoticeEvent struct { NoticeEvent GroupId int64 `json:"group_id"` // 群号 UserId int64 `json:"user_id"` // 群成员 QQ 号 CardNew string `json:"card_new"` // 新名片 CardOld string `json:"card_old"` // 旧名片 }
群成员名片更新
type GroupDecreaseNoticeEvent ¶
type GroupDecreaseNoticeEvent struct { NoticeEvent SubType string `json:"sub_type"` // 通知子类型,leave, kick, kick_me GroupId int64 `json:"group_id"` // 群号 UserId int64 `json:"user_id"` // 离开者 QQ 号 OperatorId int64 `json:"operator_id"` // 操作者 QQ 号 }
群成员减少通知
func (*GroupDecreaseNoticeEvent) GetSessionId ¶
func (e *GroupDecreaseNoticeEvent) GetSessionId() string
func (*GroupDecreaseNoticeEvent) GetSubType ¶
func (e *GroupDecreaseNoticeEvent) GetSubType() string
type GroupHonorInfo ¶
type GroupHonorInfo struct { GroupId int64 CurrentTalkative *CurrentTalkative TalkativeList []HonorListItem PerformerList []HonorListItem LegendList []HonorListItem StrongNewbieList []HonorListItem EmotionList []HonorListItem }
type GroupIncreaseNoticeEvent ¶
type GroupIncreaseNoticeEvent struct { NoticeEvent SubType string `json:"sub_type"` // 通知子类型,approve, invite GroupId int64 `json:"group_id"` // 群号 UserId int64 `json:"user_id"` // 新成员 QQ 号 OperatorId int64 `json:"operator_id"` // 操作者 QQ 号 }
群成员增加通知
func (*GroupIncreaseNoticeEvent) GetSessionId ¶
func (e *GroupIncreaseNoticeEvent) GetSessionId() string
func (*GroupIncreaseNoticeEvent) GetSubType ¶
func (e *GroupIncreaseNoticeEvent) GetSubType() string
type GroupMemberInfo ¶
type GroupMessageEvent ¶
type GroupMessageEvent struct { MessageEvent GroupId int64 `json:"group_id"` // 群号 Sender *GroupMessageEventSender `json:"sender"` // 发送人信息 Anonymous *Anonymous `json:"anonymous"` }
func (*GroupMessageEvent) GetEventDescription ¶
func (e *GroupMessageEvent) GetEventDescription() string
func (*GroupMessageEvent) GetSessionId ¶
func (e *GroupMessageEvent) GetSessionId() string
type GroupMessageEventSender ¶
type GroupRecallNoticeEvent ¶
type GroupRecallNoticeEvent struct { NoticeEvent GroupId int64 `json:"group_id"` // 群号 UserId int64 `json:"user_id"` // 撤回者 QQ 号 OperatorId int64 `json:"operator_id"` // 操作者 QQ 号 MessageId int64 `json:"message_id"` // 消息 ID }
群消息撤回通知
func (*GroupRecallNoticeEvent) GetSessionId ¶
func (e *GroupRecallNoticeEvent) GetSessionId() string
type GroupRequestEvent ¶
type GroupRequestEvent struct { Event RequestType string `json:"request_type"` // 请求类型,group SubType string `json:"sub_type"` // 请求子类型,add、invite,分别表示加群请求、邀请登录号入群 GroupId int64 `json:"group_id"` // 群号 UserId int64 `json:"user_id"` // 发送请求的QQ号 Comment string `json:"comment"` // 验证消息 Flag string `json:"flag"` // 请求请求 flag,在调用处理请求的 API 时需要传入标识 }
加群请求事件
func (*GroupRequestEvent) GetSecondType ¶
func (e *GroupRequestEvent) GetSecondType() string
func (*GroupRequestEvent) GetSessionId ¶
func (e *GroupRequestEvent) GetSessionId() string
func (*GroupRequestEvent) GetSubType ¶
func (e *GroupRequestEvent) GetSubType() string
type GroupUploadNoticeEvent ¶
type GroupUploadNoticeEvent struct { NoticeEvent GroupId int64 `json:"group_id"` // 群号 UserId int64 `json:"user_id"` // 上传者的QQ号 File struct { Id string `json:"id"` // 文件 ID Name string `json:"name"` // 文件名 Size int64 `json:"size"` // 文件大小 BusId string `json:"bus_id"` // 文件公众号 ID } `json:"file"` }
群文件上传通知
func (*GroupUploadNoticeEvent) GetSessionId ¶
func (e *GroupUploadNoticeEvent) GetSessionId() string
type Handler ¶
type Handler struct {
// contains filtered or unexported fields
}
func (*Handler) NewHandler ¶
新建一个Handler,用于处理指定类型的事件
type HandlerFunc ¶
type HandlerFunc func(*Context)
type HeartbeatMetaEvent ¶
type HeartbeatMetaEvent struct { Event MetaEventType string `json:"meta_event_type"` // 元事件类型,heartbeat Status struct { Online bool `json:"online"` // 在线状态 Good bool `json:"good"` // 同online } `json:"status"` Interval int64 `json:"interval"` // 元事件心跳间隔,单位ms }
func (*HeartbeatMetaEvent) GetSecondType ¶
func (e *HeartbeatMetaEvent) GetSecondType() string
type HonorListItem ¶
type HonorNoticeEvent ¶
type HonorNoticeEvent struct { NoticeEvent SubType string `json:"sub_type"` // 通知子类型,honor GroupId int64 `json:"group_id"` // 群号 UserId int64 `json:"user_id"` // QQ 号 HonorType string `json:"honor_type"` // 荣誉类型,talkative、performer、emotion,分别表示龙王、群聊之火、快乐源泉 }
群成员荣誉变更
func (*HonorNoticeEvent) GetSessionId ¶
func (e *HonorNoticeEvent) GetSessionId() string
func (*HonorNoticeEvent) GetSubType ¶
func (e *HonorNoticeEvent) GetSubType() string
type I_Event ¶
type I_Event interface { GetPostType() string // 获取事件的上报类型,有message, notice, request, meta_event GetSecondType() string // 获取事件的第二级类型。 GetSubType() string // 获取第三级类型。部分事件没有这个字段,则返回空字符串 GetEventName() EventName // 获取事件的名称,即完整类型。形如:notice.group.set GetEventDescription() string // 获取事件的描述,一般用于日志输出 IsMessageEvent() bool IsToMe() bool GetSessionId() string // 获取事件的会话ID,用于区分不同的会话。私聊为"QQ号",群聊中对应"QQ号@群号"。 GetMessage() *Message // 提取消息。非消息事件返回nil ExtractPlainText() string // 提取消息的纯文本。非消息事件返回空字符串 }
func ConvertJsonObjectToEvent ¶ added in v0.2.1
从JSON对象中生成Event对象(指针)
type LifeCycleMetaEvent ¶
type LifeCycleMetaEvent struct { Event MetaEventType string `json:"meta_event_type"` // 元事件类型,lifecycle SubType string `json:"sub_type"` // 元事件子类型,enable、disable、connect }
func (*LifeCycleMetaEvent) GetSecondType ¶
func (e *LifeCycleMetaEvent) GetSecondType() string
func (*LifeCycleMetaEvent) GetSubType ¶
func (e *LifeCycleMetaEvent) GetSubType() string
type LuckyKingNoticeEvent ¶
type LuckyKingNoticeEvent struct { NoticeEvent SubType string `json:"sub_type"` // 通知子类型,lucky_king GroupId int64 `json:"group_id"` // 群号 UserId int64 `json:"user_id"` // 发红包者的 QQ 号 TargetId int64 `json:"target_id"` // 运气王的 QQ 号 }
运气王通知
func (*LuckyKingNoticeEvent) GetSessionId ¶
func (e *LuckyKingNoticeEvent) GetSessionId() string
func (*LuckyKingNoticeEvent) GetSubType ¶
func (e *LuckyKingNoticeEvent) GetSubType() string
type Message ¶
type Message []MessageSegment
func ConvertJsonArrayToMessage ¶ added in v0.2.1
func MsgMustPrintf ¶
作用同MsgPrintf,参数过多过少时会panic
func MsgPrint ¶
func MsgPrint(msgs ...interface{}) (msg Message)
将这些参数转换成一个Message
参数类型限制为string、(*)Message、MessageSegment、[]MessageSegment, 非上述类型的参数将被转换成一个Text消息段
func MsgPrintf ¶
根据模板和参数生成消息对象。参数过多过少都会返回error。
使用"{}"作为消息段的占位符。例如:
Format("{}你好啊%s", At(114514), "李田所") // 返回:[{at:114514},{text:"你好啊李田所"}]
如想"{}"不被解析为占位符,则使用"{{}}"。例如:
Format("{{}}你好啊%s", "李田所") // 返回:[{text:"{}你好啊李田所"}]
func (*Message) Append ¶
func (m *Message) Append(t t_StringOrSegment)
添加一个消息段(或字符串)到消息数组末尾。泛型版本的AppendXXXX
func (*Message) ExtendSegmentArray ¶
func (m *Message) ExtendSegmentArray(segs []MessageSegment)
拼接多个消息段到消息数组末尾
func (Message) FilterByType ¶
func (m Message) FilterByType(segmentType string) []MessageSegment
type MessageEvent ¶
type MessageEvent struct { Event MessageType string `json:"message_type"` // 消息类型,group, private SubType string `json:"sub_type"` // 消息子类型,friend, group, other | normal, anonymous, notice MessageId int32 `json:"message_id"` // 消息ID UserId int64 `json:"user_id"` // 消息发送者的QQ号 Message Message `json:"message"` // 消息内容 RawMessage string `json:"raw_message"` // 原始消息内容 Font int32 `json:"font"` // 字体 }
func (*MessageEvent) ExtractPlainText ¶
func (e *MessageEvent) ExtractPlainText() string
func (*MessageEvent) GetMessage ¶
func (e *MessageEvent) GetMessage() *Message
func (*MessageEvent) GetSecondType ¶
func (e *MessageEvent) GetSecondType() string
func (*MessageEvent) GetSessionId ¶
func (e *MessageEvent) GetSessionId() string
func (*MessageEvent) GetSubType ¶
func (e *MessageEvent) GetSubType() string
func (*MessageEvent) IsToMe ¶
func (e *MessageEvent) IsToMe() bool
type MessageEventSender ¶
type MessageSegment ¶
type MessageSegment struct { Type string `json:"type"` Data msgSegData `json:"data"` }
func (*MessageSegment) IsText ¶
func (seg *MessageSegment) IsText() bool
func (MessageSegment) String ¶
func (seg MessageSegment) String() string
type Middleware ¶ added in v0.1.4
func FromSession ¶
func FromSession(sessionId string) Middleware
func OnEvent ¶
func OnEvent(eventName EventName) Middleware
func ShellLikeCommand ¶ added in v0.2.0
func ShellLikeCommand(cmd string, args interface{}, whenFailed ParseFailedAction) Middleware
命令行命令。
cmd为命令名,会受命令前缀影响,例如:命令前缀为"!",命令为"test",则为"!test"。
args为命令参数,传入结构体,**注意,不会向该结构体写入数据**。 用法见https://github.com/alexflint/go-arg。
whenFailed为解析失败时的处理方式,推荐使用ParseFailedAction_AutoReply
type NoticeEvent ¶
func (*NoticeEvent) GetSecondType ¶
func (e *NoticeEvent) GetSecondType() string
type OfflineFileNoticeEvent ¶
type OfflineFileNoticeEvent struct { NoticeEvent UserId int64 `json:"user_id"` // 用户 ID File struct { Name string `json:"name"` // 文件名 Size int64 `json:"size"` // 文件大小 Url string `json:"url"` // 下载链接 } `json:"file"` }
接收到离线文件
type ParseFailedAction ¶ added in v0.2.0
type ParseFailedAction int
ShellLikeCommand解析错误时要采取的动作
const ( // 无法解析时,自动回复错误信息 ParseFailedAction_AutoReply ParseFailedAction = iota // 无法解析时,跳过这个Handler ParseFailedAction_Skip // 无法解析时,允许进入这个Handler,交由用户处理 ParseFailedAction_LetMeHandle )
type Plugin ¶
type Plugin interface { Init(hub *PluginHub) // 初始化插件 GetPluginInfo() PluginInfo }
type PluginConfigMap ¶ added in v0.1.4
type PluginConfigMap map[string]interface{} // 插件配置
type PluginHookCallback ¶ added in v0.2.0
type PluginHookCallback func(*PluginHub)
type PluginHub ¶ added in v0.2.0
type PluginHub struct {
// contains filtered or unexported fields
}
插件的所有Handler都挂载在这上面
func (*PluginHub) GetEngineConfig ¶ added in v0.2.0
func (p *PluginHub) GetEngineConfig() *BaseConfig
func (*PluginHub) GetPluginConfig ¶ added in v0.2.0
func (*PluginHub) GetPluginId ¶ added in v0.2.0
func (*PluginHub) NewHandler ¶ added in v0.2.0
新建一个Handler,用于处理指定类型的事件,不写则处理所有类型的事件
func (*PluginHub) Use ¶ added in v0.2.0
func (p *PluginHub) Use(middlewares ...Middleware)
type PluginInfo ¶
插件信息,其中Name和Author共同唯一标识一个插件
type PokeNoticeEvent ¶
type PokeNoticeEvent struct { NoticeEvent SubType string `json:"sub_type"` // 通知子类型,poke GroupId int64 `json:"group_id"` // 群号 UserId int64 `json:"user_id"` // 发送戳一戳的 QQ 号 TargetId int64 `json:"target_id"` // 被戳一戳的 QQ 号 }
戳一戳通知
func (*PokeNoticeEvent) GetSessionId ¶
func (e *PokeNoticeEvent) GetSessionId() string
func (*PokeNoticeEvent) GetSubType ¶
func (e *PokeNoticeEvent) GetSubType() string
type PrivateMessageEvent ¶
type PrivateMessageEvent struct { MessageEvent Sender *MessageEventSender `json:"sender"` // 发送人信息 }
func (*PrivateMessageEvent) GetEventDescription ¶
func (e *PrivateMessageEvent) GetEventDescription() string
type ProviderConfigMap ¶ added in v0.2.1
type ProviderConfigMap map[string]interface{} // 服务提供者配置
func (ProviderConfigMap) DecodeTo ¶ added in v0.2.1
func (mp ProviderConfigMap) DecodeTo(v interface{}) error