db

package
v2.0.0-...-e570596 Latest Latest
Warning

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

Go to latest
Published: Nov 6, 2023 License: AGPL-3.0 Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Decrypt

func Decrypt(ciphertext []byte, key [32]byte) (plaintext []byte, err error)

Decrypt decrypts data using 256-bit AES-GCM. This both hides the content of the data and provides a check that it hasn't been altered. Expects input form nonce|ciphertext|tag where '|' indicates concatenation.

func Encrypt

func Encrypt(plaintext []byte, key [32]byte) (ciphertext []byte, err error)

Encrypt encrypts data using 256-bit AES-GCM. This both hides the content of the data and provides a check that it hasn't been altered. Output takes the form nonce|ciphertext|tag where '|' indicates concatenation.

func RunMigrations

func RunMigrations(postgres string) (err error)

RunMigrations runs all of the migrations in migrations/.

Types

type Channels

type Channels struct {
	Channels  LogChannels
	Redirects Redirects
	Ignores   Ignores
}

type DB

type DB struct {
	*pgxpool.Pool

	Redis radix.Client
	// contains filtered or unexported fields
}

func New

func New(postgres, redis, aesKey string, shouldMigrate bool) (*DB, error)

func (*DB) Channels

func (db *DB) Channels(guildID discord.GuildID) (chs Channels, err error)

func (*DB) CreateGuild

func (db *DB) CreateGuild(id discord.GuildID) (alreadyExists bool, err error)

func (*DB) DeleteMessage

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

DeleteMessage deletes a message from the database

func (*DB) GetMessage

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

GetMessage gets a single message

func (*DB) HasPKInfo

func (db *DB) HasPKInfo(msgID discord.MessageID) (exists bool)

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

func (db *DB) IsMessageIgnored(id discord.MessageID) (isIgnored bool, err error)

func (*DB) SetChannels

func (db *DB) SetChannels(guildID discord.GuildID, chs Channels) error

func (*DB) UpdatePKInfo

func (db *DB) UpdatePKInfo(msgID, originalID 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.

type Ignores

type Ignores struct {
	GlobalChannels []discord.ChannelID         `json:"global_channels"`
	GlobalUsers    []discord.UserID            `json:"global_users"`
	PerChannel     map[string][]discord.UserID `json:"per_channel"`
}

type LogChannels

type LogChannels struct {
	GuildUpdate             discord.ChannelID `json:"GUILD_UPDATE"`
	GuildEmojisUpdate       discord.ChannelID `json:"GUILD_EMOJIS_UPDATE"`
	GuildRoleCreate         discord.ChannelID `json:"GUILD_ROLE_CREATE"`
	GuildRoleUpdate         discord.ChannelID `json:"GUILD_ROLE_UPDATE"`
	GuildRoleDelete         discord.ChannelID `json:"GUILD_ROLE_DELETE"`
	ChannelCreate           discord.ChannelID `json:"CHANNEL_CREATE"`
	ChannelUpdate           discord.ChannelID `json:"CHANNEL_UPDATE"`
	ChannelDelete           discord.ChannelID `json:"CHANNEL_DELETE"`
	GuildMemberAdd          discord.ChannelID `json:"GUILD_MEMBER_ADD"`
	GuildMemberUpdate       discord.ChannelID `json:"GUILD_MEMBER_UPDATE"`
	GuildKeyRoleUpdate      discord.ChannelID `json:"GUILD_KEY_ROLE_UPDATE"`
	GuildMemberNickUpdate   discord.ChannelID `json:"GUILD_MEMBER_NICK_UPDATE"`
	GuildMemberAvatarUpdate discord.ChannelID `json:"GUILD_MEMBER_AVATAR_UPDATE"`
	GuildMemberRemove       discord.ChannelID `json:"GUILD_MEMBER_REMOVE"`
	GuildMemberKick         discord.ChannelID `json:"GUILD_MEMBER_KICK"`
	GuildBanAdd             discord.ChannelID `json:"GUILD_BAN_ADD"`
	GuildBanRemove          discord.ChannelID `json:"GUILD_BAN_REMOVE"`
	InviteCreate            discord.ChannelID `json:"INVITE_CREATE"`
	InviteDelete            discord.ChannelID `json:"INVITE_DELETE"`
	MessageUpdate           discord.ChannelID `json:"MESSAGE_UPDATE"`
	MessageDelete           discord.ChannelID `json:"MESSAGE_DELETE"`
	MessageDeleteBulk       discord.ChannelID `json:"MESSAGE_DELETE_BULK"`
}

LogChannels is the map of log channels stored per server

func (LogChannels) For

func (lc LogChannels) For(evName string) discord.ChannelID

For returns the channel ID for the given event.

type Message

type Message struct {
	ID         discord.MessageID
	OriginalID *discord.MessageID
	UserID     discord.UserID
	ChannelID  discord.ChannelID
	GuildID    discord.GuildID

	Content  string `db:"-"`
	Username string `db:"-"`

	EncryptedContent  []byte `db:"content"`
	EncryptedUsername []byte `db:"username"`

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

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

	AttachmentSize uint64
}

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 Redirects

type Redirects map[string]discord.ChannelID

Jump to

Keyboard shortcuts

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