rei

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

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

Go to latest
Published: Mar 10, 2023 License: GPL-3.0 Imports: 27 Imported by: 38

README

看板娘

ReiBot

Lightweight Telegram bot framework


Instructions

Note: This framework is built mainly for Chinese users thus may display hard-coded Chinese prompts during the interaction.

This framework is a simple wrapper for go-telegram-bot-api, aiming to make the event processing easier.

Quick Start

Here is a plugin-based example, see more in the example folder

plugin-based example

package main

import (
	rei "github.com/fumiama/ReiBot"
	tgba "github.com/go-telegram-bot-api/telegram-bot-api/v5"
)

func main() {
	rei.OnMessagePrefix("echo").SetBlock(true).SecondPriority().
		Handle(func(ctx *rei.Ctx) {
			args := ctx.State["args"].(string)
			if args == "" {
				return
			}
			ctx.SendPlainMessage(false, args)
		})
	rei.Run(rei.Bot{
		Token:  "",
		Buffer: 256,
		UpdateConfig: tgba.UpdateConfig{
			Offset:  0,
			Limit:   0,
			Timeout: 60,
		},
		Debug: true,
	})
}

Event-Based

If Handler in Bot is implemented, the plugin function will be disabled.

event-based example

package main

import (
	"strings"

	rei "github.com/fumiama/ReiBot"
	tgba "github.com/go-telegram-bot-api/telegram-bot-api/v5"
	log "github.com/sirupsen/logrus"
)

func main() {
	rei.Run(rei.Bot{
		Token:  "",
		Buffer: 256,
		UpdateConfig: tgba.UpdateConfig{
			Offset:  0,
			Limit:   0,
			Timeout: 60,
		},
		Debug: true,
		Handler: &rei.Handler{
			OnMessage: func(updateid int, bot *rei.TelegramClient, msg *tgba.Message) {
				if len(msg.Text) <= len("测试") {
					return
				}
				if !strings.HasPrefix(msg.Text, "测试") {
					return
				}
				_, err := bot.Send(tgba.NewMessage(msg.Chat.ID, msg.Text[len("测试"):]))
				if err != nil {
					log.Errorln(err)
				}
			},
			OnEditedMessage: func(updateid int, bot *rei.TelegramClient, msg *tgba.Message) {
				if len(msg.Text) <= len("测试") {
					return
				}
				if !strings.HasPrefix(msg.Text, "测试") {
					return
				}
				_, err := bot.Send(tgba.NewMessage(msg.Chat.ID, "已编辑:"+msg.Text[len("测试"):]))
				if err != nil {
					log.Errorln(err)
				}
			},
		},
	})
}

Thanks

Documentation

Overview

Package rei ReiBot created in 2022.5.31

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AdminPermission

func AdminPermission(ctx *Ctx) bool

AdminPermission only triggered by the group admins or higher permission

func CreaterPermission

func CreaterPermission(ctx *Ctx) bool

CreaterPermission only triggered by the group creater or higher permission

func Delete

func Delete(service string)

Delete 删除插件控制器, 不会删除数据

func ForEachByPrio

func ForEachByPrio(iterator func(i int, manager *ctrl.Control[*Ctx]) bool)

ForEachByPrio iterates through managers by their priority.

func IsPhoto

func IsPhoto(ctx *Ctx) bool

IsPhoto 消息是图片返回 true

this rule only supports tgba.Message

func Lookup

func Lookup(service string) (*ctrl.Control[*Ctx], bool)

func OnlyChannel

func OnlyChannel(ctx *Ctx) bool

OnlyChannel requires that the ctx.Event is channel message

func OnlyGroup

func OnlyGroup(ctx *Ctx) bool

OnlyGroup requires that the ctx.Event is group message

func OnlyPrivate

func OnlyPrivate(ctx *Ctx) bool

OnlyPrivate requires that the ctx.Event is private message

func OnlyPublic

func OnlyPublic(ctx *Ctx) bool

OnlyPublic requires that the ctx.Event is group or supergroup message

func OnlySuperGroup

func OnlySuperGroup(ctx *Ctx) bool

OnlySuperGroup requires that the ctx.Event is supergroup message

