example_concern

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Nov 18, 2021 License: AGPL-3.0 Imports: 7 Imported by: 0

README

Example Concern

这个包包含一个样例concern实现以供参考,支持:

  • /watch -s example -t example ID

使用上面的site和type参数订阅,订阅后每分钟会有50%的概率推送一次订阅的ID

  • /unwatch -s example -t example ID

取消上面的订阅

  • /list

查看当前订阅

使用时需要在main中引入:

_ "github.com/Sora233/DDBOT/_example/concern"

目录结构

notify.go

这个文件通过实现concern.Notify定义了推送的格式

config.go

这个文件重写了concern.Hook,通过FilterHook实现50%概率推送

concern.go

这个文件实现了concern.Concern,并使用了自带的EmitQueue作为状态刷新机制,产生concern.Notify事件,并发送给框架进行推送

Documentation

Index

Constants

View Source
const (
	Site string = "example"

	// Example 定义了本插件支持的一种订阅类型,如果支持多种订阅类型,可以继续定义更多
	Example concern_type.Type = "example"
)

Variables

This section is empty.

Functions

func NewConcern

func NewConcern(notify chan<- concern.Notify) *exampleConcern

NewConcern 返回一个新的 exampleConcern, 推荐像这样将 notify channel 通过参数传进来,方便编写单元测试 此处使用的 concern.NewStateManagerWithStringID 适用于 string 类型的id 如果 ParseId 中选择了int64类型, 则此处可以选择 concern.NewStateManagerWithInt64ID

Types

type Event

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

Event 实现 concern.Event 接口

func (*Event) GetUid

func (e *Event) GetUid() interface{}

func (*Event) Logger

func (e *Event) Logger() *logrus.Entry

func (*Event) Site

func (e *Event) Site() string

func (*Event) Type

func (e *Event) Type() concern_type.Type

type GroupConcernConfig

type GroupConcernConfig struct {
	concern.IConfig
}

GroupConcernConfig 创建一个新结构,准备重写 FilterHook

func NewGroupConcernConfig

func NewGroupConcernConfig(g concern.IConfig) *GroupConcernConfig

NewGroupConcernConfig 创建一个新的 GroupConcernConfig

func (*GroupConcernConfig) FilterHook

FilterHook 自定义推送过滤逻辑

type Notify

type Notify struct {
	Event
	// contains filtered or unexported fields
}

Notify 实现 concern.Notify 接口

func (*Notify) GetGroupCode

func (n *Notify) GetGroupCode() int64

func (*Notify) Logger

func (n *Notify) Logger() *logrus.Entry

func (*Notify) ToMessage

func (n *Notify) ToMessage() *mmsg.MSG

Jump to

Keyboard shortcuts

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