gonebot

package module
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Feb 9, 2023 License: MIT Imports: 21 Imported by: 0

README

Under development

接口不稳定,随时变化,也许还有潜在BUG

QQ机器人框架

基于Onebot 11标准实现的Bot开发框架,致力于提供简单易用的API。

具体实践可以看这里KaguyaGo

写这玩意的原因是Nonebot占用的内存太大了,服务器吃不消。

文档

文档正在编写。

如果你发现文档里面的例子用不了,也许可能是我写了新代码并且改了文档,但又没有发布新版本。

TODO

  • Mock
  • 键值数据库存储
  • 插件管理页面(这玩意应该会下放到KaguyaGo作为插件实现,总之画个饼)

Documentation

Index

Constants

View Source
const (
	PostType_MetaEvent    = "meta_event"
	PostType_MessageEvent = "message"
	PostType_NoticeEvent  = "notice"
	PostType_RequestEvent = "request"
)
View Source
const (
	MusicType_QQ    = "qq"  // QQ 音乐
	MusicType_163   = "163" // 网易云音乐
	MusicType_XiaMi = "xm"  // 虾米音乐
)

Variables

View Source
var (
	ErrInvalidMessageType = errors.New("不正确的message type")
	ErrMissingAnonymous   = errors.New("缺少anonymous对象")
)
View Source
var GlobalHooks globalHookManager = globalHookManager{
	// contains filtered or unexported fields
}

全局钩子,不隶属于特定的Engine实例。Engine的生命周期钩子也会在这里触发

View Source
var MsgFactory = messageSegmentFactory{}

Functions

func Escape

func Escape(s string, escapeComma bool) (res string)

转义CQ码

func GetPluginConfig added in v0.1.4

func GetPluginConfig(plugin Plugin) interface{}

获取插件配置

func LoadCustomConfig

func LoadCustomConfig(path string, cfgPtr Config)

载入自定义配置文件,文件为YAML。自定义配置的结构体必须继承BaseConfig

func RegisterPlugin added in v0.1.4

func RegisterPlugin(plugin Plugin, pluginConfig interface{})

注册插件。插件配置结构体pluginConfig可选,使用反射映射到字段,无则传nil

func RegisterProvider added in v0.2.1

func RegisterProvider(name string, provider Provider)

注册一个Provider

func Unescape

func Unescape(s string) (res string)

反转义CQ码

Types

type Anonymous

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

type ApiParams

type ApiParams map[string]interface{}

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 LoadConfig

func LoadConfig(path string) *BaseConfig

载入配置文件

func (*BaseConfig) GetBaseConfig

func (cfg *BaseConfig) GetBaseConfig() *BaseConfig

type Bot

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

func (*Bot) CallApi

func (bot *Bot) CallApi(action string, params ApiParams) (*gjson.Result, error)

func (*Bot) CanSendImage

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

检查是否可以发送图片

func (*Bot) CanSendRecord

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

检查是否可以发送语音

func (*Bot) ClearCache

func (bot *Bot) ClearCache() error

清理缓存

func (*Bot) DeleteMsg

func (bot *Bot) DeleteMsg(messageId int32) error

撤回消息

func (*Bot) GetCookies

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

获取 Cookies

func (*Bot) GetCredentials

func (bot *Bot) GetCredentials(domain string) (*QQCredential, error)

获取 QQ 相关接口凭证

func (*Bot) GetCsrfToken

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

获取 CSRF Token

func (*Bot) GetForwardMsg

func (bot *Bot) GetForwardMsg(messageId int32) (*Message, error)

获取合并转发消息

func (*Bot) GetFriendList

func (bot *Bot) GetFriendList() (*[]FriendInfo, error)

获取好友列表

func (*Bot) GetGroupHonorInfo

func (bot *Bot) GetGroupHonorInfo(groupId int64, type_ string) (*GroupHonorInfo, error)

获取群荣誉信息

func (*Bot) GetGroupInfo

func (bot *Bot) GetGroupInfo(groupId int64) (*GroupInfo, error)

