bot

package
v0.0.0-...-5e00ec5 Latest Latest
Warning

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

Go to latest
Published: Jul 1, 2023 License: AGPL-3.0, AGPL-3.0-or-later Imports: 26 Imported by: 5

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrSMSRequestError = errors.New("sms request error")

ErrSMSRequestError SMS请求出错

Functions

func GenRandomDevice

func GenRandomDevice()

GenRandomDevice 生成随机设备信息

func Init

func Init()

Init 快速初始化 使用 config.GlobalConfig 初始化账号 使用 ./device.json 初始化设备信息

func Login

func Login()

Login 登录

func RefreshList

func RefreshList()

RefreshList 刷新联系人

func RegisterModule

func RegisterModule(instance Module)

RegisterModule - 向全局添加 Module

func StartService

func StartService()

StartService 启动服务 根据 Module 生命周期 此过程应在Login前调用 请勿重复调用

func Stop

func Stop()

Stop 停止所有服务 调用此函数并不会使Bot离线

func UseDevice

func UseDevice(device []byte) error

UseDevice 使用 device 进行初始化设备信息

Types

type Bot

type Bot struct {
	*client.QQClient
	// contains filtered or unexported fields
}

Bot 全局 Bot

var Instance *Bot

Instance Bot 实例

func (*Bot) ReLogin

func (bot *Bot) ReLogin(e *client.ClientDisconnectedEvent) error

ReLogin 掉线时可以尝试使用会话缓存重新登陆,只允许在OnDisconnected中调用

type Module

type Module interface {
	MiraiGoModule() ModuleInfo

	// Init 初始化
	// 待所有 Module 初始化完成后
	// 进行服务注册 Serve
	Init()

	// PostInit 第二次初始化
	// 调用该函数时,所有 Module 都已完成第一段初始化过程
	// 方便进行跨Module调用
	PostInit()

	// Serve 向Bot注册服务函数
	// 结束后调用 Start
	Serve(bot *Bot)

	// Start 启用Module
	// 此处调用为
	// “` go
	// go Start()
	// “`
	// 结束后进行登录
	Start(bot *Bot)

	// Stop 应用结束时对所有 Module 进行通知
	// 在此进行资源回收
	Stop(bot *Bot, wg *sync.WaitGroup)
}

Module MiraiGo 中的模块 用于进行模块化设计

type ModuleID

type ModuleID string

ModuleID 模块ID 请使用 小写 并用 _ 代替空格 Example: - logiase.autoreply

func (ModuleID) Name

func (id ModuleID) Name() string

Name - 获取一个 Module 的 Name

func (ModuleID) Namespace

func (id ModuleID) Namespace() string

Namespace - 获取一个 Module 的 Namespace

type ModuleInfo

type ModuleInfo struct {
	// ID 模块的名称
	// 应全局唯一
	ID ModuleID

	// Instance 返回 Module
	Instance Module
}

ModuleInfo 模块信息

func GetModule

func GetModule(name string) (ModuleInfo, error)

GetModule - 获取一个已注册的 Module 的 ModuleInfo

func (ModuleInfo) String

func (mi ModuleInfo) String() string

Jump to

Keyboard shortcuts

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