func OnlyToMe

func OnlyToMe(ctx *Ctx) bool

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

this rule only supports tgba.Message

func ParseShell

func ParseShell(s string) []string

ParseShell 将指令转换为指令参数. modified from https://github.com/mattn/go-shellwords

func RangeBot

func RangeBot(iter func(id int64, ctx *Ctx) bool)

RangeBot 遍历所有bot (Ctx)实例

单次操作返回 true 则继续遍历,否则退出

func Run

func Run(bots ...Bot)

Run clients and block self in listening last one

func Start

func Start(bots ...Bot)

Start clients without blocking

func SuperUserPermission

func SuperUserPermission(ctx *Ctx) bool

SuperUserPermission only triggered by the bot's owner

func UserOrGrpAdmin

func UserOrGrpAdmin(ctx *Ctx) bool

UserOrGrpAdmin 允许用户单独使用或群管使用

Types

type Bot

type Bot struct {
	// Token bot 的 token
	//    see https://core.telegram.org/bots#3-how-do-i-create-a-bot
	Token string
	// Buffer 控制消息队列的长度
	Buffer int
	// UpdateConfig 配置消息获取
	tgba.UpdateConfig
	// SuperUsers 超级用户
	SuperUsers []int64
	// Debug 控制调试信息的输出与否
	Debug bool
	// Handler 注册对各种事件的处理
	Handler *Handler
	// contains filtered or unexported fields
}

Bot bot 的配置

type Ctx

type Ctx struct {
	Event
	State
	Caller  *TelegramClient
	Message *tgba.Message

	IsToMe bool
	// contains filtered or unexported fields
}

func GetBot

func GetBot(id int64) *Ctx

GetBot 获取指定的bot (Ctx) 实例

func (*Ctx) Block

func (ctx *Ctx) Block()

Block 匹配成功后阻止后续触发

func (*Ctx) Break

func (ctx *Ctx) Break()

Block 在 pre, rules, mid 阶段阻止后续触发

func (*Ctx) CheckSession

func (ctx *Ctx) CheckSession() Rule

CheckSession 判断会话连续性

func (*Ctx) Parse

func (ctx *Ctx) Parse(model interface{}) (err error)

Parse 将 Ctx.State 映射到结构体

func (*Ctx) Send

func (ctx *Ctx) Send(replytosender bool, c tgba.Chattable) (tgba.Message, error)

Send 发送消息到对方

c.ChatID = ctx.Message.Chat.ID
if replytosender {
	c.ReplyToMessageID = ctx.Message.MessageID
}

func (*Ctx) SendAudio

func (ctx *Ctx) SendAudio(file tgba.RequestFileData, replytosender bool, caption string, captionentities ...tgba.MessageEntity) (tgba.Message, error)

SendAudio 发送音频消息到对方

func (*Ctx) SendMessage

func (ctx *Ctx) SendMessage(replytosender bool, text string, entities ...tgba.MessageEntity) (tgba.Message, error)

SendMessage 发送富文本消息到对方

func (*Ctx) SendPhoto

func (ctx *Ctx) SendPhoto(file tgba.RequestFileData, replytosender bool, caption string, captionentities ...tgba.MessageEntity) (tgba.Message, error)

SendPhoto 发送图片消息到对方

func (*Ctx) SendPlainMessage

func (ctx *Ctx) SendPlainMessage(replytosender bool, printable ...any) (tgba.Message, error)

SendPlainMessage 发送无 entities 文本消息到对方

type Engine

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

Engine is the pre_handler, mid_handler, post_handler manager

func Register

func Register(service string, o *ctrl.Options[*Ctx]) *Engine

Register 注册插件控制器

func (*Engine) ApplySingle

func (e *Engine) ApplySingle(s *Single[int64]) *Engine

ApplySingle 应用反并发

func (*Engine) DataFolder

func (e *Engine) DataFolder() string

DataFolder 本插件数据目录, 默认 data/rbp/

func (*Engine) Delete

func (e *Engine) Delete()

Delete 移除该 Engine 注册的所有 Matchers

func (*Engine) GetLazyData

func (e *Engine) GetLazyData(filename string, isDataMustEqual bool) ([]byte, error)

