db

package
v0.0.0-...-ab45ee7 Latest Latest
Warning

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

Go to latest
Published: Oct 24, 2024 License: AGPL-3.0 Imports: 28 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultRedirectMap = RedirectMap{}

DefaultRedirectMap is an empty redirect map

View Source
var EventDescs map[string]string = map[string]string{
	"GUILD_UPDATE":        "Guild Update: changes to the server",
	"GUILD_EMOJIS_UPDATE": "Guild Emojis Update: changes to custom emotes",

	"GUILD_ROLE_CREATE": "Guild Role Create: roles being created",
	"GUILD_ROLE_UPDATE": "Guild Role Update: changes to roles",
	"GUILD_ROLE_DELETE": "Guild Role Delete: roles being deleted",

	"CHANNEL_CREATE": "Channel Create: channels being created",
	"CHANNEL_UPDATE": "Channel Update: changes to channels",
	"CHANNEL_DELETE": "Channel Delete: channels being deleted",

	"GUILD_MEMBER_ADD":         "Guild Member Add: members joining",
	"GUILD_MEMBER_UPDATE":      "Guild Member Update: roles being added/removed from members",
	"GUILD_MEMBER_NICK_UPDATE": "Guild Member Nick Update: avatar and nickname changes",
	"GUILD_KEY_ROLE_UPDATE":    "Key Role Update: key roles added/removed to users",
	"GUILD_MEMBER_REMOVE":      "Guild Member Remove: members leaving",
	"GUILD_MEMBER_KICK":        "Guild Member Kick: members being kicked",

	"GUILD_BAN_ADD":    "Guild Ban Add: members being banned",
	"GUILD_BAN_REMOVE": "Guild Ban Remove: members being unbanned",

	"INVITE_CREATE": "Invite Create: invites being created",
	"INVITE_DELETE": "Invite Delete: invites being deleted",

	"MESSAGE_UPDATE":      "Message Update: edited messages",
	"MESSAGE_DELETE":      "Message Delete: deleted messages",
	"MESSAGE_DELETE_BULK": "Message Delete Bulk: bulk deleted messages",
}

EventDescs is a description of events used in command options

View Source
var Events []string = []string{
	"GUILD_UPDATE",
	"GUILD_EMOJIS_UPDATE",

	"GUILD_ROLE_CREATE",
	"GUILD_ROLE_UPDATE",
	"GUILD_ROLE_DELETE",

	"CHANNEL_CREATE",
	"CHANNEL_UPDATE",
	"CHANNEL_DELETE",

	"GUILD_MEMBER_ADD",
	"GUILD_MEMBER_UPDATE",
	"GUILD_MEMBER_NICK_UPDATE",
	"GUILD_KEY_ROLE_UPDATE",
	"GUILD_MEMBER_REMOVE",

	"GUILD_BAN_ADD",
	"GUILD_BAN_REMOVE",
	"GUILD_MEMBER_KICK",

	"INVITE_CREATE",
	"INVITE_DELETE",

	"MESSAGE_UPDATE",
	"MESSAGE_DELETE",
	"MESSAGE_DELETE_BULK",
}

Events is a list of all available events

Functions

func ShouldReportError

func ShouldReportError(err error) bool

ShouldReportError returns true if err should be reported to Sentry.

Types

type DB

type DB struct {
	Pool *pgxpool.Pool

	Hub *sentry.Hub

	// Used for encryption
	AESKey [32]byte

	Stats *stats.Client
}

DB ...

func New

func New(url string, hub *sentry.Hub) (*DB, error)

New ...

func (*DB) BanSystem

func (db *DB) BanSystem(guild discord.GuildID, uuid uuid.UUID) (err error)

BanSystem bans the given system

func (*DB) Channels

func (db *DB) Channels(id discord.GuildID) (ch EventMap, err error)

Channels gets the server's event:channel map

func (*DB) CreateServerIfNotExists

func (db *DB) CreateServerIfNotExists(g *gateway.GuildCreateEvent)

CreateServerIfNotExists ...

func (*DB) DeleteMessage

func (db *DB) DeleteMessage(id discord.MessageID) (err error)

DeleteMessage deletes a message from the database

func (*DB) Exec

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

Exec ...

func (*DB) GetInviteName

func (db *DB) GetInviteName(code string) (name string, err error)

GetInviteName gets an invite by name. If the invite is not found, returns "Unnamed".

func (*DB) GetInvites

func (db *DB) GetInvites(guildID discord.GuildID) (Invites, error)

GetInvites gets this guild's named invites

func (*DB) GetMessage

func (db *DB) GetMessage(id discord.MessageID) (m *Message, err error)

GetMessage gets a single message

func (*DB) GuildWatchlist

func (db *DB) GuildWatchlist(id discord.GuildID) (l []WatchlistUser, err error)

GuildWatchlist gets the watchlist for the given guild ID.

func (*DB) IgnoreMessage

func (db *DB) IgnoreMessage(id discord.MessageID) error

func (*DB) InsertMessage

func (db *DB) InsertMessage(m Message) (err error)

InsertMessage inserts a message

func (*DB) IsBlacklisted

func (db *DB) IsBlacklisted(guildID discord.GuildID, channelID discord.ChannelID) (blacklisted bool)

func (*DB) IsIgnored

