db

package
v0.0.0-...-a139185 Latest Latest
Warning

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

Go to latest
Published: May 25, 2023 License: AGPL-3.0 Imports: 29 Imported by: 0

Documentation

Index

Constants

View Source
const DisputedText = "" /* 248-byte string literal not displayed */

DisputedText ...

View Source
const EmbedColour = 0xd14171

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 (
	ErrMoreThanOneRow = errors.New("more than one row returned")
	ErrTooManyForms   = errors.New("too many forms given")
	ErrNoForms        = errors.New("no forms given")
)

Errors ...

View Source
var Debug = func(template string, args ...interface{}) {}

Debug is a debug logging function

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

Errors related to database operations

Functions

func IsOurProblem

func IsOurProblem(e error) bool

IsOurProblem checks if an error is "our problem", as in, should be in the logs and reported to Sentry. Will be expanded eventually once we get more insight into what type of errors we get.

Types

type Category

type Category struct {
	ID   int    `json:"id"`
	Name string `json:"name"`
}

Category is a single category

type Contributor

type Contributor struct {
	UserID   discord.UserID
	Category int64
	Name     string
	Override *string
}

Contributor is a single contributor.

type ContributorCategory

type ContributorCategory struct {
	ID     int64
	Name   string
	RoleID *discord.RoleID
}

ContributorCategory is a category of contributors, optionally with a role.

type DB

type DB struct {
	// Embedded search methods
	search.Searcher
	*pgxpool.Pool

	GuildCache *ttlcache.Cache

	Config common.Config

	Snowflake *snowflake.Generator

	Timeout time.Duration

	TermBaseURL string

	IncFunc func()
	// contains filtered or unexported fields
}

Db ...

func Init

func Init(url string) (db *DB, err error)

Init ...

func (*DB) AddCategory

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

AddCategory ...

func (*DB) AddContributor

func (db *DB) AddContributor(cat int64, userID discord.UserID, name string) (err error)

AddContributor adds a contributor.

func (*DB) AddContributorCategory

func (db *DB) AddContributorCategory(name string, roleID *discord.RoleID) (cat ContributorCategory, err error)

AddContributorCategory adds a contributor category.

func (*DB) AddExplanation

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

AddExplanation adds an explanation to the database

func (*DB) AddFile

func (db *DB) AddFile(filename, contentType string, data []byte) (f *File, err error)

AddFile adds a file

func (*DB) AddPronoun

func (db *DB) AddPronoun(p PronounSet) (id int, err error)

AddPronoun adds a pronoun set, returning the ID

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 string, channelIDs []string) (err error)

AddToBlacklist adds the given channelID to the blacklist for guildID

func (*DB) CaptureError

func (db *DB) CaptureError(ctx bcr.Contexter, e error) *sentry.EventID

CaptureError captures an error with additional context

func (*DB) CategoryFromID

func (db *DB) CategoryFromID(id int) (c *Category)

CategoryFromID ...

func (*DB) CategoryFromRole

func (db *DB) CategoryFromRole(id discord.RoleID) *ContributorCategory

CategoryFromRole gets a contributor category from a role ID.

func (*DB) CategoryID

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

CategoryID gets the ID from a category name

func (*DB) Context

func (db *DB) Context() (context.Context, context.CancelFunc)

Context is a convenience method to get a context.Context with the database's timeout

func (*DB) ContributorCategories

func (db *DB) ContributorCategories() ([]ContributorCategory, error)

ContributorCategories ...

func (*DB) ContributorCategory

func (db *DB) ContributorCategory(name string) *ContributorCategory

ContributorCategory ...

func (*DB) Contributors

func (db *DB) Contributors(id int64) ([]Contributor, error)

Contributors ...

func (*DB) CreateServerIfNotExists

func (db *DB) CreateServerIfNotExists(guildID string) (exists bool, err error)

CreateServerIfNotExists returns true if the server exists

