Documentation ¶
Index ¶
- Constants
- Variables
- func AddCount() uint64
- func GenerateToken() string
- func GetCount() uint64
- type Category
- type Db
- func (db *Db) AddAdmin(id string) (err error)
- func (db *Db) AddCategory(name string) (id int, err error)
- func (db *Db) AddExplanation(e *Explanation) (ex *Explanation, err error)
- func (db *Db) AddTerm(t *Term) (*Term, error)
- func (db *Db) AddToBlacklist(guildID, channelID string) (err error)
- func (db *Db) CategoryID(s string) (id int, err error)
- func (db *Db) CreateServerIfNotExists(guildID string) (err error)
- func (db *Db) CtxInBlacklist(ctx *bcr.Context) bool
- func (db *Db) GetAdmins() (admins []string, err error)
- func (db *Db) GetAllExplanations() (e []*Explanation, err error)
- func (db *Db) GetBlacklist(guildID string) (b []string, err error)
- func (db *Db) GetCategories() (c []*Category, err error)
- func (db *Db) GetCategoryTerms(id int, mask TermFlag) (terms []*Term, err error)
- func (db *Db) GetExplanation(s string) (e *Explanation, err error)
- func (db *Db) GetOrCreateToken(userID string) (token string, err error)
- func (db *Db) GetTerm(id int) (t *Term, err error)
- func (db *Db) GetTerms(mask TermFlag) (terms []*Term, err error)
- func (db *Db) IsBlacklisted(guildID, channelID string) (b bool)
- func (db *Db) RandomTerm() (t *Term, err error)
- func (db *Db) RemoveFromBlacklist(guildID, channelID string) (err error)
- func (db *Db) RemoveTerm(id int) (err error)
- func (db *Db) ResetToken(userID string) (token string, err error)
- func (db *Db) Search(input string, limit int) (terms []*Term, err error)
- func (db *Db) SetCW(id int, text string) (err error)
- func (db *Db) SetFlags(id int, flags TermFlag) (err error)
- func (db *Db) SetNote(id int, note string) (err error)
- func (db *Db) TermCount() (count int)
- func (db *Db) UpdateAliases(id int, aliases []string) (err error)
- func (db *Db) UpdateDesc(id int, desc string) (err error)
- func (db *Db) UpdateSource(id int, source string) (err error)
- func (db *Db) UpdateTitle(id int, title string) (err error)
- func (db *Db) ValidateToken(token string) (t bool)
- type Explanation
- type Term
- type TermFlag
Constants ¶
const DBVersion = 8
DBVersion is the current database version
const EmbedColour = 0xe00d7a
EmbedColour is the embed colour used throughout the bot
Variables ¶
var ( ErrorAlreadyBlacklisted = errors.New("channel is already blacklisted") ErrorNotBlacklisted = errors.New("channel is not blacklisted") )
Errors for setting the blacklist
var ( ErrInvalidToken = errors.New("invalid token") ErrTokenExpired = errors.New("token has expired") )
Errors regarding tokens
var DBVersions []string = []string{
`alter table public.terms add column flags integer not null default 0;
update public.info set schema_version = 2;`,
`alter table public.terms drop column searchtext;
alter table public.terms add column searchtext tsvector generated always as (
setweight(to_tsvector('english', "name"), 'A') ||
setweight(to_tsvector('english', "description"), 'B') ||
setweight(to_tsvector('english', "source"), 'C') ||
setweight(array_to_tsvector("aliases"), 'A')
) stored;
update public.info set schema_version = 3;`,
`alter table public.terms add column content_warnings text not null default '';
update public.info set schema_version = 4;`,
`create index term_names_alphabetical on public.terms (name, id);
update public.info set schema_version = 5;`,
`alter table public.terms add column last_modified timestamp;
update public.terms set last_modified = created where last_modified is null;
alter table public.terms alter column last_modified set default (current_timestamp at time zone 'utc');
alter table public.terms alter column last_modified set not null;
update public.info set schema_version = 6;`,
`create table if not exists admin_tokens (
user_id text primary key,
token text not null,
expires timestamp not null default (now() + interval '30 days')::timestamp
);
update public.info set schema_version = 7;`,
`alter table public.terms add column note text not null default '';
update public.info set schema_version = 8;`,
}
DBVersions is a slice of schemas for every database version
var (
ErrorNoRowsAffected = errors.New("no rows affected")
)
Errors related to database operations
Functions ¶
Types ¶
type Db ¶
type Db struct { Pool *pgxpool.Pool Sugar *zap.SugaredLogger GuildCache *ttlcache.Cache }
Db ...
func (*Db) AddExplanation ¶
func (db *Db) AddExplanation(e *Explanation) (ex *Explanation, err error)
AddExplanation adds an explanation to the database
func (*Db) AddToBlacklist ¶
AddToBlacklist adds the given channelID to the blacklist for guildID
func (*Db) CategoryID ¶
CategoryID gets the ID from a category name
func (*Db) CreateServerIfNotExists ¶
CreateServerIfNotExists ...
func (*Db) CtxInBlacklist ¶
CtxInBlacklist is a wrapper around IsBlacklisted for bcr
func (*Db) GetAllExplanations ¶
func (db *Db) GetAllExplanations() (e []*Explanation, err error)
GetAllExplanations ...
func (*Db) GetBlacklist ¶
GetBlacklist returns the channel blacklist for guildID
func (*Db) GetCategories ¶
GetCategories ...
func (*Db) GetCategoryTerms ¶
GetCategoryTerms gets terms by category
func (*Db) GetExplanation ¶
func (db *Db) GetExplanation(s string) (e *Explanation, err error)
GetExplanation ...
func (*Db) GetOrCreateToken ¶
GetOrCreateToken gets or creates a token for the given user
func (*Db) IsBlacklisted ¶
IsBlacklisted returns true if a channel is blacklisted
func (*Db) RandomTerm ¶
RandomTerm gets a random term from the database
func (*Db) RemoveFromBlacklist ¶
RemoveFromBlacklist removes the given channelID from the blacklist for guildID
func (*Db) RemoveTerm ¶
RemoveTerm removes a term from the database
func (*Db) ResetToken ¶
ResetToken ...
func (*Db) UpdateAliases ¶
UpdateAliases updates the aliases for a term
func (*Db) UpdateDesc ¶
UpdateDesc updates the description for a term
func (*Db) UpdateSource ¶
UpdateSource updates the source for a term
func (*Db) UpdateTitle ¶
UpdateTitle updates the title for a term
func (*Db) ValidateToken ¶
ValidateToken checks if a token is valid and not expired
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"` }
Explanation is a single explanation
type Term ¶
type Term struct { ID int `json:"id"` Category int `json:"category_id"` CategoryName string `json:"category"` Name string `json:"name"` Aliases []string `json:"aliases"` Description string `json:"description"` Note string `json:"note,omitempty"` Source string `json:"source"` Created time.Time `json:"created"` LastModified time.Time `json:"last_modified"` ContentWarnings string `json:"content_warnings,omitempty"` Flags TermFlag `json:"flags"` // Rank is only populated with db.Search() Rank float64 `json:"rank,omitempty"` // Headline is only populated with db.Search() Headline string `json:"headline,omitempty"` }
Term holds info on a single term
func (*Term) RandomHidden ¶
RandomHidden returns true if the term is hidden from the random command
func (*Term) SearchHidden ¶
SearchHidden returns true if the term is hidden from search results