leafBot

package module
v1.1.5 Latest Latest
Warning

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

Go to latest
Published: Oct 22, 2021 License: AGPL-3.0 Imports: 34 Imported by: 0

README

LeafBot

LeafBot

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

cqhttp


已添加windows的gui界面,前提是基于chorme引擎

特别感谢wdvxdr1123大佬的CQ码解析和消息部分
安装
    go get github.com/huoxue1/leafBot

插件仓库已移动到leafBotPlugin,若需使用内置插件,请查看该仓库

特别感谢

wdvxdr1123/ZeroBot <借鉴思路>

Mrs4s/go-cqhttp <onebot实现>

nonebot/nonebot2 <流程借鉴>

示例

Documentation

Overview

Package leafBot @Description:

Package leafBot @Description:

Index

Constants

View Source
const (
	JSON  = "json"
	HJSON = "hjson"
	YAML  = "yaml"
)

Variables

View Source
var (
	ConnectHandles      ConnectChain
	DisConnectHandles   DisConnectChain
	MessageHandles      MessageChain
	RequestHandles      RequestChain
	NoticeHandles       NoticeChain
	CommandHandles      CommandChain
	MetaHandles         MetaChain
	PretreatmentHandles PretreatmentChain
)
View Source
var (
	DefaultConfig = new(Config)
)
View Source
var ENABLE = false // 是否启用gui
View Source
var (
	MessageChan = make(chan Event, 10)
)

Functions

func BanPluginByID

func BanPluginByID(id string)

BanPluginByID * * @Description: 根据id禁用插件 * @param id

func BanPluginByName

func BanPluginByName(name string) int

BanPluginByName * * @Description: 禁用某个插件 * @param name 插件名 * @return int 禁用的插件个数

func CallApi

func CallApi(ctx *gin.Context)

func Cors added in v1.1.3

func Cors() gin.HandlerFunc

func GetConfig

func GetConfig(ctx *gin.Context)

func GetEngine added in v1.1.4

func GetEngine() (*gin.Engine, error)

GetEngine *

  • @Description: 获取web的引擎
  • @return *gin.Engine
  • @return error
  • example

func GetFont added in v1.1.4

func GetFont() []byte

GetFont *

  • @Description: 向外导出思源黑体字体文件
  • @return []byte
  • example

func GetFriendList

func GetFriendList(ctx *gin.Context)

func GetGroupList

func GetGroupList(ctx *gin.Context)

func GetHandleList

func GetHandleList() map[string][]BaseHandle

func InitBots

func InitBots()

InitBots

@Description:

func InitPluginManager

func InitPluginManager()

func InitWindow

func InitWindow()

InitWindow *

  • @Description:
  • example

func LoadConfig

func LoadConfig()

func LoadDriver added in v1.1.2

func LoadDriver(driver2 Driver)

LoadDriver *

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

func MustReply added in v1.1.4

func MustReply(event Event, api Api, state *State) bool

MustReply *

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

func OnlyGroupMessage

func OnlyGroupMessage(event Event, _ Api) bool

OnlyGroupMessage *

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

func OnlySuperUser

func OnlySuperUser(event Event, _ Api, _ *State) bool

OnlySuperUser *

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

func OnlyToMe

func OnlyToMe(event Event, _ Api, state *State) bool

OnlyToMe *

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

func OpenUi added in v1.1.0

func OpenUi()

func StartPlugin

func StartPlugin(name string) int

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{}
}

Api @Description:

func GetBotById

func GetBotById(id int) Api

GetBotById

@Description:
@param id int
@return Api

type BaseHandle

type BaseHandle struct {
	ID         string
	Name       string
	Enable     bool
	IsAdmin    bool
	HandleType string
}

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(f func(event Event, bot Api, state *State))
	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"`
	LogTruncate      bool     `json:"log_truncate" yaml:"log_truncate" hjson:"log_truncate"`
	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"`
}

Config @Description:

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 Connect

type Connect struct {
	SelfID     int64
	Host       string
	ClientRole string
}

type ConnectChain

type ConnectChain []*connectHandle

type ConnectInt

type ConnectInt interface {
	SetPluginName(name string) *connectHandle
	AddHandle(func(connect Connect, bot Api))
}

type DisConnectChain

type DisConnectChain []*disConnectHandle

type DisConnectInt