获取群信息

func (*Bot) GetGroupList

func (bot *Bot) GetGroupList() (*[]GroupInfo, 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) GetImage

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

获取图片

func (*Bot) GetLoginInfo

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

获取登录号信息

func (*Bot) GetMsg

func (bot *Bot) GetMsg(messageId int32) (*ApiResponse_GetMsg, error)

获取消息

func (*Bot) GetRecord

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

获取语音

func (*Bot) GetSelfId

func (bot *Bot) GetSelfId() int64

func (*Bot) GetStatus

func (bot *Bot) GetStatus() (*Status, error)

获取运行状态

func (*Bot) GetStrangerInfo

func (bot *Bot) GetStrangerInfo(userId int64) (*StrangerInfo, error)

获取陌生人信息

func (*Bot) GetVersionInfo

func (bot *Bot) GetVersionInfo() (*VesionInfo, error)

获取版本信息

func (*Bot) Init

func (bot *Bot) Init(provider Provider)

func (*Bot) SendGroupMsg

func (bot *Bot) SendGroupMsg(groupId int64, message Message, autoEscape bool) (int32, error)

发送群消息

func (*Bot) SendLike

func (bot *Bot) SendLike(userId int64, times int) error

发送好友赞

func (*Bot) SendMsg

func (bot *Bot) SendMsg(messageType string, userId, groupId int64, message Message, autoEscape bool) (int32, error)

发送消息

func (*Bot) SendPrivateMsg

func (bot *Bot) SendPrivateMsg(userId int64, message Message, autoEscape bool) (int32, error)

发送私聊消息

func (*Bot) SetFriendAddRequest

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

处理加好友请求

func (*Bot) SetGroupAddRequest

func (bot *Bot) SetGroupAddRequest(flag string, subType int, approve bool, reason string) error

处理加群请求/邀请

func (*Bot) SetGroupAdmin

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

群组设置管理员

func (*Bot) SetGroupAnonymous

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

群组开关匿名

func (*Bot) SetGroupAnonymousBan

func (bot *Bot) SetGroupAnonymousBan(groupId int64, anonymous *Anonymous, anonymousFlag string, duration int) error

群组匿名用户禁言

func (*Bot) SetGroupBan

func (bot *Bot) SetGroupBan(groupId int64, userId int64, duration int) error

群组单人禁言

func (*Bot) SetGroupCard

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

设置群名片(群备注)

func (*Bot) SetGroupDismiss

func (bot *Bot) SetGroupDismiss(groupId int64) error

解散群组

func (*Bot) SetGroupKick

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

群组踢人

func (*Bot) SetGroupLeave

func (bot *Bot) SetGroupLeave(groupId int64) error

退出群组

func (*Bot) SetGroupName

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

设置群名

func (*Bot) SetGroupSpecialTitle

func (bot *Bot) SetGroupSpecialTitle(groupId int64, userId int64, specialTitle string, duration int) error

设置群组专属头衔

func (*Bot) SetGroupWholeBan

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

群组全员禁言

func (*Bot) SetRestart

func (bot *Bot) SetRestart(delay int) error

重启 OneBot 实现

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) Abort added in v0.1.4

func (a *Context) Abort()

func (*Context) ApproveFriendRequest

func (ctx *Context) ApproveFriendRequest() (err error)

同意加好友请求

func (*Context) ApproveGroupRequest

func (ctx *Context) ApproveGroupRequest() (err error)

同意加群请求、或被邀请入群请求

func (*Context) AtSender added in v0.2.0

func (ctx *Context) AtSender(b bool) *Context

func (*Context) Ban

func (ctx *Context) Ban(duration int) (err error)

禁言

func (*Context) Delete

func (ctx *Context) Delete() (err error)

撤回事件对应的消息

func (*Context) Get

func (ctx *Context) Get(key string) (v interface{}, exist bool)

func (*Context) GetCommandMatchResult added in v0.2.0