func (db *DB) IsIgnored(id discord.MessageID) (exists bool)

func (*DB) IsSystemBanned

func (db *DB) IsSystemBanned(guild discord.GuildID, id string, uuid uuid.UUID) (banned bool, err error)

IsSystemBanned returns true if the system is banned

func (*DB) NameInvite

func (db *DB) NameInvite(guildID discord.GuildID, code, name string) (err error)

NameInvite names an invite

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

func (db *DB) Redirects(id discord.GuildID) (m RedirectMap, err error)

Redirects gets the server's channel:channel map

func (*DB) Report

func (db *DB) Report(ctx ErrorContext, err error) *sentry.EventID

Report reports an error.

func (*DB) ReportCtx

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

ReportCtx reports an error and sends the event ID to the context channel, if possible

func (*DB) ReportEmbed

func (db *DB) ReportEmbed(ctx bcr.Contexter, id *sentry.EventID) (err error)

ReportEmbed ...

func (*DB) SetChannels

func (db *DB) SetChannels(id discord.GuildID, ch EventMap) (err error)

SetChannels ...

func (*DB) SetRedirects

func (db *DB) SetRedirects(id discord.GuildID, m RedirectMap) (err error)

SetRedirects sets the server's channel:channel map

func (*DB) UnbanSystem

func (db *DB) UnbanSystem(guild discord.GuildID, id string, uuid uuid.UUID) (err error)

UnbanSystem unbans the given system

func (*DB) UpdatePKInfo

func (db *DB) UpdatePKInfo(msgID discord.MessageID, userID pkgo.Snowflake, system, member string) (err error)

UpdatePKInfo updates the PluralKit info for the given message, if it exists in the database.

func (*DB) UpdateUserID

func (db *DB) UpdateUserID(msgID discord.MessageID, userID discord.UserID) (err error)

UpdateUserID updates *just* the user ID for the given message, if it exists in the database.

func (*DB) UserWatchlist

func (db *DB) UserWatchlist(guildID discord.GuildID, userID discord.UserID) (w *WatchlistUser, err error)

UserWatchlist returns the watchlist entry for a user, if any.

func (*DB) WatchlistAdd

func (db *DB) WatchlistAdd(guildID discord.GuildID, userID, modID discord.UserID, reason string) (w WatchlistUser, err error)

WatchlistAdd adds a user to the watchlist, or updates the reason.

func (*DB) WatchlistRemove

func (db *DB) WatchlistRemove(guildID discord.GuildID, userID discord.UserID) (err error)

WatchlistRemove removes a user from the watchlist.

type ErrorContext

type ErrorContext struct {
	Event   string
	Command string

	UserID  discord.UserID
	GuildID discord.GuildID
}

ErrorContext is the context for an error

type EventMap

type EventMap map[string]discord.ChannelID

EventMap is a map of event names → log channels

var DefaultEventMap EventMap = EventMap{
	"GUILD_UPDATE":        0,
	"GUILD_EMOJIS_UPDATE": 0,

	"GUILD_ROLE_CREATE": 0,
	"GUILD_ROLE_UPDATE": 0,
	"GUILD_ROLE_DELETE": 0,

	"CHANNEL_CREATE": 0,
	"CHANNEL_UPDATE": 0,
	"CHANNEL_DELETE": 0,

	"GUILD_MEMBER_ADD":         0,
	"GUILD_MEMBER_UPDATE":      0,
	"GUILD_MEMBER_NICK_UPDATE": 0,
	"GUILD_KEY_ROLE_UPDATE":    0,
	"GUILD_MEMBER_REMOVE":      0,

	"GUILD_BAN_ADD":     0,
	"GUILD_BAN_REMOVE":  0,
	"GUILD_MEMBER_KICK": 0,

	"INVITE_CREATE": 0,
	"INVITE_DELETE": 0,

	"MESSAGE_UPDATE":      0,
	"MESSAGE_DELETE":      0,
	"MESSAGE_DELETE_BULK": 0,
}

DefaultEventMap is an event map with all events set to 0

type Invite

type Invite struct {
	Code, Name string
}

type Invites

type Invites []Invite

func (Invites) Name

func (i Invites) Name(code string) string

type Message

type Message struct {
	MsgID     discord.MessageID
	UserID    discord.UserID
	ChannelID discord.ChannelID
	ServerID  discord.GuildID

	Content  string
	Username string

	// These are only filled if the message was proxied by PluralKit
	Member *string
	System *string

	Metadata    *Metadata `db:"-"`
	RawMetadata *[]byte   `db:"metadata"`
}

Message is a single message

type Metadata

type Metadata struct {
	UserID   *discord.UserID `json:"user_id,omitempty"`
	Username string          `json:"username,omitempty"`
	Avatar   string          `json:"avatar,omitempty"`
	Embeds   []discord.Embed `json:"embeds,omitempty"`
}

Metadata is optional message metadata

type RedirectMap

type RedirectMap = map[string]discord.ChannelID

RedirectMap is a map of origin channels → redirect channels. Key is string type so it can get encoded into JSON to store in the database

type WatchlistUser

type WatchlistUser struct {
	GuildID discord.GuildID
	UserID  discord.UserID

	Moderator discord.UserID
	Added     time.Time

	Reason string
}

WatchlistUser is a single user on the watchlist.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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