bot

package
v0.4.11 Latest Latest
Warning

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

Go to latest
Published: Jul 31, 2023 License: MIT Imports: 27 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddHttpRouteHandler added in v0.4.0

func AddHttpRouteHandler(path, addr string, handler func(*gin.Context) bool)

新增一个http路由,用于与机器人同时运行,避免占用同一个端口,以及允许使用短路机制处理请求 path: 路由路径 addr: 路由地址 handler: 路由处理器,返回true则短路,返回false则继续执行(系统将在所有同路径端口的handler都不短路后再处理消息)

func RemoveHttpRouteHandler added in v0.4.0

func RemoveHttpRouteHandler(path, addr string, handler func(*gin.Context) bool)

func StartAll added in v0.4.0

func StartAll()

开始运行所有机器人和 HTTP 服务器

func StartAllBot

func StartAllBot()

func StartAllHttpServer added in v0.4.0

func StartAllHttpServer()

Types

type Bot added in v0.4.10

type Bot struct {
	Base models.BotBase // 机器人基本信息

	Api    *apis.ApiBase          // api接口
	Logger logger.LoggerInterface // 日志记录器
	// contains filtered or unexported fields
}

func NewBot

func NewBot(bot_id, bot_secret, bot_pubkey, path, addr string) *Bot

NewBot 创建一个机器人实例,bot_id 为机器人的id,bot_secret 为机器人的secret,path 为接收事件的路径(如"/"),addr 为接收事件的地址(如":8888"); 机器人实例创建后,需要调用 Run() 方法启动机器人; 对于消息处理,可以通过 AddPreprocessor() 方法添加预处理器,通过 AddOnCommand() 方法添加命令处理器,通过 AddListener() 方法添加事件监听器; 对于插件,可以通过 AddPlugin() 方法添加插件; 整体消息处理的运行与短路顺序为: [main]预处理器 -> [插件]预处理器 -> [插件]令处理器 -> [main]命令处理器 -> [main]事件监听器;

func (*Bot) AddListenerAddQuickEmoticon added in v0.4.10

func (_bot *Bot) AddListenerAddQuickEmoticon(listener events.BotListenerAddQuickEmoticon)

func (*Bot) AddListenerAuditCallback added in v0.4.10

func (_bot *Bot) AddListenerAuditCallback(listener events.BotListenerAuditCallback)

func (*Bot) AddListenerCreateRobot added in v0.4.10

func (_bot *Bot) AddListenerCreateRobot(listener events.BotListenerCreateRobot)

func (*Bot) AddListenerDeleteRobot added in v0.4.10

func (_bot *Bot) AddListenerDeleteRobot(listener events.BotListenerDeleteRobot)

func (*Bot) AddListenerJoinVilla added in v0.4.10

func (_bot *Bot) AddListenerJoinVilla(listener events.BotListenerJoinVilla)

func (*Bot) AddListenerSendMessage added in v0.4.10

func (_bot *Bot) AddListenerSendMessage(listener events.BotListenerSendMessage)

func (*Bot) AddOnCommand added in v0.4.10

func (_bot *Bot) AddOnCommand(plugin commands.OnCommand) error

func (*Bot) AddPreprocessor added in v0.4.10

func (_bot *Bot) AddPreprocessor(preprocessor commands.Preprocessor) error

func (*Bot) AddlistenerRawRequest added in v0.4.10

func (_bot *Bot) AddlistenerRawRequest(listener events.BotListenerRawRequest)

不对回调请求进行任何处理,直接返回到这里注册的监听器,允许用户自行处理回调请求(注意:将根据端口和路径发送回调请求,如使用同端口同路径多机器人,请自行分辨机器人)

func (*Bot) CancelWaitForCommand added in v0.4.10

func (_bot *Bot) CancelWaitForCommand(identify string) error

取消等待特定指令的注册

func (*Bot) GetPluginNames added in v0.4.10

func (_bot *Bot) GetPluginNames() []string

func (*Bot) RemoveListenerAddQuickEmoticon added in v0.4.10

func (_bot *Bot) RemoveListenerAddQuickEmoticon(listener events.BotListenerAddQuickEmoticon)

func (*Bot) RemoveListenerAuditCallback added in v0.4.10

func (_bot *Bot) RemoveListenerAuditCallback(listener events.BotListenerAuditCallback)

func (*Bot) RemoveListenerCreateRobot added in v0.4.10

func (_bot *Bot) RemoveListenerCreateRobot(listener events.BotListenerCreateRobot)

func (*Bot) RemoveListenerDeleteRobot added in v0.4.10

func (_bot *Bot) RemoveListenerDeleteRobot(listener events.BotListenerDeleteRobot)

func (*Bot) RemoveListenerJoinVilla added in v0.4.10

func (_bot *Bot) RemoveListenerJoinVilla(listener events.BotListenerJoinVilla)

func (*Bot) RemoveListenerSendMessage added in v0.4.10

func (_bot *Bot) RemoveListenerSendMessage(listener events.BotListenerSendMessage)

func (*Bot) RemoveOnCommand added in v0.4.10

func (_bot *Bot) RemoveOnCommand(plugin commands.OnCommand) error

func (*Bot) RemovePreprocessor added in v0.4.10

func (_bot *Bot) RemovePreprocessor(preprocessor commands.Preprocessor) error

func (*Bot) RemovelistenerRawRequest added in v0.4.10

func (_bot *Bot) RemovelistenerRawRequest(listener events.BotListenerRawRequest)

func (*Bot) SetAPITimeout added in v0.4.10

func (_bot *Bot) SetAPITimeout(timeout time.Duration)

设置API的超时时间,默认为1分钟

func (*Bot) SetFilterSelfMsg added in v0.4.10

func (_bot *Bot) SetFilterSelfMsg(is_filter bool)

设置是否过滤自己发送的消息,默认为true

func (*Bot) SetLogger added in v0.4.10

func (_bot *Bot) SetLogger(logger logger.LoggerInterface)

设置bot的日志记录器,默认为os.Stdout+一个log档案

func (*Bot) SetPluginEnabled added in v0.4.10

func (_bot *Bot) SetPluginEnabled(plugin_name string, is_enable bool)

设置是否启用某一插件

func (*Bot) SetPluginsShortCircuitAffectMain added in v0.4.10

func (_bot *Bot) SetPluginsShortCircuitAffectMain(is_affect bool)

设置插件中的指令短路是否会影响主程序其余指令和监听器的执行,默认为false

func (*Bot) SetUseDefaultLogger added in v0.4.10

func (_bot *Bot) SetUseDefaultLogger(is_use bool)

设置是否使用默认的日志记录器,默认为false

func (*Bot) SetVerifyMsgSignature added in v0.4.10

func (_bot *Bot) SetVerifyMsgSignature(is_verify bool)

设置是否验证消息签名,默认为true

func (*Bot) Start added in v0.4.10

func (_bot *Bot) Start() error

func (*Bot) WaitForCommand added in v0.4.10

func (_bot *Bot) WaitForCommand(reg models.WaitForCommandRegister) (*events.EventSendMessage, error)

等待特定指令的触发,并回传触发该指令的消息事件(或超时错误); 用于暂停处理当前消息链,等待特定指令的触发或超时再回复

Jump to

Keyboard shortcuts

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