leafbot

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

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

Go to latest
Published: May 23, 2023 License: AGPL-3.0 Imports: 19 Imported by: 0

README

LeafBot

LeafBot

✨ 基于 go-cqhttp,使用OneBot标准的插件 ✨

cqhttp


安装

    go get github.com/huoxue1/leafBot
插件仓库已移动到leafBotPlugin,若需使用内置插件,请查看该仓库

通信方式

  • cqhttp的正向websocket通信
  • cqhttp的反向websocket通信
  • cqhttp的http通信

特别感谢

wdvxdr1123/ZeroBot <借鉴思路>

Mrs4s/go-cqhttp <onebot实现>

nonebot/nonebot2 <流程借鉴>

Documentation

Overview

Package leafbot @Description:

Package leafbot @Description:

Package leafbot @Description:

Index

Constants

View Source
const (
	COMMAND      = "command"
	MESSAGE      = "message"
	REQUEST      = "request"
	REGEX        = "regex"
	NOTICE       = "notice"
	META         = "meta"
	CONNECT      = "connect"
	DISCONNECT   = "dis_connect"
	SELF_MESSAGE = "message_sent"
)

Variables

View Source
var DefaultConfig = Config{
	NickName:     []string{"leafBot"},
	Admin:        0,
	SuperUser:    nil,
	CommandStart: []string{"/"},
	LogLevel:     "",
}

Functions

func AddPlugin

func AddPlugin(pluginName string, help map[string]string, matcher Matcher)

AddPlugin *

  • @Description:
  • @param pluginName
  • @param help
  • @param matcher

func InitBots

func InitBots(config Config)

InitBots

@Description:

func LoadConfig

func LoadConfig(config *Config)

func LoadDriver

func LoadDriver(driver2 Driver)

LoadDriver *

  • @Description: 为leafBot注册一个驱动
  • @param driver2 实现了Driver接口的驱动
  • example

func MustReply

func MustReply(ctx *Context) bool

MustReply *

  • @Description:
  • @param event
  • @param api
  • @param state
  • @return bool
  • example

func OnlyGroupMessage

func OnlyGroupMessage(ctx *Context) bool

OnlyGroupMessage *

  • @Description:
  • @param event
  • @param _
  • @return bool
  • example

func OnlySuperUser

func OnlySuperUser(ctx *Context) bool

OnlySuperUser *

  • @Description: 加了该rule的插件只会对配置文件中配置的管理员用户进行响应
  • @param event leafBot event
  • @param bot bot实例对象
  • @return bool 是否通过该rule验证
  • example

func OnlyToMe

func OnlyToMe(ctx *Context) bool

OnlyToMe *

  • @Description: 添加了该rule的插件需要在群里艾特或者私聊才会进行响应
  • @param event leafBot event
  • @param bot bot实例对象
  • @return bool 返回是否验证通过该rule
  • example

Types

type API

type API interface {
	CallApi(action string, params interface{}) gjson.Result
	SendGroupMsg(groupID int64, message interface{}) int32
	SendPrivateMsg(userID int64, message interface{}) int32
}

API @Description:

func GetBotById

func GetBotById(id int64) API

GetBotById

@Description:
@param id int
@return Api

type Action

type Action func(ctx *Context)

type CommandMatcher

type CommandMatcher interface {
	Matcher
	GetCommand() string
	GetAlias() []string
	GetRegexMatcher() string
}

插件的基本接口,实现Handler接口即可成为一个插件

type Config

type Config struct {
	NickName     []string `json:"nick_name" yaml:"nick_name" hjson:"nick_name"`
	Admin        int64    `json:"admin" yaml:"admin" hjson:"admin"`
	SuperUser    []int64  `json:"super_user" yaml:"super_user" hjson:"super_user"`
	CommandStart []string `json:"command_start" yaml:"command_start" hjson:"command_start"`
	LogLevel     string   `json:"log_level" yaml:"log_level"`
}

Config @Description: 配置信息

func GetConfig

func GetConfig() *Config

type Conn

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:

type Context

