replier

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Feb 21, 2021 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package replier provides the delayed replier.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Cancel

func Cancel(ctx *plugin.Context)

Cancel cancels the replier, making ongoing calls to one of the Reply methods return errors.Abort.

func NewMiddleware

func NewMiddleware(o *Options) bot.MiddlewareFunc

NewMiddleware creates a new middleware for the passed *Replier, that stores the replier in the *plugin.Context.

func NoSplit

func NoSplit(message string) []string

NoSplit is a Splitter that never splits a message.

func Reply

func Reply(ctx *plugin.Context, content string) ([]discord.Message, error)

Reply sends a textual reply in the invoking channel. The passed content may be split in accordance with the SplitterFunc defined in the replier's Options.

func ReplyDM

func ReplyDM(ctx *plugin.Context, content string) ([]discord.Message, error)

ReplyDM sends a textual reply in a direct message channel with the invoking user. The passed content may be split in accordance with the SplitterFunc defined in the replier's Options.

func ReplyDMWithDelay

func ReplyDMWithDelay(ctx *plugin.Context, content string, f DelayFunc) ([]discord.Message, error)

ReplyDMWithDelay is the same as Reply, but uses the passed DelayFunc instead of the replier's default.

func ReplyWithDelay

func ReplyWithDelay(ctx *plugin.Context, content string, f DelayFunc) ([]discord.Message, error)

ReplyWithDelay is the same as Reply, but uses the passed DelayFunc instead of the replier's default.

Types

type DelayFunc

type DelayFunc func(message string) time.Duration

DelayFunc is the function type used to calculate how long a specific message shall be delayed.

func RandomizedDelay

func RandomizedDelay(runeDelay time.Duration, randomFactor float64) DelayFunc

RandomizedDelay returns a delay that consists of a fixed character-based delay.

func StaticDelay

func StaticDelay(d time.Duration) DelayFunc

StaticDelay is a DelayFunc that always returns the same delay.

type Options

type Options struct {
	// DefaultDelayFunc is the DelayFunc used if no replacement was
	// provided.
	//
	// Default: RandomizedDelay(500*time.Millesecond, 0.1)
	DefaultDelayFunc DelayFunc
	// Splitter is the Splitter used to split messages.
	//
	// Default: NoSplit
	Splitter Splitter
	// NoTyping specifies that no typing event shall be sent.
	//
	// Default: false
	NoTyping bool
}

Options holds the configuration of the replier.

type Splitter

type Splitter func(message string) []string

Splitter is the function used to split messages into smaller ones.

func FieldsFuncSplitter

func FieldsFuncSplitter(f func(rune) bool) Splitter

FieldsFuncSplitter creates a new Splitter that splits, as if f was handed to strings.FieldsFunc.

Jump to

Keyboard shortcuts

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