下载并获取本 engine 文件夹下的懒加载数据

func (*Engine) On

func (e *Engine) On(typ string, rules ...Rule) *Matcher

On 添加新的指定消息类型的匹配器

func (*Engine) OnCallbackQuery

func (e *Engine) OnCallbackQuery(rules ...Rule) *Matcher

OnCallbackQuery ...

func (*Engine) OnCallbackQueryFullMatch

func (e *Engine) OnCallbackQueryFullMatch(src string, rules ...Rule) *Matcher

OnCallbackQueryFullMatch 完全匹配触发器

func (*Engine) OnCallbackQueryFullMatchGroup

func (e *Engine) OnCallbackQueryFullMatchGroup(src []string, rules ...Rule) *Matcher

OnCallbackQueryFullMatchGroup 完全匹配触发器组

func (*Engine) OnCallbackQueryKeyword

func (e *Engine) OnCallbackQueryKeyword(keyword string, rules ...Rule) *Matcher

OnCallbackQueryKeyword 关键词触发器

func (*Engine) OnCallbackQueryKeywordGroup

func (e *Engine) OnCallbackQueryKeywordGroup(keywords []string, rules ...Rule) *Matcher

OnCallbackQueryKeywordGroup 关键词触发器组

func (*Engine) OnCallbackQueryPrefix

func (e *Engine) OnCallbackQueryPrefix(prefix string, rules ...Rule) *Matcher

OnCallbackQueryPrefix 前缀触发器

func (*Engine) OnCallbackQueryPrefixGroup

func (e *Engine) OnCallbackQueryPrefixGroup(prefix []string, rules ...Rule) *Matcher

OnCallbackQueryPrefixGroup 前缀触发器组

func (*Engine) OnCallbackQueryRegex

func (e *Engine) OnCallbackQueryRegex(regexPattern string, rules ...Rule) *Matcher

OnCallbackQueryRegex 正则触发器

func (*Engine) OnCallbackQuerySuffix

func (e *Engine) OnCallbackQuerySuffix(suffix string, rules ...Rule) *Matcher

OnCallbackQuerySuffix 后缀触发器

func (*Engine) OnCallbackQuerySuffixGroup

func (e *Engine) OnCallbackQuerySuffixGroup(suffix []string, rules ...Rule) *Matcher

OnCallbackQuerySuffixGroup 后缀触发器组

func (*Engine) OnChannelPost

func (e *Engine) OnChannelPost(rules ...Rule) *Matcher

OnChannelPost ...

func (*Engine) OnChatJoinRequest

func (e *Engine) OnChatJoinRequest(rules ...Rule) *Matcher

OnChatJoinRequest ...

func (*Engine) OnChatMember

func (e *Engine) OnChatMember(rules ...Rule) *Matcher

OnChatMember ...

func (*Engine) OnChosenInlineResult

func (e *Engine) OnChosenInlineResult(rules ...Rule) *Matcher

OnChosenInlineResult ...

func (*Engine) OnEditedChannelPost

func (e *Engine) OnEditedChannelPost(rules ...Rule) *Matcher

OnEditedChannelPost ...

func (*Engine) OnEditedMessage

func (e *Engine) OnEditedMessage(rules ...Rule) *Matcher

OnEditedMessage 修改消息触发器

func (*Engine) OnInlineQuery

func (e *Engine) OnInlineQuery(rules ...Rule) *Matcher

OnInlineQuery ...

func (*Engine) OnMessage

func (e *Engine) OnMessage(rules ...Rule) *Matcher

OnMessage 消息触发器

func (*Engine) OnMessageCommand

func (e *Engine) OnMessageCommand(commands string, rules ...Rule) *Matcher

OnMessageCommand 命令触发器

func (*Engine) OnMessageCommandGroup

func (e *Engine) OnMessageCommandGroup(commands []string, rules ...Rule) *Matcher

OnMessageCommandGroup 命令触发器组

func (*Engine) OnMessageFullMatch

func (e *Engine) OnMessageFullMatch(src string, rules ...Rule) *Matcher

OnMessageFullMatch 完全匹配触发器

func (*Engine) OnMessageFullMatchGroup