func (*DB) CtxInBlacklist

func (db *DB) CtxInBlacklist(ctx bcr.Contexter) bool

CtxInBlacklist is a wrapper around IsBlacklisted for bcr

func (*DB) DeleteServer

func (db *DB) DeleteServer(guildID string) (err error)

DeleteServer deletes a server's database entry

func (*DB) Error

func (db *DB) Error(id string) (e *Error, err error)

Error ...

func (*DB) Exec

func (db *DB) Exec(ctx context.Context, sql string, args ...interface{}) (pgconn.CommandTag, error)

Exec ...

func (*DB) File

func (db *DB) File(id snowflake.ID) (f File, err error)

File gets a file from the database

func (*DB) FileName

func (db *DB) FileName(s string) (f []File, err error)

FileName returns files with the given string in their name

func (*DB) Files

func (db *DB) Files() (f []File, err error)

Files gets all files

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) GetCategories

func (db *DB) GetCategories() (c []*Category, err error)

GetCategories ...

func (*DB) GetCategoryTerms

func (db *DB) GetCategoryTerms(id int, mask search.TermFlag) (terms []*Term, err error)

GetCategoryTerms gets terms by category

func (*DB) GetCmdExplanations

func (db *DB) GetCmdExplanations() (e []*Explanation, err error)

GetCmdExplanations ...

func (*DB) GetExplanation

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

GetExplanation ...

func (*DB) GetPronoun

func (db *DB) GetPronoun(forms ...string) (sets []*PronounSet, err error)

GetPronoun gets a pronoun from the database gods this function is shit but idc, if it works it works

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 search.TermFlag) (terms []*Term, err error)

GetTerms gets all terms not blocked by the given mask

func (*DB) IncrementPronounUse

func (db *DB) IncrementPronounUse(p *PronounSet)

func (*DB) InternalError

func (db *DB) InternalError(ctx bcr.Contexter, e error) error

InternalError sends an error message and logs the error to the database

func (*DB) IsBlacklisted

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

IsBlacklisted returns true if a channel is blacklisted

func (*DB) LinkTerms

func (db *DB) LinkTerms(input string) string

LinkTerms creates a strings.Replacer for all links in the page

func (*DB) OverrideContributorName

func (db *DB) OverrideContributorName(userID discord.UserID, override *string) (err error)

OverrideContributorName overrides the contributor's name.

func (*DB) Pronouns

func (db *DB) Pronouns(order PronounOrder) (p []*PronounSet, err error)

Pronouns ...

func (*DB) Query

func (db *DB) Query(ctx context.Context, sql string, args ...interface{}) (pgx.Rows, error)

Query ...

func (*DB) QueryRow

func (db *DB) QueryRow(ctx context.Context, sql string, args ...interface{}) pgx.Row

QueryRow ...

func (*DB) RandomPronouns

func (db *DB) RandomPronouns() (p *PronounSet, err error)

RandomPronouns gets a random pronoun set from the database

func (*DB) RandomTerm

func (db *DB) RandomTerm(ignore []string) (t *Term, err error)

RandomTerm gets a random term from the database

func (*DB) RandomTermCategory

func (db *DB) RandomTermCategory(id int, ignore []string) (t *Term, err error)

RandomTermCategory gets a random term from the database from the specified category

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) SetAsCommand

func (db *DB) SetAsCommand(id int, b bool) (err error)

SetAsCommand ...

func (*DB) SetCW

func (db *DB) SetCW(id int, text string) (err error)

SetCW sets the content warning for a term

func (*DB) SetFlags

func (db *DB) SetFlags(id int, flags search.TermFlag) (err error)

SetFlags sets the flags for a term

func (*DB) SetNote

func (db *DB) SetNote(id int, note string) (err error)

SetNote updates the note for a term

func (*DB) SetSentry

func (db *DB) SetSentry(hub *sentry.Hub)