func (ctx *Context) GetCommandMatchResult() *commandMatchResult

获取Command的匹配结果

func (*Context) GetInt

func (ctx *Context) GetInt(key string) (i int)

func (*Context) GetInt64

func (ctx *Context) GetInt64(key string) (i64 int64)

func (*Context) GetKeywordMatchResult added in v0.2.0

func (ctx *Context) GetKeywordMatchResult() string

获取Keyword的匹配结果

func (*Context) GetMap

func (ctx *Context) GetMap(key string) (m map[string]interface{})

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) GetSlice

func (ctx *Context) GetSlice(key string) (s []interface{})

func (*Context) GetString

func (ctx *Context) GetString(key string) (s string)

func (*Context) GetSuffixMatchResult added in v0.2.0

func (ctx *Context) GetSuffixMatchResult() *suffixMatchResult

获取EndsWith的匹配结果

func (*Context) Kick

func (ctx *Context) Kick() (err error)

踢出群聊

func (*Context) MustGet

func (ctx *Context) MustGet(key string) interface{}

func (*Context) Next added in v0.1.4

func (a *Context) Next() bool

继续后续执行(后续执行完毕后才返回),返回值代表是否事件被Handler处理过

func (*Context) Prompt

func (ctx *Context) Prompt(message Message, timeout int) *Message

发送提示消息,并获取它的回复(同一Session)。

func (*Context) RejectFriendRequest

func (ctx *Context) RejectFriendRequest() (err error)

拒绝加好友请求

func (*Context) RejectGroupRequest

func (ctx *Context) RejectGroupRequest(reason string) (err error)

拒绝加群请求、或被邀请入群请求

func (*Context) Reply

func (ctx *Context) Reply(args ...interface{}) (err error)

回复

func (*Context) ReplyMsg

func (ctx *Context) ReplyMsg(msg Message) (err error)

使用Message对象回复

func (*Context) ReplyRaw

func (ctx *Context) ReplyRaw(msg Message) (err error)

回复,并对消息存在的CQ码进行转义

func (*Context) ReplyText

func (ctx *Context) ReplyText(text string) (err error)

文字回复

func (*Context) Replyf

func (ctx *Context) Replyf(tmpl string, args ...interface{}) (err error)

回复

func (*Context) Set

func (ctx *Context) Set(key string, value interface{})

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 CurrentTalkative struct {
	UserId   int64
	Nickname string
	Avatar   string
	DayCount int
}

type Engine

type Engine struct {
	Handler
	Config Config

	Hooks engineHookManager
	// contains filtered or unexported fields
}

func NewEngine

func NewEngine(cfg Config) *Engine

func NewEngineWithProvider added in v0.2.1

func NewEngineWithProvider(cfg Config, provider Provider) *Engine

直接指定Provider,忽略配置文件

func (*Engine) Run

func (engine *Engine) Run()

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 (e *Event) ExtractPlainText() string

func (*Event) GetEventDescription

func (e *Event) GetEventDescription() string

获取事件的描述,一般用于日志输出

func (*Event) GetEventName

func (e *Event) GetEventName() EventName

获取事件的名称,形如:notice.group.set

func (*Event) GetMessage

func (e *Event) GetMessage() *Message

func (*Event) GetPostType

func (e *Event) GetPostType() string

获取事件的上报类型,有message, notice, request, meta_event

func (*Event) GetSecondType

func (e *Event) GetSecondType() string

func (*Event) GetSessionId

func (e *Event) GetSessionId() string

func (*Event) GetSubType

func (e *Event) GetSubType() string

func (*Event) IsMessageEvent

func (e *Event) IsMessageEvent() bool

func (*Event) IsToMe

func (e *Event) IsToMe() bool

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 FriendInfo struct {
	UserId   int64
	Nickname string
	Remark   string
}

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 GroupInfo

type GroupInfo struct {
	GroupId        int64
	GroupName      string
	MemberCount    int
	MaxMemberCount int
}

type GroupMemberInfo

