db

package
v0.0.0-...-457133c Latest Latest
Warning

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

Go to latest
Published: Mar 21, 2023 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DBClearLoop

func DBClearLoop(c chan bool)

func DeleteMessage

func DeleteMessage(id string)

Remove a message from the message pool

func DeleteMessagesByAuthor

func DeleteMessagesByAuthor(userID string)

Remove all the messages from the pool by author 'userID'

func Init

func Init()

Types

type Author

type Author struct {
	ID          string    `json:"id"`
	Name        string    `json:"name"`
	Color       string    `json:"color"`
	Pronouns    pronoun   `json:"pronouns"`
	TimeFetched time.Time `json:"-"`
}

func ProcessAuthor

func ProcessAuthor(raw *twitch.User) *Author

Parse a raw twitch user into a local author. If the db contains the user & they has not expired, it will return the already made author.

func (Author) String

func (a Author) String() string

type DB

type DB struct {
	Messages         map[string]*Message
	OldestMessages   Ring[*Message]
	Authors          map[string]*Author
	MessagesByAuthor map[string]map[string]*Message

	*sync.Mutex
}

type Emote

type Emote struct {
	URL string `json:"url"`
	// [][start, end]
	Positions [][2]int `json:"positions"`
}

func ProcessEmotes

func ProcessEmotes(str string, base []*twitch.Emote) []*Emote

type Message

type Message struct {
	ID      string    `json:"id"`
	Author  *Author   `json:"author"`
	Content string    `json:"content"`
	Time    time.Time `json:"time"`
	Emotes  []*Emote  `json:"emotes"`
	Bits    int       `json:"bits"`
	Action  bool      `json:"action"`
	Parent  *Message  `json:"reply"`
}

func FetchMessage

func FetchMessage(id string) *Message

Get a message by ID (from the message pool)

func FetchMessages

func FetchMessages() []*Message

Get all the available messages from the considered pool

func ProcessMessage

func ProcessMessage(raw *twitch.PrivateMessage) *Message

Parse a raw twitch message into a readable local message and add it to the pool If the message has already been added to the pool, no more processing will be done to it.

func (Message) String

func (msg Message) String() string

type Ring

type Ring[T any] []T

func NewRing

func NewRing[T any](size int) Ring[T]

func (Ring[T]) Add

func (r Ring[T]) Add(v T)

func (Ring[T]) Delete

func (r Ring[T]) Delete(deleteIndex int)

func (Ring[T]) Shift

func (r Ring[T]) Shift(n int)

n must always be >= 0

Jump to

Keyboard shortcuts

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