func (e *Engine) OnMessageFullMatchGroup(src []string, rules ...Rule) *Matcher

OnMessageFullMatchGroup 完全匹配触发器组

func (*Engine) OnMessageKeyword

func (e *Engine) OnMessageKeyword(keyword string, rules ...Rule) *Matcher

OnMessageKeyword 关键词触发器

func (*Engine) OnMessageKeywordGroup

func (e *Engine) OnMessageKeywordGroup(keywords []string, rules ...Rule) *Matcher

OnMessageKeywordGroup 关键词触发器组

func (*Engine) OnMessagePrefix

func (e *Engine) OnMessagePrefix(prefix string, rules ...Rule) *Matcher

OnMessagePrefix 前缀触发器

func (*Engine) OnMessagePrefixGroup

func (e *Engine) OnMessagePrefixGroup(prefix []string, rules ...Rule) *Matcher

OnMessagePrefixGroup 前缀触发器组

func (*Engine) OnMessageRegex

func (e *Engine) OnMessageRegex(regexPattern string, rules ...Rule) *Matcher

OnMessageRegex 正则触发器

func (*Engine) OnMessageShell

func (e *Engine) OnMessageShell(command string, model interface{}, rules ...Rule) *Matcher

OnMessageShell shell命令触发器

func (*Engine) OnMessageSuffix

func (e *Engine) OnMessageSuffix(suffix string, rules ...Rule) *Matcher

OnMessageSuffix 后缀触发器

func (*Engine) OnMessageSuffixGroup

func (e *Engine) OnMessageSuffixGroup(suffix []string, rules ...Rule) *Matcher

OnMessageSuffixGroup 后缀触发器组

func (*Engine) OnMyChatMember

func (e *Engine) OnMyChatMember(rules ...Rule) *Matcher

OnMyChatMember ...

func (*Engine) OnPoll

func (e *Engine) OnPoll(rules ...Rule) *Matcher

OnPoll ...

func (*Engine) OnPollAnswer

func (e *Engine) OnPollAnswer(rules ...Rule) *Matcher

OnPollAnswer ...

func (*Engine) OnPreCheckoutQuery

func (e *Engine) OnPreCheckoutQuery(rules ...Rule) *Matcher

OnPreCheckoutQuery ...

func (*Engine) OnShippingQuery

func (e *Engine) OnShippingQuery(rules ...Rule) *Matcher

OnShippingQuery ...

func (*Engine) UseMidHandler

func (e *Engine) UseMidHandler(rules ...Rule)

UseMidHandler 向该 Engine 添加新 MidHandler(Rule), 会在 Rule 判断后, Matcher 触发前触发,如果 midHandler 没有通过,则 Matcher 不会触发

可用于速率限制等

func (*Engine) UsePostHandler

func (e *Engine) UsePostHandler(handler ...Process)

UsePostHandler 向该 Engine 添加新 PostHandler(Rule), 会在 Matcher 触发后触发,如果 PostHandler 返回 false, 则后续的 post handler 不会触发

可用于速率限制等

func (*Engine) UsePreHandler

func (e *Engine) UsePreHandler(rules ...Rule)

UsePreHandler 向该 Engine 添加新 PreHandler(Rule), 会在 Rule 判断前触发,如果 preHandler 没有通过,则 Rule, Matcher 不会触发

可用于分群组管理插件等

type Event

type Event struct {
	// Type is the non-null field name in Update
	Type string
	// UpdateID is the update's unique identifier.
	UpdateID int
	// Value is the non-null field value in Update
	Value any
	// contains filtered or unexported fields
}

Event ...

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 *Ctx

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

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

func (*FutureEvent) Repeat

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

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

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

func (*FutureEvent) Take

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

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

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

type GeneralHandleType

type GeneralHandleType func(int, *TelegramClient, unsafe.Pointer)

type Handler

