channel

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Dec 14, 2024 License: GPL-3.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNotCopypasta = errors.New("not copypasta")

ErrNotCopypasta is a sentinel error returned by MemeDetector.Check when a message is not copypasta.

Functions

This section is empty.

Types

type Channel

type Channel struct {
	// Name is the name of the channel.
	Name string
	// Message sends a message to the channel with an optional reply message ID.
	Message func(ctx context.Context, msg message.Sent)
	// Learn and Send are the channel tags.
	Learn, Send string
	// Block is a regex that matches messages which should not be used for
	// learning or copypasta.
	Block *regexp.Regexp
	// Meme is a regex that matches messages which bypass Block only for copypasta.
	Meme *regexp.Regexp
	// Responses is the probability that a received message will trigger a
	// random response.
	Responses float64
	// Rate is the rate limiter for messages. Attempts to speak in excess of
	// the rate limit are dropped.
	Rate *rate.Limiter
	// Ignore is the set of ignored user IDs.
	Ignore map[string]bool
	// Mod is the set of designated moderators' user IDs.
	Mod map[string]bool
	// History is a list of recent messages seen in the channel.
	// Note that messages which are forgotten due to moderation are not removed
	// from this list in general.
	History History[*message.Received[message.User]]
	// Memery is the meme detector for the channel.
	Memery *MemeDetector
	// Emotes is the distribution of emotes.
	Emotes *pick.Dist[string]
	// Effects is the distribution of effects.
	Effects *pick.Dist[string]
	// Silent is the earliest time that speaking and learning is allowed in the
	// channel as nanoseconds from the Unix epoch.
	Silent atomic.Int64
	// Extra is extra channel data that may be added by commands.
	Extra sync.Map // map[any]any; key is a type
	// Enabled indicates whether a channel is allowed to learn messages.
	Enabled atomic.Bool
}

func (*Channel) SilentTime

func (ch *Channel) SilentTime() time.Time

type History

type History[M any] struct {
	// contains filtered or unexported fields
}

History is a history of recent messages. Entries automatically expire after fifteen minutes.

func (*History[M]) Add

func (h *History[M]) Add(now time.Time, msg M)

func (*History[M]) All

func (h *History[M]) All() iter.Seq[M]

All yields the messages in the history, approximately in order from oldest to newest.

type MemeDetector

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

MemeDetector is literally a meme detector.

func NewMemeDetector

func NewMemeDetector(need int, within time.Duration) *MemeDetector

NewMemeDetector creates.

func (*MemeDetector) Block

func (m *MemeDetector) Block(t time.Time, msg string)

Block adds a message as a meme directly, preventing its reuse for fifteen minutes from t.

func (*MemeDetector) Check

func (m *MemeDetector) Check(t time.Time, from, msg string) error

Check determines whether a message is a meme. If it is not, the returned error is NotCopypasta. Times passed to Check should be monotonic, as messages outside the detector's threshold are removed.

func (*MemeDetector) Unblock

func (m *MemeDetector) Unblock(msg string)

Unblock removes a message as a meme, allowing its reuse immediately.

Jump to

Keyboard shortcuts

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