cbdb

package
v1.0.0 Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const DBVersion = 7

DBVersion is the current database version

Variables

View Source
var DBVersions []string = []string{
	`create table if not exists notes (
		id 			serial		primary key,
		guild_id 	text		not null,
		user_id 	text		not null,
		mod_id 		text		not null,
		note 		text		not null,
		created 	timestamp	not null default (current_timestamp at time zone 'utc')
	);
	
	update public.info set schema_version = 2;`,

	`create table if not exists mod_log (
		id			serial		primary key,
		guild_id	text		not null,
		user_id		text		not null,
		mod_id		text		not null,
		type		modaction	not null,
		reason		text		not null,
		created		timestamp	not null default (current_timestamp at time zone 'utc')
	);
	
	update public.info set schema_version = 3;`,

	`create table if not exists triggers (
		id			serial		primary key,
		guild_id	text		not null,
		created_by	text		not null,
		modified	timestamp	not null default (current_timestamp at time zone 'utc'),
		trigger		text		not null,
		response	text		not null
	);
	
	update public.info set schema_version = 4;`,

	`create table if not exists yag_import (
		guild_id		text primary key	references public.guild_settings (guild_id)	on delete cascade,
		log_channel		text not null default '',
		enabled			boolean default false
	);
	
	update public.info set schema_version = 5;`,

	`alter table public.mod_log add column yag_id int;
	
	update public.info set schema_version = 6;`,

	`drop table starboard_blacklisted_channels;

	alter table public.guild_settings add column sb_blacklist text[] not null default array[]::text[];
	alter table public.guild_settings add column cmd_blacklist text[] not null default array[]::text[];

	update public.info set schema_version = 7;`,
}

DBVersions is a slice of schemas for every database version

Functions

This section is empty.

Types

type BoltDb

type BoltDb struct {
	Bolt *bolt.DB
}

BoltDb gives access to the bolt database

func BoltInit

func BoltInit(db *bolt.DB) (*BoltDb, error)

BoltInit initialises a bolt database object

func (*BoltDb) AddError

func (db *BoltDb) AddError(cmdErr CmdError) (err error)

AddError adds an error to the database

func (*BoltDb) GetError

func (db *BoltDb) GetError(id string) (cmdErr CmdError, err error)

GetError gets an error by ID

func (*BoltDb) InitForGuild

func (db *BoltDb) InitForGuild(guildID string) (err error)

InitForGuild initialises the buckets for a guild

type CmdError

type CmdError struct {
	ErrorID string
	Error   string
}

CmdError is the error + its ID

type Db

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

Db gives access to the database

func DbInit

func DbInit(config structs.BotConfig) (db *Db, err error)

DbInit initialises a database pool struct

func (*Db) AddNote

func (db *Db) AddNote(note *Note) (err error)

AddNote adds a note to the database

func (*Db) AddToModLog

func (db *Db) AddToModLog(entry *ModLogEntry) (out *ModLogEntry, err error)

AddToModLog adds the specified partial ModLogEntry to the moderation log, and returns the full object

func (*Db) AddToStarboardBlacklist added in v1.0.0

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

AddToStarboardBlacklist adds the given channelID to the blacklist for guildID

func (*Db) AddTrigger added in v1.0.0

func (db *Db) AddTrigger(t *Trigger) (*Trigger, error)

AddTrigger ...

func (*Db) AllNotes

func (db *Db) AllNotes(guildID string) (notes []*Note, err error)

AllNotes gets all the notes for the specified guild.

func (*Db) DelNote

func (db *Db) DelNote(guildID string, id int) (err error)

DelNote deletes a note from the database

func (*Db) DeleteStarboardEntry

func (db *Db) DeleteStarboardEntry(messageID string) error

DeleteStarboardEntry deletes an entry from the database

func (*Db) EditTrigger added in v1.0.0

func (db *Db) EditTrigger(guildID string, triggerID int, t *Trigger) (*Trigger, error)

EditTrigger ...

func (*Db) GetAllLogs

func (db *Db) GetAllLogs(guildID string) (out []*ModLogEntry, err error)

GetAllLogs gets *all* the mod logs for a guild

func (*Db) GetDBGuildSettings

func (db *Db) GetDBGuildSettings(g string) (s structs.GuildSettings, err error)

GetDBGuildSettings gets the guild settings from the database

func (*Db) GetGuildSettings

func (db *Db) GetGuildSettings(g string) (s structs.GuildSettings, err error)

GetGuildSettings gets the guild settings for a specific guild