type GroupMemberInfo struct {
	GroupId         int64
	UserId          int64
	Nickname        string
	Card            string
	Sex             string
	Age             int
	Area            string
	JoinTime        int
	LastSentTime    int
	Level           string
	Role            string
	Unfriendly      bool
	Title           string
	TitleExpireTime int
	CardChangeable  bool
}

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 GroupMessageEventSender struct {
	MessageEventSender
	Card  string `json:"card"`  // 群名片/备注
	Area  string `json:"area"`  // 地区
	Level string `json:"level"` // 成员等级
	Role  string `json:"role"`  // 角色,owner 或 admin 或 member
	Title string `json:"title"` // 专属头衔
}

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) Handle

func (h *Handler) Handle(f HandlerFunc)

指定事件处理函数

func (*Handler) NewHandler

func (h *Handler) NewHandler(eventTypes ...EventName) (handler *Handler)

新建一个Handler,用于处理指定类型的事件

func (*Handler) NewRemovableHandler

func (h *Handler) NewRemovableHandler(eventTypes ...EventName) (handler *Handler, remove func())

新建一个可以被删除的Handler,用于处理指定类型的事件。

调用remove方法可以删除当前Handler。

func (*Handler) Use

func (h *Handler) Use(middlewares ...Middleware) *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 HonorListItem struct {
	UserId      int64
	Nickname    string
	Avatar      string
	Description string
}

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

func ConvertJsonObjectToEvent(obj gjson.Result) I_Event

从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 LoginInfo

type LoginInfo struct {
	UserId   int64
	Nickname 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 ConvertJsonArrayToMessage(m []gjson.Result) (msg Message)

func MsgMustPrintf

func MsgMustPrintf(tmpl string, args ...interface{}) (msg Message)

作用同MsgPrintf,参数过多过少时会panic

func MsgPrint

func MsgPrint(msgs ...interface{}) (msg Message)

将这些参数转换成一个Message

参数类型限制为string、(*)Message、MessageSegment、[]MessageSegment, 非上述类型的参数将被转换成一个Text消息段

func MsgPrintf

func MsgPrintf(tmpl string, args ...interface{}) (msg Message, err error)

根据模板和参数生成消息对象。参数过多过少都会返回error。

使用"{}"作为消息段的占位符。例如:

Format("{}你好啊%s", At(114514), "李田所")
// 返回:[{at:114514},{text:"你好啊李田所"}]

如想"{}"不被解析为占位符,则使用"{{}}"。例如:

Format("{{}}你好啊%s", "李田所")
// 返回:[{text:"{}你好啊李田所"}]

func (*Message) Append

func (m *Message) Append(t t_StringOrSegment)

添加一个消息段(或字符串)到消息数组末尾。泛型版本的AppendXXXX

func (*Message) AppendSegment

func (m *Message) AppendSegment(seg MessageSegment)

添加一个消息段到消息数组末尾

func (*Message) AppendText

func (m *Message) AppendText(t string)

添加一个字符串到消息数组末尾

func (*Message) Extend

func (m *Message) Extend(msg t_MessageOrSegmentArray) (err error)

拼接一个消息数组或多个消息段到消息数组末尾。泛型版本的ExtendXXXX

func (*Message) ExtendMessage

func (m *Message) ExtendMessage(msg Message)

拼接一个消息数组到消息数组末尾

func (*Message) ExtendSegmentArray

func (m *Message) ExtendSegmentArray(segs []MessageSegment)

拼接多个消息段到消息数组末尾

func (Message) ExtractPlainText

func (m Message) ExtractPlainText() (text string)

提取消息内纯文本消息

func (Message) FilterByType

func (m Message) FilterByType(segmentType string) []MessageSegment

func (Message) Len

func (m Message) Len() int

func (Message) String

func (m Message) String() string

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 MessageEventSender struct {
	UserId   int64  `json:"user_id"`  // 消息发送者的QQ号
	Nickname string `json:"nickname"` // 消息发送者的昵称
	Sex      string `json:"sex"`      // 性别,male 或 female 或 unknown
	Age      int32  `json:"age"`
}

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

type Middleware func(*Context) bool

func Command

func Command(cmd ...string) Middleware

事件为MessageEvent,且消息开头为指令

func EndsWith

func EndsWith(suffix ...string) Middleware

事件为MessageEvent,且消息以某个后缀结尾

func FromAdmin added in v0.2.0

func FromAdmin() Middleware

仅群组管理员

func FromAdminOrHigher added in v0.2.0

func FromAdminOrHigher() Middleware

群组管理员及更高权限,包括群主、超管

func FromGroup

func FromGroup(groupIds ...int64) Middleware

限制来自某些群聊,当参数为空时,表示全部群聊都可

func FromOwner added in v0.2.0

func FromOwner() Middleware

仅群组群主

func FromOwnerOrHigher added in v0.2.0

func FromOwnerOrHigher() Middleware

群组群主及更高权限,包括超管

func FromPrivate

func FromPrivate(userIds ...int64) Middleware

限制来自某些人的私聊,当参数为空时,表示只要是私聊都可

func FromSession

func FromSession(sessionId string) Middleware

func FromSuperuser added in v0.2.0

func FromSuperuser() Middleware

仅超管,群聊和私聊都可

func FromUser

func FromUser(userIds ...int64) Middleware

消息来源于某些人,必须传入至少一个参数

func FullMatch

func FullMatch(text ...string) Middleware

完全匹配

func Keyword

func Keyword(keywords ...string) Middleware

事件为MessageEvent,且消息中包含其中某个关键词

func OnEvent

func OnEvent(eventName EventName) Middleware

func OnlyToMe

func OnlyToMe() Middleware

与Bot相关

func Regex

func Regex(regex regexp.Regexp) Middleware

事件为MessageEvent,且消息中存在子串满足正则表达式

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

func StartsWith

func StartsWith(prefix ...string) Middleware

事件为MessageEvent,且消息以某个前缀开头

type NoticeEvent

type NoticeEvent struct {
	Event
	NoticeType string `json:"notice_type"` // 通知类型,group, private
}

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) GetBot added in v0.2.0