type Handler struct {
	OnMessage func(updateid int, bot *TelegramClient, msg *tgba.Message)

	OnEditedMessage func(updateid int, bot *TelegramClient, msg *tgba.Message)

	OnChannelPost func(updateid int, bot *TelegramClient, msg *tgba.Message)

	OnEditedChannelPost func(updateid int, bot *TelegramClient, msg *tgba.Message)

	OnInlineQuery func(updateid int, bot *TelegramClient, q *tgba.InlineQuery)

	OnChosenInlineResult func(updateid int, bot *TelegramClient, r *tgba.ChosenInlineResult)

	OnCallbackQuery func(updateid int, bot *TelegramClient, q *tgba.CallbackQuery)

	OnShippingQuery func(updateid int, bot *TelegramClient, q *tgba.ShippingQuery)

	OnPreCheckoutQuery func(updateid int, bot *TelegramClient, q *tgba.PreCheckoutQuery)

	OnPoll func(updateid int, bot *TelegramClient, p *tgba.Poll)

	OnPollAnswer func(updateid int, bot *TelegramClient, pa *tgba.PollAnswer)

	OnMyChatMember func(updateid int, bot *TelegramClient, m *tgba.ChatMemberUpdated)

	OnChatMember func(updateid int, bot *TelegramClient, m *tgba.ChatMemberUpdated)

	OnChatJoinRequest func(updateid int, bot *TelegramClient, r *tgba.ChatJoinRequest)
}

type Manager

type Manager ctrl.Manager[*Ctx]

type Matcher

type Matcher struct {
	// Temp 是否为临时Matcher,临时 Matcher 匹配一次后就会删除当前 Matcher
	Temp bool
	// Block 是否阻断后续 Matcher,为 true 时当前Matcher匹配成功后,后续Matcher不参与匹配
	Block bool
	// Break 是否退出后续匹配流程, 只有 rule 返回 false 且此值为真才会退出, 且不对 mid handler 以下的 rule 生效
	Break bool

	// Event 当前匹配到的事件
	Event *Event
	// Type 匹配的事件类型
	Type string
	// Rules 匹配规则
	Rules []Rule
	// Process 处理事件的函数
	Process Process
	// Engine 注册 Matcher 的 Engine,Engine可为一系列 Matcher 添加通用 Rule 和 其他钩子
	Engine *Engine
	// contains filtered or unexported fields
}

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

func On

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

On 添加新的指定消息类型的匹配器(默认Engine)

func OnCallbackQuery

func OnCallbackQuery(rules ...Rule) *Matcher

OnCallbackQuery ...

func OnCallbackQueryFullMatch

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

OnCallbackQueryFullMatch 完全匹配触发器

func OnCallbackQueryFullMatchGroup

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

OnCallbackQueryFullMatchGroup 完全匹配触发器组

func OnCallbackQueryKeyword

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

OnCallbackQueryKeyword 关键词触发器

func OnCallbackQueryKeywordGroup

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

OnCallbackQueryKeywordGroup 关键词触发器组

func OnCallbackQueryPrefix

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

OnCallbackQueryPrefix 前缀触发器

func OnCallbackQueryPrefixGroup

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

OnCallbackQueryPrefixGroup 前缀触发器组

func OnCallbackQueryRegex

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

OnCallbackQueryRegex 正则触发器

func OnCallbackQuerySuffix

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

OnCallbackQuerySuffix 后缀触发器

func OnCallbackQuerySuffixGroup

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

OnCallbackQuerySuffixGroup 后缀触发器组

func OnChannelPost

func OnChannelPost(rules ...Rule) *Matcher

OnChannelPost ...

func OnChatJoinRequest

func OnChatJoinRequest(rules ...Rule) *Matcher

OnChatJoinRequest ...

func OnChatMember

func OnChatMember(rules ...Rule) *Matcher

OnChatMember ...

func OnChosenInlineResult

func OnChosenInlineResult(rules ...Rule) *Matcher

OnChosenInlineResult ...

func OnEditedChannelPost

func OnEditedChannelPost(rules ...Rule) *Matcher

OnEditedChannelPost ...

func OnEditedMessage

func OnEditedMessage(rules ...Rule) *Matcher

OnEditedMessage 修改消息触发器

func OnInlineQuery

func OnInlineQuery(rules ...Rule) *Matcher

OnInlineQuery ...

func OnMessage

func OnMessage(rules ...Rule) *Matcher

OnMessage 消息触发器

