history

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Nov 16, 2019 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Reverse

func Reverse(results []Item)

Reverse reverses an []Item, in-place.

Types

type Buffer

type Buffer struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

Buffer is a ring buffer holding message/event history for a channel or user

func NewHistoryBuffer

func NewHistoryBuffer(size int, window time.Duration) (result *Buffer)

func (*Buffer) Add

func (list *Buffer) Add(item Item)

Add adds a history item to the buffer

func (*Buffer) Between

func (list *Buffer) Between(after, before time.Time, ascending bool, limit int) (results []Item, complete bool)

Between returns all history items with a time `after` <= time <= `before`, with an indication of whether the results are complete or are missing items because some of that period was discarded. A zero value of `before` is considered higher than all other times.

func (*Buffer) Enabled

func (list *Buffer) Enabled() bool

Enabled returns whether the buffer is currently storing messages (a disabled buffer blackholes everything it sees)

func (*Buffer) Initialize

func (hist *Buffer) Initialize(size int, window time.Duration)

func (*Buffer) LastDiscarded

func (list *Buffer) LastDiscarded() time.Time

LastDiscarded returns the latest time of any entry that was evicted from the ring buffer.

func (*Buffer) Latest

func (list *Buffer) Latest(limit int) (results []Item)

Latest returns the items most recently added, up to `limit`. If `limit` is 0, it returns all items.

func (*Buffer) Match

func (list *Buffer) Match(predicate Predicate, ascending bool, limit int) (results []Item)

Match returns all history items such that `predicate` returns true for them. Items are considered in reverse insertion order if `ascending` is false, or in insertion order if `ascending` is true, up to a total of `limit` matches if `limit` > 0 (unlimited otherwise). `predicate` MAY be a closure that maintains its own state across invocations; it MUST NOT acquire any locks or otherwise do anything weird. Results are always returned in insertion order.

func (*Buffer) Resize

func (list *Buffer) Resize(maximumSize int, window time.Duration)

Resize shrinks or expands the buffer

type Item

type Item struct {
	Type ItemType

	Nick string
	// this is the uncasefolded account name, if there's no account it should be set to "*"
	AccountName string
	// for non-privmsg items, we may stuff some other data in here
	Message utils.SplitMessage
	Tags    map[string]string
	Params  [1]string
}

Item represents an event (e.g., a PRIVMSG or a JOIN) and its associated data

func (*Item) HasMsgid

func (item *Item) HasMsgid(msgid string) bool

HasMsgid tests whether a message has the message id `msgid`.

type ItemType

type ItemType uint
const (
	Privmsg ItemType
	Notice
	Join
	Part
	Kick
	Quit
	Mode
	Tagmsg
	Nick
)

type Predicate

type Predicate func(item Item) (matches bool)

Jump to

Keyboard shortcuts

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