func (*Db) GetModLogs

func (db *Db) GetModLogs(guildID, userID string) (out []*ModLogEntry, err error)

GetModLogs gets all the mod logs for a user

func (*Db) GetOrigStarboardMessage

func (db *Db) GetOrigStarboardMessage(m string) (s string)

GetOrigStarboardMessage ...

func (*Db) GetStarboardBlacklist added in v1.0.0

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

GetStarboardBlacklist returns the channel blacklist for guildID

func (*Db) GetStarboardEntry

func (db *Db) GetStarboardEntry(m string) (s string)

GetStarboardEntry gets the starboard entry for the given ID

func (*Db) InStarboardBlacklist added in v1.0.0

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

InStarboardBlacklist checks if the given channelID is in the blacklist for guildID

func (*Db) InitSettingsForGuild

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

InitSettingsForGuild initialises the settings for a guild iif it doesn't have any yet

func (*Db) InsertStarboardEntry

func (db *Db) InsertStarboardEntry(messageID, channelID, guildID, starboardMessageID string) error

InsertStarboardEntry inserts an entry into the database

func (*Db) Notes

func (db *Db) Notes(guildID, userID string) (notes []*Note, err error)

Notes gets all the notes for a user in a guild

func (*Db) RemoveFromGuildCache

func (db *Db) RemoveFromGuildCache(g string) (err error)

RemoveFromGuildCache removes a cache entry

func (*Db) RemoveFromStarboardBlacklist added in v1.0.0

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

RemoveFromStarboardBlacklist removes the given channelID from the blacklist for guildID

func (*Db) RemoveTrigger added in v1.0.0

func (db *Db) RemoveTrigger(guildID string, triggerID int) (err error)

RemoveTrigger ...

func (*Db) SetGatekeeperChannel

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

SetGatekeeperChannel sets the gatekeeper channel for the given guild

func (*Db) SetGatekeeperMsg

func (db *Db) SetGatekeeperMsg(guildID, msg string) (err error)

SetGatekeeperMsg sets the gatekeeper message for the given guild

func (*Db) SetGatekeeperRoles

func (db *Db) SetGatekeeperRoles(guildID string, roles []string) (err error)

SetGatekeeperRoles sets the gatekeeper roles for the given guild

func (*Db) SetMemberRoles

func (db *Db) SetMemberRoles(guildID string, roles []string) (err error)

SetMemberRoles sets the gatekeeper roles for the given guild

func (*Db) SetModLogChannel

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

SetModLogChannel sets the moderation log channel for the guild

func (*Db) SetStarboardChannel

func (db *Db) SetStarboardChannel(channelID, guildID string) error

SetStarboardChannel sets the starboard channel for a guild

func (*Db) SetStarboardLimit

func (db *Db) SetStarboardLimit(limit int, guildID string) error

SetStarboardLimit sets the starboard limit for a guild

func (*Db) SetWelcomeChannel

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

SetWelcomeChannel sets the welcome channel for the given guild

func (*Db) SetWelcomeMsg

func (db *Db) SetWelcomeMsg(guildID, msg string) (err error)

SetWelcomeMsg sets the welcome message for the given guild

func (*Db) StarboardEmoji

func (db *Db) StarboardEmoji(g, e string) (err error)

StarboardEmoji ...

func (*Db) ToggleSenderCanReact

func (db *Db) ToggleSenderCanReact(g string) (err error)

ToggleSenderCanReact ...

func (*Db) Triggers added in v1.0.0

func (db *Db) Triggers(id string) (out []*Trigger, err error)

Triggers gets all triggers for a guild

type ModLogEntry

type ModLogEntry struct {
	ID      int       `json:"id"`
	GuildID string    `json:"guild_id"`
	UserID  string    `json:"user_id"`
	ModID   string    `json:"mod_id"`
	Type    string    `json:"type"`
	Reason  string    `json:"reason"`
	Time    time.Time `json:"timestamp"`
}

ModLogEntry is an entry in the mod log

type Note

type Note struct {
	ID      int       `json:"id"`
	GuildID string    `json:"guild_id"`
	UserID  string    `json:"user_id"`
	ModID   string    `json:"mod_id"`
	Note    string    `json:"note"`
	Created time.Time `json:"created"`
}

Note holds the data for a note

type Trigger added in v1.0.0

type Trigger struct {
	ID       int
	GuildID  string
	Creator  string
	Modified time.Time
	Trigger  string
	Response string
}

Trigger ...

Jump to

Keyboard shortcuts

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