type Context struct {
	Event *Event
	Bot   API

	State    *State
	RawEvent gjson.Result

	UserID  int64
	GroupID int64
	SelfID  int64
}

Context @Description: 上下文管理对象

func (*Context) CallApi

func (ctx *Context) CallApi(action string, param interface{}) gjson.Result

func (*Context) CanSendImage

func (ctx *Context) CanSendImage() bool

CanSendImage

@Description:
@receiver b
@return Bool

func (*Context) CanSendRecord

func (ctx *Context) CanSendRecord() bool

CanSendRecord

@Description:
@receiver b
@return Bool

func (*Context) CheckUrlSafely

func (ctx *Context) CheckUrlSafely(url string) int

CheckUrlSafely *

  • @Description:
  • @receiver ctx
  • @param url
  • @return int

func (*Context) CleanCache

func (ctx *Context) CleanCache()

CleanCache *

  • @Description:
  • @receiver b
  • example

func (*Context) DeleteEssenceMsg

func (ctx *Context) DeleteEssenceMsg(messageId int)

DeleteEssenceMsg *

  • @Description:
  • @receiver ctx
  • @param messageId

func (*Context) DeleteMsg

func (ctx *Context) DeleteMsg(messageId int32)

DeleteMsg *

  • @Description:
  • @receiver ctx
  • @param messageId

func (*Context) DownloadFile

func (ctx *Context) DownloadFile(url string, threadCount int, headers []string) gjson.Result

DownloadFile

@Description:
@receiver b
@param url string
@param threadCount int
@param headers []string
@return DownloadFilePath

func (*Context) GetAtUsers

func (ctx *Context) GetAtUsers() (users []int64)

GetAtUsers *

  • @Description: 获取消息中At的所有人的qq
  • @receiver ctx
  • @return users

func (*Context) GetCookies

func (ctx *Context) GetCookies(domain string) gjson.Result

GetCookies

@Description:
@receiver b
@param domain string
@return Cookie

func (*Context) GetCredentials

func (ctx *Context) GetCredentials(domain string) gjson.Result

GetCredentials

@Description:
@receiver b
@param domain string
@return Credentials

func (*Context) GetCsrfToken

func (ctx *Context) GetCsrfToken() gjson.Result

GetCsrfToken

@Description:
@receiver b
@return CsrfToken

func (*Context) GetEssenceMsgList

func (ctx *Context) GetEssenceMsgList(groupID int64) gjson.Result

GetEssenceMsgList *

  • @Description:
  • @receiver ctx
  • @param groupID
  • @return gjson.Result

func (*Context) GetForwardMsg

func (ctx *Context) GetForwardMsg(messageId int) gjson.Result

GetForwardMsg

@Description:
@receiver b
@param messageId int
@return []ForwardMsg

func (*Context) GetFriendList

func (ctx *Context) GetFriendList() gjson.Result

GetFriendList *

  • @Description:
  • @receiver b
  • @return gjson.Result
  • example

func (*Context) GetGroupAtAllRemain

func (ctx *Context) GetGroupAtAllRemain(groupID int64) gjson.Result

GetGroupAtAllRemain

@Description:
@receiver b
@param groupID int64
@return GroupAtAllRemain

func (*Context) GetGroupFileSystemInfo

func (ctx *Context) GetGroupFileSystemInfo(groupID int64) gjson.Result

GetGroupFileSystemInfo

@Description:
@receiver b
@param groupID int64
@return GroupFileSystemInfo

func (*Context) GetGroupFileUrl

func (ctx *Context) GetGroupFileUrl(groupID int64, fileId string, busid int) gjson.Result

GetGroupFileUrl

@Description:
@receiver b
@param groupID int64
@param fileId string
@param busid int
@return FileUrl

func (*Context) GetGroupFilesByFolder

func (ctx *Context) GetGroupFilesByFolder(groupID int64, folderId string) gjson.Result

GetGroupFilesByFolder

@Description:
@receiver b
@param groupID int64
@param folderId string
@return GroupFilesByFolder

func (*Context) GetGroupHonorInfo

