db

package
v0.0.0-...-6a4a4b0 Latest Latest
Warning

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

Go to latest
Published: Dec 30, 2020 License: AGPL-3.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const DBVersion = 2

DBVersion is the current database version

View Source
const EmbedColour = 0xe00d7a

EmbedColour is the embed colour used throughout the bot

Variables

View Source
var (
	ErrorAlreadyBlacklisted = errors.New("channel is already blacklisted")
	ErrorNotBlacklisted     = errors.New("channel is not blacklisted")
)

Errors for setting the blacklist

View Source
var DBVersions []string = []string{
	`alter table public.terms add column flags integer not null default 0;
    update public.info set schema_version = 2;`,
}

DBVersions is a slice of schemas for every database version

View Source
var (
	ErrorNoRowsAffected = errors.New("no rows affected")
)

Errors related to database operations

Functions

This section is empty.

Types

type Db

type Db struct {
	Pool       *pgxpool.Pool
	Sugar      *zap.SugaredLogger
	GuildCache *ttlcache.Cache
}

Db ...

func Init

func Init(url string, sugar *zap.SugaredLogger) (db *Db, err error)

Init ...

func (*Db) AddCategory

func (db *Db) AddCategory(name string) (id int, err error)

AddCategory ...

func (*Db) AddExplanation

func (db *Db) AddExplanation(e *Explanation) (ex *Explanation, err error)

AddExplanation adds an explanation to the database

func (*Db) AddTerm

func (db *Db) AddTerm(t *Term) (*Term, error)

AddTerm adds a term to the database

func (*Db) AddToBlacklist

func (db *Db) AddToBlacklist(guildID, channelID string) (err error)

AddToBlacklist adds the given channelID to the blacklist for guildID

func (*Db) CategoryID

func (db *Db) CategoryID(s string) (id int, err error)

CategoryID gets the ID from a category name

func (*Db) CreateServerIfNotExists

func (db *Db) CreateServerIfNotExists(guildID string) (err error)

CreateServerIfNotExists ...

func (*Db) CtxInBlacklist

func (db *Db) CtxInBlacklist(ctx *crouter.Ctx) bool

CtxInBlacklist is a wrapper around IsBlacklisted for crouter

func (*Db) GetAllExplanations

func (db *Db) GetAllExplanations() (e []*Explanation, err error)

GetAllExplanations ...

func (*Db) GetBlacklist

func (db *Db) GetBlacklist(guildID string) (b []string, err error)

GetBlacklist returns the channel blacklist for guildID

func (*Db) GetExplanation

func (db *Db) GetExplanation(s string) (e *Explanation, err error)

GetExplanation ...

func (*Db) GetTerm

func (db *Db) GetTerm(id int) (t *Term, err error)

GetTerm gets a term by ID

func (*Db) GetTerms

func (db *Db) GetTerms(mask TermFlag) (terms []*Term, err error)

GetTerms gets all terms not blocked by the given mask

func (*Db) IsBlacklisted

func (db *Db) IsBlacklisted(guildID, channelID string) (b bool)

IsBlacklisted returns true if a channel is blacklisted

func (*Db) RandomTerm

func (db *Db) RandomTerm() (t *Term, err error)

RandomTerm gets a random term from the database

func (*Db) RemoveFromBlacklist

func (db *Db) RemoveFromBlacklist(guildID, channelID string) (err error)

RemoveFromBlacklist removes the given channelID from the blacklist for guildID

func (*Db) RemoveTerm

func (db *Db) RemoveTerm(id int) (err error)

RemoveTerm removes a term from the database

func (*Db) Search

func (db *Db) Search(input string, limit int) (terms []*Term, err error)

Search searches the database for terms

func (*Db) SetFlags

func (db *Db) SetFlags(id int, flags TermFlag) (err error)

SetFlags sets the flags for a term

type Explanation

type Explanation struct {
	ID          int
	Name        string
	Aliases     []string
	Description string
	Created     time.Time
}

Explanation is a single explanation

type Term

type Term struct {
	ID           int       `json:"id"`
	Category     int       `json:"-"`
	CategoryName string    `json:"category"`
	Name         string    `json:"name"`
	Aliases      []string  `json:"aliases"`
	Description  string    `json:"description"`
	Source       string    `json:"source"`
	Created      time.Time `json:"created"`

	Flags TermFlag `json:"flags"`

	// Rank is only populated with db.Search()
	Rank float64 `json:"-"`
	// Headline is only populated with db.Search()
	Headline string `json:"-"`
}

Term holds info on a single term

func (*Term) RandomHidden

func (t *Term) RandomHidden() bool

RandomHidden returns true if the term is hidden from the random command

func (*Term) SearchHidden

func (t *Term) SearchHidden() bool

SearchHidden returns true if the term is hidden from search results

func (*Term) TermEmbed

func (t *Term) TermEmbed() *discordgo.MessageEmbed

TermEmbed creates a Discord embed from a term object

func (*Term) Warning

func (t *Term) Warning() bool

Warning returns true if the term has a warning on its term card

type TermFlag

type TermFlag int

TermFlag ...

const (
	FlagSearchHidden TermFlag = 1 << iota
	FlagRandomHidden
	FlagShowWarning
)

Constants for term flags

Jump to

Keyboard shortcuts

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