zero

package module
v0.9.2 Latest Latest
Warning

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

Go to latest
Published: Feb 23, 2021 License: AGPL-3.0 Imports: 15 Imported by: 562

README

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AdminPermission

func AdminPermission(event *Event, state State) bool

AdminPermission only triggered by the group admins or higher permission

func CallAction

func CallAction(action string, params Params) gjson.Result

CallAction 调用 cqhttp API

func OnlyGroup

func OnlyGroup(event *Event, _ State) bool

OnlyGroup requires that the event is public/group message

func OnlyPrivate

func OnlyPrivate(event *Event, _ State) bool

OnlyPrivate requires that the event is private message

func OnlyToMe

func OnlyToMe(event *Event, _ State) bool

OnlyToMe only triggered in conditions of @bot or begin with the nicknames

func OwnerPermission

func OwnerPermission(event *Event, state State) bool

OwnerPermission only triggered by the group owner or higher permission

func RegisterPlugin

func RegisterPlugin(plugin IPlugin)

RegisterPlugin register the plugin to ZeroBot

func Run

func Run(op Config)

Run 主函数初始化

func Send

func Send(event Event, message interface{}) int64

Send 快捷发送消息

func SendGroupForwardMessage

func SendGroupForwardMessage(groupID int64, message message.Message) gjson.Result

SendGroupForwardMessage 发送合并转发(群) https://github.com/Mrs4s/go-cqhttp/blob/master/docs/cqhttp.md#%E5%9B%BE%E7%89%87ocr

func SuperUserPermission

func SuperUserPermission(event *Event, _ State) bool

SuperUserPermission only triggered by the bot's owner

Types

type APIRequest added in v0.9.2

type APIRequest struct {
	Action string `json:"action"`
	Params Params `json:"params"`
	Echo   uint64 `json:"echo"` // 该项不用填写,由Driver生成
}

APIRequest is the request sending to the cqhttp https://github.com/howmanybots/onebot/blob/master/v11/specs/communication/ws.md

type APIResponse added in v0.9.2

type APIResponse struct {
	Status  string       `json:"status"`
	Data    gjson.Result `json:"data"`
	Msg     string       `json:"msg"`
	Wording string       `json:"wording"`
	RetCode int64        `json:"retcode"`
	Echo    uint64       `json:"echo"`
}

APIResponse is the response of calling API https://github.com/howmanybots/onebot/blob/master/v11/specs/communication/ws.md

type Config

type Config struct {
	Host          string   `json:"host"`           //host地址
	Port          string   `json:"port"`           //端口
	AccessToken   string   `json:"access_token"`   //认证token
	NickName      []string `json:"nickname"`       //机器人名称
	CommandPrefix string   `json:"command_prefix"` //触发命令
	SuperUsers    []string `json:"super_users"`    //超级用户
	SelfID        string   `json:"self_id"`        // 机器人账号
	Driver        Driver   `json:"-"`
}

Config is config of zero bot

var BotConfig Config

BotConfig 运行中bot的配置,是Run函数的参数的拷贝

type Driver added in v0.9.2

type Driver interface {
	Connect(url string, accessToken string)
	Listen(func([]byte))
	Send(APIRequest) (APIResponse, error)
}

Driver 与OneBot通信的驱动,使用driver.DefaultWebSocketDriver

type Event

type Event struct {
	Time          int64               `json:"time"`
	PostType      string              `json:"post_type"`
	DetailType    string              `json:"-"`
	MessageType   string              `json:"message_type"`
	SubType       string              `json:"sub_type"`
	MessageID     int64               `json:"message_id"`
	GroupID       int64               `json:"group_id"`
	UserID        int64               `json:"user_id"`
	RawMessage    string              `json:"raw_message"` // raw_message is always string
	Anonymous     interface{}         `json:"anonymous"`
	AnonymousFlag string              `json:"anonymous_flag"` // This field is deprecated and will get removed, see #11
	Event         string              `json:"event"`
	NoticeType    string              `json:"notice_type"` // This field is deprecated and will get removed, see #11
	OperatorID    int64               `json:"operator_id"` // This field is used for Notice Event
	File          *File               `json:"file"`
	RequestType   string              `json:"request_type"`
	Flag          string              `json:"flag"`
	Comment       string              `json:"comment"` // This field is used for Request Event
	Message       message.Message     `json:"-"`       // Message parsed
	Sender        *User               `json:"sender"`
	NativeMessage jsoniter.RawMessage `json:"message"`
	IsToMe        bool                `json:"-"`
	RawEvent      gjson.Result        `json:"-"` // raw event
}

Event is the event emitted form cqhttp

type File

type File struct {
	ID    string `json:"id"`
	Name  string `json:"name"`
	Size  int64  `json:"size"`
	BusID int64  `json:"busid"`
}