func (ctx *Context) GetGroupHonorInfo(groupID int64, honorType string) gjson.Result

GetGroupHonorInfo

@Description:
@receiver b
@param groupID int64
@param honorType string
@return GroupHonorInfo

func (*Context) GetGroupInfo

func (ctx *Context) GetGroupInfo(groupID int64, noCache bool) gjson.Result

GetGroupInfo *

  • @Description:
  • @receiver b
  • @param groupID
  • @param noCache
  • @return gjson.Result
  • example

func (*Context) GetGroupList

func (ctx *Context) GetGroupList() gjson.Result

GetGroupList

@Description:
@receiver b
@return []GroupInfo

func (*Context) GetGroupMemberInfo

func (ctx *Context) GetGroupMemberInfo(groupID int64, userId int64, noCache bool) gjson.Result

GetGroupMemberInfo

@Description:
@receiver b
@param groupID int64
@param userId int
@param noCache bool
@return GroupMemberInfo

func (*Context) GetGroupMemberList

func (ctx *Context) GetGroupMemberList(groupID int64) gjson.Result

GetGroupMemberList

@Description:
@receiver b
@param groupID int64
@return []GroupMemberInfo

func (*Context) GetGroupMsgHistory

func (ctx *Context) GetGroupMsgHistory(messageSeq int64, groupID int64) gjson.Result

GetGroupMsgHistory

@Description:
@receiver b
@param messageSeq int64
@param groupID int64
@return MessageHistory

func (*Context) GetGroupRootFiles

func (ctx *Context) GetGroupRootFiles(groupID int64) gjson.Result

GetGroupRootFiles

@Description:
@receiver b
@param groupID int64
@return GroupRootFiles

func (*Context) GetGroupSystemMsg

func (ctx *Context) GetGroupSystemMsg() gjson.Result

GetGroupSystemMsg

@Description:
@receiver b
@return GroupSystemMsg

func (*Context) GetGuildChannelList

func (ctx *Context) GetGuildChannelList(guildID int64, noCache bool) gjson.Result

func (*Context) GetGuildList

func (ctx *Context) GetGuildList() gjson.Result

func (*Context) GetGuildMembers

func (ctx *Context) GetGuildMembers(guildID int64) gjson.Result

func (*Context) GetGuildMetaByQuest

func (ctx *Context) GetGuildMetaByQuest(guildID int64) gjson.Result

func (*Context) GetGuildServiceProfile

func (ctx *Context) GetGuildServiceProfile() gjson.Result

func (*Context) GetImage

func (ctx *Context) GetImage(file string) gjson.Result

GetImage

@Description:
@receiver b
@param file string
@return Image

func (*Context) GetImages

func (ctx *Context) GetImages() (images []message2.MessageSegment)

GetImages *

  • @Description: 获取消息中所有的图片
  • @receiver ctx
  • @return images

func (*Context) GetLoginInfo

func (ctx *Context) GetLoginInfo() gjson.Result

GetLoginInfo

@Description:
@receiver b
@return LoginInfo

func (*Context) GetMoreEvent

func (ctx *Context) GetMoreEvent(rules ...Rule) (chan Event, func())

GetMoreEvent

@Description: 获取一个通道不断从用户获取消息
@receiver b
@param rules ...Rule
@return int  int 对应session在队列中的编号,后面关闭需要该编号
@return chan  Event  事件通道

func (*Context) GetMsg

func (ctx *Context) GetMsg(messageId int32) gjson.Result

GetMsg *

  • @Description:
  • @receiver ctx
  • @param messageId
  • @return gjson.Result

func (*Context) GetMsgSpecial

func (ctx *Context) GetMsgSpecial(messageId int) gjson.Result

GetMsgSpecial

@Description:
@receiver b
@param messageId int
@return MsgData

func (*Context) GetOneEvent

func (ctx *Context) GetOneEvent(rules ...Rule) (Event, error)

GetOneEvent

@Description: 向session队列里面添加一个对象,等待用户的响应,设置超时时间
@receiver b
@param rules ...Rule
@return Event  Event
@return error  error

func (*Context) GetOnlineClients