SetSentry ...

func (*DB) TagTerms

func (db *DB) TagTerms(tag string) (t []*Term, err error)

TagTerms ...

func (*DB) Tags

func (db *DB) Tags() (s []string, err error)

Tags gets all tags from the database

func (*DB) TermCount

func (db *DB) TermCount() (count int)

TermCount ...

func (*DB) TermEmbed

func (db *DB) TermEmbed(t *Term) discord.Embed

TermEmbed creates a Discord embed from a term object

func (*DB) TermName

func (db *DB) TermName(n string) (t []*Term, err error)

TermName gets a term by name

func (*DB) TermsSince

func (db *DB) TermsSince(d time.Time) (t []*Term, err error)

TermsSince returns all terms added since the specified date

func (*DB) Time

func (db *DB) Time(s snowflake.ID) time.Time

Time gets the time from a snowflake

func (*DB) UntaggedTerms

func (db *DB) UntaggedTerms() (t []*Term, err error)

UntaggedTerms ...

func (*DB) UpdateAliases

func (db *DB) UpdateAliases(id int, aliases []string) (err error)

UpdateAliases updates the aliases for a term

func (*DB) UpdateContributorName

func (db *DB) UpdateContributorName(userID discord.UserID, newName string) (err error)

UpdateContributorName updates the contributor's Discord name.

func (*DB) UpdateDesc

func (db *DB) UpdateDesc(id int, desc string) (err error)

UpdateDesc updates the description for a term

func (*DB) UpdateImage

func (db *DB) UpdateImage(id int, img string) (err error)

UpdateImage updates the image for a term

func (*DB) UpdateSource

func (db *DB) UpdateSource(id int, source string) (err error)

UpdateSource updates the source for a term

func (*DB) UpdateTags

func (db *DB) UpdateTags(id int, tags []string) (err error)

UpdateTags updates the tags for a term

func (*DB) UpdateTitle

func (db *DB) UpdateTitle(id int, title string) (err error)

UpdateTitle updates the title for a term

type Error

type Error struct {
	ID      uuid.UUID
	Command string
	UserID  discord.UserID
	Channel discord.ChannelID
	Error   string
	Time    time.Time
}

Error ...

type Explanation

type Explanation struct {
	ID          int       `json:"id"`
	Name        string    `json:"name"`
	Aliases     []string  `json:"aliases"`
	Description string    `json:"description"`
	Created     time.Time `json:"created"`

	AsCommand bool `json:"-"`
}

Explanation is a single explanation

type File

type File struct {
	ID snowflake.ID

	Filename    string
	ContentType string

	Source      string
	Description string

	Data []byte
	// contains filtered or unexported fields
}

File is a single file

func (File) URL

func (f File) URL() string

URL ...

type PronounOrder

type PronounOrder int
const (
	AlphabeticPronounOrder PronounOrder = iota
	UsesPronounOrder
	RandomPronounOrder
)

type PronounSet

type PronounSet struct {
	ID         int    `json:"id"`
	Subjective string `json:"subjective"`
	Objective  string `json:"objective"`
	PossDet    string `json:"possessive_determiner"`
	PossPro    string `json:"possessive_pronoun"`
	Reflexive  string `json:"reflexive"`
	Uses       int64  `json:"uses"`

	Sorting int `json:"-"`
}

PronounSet is a single set of pronouns

func (PronounSet) String

func (p PronounSet) String() string

type Term

type Term = search.Term

Term is an alias to search.Term

Directories

Path Synopsis
Package search contains types for searching for terms.
Package search contains types for searching for terms.
pg
Package pg implements the search.Searcher interface with the existing PostgreSQL database.
Package pg implements the search.Searcher interface with the existing PostgreSQL database.
typesense
Package typesense implements search methods with a Typesense search server.
Package typesense implements search methods with a Typesense search server.

Jump to

Keyboard shortcuts

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