type DisConnectInt interface {
	SetPluginName(name string) *disConnectHandle
	AddHandle(func(selfId int64))
}

type Driver added in v1.1.2

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{}
	// SetAddress
	// @Description: 设置driver的运行地址
	// @param string2
	//
	SetAddress(string2 string)

	SetPort(port int)
}

Driver @Description:

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

func (e Event) CloseMessageChan(id int)

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

func (e Event) GetMoreEvent(rules ...Rule) (int, chan Event)

GetMoreEvent

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

func (Event) GetMsg

func (e Event) GetMsg() message.Message

GetMsg *

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

func (Event) GetOneEvent added in v1.1.2

func (e Event) GetOneEvent(rules ...Rule) (Event, error)

GetOneEvent

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

func (Event) GetPlainText

func (e Event) GetPlainText() string

func (Event) Send added in v1.1.2

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 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 MessageInt interface {
	SetPluginName(name string) *messageHandle
	AddRule(rule Rule) *messageHandle
	SetWeight(weight int) *messageHandle
	AddHandle(func(event Event, bot Api, state *State))
}

type MetaChain

type MetaChain []*metaHandle

func (MetaChain) Len

func (m MetaChain) Len() int

func (MetaChain) Less

func (m MetaChain) Less(i, j int) bool

func (MetaChain) Swap

func (m MetaChain) Swap(i, j int)

type MetaInt

type MetaInt interface {
	SetPluginName(name string) *metaHandle
	AddRule(rule Rule) *metaHandle
	SetWeight(weight int) *metaHandle
	AddHandle(func(event Event, bot Api))
}

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 NoticeInt

type NoticeInt interface {
	SetPluginName(name string) *noticeHandle
	AddRule(rule Rule) *noticeHandle
	SetWeight(weight int) *noticeHandle
	AddHandle(func(event Event, bot Api))
}

type Option added in v1.1.3

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

type Options added in v1.1.2

type Options struct {
}

type Plugin added in v1.1.1

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

func NewPlugin added in v1.1.1

func NewPlugin(name string) *Plugin

NewPlugin *

  • @Description:
  • @param name
  • @return *Plugin
  • example

func (*Plugin) OnCommand added in v1.1.1

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

func (*Plugin) OnConnect added in v1.1.1

func (p *Plugin) OnConnect() *connectHandle

func (*Plugin) OnDisConnect added in v1.1.1

func (p *Plugin) OnDisConnect() *disConnectHandle

func (*Plugin) OnEndWith added in v1.1.1

func (p *Plugin) OnEndWith(str string, options ...Option) *messageHandle

func (*Plugin) OnFullMatch added in v1.1.4

func (p *Plugin) OnFullMatch(match string, options ...Option) *messageHandle

func (*Plugin) OnFullMatchGroup added in v1.1.4

func (p *Plugin) OnFullMatchGroup(matchs []string, options ...Option) *messageHandle

func (*Plugin) OnKeyWords added in v1.1.1

func (p *Plugin) OnKeyWords(keyword string, options ...Option) *messageHandle

func (*Plugin) OnMessage added in v1.1.1

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

func (*Plugin) OnMeta added in v1.1.1

func (p *Plugin) OnMeta() *metaHandle

func (*Plugin) OnNotice added in v1.1.1

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

func (*Plugin) OnPretreatment added in v1.1.1

func (p *Plugin) OnPretreatment() *PretreatmentHandle

func (*Plugin) OnRegex added in v1.1.1

func (p *Plugin) OnRegex(regex string, options ...Option) *commandHandle

func (*Plugin) OnRequest added in v1.1.1

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

func (*Plugin) OnStartWith added in v1.1.1

func (p *Plugin) OnStartWith(str string, options ...Option) *messageHandle

func (*Plugin) OnTime added in v1.1.1

func (p *Plugin) OnTime(crons string, selfId int, handle func(bot Api))

func (*Plugin) SetHelp added in v1.1.1

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

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 (*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 RequestInt interface {
	SetPluginName(name string) *requestHandle
	AddRule(rule Rule) *requestHandle
	SetWeight(weight int) *requestHandle
	AddHandle(func(event Event, bot Api))
}

type Rule

type Rule func(Event, Api, *State) 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
gui
Package utils @Description: Package utils @Description:
Package utils @Description: Package utils @Description:

Jump to

Keyboard shortcuts

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