func (ctx *Context) GetOnlineClients(noCache bool) gjson.Result

GetOnlineClients *

  • @Description:
  • @receiver b
  • @param noCache
  • @return gjson.Result
  • example

func (*Context) GetQuestion

func (ctx *Context) GetQuestion(question string) (string, error)

GetQuestion *

  • @Description: 向当前用户发送一个问题,并获取答案
  • @receiver ctx
  • @param question
  • @return string
  • @return error

func (*Context) GetRecord

func (ctx *Context) GetRecord(file, outFormat string) gjson.Result

GetRecord

@Description:
@receiver b
@param file file
@param outFormat string
@return Record

func (*Context) GetStatus

func (ctx *Context) GetStatus() gjson.Result

GetStatus

@Description:
@receiver b
@return OnlineStatus

func (*Context) GetStrangerInfo

func (ctx *Context) GetStrangerInfo(userId int, noCache bool) gjson.Result

GetStrangerInfo

@Description:
@receiver b
@param userId int
@param noCache bool
@return Senders

func (*Context) GetVipInfoTest

func (ctx *Context) GetVipInfoTest(userId int64) gjson.Result

GetVipInfoTest

@Description:
@receiver b
@param UserId int
@return VipInfo

func (*Context) GetWordSlices

func (ctx *Context) GetWordSlices(content string) gjson.Result

GetWordSlices

@Description:
@receiver b
@param content string
@return []string

func (*Context) OcrImage

func (ctx *Context) OcrImage(image string) gjson.Result

OcrImage

@Description:
@receiver b
@param image string
@return OcrImage

func (*Context) ReloadEventFilter

func (ctx *Context) ReloadEventFilter()

ReloadEventFilter

@Description:
@receiver b

func (*Context) Send

func (ctx *Context) Send(message interface{}) int32

Send *

  • @Description: 使用上下文对象方便的回复当前会话
  • @receiver ctx
  • @param message
  • @return int32

func (*Context) SendGroupForwardMsg

func (ctx *Context) SendGroupForwardMsg(groupID int64, messages interface{})

SendGroupForwardMsg

@Description:
@receiver b
@param groupID int64
@param messages []Node

func (*Context) SendGroupMsg

func (ctx *Context) SendGroupMsg(groupId int64, message interface{}) int32

func (*Context) SendGroupNotice

func (ctx *Context) SendGroupNotice(groupID int64, content string)

SendGroupNotice

@Description:
@receiver b
@param groupID int64
@param content string

func (*Context) SendGuildChannelMsg

func (ctx *Context) SendGuildChannelMsg(guildID, channelID int64, message interface{}) gjson.Result

func (*Context) SendLike

func (ctx *Context) SendLike(userID int64, times int)

SendLike

@Description:
@receiver b
@param userId int
@param times int

func (*Context) SendMsg

func (ctx *Context) SendMsg(messageType string, userId int64, groupId int64, message interface{}) int32

SendMsg

@Description:
@receiver b
@param messageType string
@param userId int
@param groupId int
@param message string
@param autoEscape bool
@return int32

func (*Context) SendPrivateForwardMsg

func (ctx *Context) SendPrivateForwardMsg(userID int64, messages interface{})

func (*Context) SendPrivateMsg

func (ctx *Context) SendPrivateMsg(userId int64, message interface{}) int32

SendPrivateMsg *

  • @Description:
  • @receiver ctx
  • @param userId
  • @param message
  • @return int32

func (*Context) SetEssenceMsg

func (ctx *Context) SetEssenceMsg(messageId int)

SetEssenceMsg *

  • @Description:
  • @receiver ctx
  • @param messageId

func (*Context) SetFriendAddRequest

func (ctx *Context) SetFriendAddRequest(flag string, approve bool, remark string)

SetFriendAddRequest

@Description:
@receiver b
@param flag string
@param approve bool
@param remark string

func (*Context) SetGroupAddRequest

func (ctx *Context) SetGroupAddRequest(flag string, subType string, approve bool, reason string)

SetGroupAddRequest

