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 ¶
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.
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.
Click to show internal directories.
Click to hide internal directories.