Documentation ¶
Overview ¶
Package rei ReiBot created in 2022.5.31
Index ¶
- func AdminPermission(ctx *Ctx) bool
- func CreaterPermission(ctx *Ctx) bool
- func Delete(service string)
- func ForEachByPrio(iterator func(i int, manager *ctrl.Control[*Ctx]) bool)
- func IsPhoto(ctx *Ctx) bool
- func Lookup(service string) (*ctrl.Control[*Ctx], bool)
- func OnlyChannel(ctx *Ctx) bool
- func OnlyGroup(ctx *Ctx) bool
- func OnlyPrivate(ctx *Ctx) bool
- func OnlyPublic(ctx *Ctx) bool
- func OnlySuperGroup(ctx *Ctx) bool
- func OnlyToMe(ctx *Ctx) bool
- func ParseShell(s string) []string
- func RangeBot(iter func(id int64, ctx *Ctx) bool)
- func Run(bots ...Bot)
- func Start(bots ...Bot)
- func SuperUserPermission(ctx *Ctx) bool
- func UserOrGrpAdmin(ctx *Ctx) bool
- type Bot
- type Ctx
- func (ctx *Ctx) Block()
- func (ctx *Ctx) Break()
- func (ctx *Ctx) CheckSession() Rule
- func (ctx *Ctx) Parse(model interface{}) (err error)
- func (ctx *Ctx) Send(replytosender bool, c tgba.Chattable) (tgba.Message, error)
- func (ctx *Ctx) SendAudio(file tgba.RequestFileData, replytosender bool, caption string, ...) (tgba.Message, error)
- func (ctx *Ctx) SendMessage(replytosender bool, text string, entities ...tgba.MessageEntity) (tgba.Message, error)
- func (ctx *Ctx) SendPhoto(file tgba.RequestFileData, replytosender bool, caption string, ...) (tgba.Message, error)
- func (ctx *Ctx) SendPlainMessage(replytosender bool, printable ...any) (tgba.Message, error)
- type Engine
- func (e *Engine) ApplySingle(s *Single[int64]) *Engine
- func (e *Engine) DataFolder() string
- func (e *Engine) Delete()
- func (e *Engine) GetLazyData(filename string, isDataMustEqual bool) ([]byte, error)
- func (e *Engine) On(typ string, rules ...Rule) *Matcher
- func (e *Engine) OnCallbackQuery(rules ...Rule) *Matcher
- func (e *Engine) OnCallbackQueryFullMatch(src string, rules ...Rule) *Matcher
- func (e *Engine) OnCallbackQueryFullMatchGroup(src []string, rules ...Rule) *Matcher
- func (e *Engine) OnCallbackQueryKeyword(keyword string, rules ...Rule) *Matcher
- func (e *Engine) OnCallbackQueryKeywordGroup(keywords []string, rules ...Rule) *Matcher
- func (e *Engine) OnCallbackQueryPrefix(prefix string, rules ...Rule) *Matcher
- func (e *Engine) OnCallbackQueryPrefixGroup(prefix []string, rules ...Rule) *Matcher
- func (e *Engine) OnCallbackQueryRegex(regexPattern string, rules ...Rule) *Matcher
- func (e *Engine) OnCallbackQuerySuffix(suffix string, rules ...Rule) *Matcher
- func (e *Engine) OnCallbackQuerySuffixGroup(suffix []string, rules ...Rule) *Matcher
- func (e *Engine) OnChannelPost(rules ...Rule) *Matcher
- func (e *Engine) OnChatJoinRequest(rules ...Rule) *Matcher
- func (e *Engine) OnChatMember(rules ...Rule) *Matcher
- func (e *Engine) OnChosenInlineResult(rules ...Rule) *Matcher
- func (e *Engine) OnEditedChannelPost(rules ...Rule) *Matcher
- func (e *Engine) OnEditedMessage(rules ...Rule) *Matcher
- func (e *Engine) OnInlineQuery(rules ...Rule) *Matcher
- func (e *Engine) OnMessage(rules ...Rule) *Matcher
- func (e *Engine) OnMessageCommand(commands string, rules ...Rule) *Matcher
- func (e *Engine) OnMessageCommandGroup(commands []string, rules ...Rule) *Matcher
- func (e *Engine) OnMessageFullMatch(src string, rules ...Rule) *Matcher
- func (e *Engine) OnMessageFullMatchGroup(src []string, rules ...Rule) *Matcher
- func (e *Engine) OnMessageKeyword(keyword string, rules ...Rule) *Matcher
- func (e *Engine) OnMessageKeywordGroup(keywords []string, rules ...Rule) *Matcher
- func (e *Engine) OnMessagePrefix(prefix string, rules ...Rule) *Matcher
- func (e *Engine) OnMessagePrefixGroup(prefix []string, rules ...Rule) *Matcher
- func (e *Engine) OnMessageRegex(regexPattern string, rules ...Rule) *Matcher
- func (e *Engine) OnMessageShell(command string, model interface{}, rules ...Rule) *Matcher
- func (e *Engine) OnMessageSuffix(suffix string, rules ...Rule) *Matcher
- func (e *Engine) OnMessageSuffixGroup(suffix []string, rules ...Rule) *Matcher
- func (e *Engine) OnMyChatMember(rules ...Rule) *Matcher
- func (e *Engine) OnPoll(rules ...Rule) *Matcher
- func (e *Engine) OnPollAnswer(rules ...Rule) *Matcher
- func (e *Engine) OnPreCheckoutQuery(rules ...Rule) *Matcher
- func (e *Engine) OnShippingQuery(rules ...Rule) *Matcher
- func (e *Engine) UseMidHandler(rules ...Rule)
- func (e *Engine) UsePostHandler(handler ...Process)
- func (e *Engine) UsePreHandler(rules ...Rule)
- type Event
- type FutureEvent
- type GeneralHandleType
- type Handler
- type Manager
- type Matcher
- func On(typ string, rules ...Rule) *Matcher
- func OnCallbackQuery(rules ...Rule) *Matcher
- func OnCallbackQueryFullMatch(src string, rules ...Rule) *Matcher
- func OnCallbackQueryFullMatchGroup(src []string, rules ...Rule) *Matcher
- func OnCallbackQueryKeyword(keyword string, rules ...Rule) *Matcher
- func OnCallbackQueryKeywordGroup(keywords []string, rules ...Rule) *Matcher
- func OnCallbackQueryPrefix(prefix string, rules ...Rule) *Matcher
- func OnCallbackQueryPrefixGroup(prefix []string, rules ...Rule) *Matcher
- func OnCallbackQueryRegex(regexPattern string, rules ...Rule) *Matcher
- func OnCallbackQuerySuffix(suffix string, rules ...Rule) *Matcher
- func OnCallbackQuerySuffixGroup(suffix []string, rules ...Rule) *Matcher
- func OnChannelPost(rules ...Rule) *Matcher
- func OnChatJoinRequest(rules ...Rule) *Matcher
- func OnChatMember(rules ...Rule) *Matcher
- func OnChosenInlineResult(rules ...Rule) *Matcher
- func OnEditedChannelPost(rules ...Rule) *Matcher
- func OnEditedMessage(rules ...Rule) *Matcher
- func OnInlineQuery(rules ...Rule) *Matcher
- func OnMessage(rules ...Rule) *Matcher
- func OnMessageCommand(commands string, rules ...Rule) *Matcher
- func OnMessageCommandGroup(commands []string, rules ...Rule) *Matcher
- func OnMessageFullMatch(src string, rules ...Rule) *Matcher
- func OnMessageFullMatchGroup(src []string, rules ...Rule) *Matcher
- func OnMessageKeyword(keyword string, rules ...Rule) *Matcher
- func OnMessageKeywordGroup(keywords []string, rules ...Rule) *Matcher
- func OnMessagePrefix(prefix string, rules ...Rule) *Matcher
- func OnMessagePrefixGroup(prefix []string, rules ...Rule) *Matcher
- func OnMessageRegex(regexPattern string, rules ...Rule) *Matcher
- func OnMessageShell(command string, model interface{}, rules ...Rule) *Matcher
- func OnMessageSuffix(suffix string, rules ...Rule) *Matcher
- func OnMessageSuffixGroup(suffix []string, rules ...Rule) *Matcher
- func OnMyChatMember(rules ...Rule) *Matcher
- func OnPoll(rules ...Rule) *Matcher
- func OnPollAnswer(rules ...Rule) *Matcher
- func OnPreCheckoutQuery(rules ...Rule) *Matcher
- func OnShippingQuery(rules ...Rule) *Matcher
- func StoreMatcher(m *Matcher) *Matcher
- func StoreTempMatcher(m *Matcher) *Matcher
- type Option
- type Process
- type Rule
- func CheckChat(chatId ...int64) Rule
- func CheckUser(userId ...int64) Rule
- func CommandRule(commands ...string) Rule
- func FullMatchRule(src ...string) Rule
- func KeywordRule(src ...string) Rule
- func MustProvidePhoto(needphohint, failhint string) Rule
- func PrefixRule(prefixes ...string) Rule
- func RegexRule(regexPattern string) Rule
- func ReplyRule(messageID int) Rule
- func ShellRule(cmd string, model interface{}) Rule
- func SuffixRule(suffixes ...string) Rule
- type Single
- type State
- type TelegramClient
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AdminPermission ¶
AdminPermission only triggered by the group admins or higher permission
func CreaterPermission ¶
CreaterPermission only triggered by the group creater or higher permission
func ForEachByPrio ¶
ForEachByPrio iterates through managers by their priority.
func OnlyChannel ¶
OnlyChannel requires that the ctx.Event is channel message
func OnlyPrivate ¶
OnlyPrivate requires that the ctx.Event is private message
func OnlyPublic ¶
OnlyPublic requires that the ctx.Event is group or supergroup message
func OnlySuperGroup ¶
OnlySuperGroup requires that the ctx.Event is supergroup message
func OnlyToMe ¶
OnlyToMe only triggered in conditions of @bot or begin with the nicknames
this rule only supports tgba.Message
func ParseShell ¶
ParseShell 将指令转换为指令参数. modified from https://github.com/mattn/go-shellwords
func SuperUserPermission ¶
SuperUserPermission only triggered by the bot's owner
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 (*Ctx) Send ¶
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 发送富文本消息到对方
type Engine ¶
type Engine struct {
// contains filtered or unexported fields
}
Engine is the pre_handler, mid_handler, post_handler manager
func (*Engine) ApplySingle ¶
ApplySingle 应用反并发
func (*Engine) GetLazyData ¶
下载并获取本 engine 文件夹下的懒加载数据
func (*Engine) OnCallbackQuery ¶
OnCallbackQuery ...
func (*Engine) OnCallbackQueryFullMatch ¶
OnCallbackQueryFullMatch 完全匹配触发器
func (*Engine) OnCallbackQueryFullMatchGroup ¶
OnCallbackQueryFullMatchGroup 完全匹配触发器组
func (*Engine) OnCallbackQueryKeyword ¶
OnCallbackQueryKeyword 关键词触发器
func (*Engine) OnCallbackQueryKeywordGroup ¶
OnCallbackQueryKeywordGroup 关键词触发器组
func (*Engine) OnCallbackQueryPrefix ¶
OnCallbackQueryPrefix 前缀触发器
func (*Engine) OnCallbackQueryPrefixGroup ¶
OnCallbackQueryPrefixGroup 前缀触发器组
func (*Engine) OnCallbackQueryRegex ¶
OnCallbackQueryRegex 正则触发器
func (*Engine) OnCallbackQuerySuffix ¶
OnCallbackQuerySuffix 后缀触发器
func (*Engine) OnCallbackQuerySuffixGroup ¶
OnCallbackQuerySuffixGroup 后缀触发器组
func (*Engine) OnChannelPost ¶
OnChannelPost ...
func (*Engine) OnChatJoinRequest ¶
OnChatJoinRequest ...
func (*Engine) OnChatMember ¶
OnChatMember ...
func (*Engine) OnChosenInlineResult ¶
OnChosenInlineResult ...
func (*Engine) OnEditedChannelPost ¶
OnEditedChannelPost ...
func (*Engine) OnEditedMessage ¶
OnEditedMessage 修改消息触发器
func (*Engine) OnInlineQuery ¶
OnInlineQuery ...
func (*Engine) OnMessageCommand ¶
OnMessageCommand 命令触发器
func (*Engine) OnMessageCommandGroup ¶
OnMessageCommandGroup 命令触发器组
func (*Engine) OnMessageFullMatch ¶
OnMessageFullMatch 完全匹配触发器
func (*Engine) OnMessageFullMatchGroup ¶
OnMessageFullMatchGroup 完全匹配触发器组
func (*Engine) OnMessageKeyword ¶
OnMessageKeyword 关键词触发器
func (*Engine) OnMessageKeywordGroup ¶
OnMessageKeywordGroup 关键词触发器组
func (*Engine) OnMessagePrefix ¶
OnMessagePrefix 前缀触发器
func (*Engine) OnMessagePrefixGroup ¶
OnMessagePrefixGroup 前缀触发器组
func (*Engine) OnMessageRegex ¶
OnMessageRegex 正则触发器
func (*Engine) OnMessageShell ¶
OnMessageShell shell命令触发器
func (*Engine) OnMessageSuffix ¶
OnMessageSuffix 后缀触发器
func (*Engine) OnMessageSuffixGroup ¶
OnMessageSuffixGroup 后缀触发器组
func (*Engine) OnMyChatMember ¶
OnMyChatMember ...
func (*Engine) OnPollAnswer ¶
OnPollAnswer ...
func (*Engine) OnPreCheckoutQuery ¶
OnPreCheckoutQuery ...
func (*Engine) OnShippingQuery ¶
OnShippingQuery ...
func (*Engine) UseMidHandler ¶
UseMidHandler 向该 Engine 添加新 MidHandler(Rule), 会在 Rule 判断后, Matcher 触发前触发,如果 midHandler 没有通过,则 Matcher 不会触发
可用于速率限制等
func (*Engine) UsePostHandler ¶
UsePostHandler 向该 Engine 添加新 PostHandler(Rule), 会在 Matcher 触发后触发,如果 PostHandler 返回 false, 则后续的 post handler 不会触发
可用于速率限制等
func (*Engine) UsePreHandler ¶
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 ¶
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 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 OnCallbackQueryFullMatch ¶
OnCallbackQueryFullMatch 完全匹配触发器
func OnCallbackQueryFullMatchGroup ¶
OnCallbackQueryFullMatchGroup 完全匹配触发器组
func OnCallbackQueryKeyword ¶
OnCallbackQueryKeyword 关键词触发器
func OnCallbackQueryKeywordGroup ¶
OnCallbackQueryKeywordGroup 关键词触发器组
func OnCallbackQueryPrefix ¶
OnCallbackQueryPrefix 前缀触发器
func OnCallbackQueryPrefixGroup ¶
OnCallbackQueryPrefixGroup 前缀触发器组
func OnCallbackQueryRegex ¶
OnCallbackQueryRegex 正则触发器
func OnCallbackQuerySuffix ¶
OnCallbackQuerySuffix 后缀触发器
func OnCallbackQuerySuffixGroup ¶
OnCallbackQuerySuffixGroup 后缀触发器组
func OnChosenInlineResult ¶
OnChosenInlineResult ...
func OnMessageCommand ¶
OnMessageCommand 命令触发器
func OnMessageCommandGroup ¶
OnMessageCommandGroup 命令触发器组
func OnMessageFullMatch ¶
OnMessageFullMatch 完全匹配触发器
func OnMessageFullMatchGroup ¶
OnMessageFullMatchGroup 完全匹配触发器组
func OnMessageKeyword ¶
OnMessageKeyword 关键词触发器
func OnMessageKeywordGroup ¶
OnMessageKeywordGroup 关键词触发器组
func OnMessagePrefix ¶
OnMessagePrefix 前缀触发器
func OnMessagePrefixGroup ¶
OnMessagePrefixGroup 前缀触发器组
func OnMessageRegex ¶
OnMessageRegex 正则触发器
func OnMessageShell ¶
OnMessageShell shell命令触发器
func OnMessageSuffix ¶
OnMessageSuffix 后缀触发器
func OnMessageSuffixGroup ¶
OnMessageSuffixGroup 后缀触发器组
func StoreMatcher ¶
StoreMatcher store a matcher to matcher list.
func StoreTempMatcher ¶
StoreTempMatcher store a matcher only triggered once.
func (*Matcher) FutureEvent ¶
func (m *Matcher) FutureEvent(Type string, rule ...Rule) *FutureEvent
FutureEvent 返回一个 FutureEvent 实例指针,用于获取满足 Rule 的 未来事件
type Rule ¶
Rule filter the event
func CommandRule ¶
CommandRule check if the message is a command and trim the command name
this rule only supports tgba.Message
func FullMatchRule ¶
FullMatchRule check if src has the same copy of the message
func KeywordRule ¶
KeywordRule check if the message has a keyword or keywords
func MustProvidePhoto ¶
MustProvidePhoto 消息不存在图片阻塞120秒至有图片,超时返回 false
this rule only supports tgba.Message
func ReplyRule ¶
ReplyRule check if the message is replying some message
this rule only supports tgba.Message
type Single ¶
type Single[K comparable] struct { // contains filtered or unexported fields }
Single 反并发
type TelegramClient ¶
TelegramClient ...