func (p *PluginHub) GetBot() *Bot

func (*PluginHub) GetEngineConfig added in v0.2.0

func (p *PluginHub) GetEngineConfig() *BaseConfig

func (*PluginHub) GetPluginConfig added in v0.2.0

func (p *PluginHub) GetPluginConfig(plugin Plugin) interface{}

func (*PluginHub) GetPluginId added in v0.2.0

func (p *PluginHub) GetPluginId() string

func (*PluginHub) NewHandler added in v0.2.0

func (p *PluginHub) NewHandler(eventTypes ...EventName) *Handler

新建一个Handler,用于处理指定类型的事件,不写则处理所有类型的事件

func (*PluginHub) Use added in v0.2.0

func (p *PluginHub) Use(middlewares ...Middleware)

type PluginInfo

type PluginInfo struct {
	Name        string
	Author      string
	Version     string
	Description string
}

插件信息,其中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 Provider added in v0.2.1

type Provider interface {
	Init(cfg Config)
	Start()
	Stop()
	// 发送API请求。
	// 参数:route为API路径;data为请求数据。
	// 返回值:API返回值,可为map、struct、数组,总之是合法的json格式;error为错误信息。
	Request(route string, data interface{}) (interface{}, error)
	RecieveEvent(chan<- I_Event)
	OnEventHandled(I_Event)
}

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

type QQCredential

type QQCredential struct {
	Cookies   string
	CsrfToken int32
}

type Status

type Status struct {
	Online bool
	Good   bool
}

type StrangerInfo

type StrangerInfo struct {
	UserId   int64
	Nickname string
	Sex      string
	Age      int32
}

type VesionInfo

type VesionInfo struct {
	AppName         string
	AppVersion      string
	ProtocolVersion string
}

Directories

Path Synopsis
providers

Jump to

Keyboard shortcuts

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