@Description:
@receiver b
@param flag string
@param subType string
@param approve bool
@param reason string

func (*Context) SetGroupAdmin

func (ctx *Context) SetGroupAdmin(groupID int64, userId int64, enable bool)

SetGroupAdmin

@Description:
@receiver b
@param groupId int
@param userId int
@param enable bool

func (*Context) SetGroupAnonymous

func (ctx *Context) SetGroupAnonymous(groupID int64, enable bool)

SetGroupAnonymous

@Description:
@receiver b
@param groupID int64
@param enable bool

func (*Context) SetGroupAnonymousBan

func (ctx *Context) SetGroupAnonymousBan(groupID int64, flag string, duration int)

SetGroupAnonymousBan

@Description:
@receiver b
@param groupId int
@param flag string
@param duration int

func (*Context) SetGroupBan

func (ctx *Context) SetGroupBan(groupId int64, userId int64, duration int64)

SetGroupBan

@Description:
@receiver b
@param groupId int
@param userId int
@param duration int

func (*Context) SetGroupCard

func (ctx *Context) SetGroupCard(groupID int64, userId int64, card string)

SetGroupCard

@Description:
@receiver b
@param groupId int
@param userId int
@param card string

func (*Context) SetGroupKick

func (ctx *Context) SetGroupKick(groupID int64, userId int64, rejectAddRequest bool)

SetGroupKick

@Description:
@receiver b
@param groupId int
@param userId int
@param rejectAddRequest bool

func (*Context) SetGroupLeave

func (ctx *Context) SetGroupLeave(groupID int64, isDisMiss bool)

SetGroupLeave

@Description:
@receiver b
@param groupID int64
@param isDisMiss bool

func (*Context) SetGroupName

func (ctx *Context) SetGroupName(groupID int64, groupName string)

SetGroupName

@Description:
@receiver b
@param groupID int64
@param groupName string

func (*Context) SetGroupNameSpecial

func (ctx *Context) SetGroupNameSpecial(groupID int64, groupName string)

SetGroupNameSpecial

@Description:
@receiver b
@param groupID int64
@param groupName string

func (*Context) SetGroupPortrait

func (ctx *Context) SetGroupPortrait(groupID int64, file string, cache int)

SetGroupPortrait

@Description:
@receiver b
@param groupID int64
@param file string
@param cache int

func (*Context) SetGroupSpecialTitle

func (ctx *Context) SetGroupSpecialTitle(groupID int64, userId int64, specialTitle string, duration int)

SetGroupSpecialTitle

@Description:
@receiver b
@param groupID int64
@param userId int
@param specialTitle string
@param duration int

func (*Context) SetGroupWholeBan

func (ctx *Context) SetGroupWholeBan(groupId int64, enable bool)

SetGroupWholeBan

@Description:
@receiver b
@param groupId int
@param enable bool

func (*Context) SetRestart

func (ctx *Context) SetRestart(delay int)

SetRestart

@Description:
@receiver b
@param delay int

func (*Context) UploadGroupFile

func (ctx *Context) UploadGroupFile(groupID int64, file string, name string, folder string)

UploadGroupFile

@Description:
@receiver b
@param groupID int64
@param file string
@param name string
@param folder string

func (*Context) UploadPrivateFile

func (ctx *Context) UploadPrivateFile(userID int64, file, name string)

type Driver

type Driver interface {
	// Run
	// @Description: 运行该驱动的接口,该接口应该为阻塞式运行
	//
	Run()
	// GetEvent
	// @Description: 返回一个chan,该chan为事件传递的chan
	// @return chan
	//
	GetEvent() chan []byte

	OnConnect(func(selfId int64, host string, clientRole string))
	OnDisConnect(func(selfId int64))

	// GetBot
	// @Description: 获取一个实现了APi接口的bot
	// @param int64 bot的id
	// @return interface{}
	//
	GetBot(int64) interface{}
	// GetBots
	// @Description: 获取所有bot
	// @return map[int64]interface{}
	//
	GetBots() map[int64]interface{}
}

Driver @Description: 驱动器接口

type Event