type FutureEvent

type FutureEvent struct {
	Type     string
	Priority int
	Rule     []Rule
	Block    bool
}

FutureEvent 是 ZeroBot 交互式的核心,用于异步获取指定事件

func NewFutureEvent

func NewFutureEvent(Type string, Priority int, Block bool, rule ...Rule) *FutureEvent

NewFutureEvent 创建一个FutureEvent, 并返回其指针

func (*FutureEvent) Next

func (n *FutureEvent) Next() <-chan Event

Next 返回一个 chan 用于接收下一个指定事件

该 chan 必须接收,如需手动取消监听,请使用 Repeat 方法

func (*FutureEvent) Repeat

func (n *FutureEvent) Repeat() (recv <-chan Event, cancel func())

Repeat 返回一个 chan 用于接收无穷个指定事件,和一个取消监听的函数

如果没有取消监听,将不断监听指定事件

func (*FutureEvent) Take

func (n *FutureEvent) Take(num int) <-chan Event

Take 基于 Repeat 封装,返回一个 chan 接收指定数量的事件

该 chan 对象必须接收,否则将有 goroutine 泄漏,如需手动取消请使用 Repeat

type Group

type Group struct {
	ID             int64  `json:"group_id"`
	Name           string `json:"group_name"`
	MemberCount    int64  `json:"member_count"`
	MaxMemberCount int64  `json:"max_member_count"`
}

type Handler

type Handler func(matcher *Matcher, event Event, state State) Response

type Hooker

type Hooker interface {
	Hook() Rule
}

func AddHook

func AddHook(hookers ...Hooker) Hooker

func MultiHooker

func MultiHooker(h ...Hooker) Hooker

type IPlugin

type IPlugin interface {
	// GetPluginInfo 获取插件信息
	GetPluginInfo() PluginInfo
	// Start 开启工作
	Start()
}

IPlugin is the plugin of the ZeroBot

type Matcher

type Matcher struct {
	// Temp 是否为临时Matcher,临时 Matcher 匹配一次后就会删除当前 Matcher
	Temp bool
	// Block 是否阻断后续 Matcher,为 true 时当前Matcher匹配成功后,后续Matcher不参与匹配
	Block bool
	// Priority 优先级,越小优先级越高
	Priority int
	// State 上下文
	State State
	// Event 当前匹配到的事件
	Event *Event
	// Type 匹配的事件类型
	Type Rule
	// Rules 匹配规则
	Rules []Rule
	// Handler 处理事件的函数
	Handler Handler
}

Matcher 是 ZeroBot 匹配和处理事件的最小单元

func On

func On(mType string, rules ...Rule) *Matcher

On 添加新的主匹配器

func OnCommand

func OnCommand(commands string, rules ...Rule) *Matcher

OnCommand 命令触发器

func OnCommandGroup

func OnCommandGroup(commands []string, rules ...Rule) *Matcher

OnCommandGroup 命令触发器组

func OnFullMatch

func OnFullMatch(src string, rules ...Rule) *Matcher

OnFullMatch 完全匹配触发器

func OnFullMatchGroup

func OnFullMatchGroup(src []string, rules ...Rule) *Matcher

OnFullMatchGroup 完全匹配触发器组

func OnKeyword

func OnKeyword(keyword string, rules ...Rule) *Matcher

OnKeyword 关键词触发器

func OnKeywordGroup

func OnKeywordGroup(keywords []string, rules ...Rule) *Matcher

OnKeywordGroup 关键词触发器组

func OnMessage

func OnMessage(rules ...Rule) *Matcher

OnMessage 消息触发器

func OnMetaEvent

func OnMetaEvent(rules ...Rule) *Matcher

OnMetaEvent 元事件触发器

func OnNotice

func OnNotice(rules ...Rule) *Matcher

OnNotice 系统提示触发器

func OnPrefix

func OnPrefix(prefix string, rules ...Rule) *Matcher

OnPrefix 前缀触发器

func OnPrefixGroup

func OnPrefixGroup(prefix []string, rules ...Rule) *Matcher

OnPrefixGroup 前缀触发器组

func OnRegex

func OnRegex(regexPattern string, rules ...Rule) *Matcher

OnRegex 正则触发器

func OnRequest

func OnRequest(rules ...Rule) *Matcher

OnRequest 请求消息触发器

func OnSuffix

func OnSuffix(suffix string, rules ...Rule) *Matcher

OnSuffix 后缀触发器

func OnSuffixGroup

func OnSuffixGroup(suffix []string, rules ...Rule) *Matcher

OnSuffixGroup 后缀触发器组

func StoreMatcher

func StoreMatcher(m *Matcher) *Matcher

StoreMatcher store a matcher to matcher list.

func StoreTempMatcher

func StoreTempMatcher(m *Matcher) *Matcher

