Documentation
¶
Index ¶
- Constants
- Variables
- func BanPluginByID(id string)
- func BanPluginByName(name string) int
- func CallApi(ctx *gin.Context)
- func GetConfig(ctx *gin.Context)
- func GetFriendList(ctx *gin.Context)
- func GetGroupList(ctx *gin.Context)
- func GetHandleList() map[string][]BaseHandle
- func GetLogLevel(level string) log.Level
- func InitBots()
- func InitPluginManager()
- func InitWindow()
- func LoadConfig()
- func LoadDriver(driver2 Driver)
- func OnCommand(command string) *commandHandle
- func OnConnect() *connectHandle
- func OnDisConnect() *disConnectHandle
- func OnEndWith(str string) *messageHandle
- func OnKeyWords(keyword string) *messageHandle
- func OnMessage(messageType string) *messageHandle
- func OnMeta() *metaHandle
- func OnNotice(noticeType string) *noticeHandle
- func OnRegex(regex string) *commandHandle
- func OnRequest(requestType string) *requestHandle
- func OnStartWith(str string) *messageHandle
- func OnTime(crons string, selfId int, handle func(bot Api))
- func OnlyGroupMessage(event Event, _ Api) bool
- func OnlySuperUser(event Event, _ Api, _ *State) bool
- func OnlyToMe(event Event, _ Api, state *State) bool
- func OpenUi()
- func StartPlugin(name string) int
- func StartPluginByID(id string)
- type Api
- type BaseHandle
- type CommandChain
- type CommandInt
- type Config
- type Conn
- type Connect
- type ConnectChain
- type ConnectInt
- type DisConnectChain
- type DisConnectInt
- type Driver
- type Event
- func (e Event) CloseMessageChan(id int)
- func (e Event) GetImages() []message.MessageSegment
- func (e Event) GetMoreEvent(rules ...Rule) (int, chan Event)
- func (e Event) GetMsg() message.Message
- func (e Event) GetOneEvent(rules ...Rule) (Event, error)
- func (e Event) GetPlainText() string
- func (e Event) Send(message interface{}) int32
- type Files
- type M
- type MessageChain
- type MessageIds
- type MessageInt
- type MetaChain
- type MetaInt
- type NoticeChain
- type NoticeInt
- type Options
- type Plugin
- func (p *Plugin) OnCommand(command string) *commandHandle
- func (p *Plugin) OnConnect() *connectHandle
- func (p *Plugin) OnDisConnect() *disConnectHandle
- func (p *Plugin) OnEndWith(str string) *messageHandle
- func (p *Plugin) OnKeyWords(keyword string) *messageHandle
- func (p *Plugin) OnMessage(messageType string) *messageHandle
- func (p *Plugin) OnMeta() *metaHandle
- func (p *Plugin) OnNotice(noticeType string) *noticeHandle
- func (p *Plugin) OnPretreatment() *PretreatmentHandle
- func (p *Plugin) OnRegex(regex string) *commandHandle
- func (p *Plugin) OnRequest(requestType string) *requestHandle
- func (p *Plugin) OnStartWith(str string) *messageHandle
- func (p *Plugin) OnTime(crons string, selfId int, handle func(bot Api))
- func (p *Plugin) SetHelp(help map[string]string)
- type PretreatmentChain
- type PretreatmentHandle
- type PretreatmentInt
- type RequestChain
- type RequestInt
- type Rule
- type Senders
- type State
- type Status
Constants ¶
const ( JSON = "json" HJSON = "hjson" YAML = "yaml" )
Variables ¶
var ( ConnectHandles ConnectChain DisConnectHandles DisConnectChain MessageHandles MessageChain RequestHandles RequestChain NoticeHandles NoticeChain CommandHandles CommandChain MetaHandles MetaChain PretreatmentHandles PretreatmentChain )
var (
DefaultConfig = new(Config)
)
var ENABLE = true // 是否启用gui
var (
MessageChan = make(chan Event, 10)
)
Functions ¶
func BanPluginByID ¶
func BanPluginByID(id string)
BanPluginByID * * @Description: 根据id禁用插件 * @param id
func BanPluginByName ¶
BanPluginByName * * @Description: 禁用某个插件 * @param name 插件名 * @return int 禁用的插件个数
func GetFriendList ¶
func GetGroupList ¶
func GetHandleList ¶
func GetHandleList() map[string][]BaseHandle
func InitPluginManager ¶
func InitPluginManager()
func InitWindow ¶
func InitWindow()
func LoadConfig ¶
func LoadConfig()
func LoadDriver ¶ added in v1.1.2
func LoadDriver(driver2 Driver)
LoadDriver *
- @Description: 为leafBot注册一个驱动
- @param driver2 实现了Driver接口的驱动
- example
func OnCommand ¶
func OnCommand(command string) *commandHandle
OnCommand *
@Description: command触发handle
@param 该插件响应的命令
@return *commandHandle
example leafBot.OnCommand("天气"). SetPluginName("天气插件"). AddHandle( func(event LeafBot.Event,bot *leafBot.Bot,args []string){
})
func OnConnect ¶
func OnConnect() *connectHandle
OnConnect *
- @Description: 在bot进行连接使响应
- @return *connectHandle
- example
func OnDisConnect ¶
func OnDisConnect() *disConnectHandle
OnDisConnect *
- @Description: 在bot断开连接时进行响应
- @return *disConnectHandle
- example
func OnKeyWords ¶ added in v1.1.1
func OnKeyWords(keyword string) *messageHandle
func OnMessage ¶
func OnMessage(messageType string) *messageHandle
OnMessage *
- @Description: message事件触发handle
- @param messageType message事件的子类型
- @return *messageHandle
- example
func OnMeta ¶
func OnMeta() *metaHandle
OnMeta *
- @Description: 元事件触发handle
- @return *metaHandle
- example
func OnNotice ¶
func OnNotice(noticeType string) *noticeHandle
OnNotice *
@Description: notice触发handle
@param noticeType notice事件类型
@return *noticeHandle
example 响应戳一戳事件的示例 leafBot.OnNotice(leafBot.NoticeTypeApi.Notify). SetPluginName("poke"). AddRule( func(event leafBot.Event, bot *leafBot.Bot) bool { if event.SubType != "poke" || event.UserId == event.SelfId || int(event.TargetId) != event.SelfId { return false } return true }).SetWeight(10). AddHandle( func(event leafBot.Event, bot *leafBot.Bot) {
})
func OnRequest ¶
func OnRequest(requestType string) *requestHandle
OnRequest *
- @Description: request事件触发handle
- @param requestType request事件的子类型
- @return *requestHandle
- example
func OnStartWith ¶
func OnStartWith(str string) *messageHandle
func OnlyGroupMessage ¶
func OnlySuperUser ¶
OnlySuperUser *
- @Description: 加了该rule的插件只会对配置文件中配置的管理员用户进行响应
- @param event leafBot event
- @param bot bot实例对象
- @return bool 是否通过该rule验证
- example
func OnlyToMe ¶
OnlyToMe *
- @Description: 添加了该rule的插件需要在群里艾特或者私聊才会进行响应
- @param event leafBot event
- @param bot bot实例对象
- @return bool 返回是否验证通过该rule
- example
func StartPlugin ¶
StartPlugin * * @Description: 启用某个插件 * @param name 插件名 * @return int 启用插件个数
func StartPluginByID ¶
func StartPluginByID(id string)
Types ¶
type Api ¶
type Api interface {
SendGroupMsg(groupId int, message interface{}) int32
SendPrivateMsg(userId int, message interface{}) int32
DeleteMsg(messageId int32)
GetMsg(messageId int32) gjson.Result
SetGroupBan(groupId int, userId int, duration int)
SetGroupCard(groupId int, userId int, card string)
SendMsg(messageType string, userId int, groupId int, message interface{}) int32
SendLike(userId int, times int)
SetGroupKick(groupId int, userId int, rejectAddRequest bool)
SetGroupAnonymousBan(groupId int, flag string, duration int)
SetGroupWholeBan(groupId int, enable bool)
SetGroupAdmin(groupId int, UserId int, enable bool)
SetGroupAnonymous(groupId int, enable bool)
SetGroupName(groupId int, groupName string)
SetGroupLeave(groupId int, isDisMiss bool)
SetGroupSpecialTitle(groupId int, userId int, specialTitle string, duration int)
SetFriendAddRequest(flag string, approve bool, remark string)
SetGroupAddRequest(flag string, subType string, approve bool, reason string)
GetLoginInfo() gjson.Result
GetStrangerInfo(userId int, noCache bool) gjson.Result
GetFriendList() gjson.Result
GetGroupInfo(groupId int, noCache bool) gjson.Result
GetGroupList() gjson.Result
GetGroupMemberInfo(groupId int, UserId int, noCache bool) gjson.Result
GetGroupMemberList(groupId int) gjson.Result
GetGroupHonorInfo(groupId int, honorType string) gjson.Result
GetCookies(domain string) gjson.Result
GetCsrfToken() gjson.Result
GetCredentials(domain string) gjson.Result
GetRecord(file, outFormat string) gjson.Result
GetImage(file string) gjson.Result
CanSendImage() bool
CanSendRecord() bool
GetStatus() gjson.Result
SetRestart(delay int)
CleanCache()
DownloadFile(url string, threadCount int, headers []string) gjson.Result
GetGroupMsgHistory(messageSeq int64, groupId int) gjson.Result
GetOnlineClients(noCache bool) gjson.Result
GetVipInfoTest(UserId int) gjson.Result
SendGroupNotice(groupId int, content string)
ReloadEventFilter()
SetEssenceMsg(messageId int)
DeleteEssenceMsg(messageId int)
GetEssenceMsgList(groupId int)
CheckUrlSafely(url string) int
UploadGroupFile(groupId int, file string, name string, folder string)
SetGroupNameSpecial(groupId int, groupName string)
SetGroupPortrait(groupId int, file string, cache int)
GetMsgSpecial(messageId int) gjson.Result
GetForwardMsg(messageId int) gjson.Result
SendGroupForwardMsg(groupId int, messages interface{})
GetWordSlices(content string) gjson.Result
OcrImage(image string) gjson.Result
GetGroupSystemMsg() gjson.Result
GetGroupFileSystemInfo(groupId int) gjson.Result
GetGroupRootFiles(groupId int) gjson.Result
GetGroupFilesByFolder(groupId int, folderId string) gjson.Result
GetGroupFileUrl(groupId int, fileId string, busid int) gjson.Result
GetGroupAtAllRemain(groupId int) gjson.Result
CallApi(action string, params interface{}) interface{}
}
type BaseHandle ¶
type CommandChain ¶
type CommandChain []*commandHandle
func (CommandChain) Len ¶
func (c CommandChain) Len() int
func (CommandChain) Less ¶
func (c CommandChain) Less(i, j int) bool
func (CommandChain) Swap ¶
func (c CommandChain) Swap(i, j int)
type CommandInt ¶
type CommandInt interface {
SetPluginName(name string) *commandHandle
AddAllies(allies string) *commandHandle
AddRule(rule Rule) *commandHandle
SetWeight(weight int) *commandHandle
SetBlock(IsBlock bool) *commandHandle
AddHandle(func(event Event, bot Api, args []string))
SetCD(types string, long int) *commandHandle
}
type Config ¶
type Config struct {
NickName []string `json:"nick_name" yaml:"nick_name" hjson:"nick_name"`
Admin int `json:"admin" yaml:"admin" hjson:"admin"`
Host string `json:"host" yaml:"host" hjson:"host"`
Port int `json:"port" yaml:"port" hjson:"port"`
LogLevel string `json:"log_level" yaml:"log_level" hjson:"log_level"`
SuperUser []int `json:"super_user" yaml:"super_user" hjson:"super_user"`
CommandStart []string `json:"command_start" yaml:"command_start" hjson:"command_start"`
EnablePlaywright bool `json:"enable_playwright" yaml:"enable_playwright" hjson:"enable_playwright"`
Plugins struct {
FlashGroupID int `json:"flash_group_id" yaml:"flash_group_id" hjson:"flash_group_id"`
AlApiToken string `json:"al_api_token" yaml:"al_api_token" hjson:"al_api_token"`
EnableReplyTome bool `json:"enable_reply_tome" yaml:"enable_reply_tome" hjson:"enable_reply_tome"`
Welcome []struct {
GroupId int `json:"group_id" yaml:"group_id" hjson:"group_id"`
Message string `json:"message" yaml:"message" hjson:"message"`
} `json:"welcome" yaml:"welcome" hjson:"welcome"`
GithubToken string `json:"github_token" yaml:"github_token" hjson:"github_token"`
AutoPassFriendRequest []string `json:"auto_pass_friend_request" yaml:"auto_pass_friend_request" hjson:"auto_pass_friend_request"`
} `json:"plugins" yaml:"plugins" hjson:"plugins"`
Datas map[string]interface{} `json:"datas" yaml:"datas" hjson:"datas"`
}
type Conn ¶ added in v1.1.2
type Conn interface {
// Do
// @Description: 执行一个api
// @param interface{}
//
Do(interface{})
// GetResponse
// @Description: 获取一次api的执行结果
// @param echo 标识一次执行的唯一参数
// @return []byte 响应结果
// @return error 超时会返回一个error
//
GetResponse(echo string) ([]byte, error)
GetSelfId() int64
}
Conn @Description: 所有bot对象都应该实现该接口
type ConnectChain ¶
type ConnectChain []*connectHandle
type ConnectInt ¶
type DisConnectChain ¶
type DisConnectChain []*disConnectHandle
type DisConnectInt ¶
type Driver ¶ added in v1.1.2
type Driver interface {
// Run
// @Description: 运行该驱动的接口,该接口应该为阻塞式运行
//
Run()
// GetEvent
// @Description: 返回一个chan,该chan为事件传递的chan
// @return chan
//
GetEvent() chan []byte
// AddContentHandle
// @Description: 为驱动注册链接事件
//
AddContentHandle()
// GetBot
// @Description: 获取一个实现了APi接口的bot
// @param int64 bot的id
// @return interface{}
//
GetBot(int64) interface{}
// GetBots
// @Description: 获取所有bot
// @return map[int64]interface{}
//
GetBots() map[int64]interface{}
// SetAddress
// @Description: 设置driver的运行地址
// @param string2
//
SetAddress(string2 string)
}
Driver @Description: 实现了该接口即可注册为leafBot的driver
type Event ¶
type Event struct {
Anonymous anonymous `json:"anonymous"`
Font int `json:"font"`
GroupId int `json:"group_id"`
Message message.Message `json:"message"`
MessageType string `json:"message_type"`
PostType string `json:"post_type"`
RawMessage string `json:"raw_message"`
SelfId int `json:"self_id"`
Sender Senders `json:"sender"`
SubType string `json:"sub_type"`
UserId int `json:"user_id"`
Time int `json:"time"`
NoticeType string `json:"notice_type"`
RequestType string `json:"request_type"`
Comment string `json:"comment"`
Flag string `json:"flag"`
OperatorId int `json:"operator_id"`
File Files `json:"file"`
Duration int64 `json:"duration"`
TargetId int64 `json:"target_id"` //运气王id
HonorType string `json:"honor_type"`
MetaEventType string `json:"meta_event_type"`
Status Status `json:"status"`
Interval int `json:"interval"`
CardNew string `json:"card_new"` //新名片
CardOld string `json:"card_old"` //旧名片
MessageIds
}
func (Event) CloseMessageChan ¶ added in v1.1.2
CloseMessageChan
@Description: 关闭session,即从等待队列中删除 @receiver b @param id int
func (Event) GetImages ¶
func (e Event) GetImages() []message.MessageSegment
func (Event) GetMoreEvent ¶ added in v1.1.2
GetMoreEvent
@Description: 获取一个通道不断从用户获取消息 @receiver b @param rules ...Rule @return int int 对应session在队列中的编号,后面关闭需要该编号 @return chan Event 事件通道
func (Event) GetOneEvent ¶ added in v1.1.2
GetOneEvent
@Description: 向session队列里面添加一个对象,等待用户的响应,设置超时时间 @receiver b @param rules ...Rule @return Event Event @return error error
func (Event) GetPlainText ¶
type M ¶
type M interface {
// contains filtered or unexported methods
}
M
通过id从插件列表获取插件 所有的插件队列都实现了该接口
type MessageChain ¶
type MessageChain []*messageHandle
func (MessageChain) Len ¶
func (m MessageChain) Len() int
func (MessageChain) Less ¶
func (m MessageChain) Less(i, j int) bool
func (MessageChain) Swap ¶
func (m MessageChain) Swap(i, j int)
type MessageIds ¶
type MessageIds struct {
MessageID int32 `json:"message_id"`
}
type MessageInt ¶
type NoticeChain ¶
type NoticeChain []*noticeHandle
func (NoticeChain) Len ¶
func (n NoticeChain) Len() int
func (NoticeChain) Less ¶
func (n NoticeChain) Less(i, j int) bool
func (NoticeChain) Swap ¶
func (n NoticeChain) Swap(i, j int)
type Plugin ¶ added in v1.1.1
func (*Plugin) OnDisConnect ¶ added in v1.1.1
func (p *Plugin) OnDisConnect() *disConnectHandle
func (*Plugin) OnKeyWords ¶ added in v1.1.1
func (*Plugin) OnPretreatment ¶ added in v1.1.1
func (p *Plugin) OnPretreatment() *PretreatmentHandle
func (*Plugin) OnStartWith ¶ added in v1.1.1
type PretreatmentChain ¶
type PretreatmentChain []*PretreatmentHandle
func (PretreatmentChain) Len ¶
func (p PretreatmentChain) Len() int
func (PretreatmentChain) Less ¶
func (p PretreatmentChain) Less(i, j int) bool
func (PretreatmentChain) Swap ¶
func (p PretreatmentChain) Swap(i, j int)
type PretreatmentHandle ¶
type PretreatmentHandle struct {
BaseHandle
// contains filtered or unexported fields
}
func OnPretreatment ¶
func OnPretreatment() *PretreatmentHandle
OnPretreatment *
- @Description: 预处理事件
- @return *PretreatmentHandle
- example
func (*PretreatmentHandle) AddHandle ¶
func (p *PretreatmentHandle) AddHandle(f func(event Event, bot Api) bool)
AddHandle *
- @Description:
- @receiver p
- @param f
func (*PretreatmentHandle) AddRule ¶
func (p *PretreatmentHandle) AddRule(rule Rule) *PretreatmentHandle
AddRule *
- @Description:
- @receiver p
- @param rule
- @return PretreatmentHandle
func (*PretreatmentHandle) SetPluginName ¶
func (p *PretreatmentHandle) SetPluginName(name string) *PretreatmentHandle
func (*PretreatmentHandle) SetWeight ¶
func (p *PretreatmentHandle) SetWeight(weight int) *PretreatmentHandle
SetWeight *
- @Description:
- @receiver p
- @param weight
- @return PretreatmentHandle
type PretreatmentInt ¶
type PretreatmentInt interface {
SetPluginName(name string) *PretreatmentHandle
AddRule(rule Rule) *PretreatmentHandle
SetWeight(weight int) *PretreatmentHandle
AddHandle(func(event Event, bot Api) bool)
}
type RequestChain ¶
type RequestChain []*requestHandle
func (RequestChain) Len ¶
func (r RequestChain) Len() int
func (RequestChain) Less ¶
func (r RequestChain) Less(i, j int) bool
func (RequestChain) Swap ¶
func (r RequestChain) Swap(i, j int)
type RequestInt ¶
type State ¶
type State struct {
Args []string
Cmd string
Allies []string
RegexResult []string
Data map[string]interface{}
}
State @Description: sdk处理消息后将内容传递给plugin
type Status ¶
type Status struct {
AppEnabled bool `json:"app_enabled"`
AppGood bool `json:"app_good"`
AppInitialized bool `json:"app_initialized"`
Good bool `json:"good"`
Online bool `json:"online"`
PluginsGood interface{} `json:"plugins_good"`
Stat struct {
PacketReceived int `json:"packet_received"`
PacketSent int `json:"packet_sent"`
PacketLost int `json:"packet_lost"`
MessageReceived int `json:"message_received"`
MessageSent int `json:"message_sent"`
DisconnectTimes int `json:"disconnect_times"`
LostTimes int `json:"lost_times"`
LastMessageTime int `json:"last_message_time"`
} `json:"stat"`
}