type Event struct {
	Anonymous     anonymous       `json:"anonymous"`
	Font          int             `json:"font"`
	GroupId       int64           `json:"group_id"`
	Message       message.Message `json:"message"`
	MessageType   string          `json:"message_type"`
	PostType      string          `json:"post_type"`
	RawMessage    string          `json:"raw_message"`
	SelfId        int64           `json:"self_id"`
	Sender        Senders         `json:"sender"`
	SubType       string          `json:"sub_type"`
	UserId        int64           `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

	GuildID   int64 `json:"guild_id"`
	ChannelID int64 `json:"channel_id"`
}

Event

  • 事件 *

func (Event) GetImages

func (e Event) GetImages() []message.MessageSegment

func (Event) GetMsg

func (e Event) GetMsg() message.Message

GetMsg *

  • @Description:
  • @receiver e
  • @return message.Message

func (Event) GetPlainText

func (e Event) GetPlainText() string

func (Event) Send

func (e Event) Send(message interface{}) int32

type Files

type Files struct {
	Id      string `json:"id"`
	Name    string `json:"name"`
	Size    int64  `json:"size"`
	Busid   int64  `json:"busid"`
	FileUrl string `json:"url"`
}

type GuildAPI

type GuildAPI interface {
	API
	// GetGuildServiceProfile
	// @Description: 获取频道系统内BOT的资料
	// https://github.com/Mrs4s/go-cqhttp/blob/master/docs/guild.md#%E8%8E%B7%E5%8F%96%E9%A2%91%E9%81%93%E7%B3%BB%E7%BB%9F%E5%86%85bot%E7%9A%84%E8%B5%84%E6%96%99
	GetGuildServiceProfile() gjson.Result

	// GetGuildList
	// @Description: 获取频道列表
	// https://github.com/Mrs4s/go-cqhttp/blob/master/docs/guild.md#%E8%8E%B7%E5%8F%96%E9%A2%91%E9%81%93%E5%88%97%E8%A1%A8
	//
	GetGuildList() gjson.Result

	// GetGuildMetaByQuest
	// @Description: 通过访客获取频道元数据
	// https://github.com/Mrs4s/go-cqhttp/blob/master/docs/guild.md#%E9%80%9A%E8%BF%87%E8%AE%BF%E5%AE%A2%E8%8E%B7%E5%8F%96%E9%A2%91%E9%81%93%E5%85%83%E6%95%B0%E6%8D%AE
	//
	GetGuildMetaByQuest(guildID int64) gjson.Result

	// GetGuildChannelList
	// @Description: 获取子频道列表
	// https://github.com/Mrs4s/go-cqhttp/blob/master/docs/guild.md#%E8%8E%B7%E5%8F%96%E5%AD%90%E9%A2%91%E9%81%93%E5%88%97%E8%A1%A8
	//
	GetGuildChannelList(guildID int64, noCache bool) gjson.Result

	// GetGuildMembers
	// @Description: 获取频道成员列表
	// https://github.com/Mrs4s/go-cqhttp/blob/master/docs/guild.md#%E8%8E%B7%E5%8F%96%E9%A2%91%E9%81%93%E6%88%90%E5%91%98%E5%88%97%E8%A1%A8
	//
	GetGuildMembers(guildID int64) gjson.Result

	// SendGuildChannelMsg
	// @Description: 发送信息到子频道
	// @param guildID 频道ID
	// @param channelID 子频道ID
	// @param message 消息
	// https://github.com/Mrs4s/go-cqhttp/blob/master/docs/guild.md#%E5%8F%91%E9%80%81%E4%BF%A1%E6%81%AF%E5%88%B0%E5%AD%90%E9%A2%91%E9%81%93
	//
	SendGuildChannelMsg(guildID, channelID int64, message interface{}) gjson.Result
}

GuildAPI @Description: 频道相关api

type Matcher

type Matcher interface {
	MatcherSet
	Enabled() bool
	GetHandler() Action
	GetRules() []Rule
	GetWeight() int
	IsBlock() bool
	GetDisAbleGroup() []int64
	GetType() string
	GetPluginType() string
}

插件的基本接口,实现Handler接口即可成为一个插件

type MatcherSet

type MatcherSet interface {
	AddRule(rule Rule) Matcher
	SetWeight(weight int) Matcher
	SetBlock(block bool) Matcher
	SetAllies(allies []string) Matcher

	Handle(action Action)
}

插件的基本接口,实现Handler接口即可成为一个插件

type MessageIds

type MessageIds struct {
	MessageID int32 `json:"message_id"`
}

type OneBotAPI

type OneBotAPI interface {
	API
	DeleteMsg(messageID int32)
	GetMsg(messageID int32) gjson.Result
	SetGroupBan(groupID int64, userID int64, duration int64)
	SetGroupCard(groupID int64, userID int64, card string)
	SendMsg(messageType string, userID int64, groupID int64, message interface{}) int32
	SendLike(userID int64, times int)
	SetGroupKick(groupID int64, userID int64, rejectAddRequest bool)
	SetGroupAnonymousBan(groupID int64, flag string, duration int)
	SetGroupWholeBan(groupID int64, enable bool)
	SetGroupAdmin(groupID int64, UserID int64, enable bool)
	SetGroupAnonymous(groupID int64, enable bool)
	SetGroupName(groupID int64, groupName string)
	SetGroupLeave(groupID int64, isDisMiss bool)
	SetGroupSpecialTitle(groupID int64, userID int64, 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 int64, noCache bool) gjson.Result
	GetGroupList() gjson.Result
	GetGroupMemberInfo(groupID int64, UserID int64, noCache bool) gjson.Result
	GetGroupMemberList(groupID int64) gjson.Result
	GetGroupHonorInfo(groupID int64, 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()

	GetGroupFileSystemInfo(groupID int64) gjson.Result
	GetGroupRootFiles(groupID int64) gjson.Result
	GetGroupFilesByFolder(groupID int64, folderID string) gjson.Result
	GetGroupFileUrl(groupID int64, fileID string, busid int) gjson.Result
	DownloadFile(url string, threadCount int, headers []string) gjson.Result
	UploadGroupFile(groupID int64, file string, name string, folder string)
	UploadPrivateFile(userID int64, file, name string)

	GetGroupMsgHistory(messageSeq int64, groupID int64) gjson.Result
	GetOnlineClients(noCache bool) gjson.Result
	GetVipInfoTest(UserID int64) gjson.Result
	SendGroupNotice(groupID int64, content string)
	ReloadEventFilter()
	SetEssenceMsg(messageID int)
	DeleteEssenceMsg(messageID int)
	GetEssenceMsgList(groupID int64) gjson.Result
	CheckUrlSafely(url string) int

	SetGroupNameSpecial(groupID int64, groupName string)
	SetGroupPortrait(groupID int64, file string, cache int)
	GetMsgSpecial(messageID int) gjson.Result
	GetForwardMsg(messageID int) gjson.Result
	SendGroupForwardMsg(groupID int64, messages interface{})
	SendPrivateForwardMsg(userID int64, messages interface{})

	GetWordSlices(content string) gjson.Result
	OcrImage(image string) gjson.Result
	GetGroupSystemMsg() gjson.Result

	GetGroupAtAllRemain(groupID int64) gjson.Result
}

OneBotAPI @Description:

type Option

type Option struct {
	Weight int
	Block  bool
	Allies []string
	Rules  []Rule
}

Option

  • 用于传递参数

type Plugin

type Plugin struct {
	Name     string
	Help     map[string]string
	Matchers []Matcher
	// contains filtered or unexported fields
}

Plugin

  • 用于记录插件的基本信息

func NewPlugin

func NewPlugin(name string, rules ...Rule) *Plugin

NewPlugin *

  • @Description: 新建一个插件
  • @param name 插件名
  • @return *Plugin 返回一个插件类型对象的指针

func (*Plugin) GetHelp

func (p *Plugin) GetHelp() map[string]string

GetHelp *

  • @Description:
  • @receiver p
  • @return map[string]string

func (*Plugin) GetMather

func (p *Plugin) GetMather() []Matcher

func (*Plugin) GetName

func (p *Plugin) GetName() string

func (*Plugin) OnCommand

func (p *Plugin) OnCommand(command string, options ...Option) Matcher

OnCommand *

  • @Description:
  • @receiver p
  • @param command
  • @param options
  • @return Matcher

func (*Plugin) OnConnect

func (p *Plugin) OnConnect(options ...Option) Matcher

OnConnect *

  • @Description:
  • @receiver p
  • @param options
  • @return Matcher

func (*Plugin) OnDisConnect

func (p *Plugin) OnDisConnect(options ...Option) Matcher

OnDisConnect *

  • @Description:
  • @receiver p
  • @param options
  • @return Matcher

func (*Plugin) OnEnd

func (p *Plugin) OnEnd(end string, options ...Option) Matcher

OnEnd *

  • @Description: 匹配消息结尾
  • @receiver p
  • @param end
  • @param options
  • @return Matcher

func (*Plugin) OnFullMatch

func (p *Plugin) OnFullMatch(content string, options ...Option) Matcher

OnFullMatch *

  • @Description:
  • @receiver p
  • @param content
  • @param options
  • @return Matcher

func (*Plugin) OnFullMatchGroup

func (p *Plugin) OnFullMatchGroup(content string, options ...Option) Matcher

OnFullMatchGroup *

  • @Description:
  • @receiver p
  • @param content
  • @param options
  • @return Matcher

func (*Plugin) OnMessage

func (p *Plugin) OnMessage(messageType string, options ...Option) Matcher

OnMessage *

  • @Description:
  • @receiver p
  • @param messageType
  • @param options
  • @return Matcher

func (*Plugin) OnMeta

func (p *Plugin) OnMeta(options ...Option) Matcher

OnMeta *

  • @Description:
  • @receiver p
  • @param options
  • @return Matcher

func (*Plugin) OnNotice

func (p *Plugin) OnNotice(noticeType string, options ...Option) Matcher

OnNotice *

  • @Description:
  • @receiver p
  • @param noticeType
  • @param options
  • @return Matcher

func (*Plugin) OnRegex

func (p *Plugin) OnRegex(regexMatcher string, options ...Option) Matcher

OnRegex *

  • @Description:
  • @receiver p
  • @param regexMatcher
  • @param options
  • @return Matcher

func (*Plugin) OnRequest

func (p *Plugin) OnRequest(requestType string, options ...Option) Matcher

OnRequest *

  • @Description:
  • @receiver p
  • @param requestType
  • @param options
  • @return Matcher

func (*Plugin) OnSelfMessage

func (p *Plugin) OnSelfMessage(options ...Option) Matcher

OnSelfMessage *

  • @Description:
  • @receiver p
  • @param options
  • @return Matcher

func (*Plugin) OnStart

func (p *Plugin) OnStart(start string, options ...Option) Matcher

OnStart *

  • @Description: 匹配消息开头
  • @receiver p
  • @param start
  • @param options
  • @return Matcher

func (*Plugin) SetHelp

func (p *Plugin) SetHelp(m map[string]string)

type PluginInt

type PluginInt interface {
	GetHelp() map[string]string
	GetName() string
	GetMather() []Matcher
	SetHelp(map[string]string)
	// contains filtered or unexported methods
}

插件的基本接口,实现Handler接口即可成为一个插件

type Rule

type Rule func(ctx *Context) bool

Rule

rule类型

type Senders

type Senders struct {
	Age      int    `json:"age"`
	Area     string `json:"area"`
	Card     string `json:"card"`
	Level    string `json:"level"`
	NickName string `json:"nickname"`
	Role     string `json:"role"`
	Sex      string `json:"sex"`
	Title    string `json:"title"`
	UserId   int    `json:"user_id"`
}

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"`
}

Directories

Path Synopsis
driver
Package message @Description: 用于message转换和封装的一个包
Package message @Description: 用于message转换和封装的一个包
Package utils @Description:
Package utils @Description:

Jump to

Keyboard shortcuts

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