StoreTempMatcher store a matcher only triggered once.

func (*Matcher) Delete

func (m *Matcher) Delete()

Delete remove the matcher from list

func (*Matcher) FutureEvent

func (m *Matcher) FutureEvent(Type string, rule ...Rule) *FutureEvent

FutureEvent 返回一个 FutureEvent 实例指针,用于获取满足 Rule 的 未来事件

func (*Matcher) Get

func (m *Matcher) Get(prompt string) string

Get ..

func (*Matcher) Handle

func (m *Matcher) Handle(handler Handler) *Matcher

Handle 直接处理事件

func (*Matcher) SetBlock

func (m *Matcher) SetBlock(block bool) *Matcher

SetBlock 设置是否阻断后面的 Matcher 触发

func (*Matcher) SetPriority

func (m *Matcher) SetPriority(priority int) *Matcher

SetPriority 设置当前 Matcher 优先级

type Message

type Message struct {
	Elements    message.Message
	MessageId   int64
	Sender      *User
	MessageType string
}

type Option deprecated

type Option = Config

Option 配置

Deprecated: use zero.Config instead.

type Params

type Params map[string]interface{}

Params is the params of call api

type PluginInfo

type PluginInfo struct {
	Author     string // 作者
	PluginName string // 插件名
	Version    string // 版本
	Details    string // 插件说明
}

PluginInfo is the plugin's information

type Response

type Response uint8
const (
	SuccessResponse Response = iota
	RejectResponse
	FinishResponse
)

type Rule

type Rule func(event *Event, state State) bool

Rule filter the event

func CheckSession

func CheckSession(e1 *Event) Rule

CheckSession 判断会话连续性

func CheckUser

func CheckUser(userId ...int64) Rule

CheckUser only triggered by specific person

func CommandRule

func CommandRule(commands ...string) Rule

CommandRule check if the message is a command and trim the command name

func FullMatchRule

func FullMatchRule(src ...string) Rule

FullMatchRule check if src has the same copy of the message

func KeywordRule

func KeywordRule(src ...string) Rule

KeywordRule check if the message has a keyword or keywords

func PrefixRule

func PrefixRule(prefixes ...string) Rule

PrefixRule check if the message has the prefix and trim the prefix

检查消息前缀

func RegexRule

func RegexRule(regexPattern string) Rule

RegexRule check if the message can be matched by the regex pattern

func ReplyRule

func ReplyRule(messageID int64) Rule

ReplyRule check if the message is replying some message

func SuffixRule

func SuffixRule(suffixes ...string) Rule

SuffixRule check if the message has the suffix and trim the suffix

检查消息后缀

func Type

func Type(type_ string) Rule

Type check the event's type

type State

type State map[string]interface{}

State store the context of a matcher.

func (State) Parse

func (state State) Parse(model interface{}) (err error)

Parse 将 State 映射到结构体

type User

type User struct {
	// Private sender
	// https://github.com/howmanybots/onebot/blob/master/v11/specs/event/message.md#%E7%A7%81%E8%81%8A%E6%B6%88%E6%81%AF
	ID       int64  `json:"user_id"`
	NickName string `json:"nickname"`
	Sex      string `json:"sex"` // "male"、"female"、"unknown"
	Age      int    `json:"age"`
	Area     string `json:"area"`
	// Group member
	// https://github.com/howmanybots/onebot/blob/master/v11/specs/event/message.md#%E7%BE%A4%E6%B6%88%E6%81%AF
	Card  string `json:"card"`
	Title string `json:"title"`
	Level string `json:"level"`
	Role  string `json:"role"` // "owner"、"admin"、"member"
	// Group anonymous
	AnonymousID   int64  `json:"anonymous_id" anonymous:"id"`
	AnonymousName string `json:"anonymous_name" anonymous:"name"`
	AnonymousFlag string `json:"anonymous_flag" anonymous:"flag"`
}

User is a user on QQ.

func (*User) Name

func (u *User) Name() string

Name displays a simple text version of a user.

func (*User) String

func (u *User) String() string

String displays a simple text version of a user. It is normally a user's card, but falls back to a nickname as available.

Directories

Path Synopsis
Package driver provides the default driver of zerobot
Package driver provides the default driver of zerobot
kv
Package kv provides a simple wrap of goleveldb for multi bucket database
Package kv provides a simple wrap of goleveldb for multi bucket database
manager
Package manager provides a simple group plugin manager.
Package manager provides a simple group plugin manager.
rate
Package rate provides a rate limiter hooker, this package is based on golang.org/x/time/rate
Package rate provides a rate limiter hooker, this package is based on golang.org/x/time/rate
shell
Package shell provides a simple shell parser for zerobot.
Package shell provides a simple shell parser for zerobot.
utils

Jump to

Keyboard shortcuts

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