func OnMessageCommand

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

OnMessageCommand 命令触发器

func OnMessageCommandGroup

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

OnMessageCommandGroup 命令触发器组

func OnMessageFullMatch

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

OnMessageFullMatch 完全匹配触发器

func OnMessageFullMatchGroup

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

OnMessageFullMatchGroup 完全匹配触发器组

func OnMessageKeyword

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

OnMessageKeyword 关键词触发器

func OnMessageKeywordGroup

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

OnMessageKeywordGroup 关键词触发器组

func OnMessagePrefix

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

OnMessagePrefix 前缀触发器

func OnMessagePrefixGroup

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

OnMessagePrefixGroup 前缀触发器组

func OnMessageRegex

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

OnMessageRegex 正则触发器

func OnMessageShell

func OnMessageShell(command string, model interface{}, rules ...Rule) *Matcher

OnMessageShell shell命令触发器

func OnMessageSuffix

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

OnMessageSuffix 后缀触发器

func OnMessageSuffixGroup

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

OnMessageSuffixGroup 后缀触发器组

func OnMyChatMember

func OnMyChatMember(rules ...Rule) *Matcher

OnMyChatMember ...

func OnPoll

func OnPoll(rules ...Rule) *Matcher

OnPoll ...

func OnPollAnswer

func OnPollAnswer(rules ...Rule) *Matcher

OnPollAnswer ...

func OnPreCheckoutQuery

func OnPreCheckoutQuery(rules ...Rule) *Matcher

OnPreCheckoutQuery ...

func OnShippingQuery

func OnShippingQuery(rules ...Rule) *Matcher

OnShippingQuery ...

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

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

Handle 直接处理事件

func (*Matcher) Limit

func (m *Matcher) Limit(limiterfn func(*Ctx) *rate.Limiter, postfn ...func(*Ctx)) *Matcher

Limit 限速器

postfn 当请求被拒绝时的操作

func (*Matcher) SetBlock

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

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

type Option

type Option[K comparable] func(*Single[K])

Option 配置项

func WithKeyFn

func WithKeyFn[K comparable](fn func(ctx *Ctx) K) Option[K]

WithKeyFn 指定反并发的 Key

func WithPostFn

func WithPostFn[K comparable](fn func(ctx *Ctx)) Option[K]

WithPostFn 指定反并发拦截后的操作

type Process

type Process func(ctx *Ctx)

Process 事件处理函数

type Rule

type Rule func(ctx *Ctx) bool

Rule filter the event

func CheckChat

func CheckChat(chatId ...int64) Rule

CheckChat only triggered in specific chat

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

this rule only supports tgba.Message

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 MustProvidePhoto

func MustProvidePhoto(needphohint, failhint string) Rule

MustProvidePhoto 消息不存在图片阻塞120秒至有图片,超时返回 false

this rule only supports tgba.Message

func PrefixRule

func PrefixRule(prefixes ...string) Rule

PrefixRule check if the text 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 int) Rule

ReplyRule check if the message is replying some message

this rule only supports tgba.Message

func ShellRule

func ShellRule(cmd string, model interface{}) Rule

ShellRule 定义shell-like规则

this rule only supports tgba.Message

func SuffixRule

func SuffixRule(suffixes ...string) Rule

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

检查消息后缀

type Single

type Single[K comparable] struct {
	// contains filtered or unexported fields
}

Single 反并发

func NewSingle

func NewSingle[K comparable](op ...Option[K]) *Single[K]

NewSingle 创建反并发中间件

func (*Single[K]) Apply

func (s *Single[K]) Apply(engine *Engine)

Apply 为指定 Engine 添加反并发功能

type State

type State map[string]interface{}

State store the context of a matcher.

type TelegramClient

type TelegramClient struct {
	tgba.BotAPI
	// contains filtered or unexported fields
}

TelegramClient ...

func NewTelegramClient

func NewTelegramClient(c *Bot) (tc TelegramClient)

NewTelegramClient ...

func (*TelegramClient) Connect

func (tc *TelegramClient) Connect()

Connect ...

func (*TelegramClient) Listen

func (tc *TelegramClient) Listen()

Listen 开始监听事件

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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