db

package
v0.0.0-...-e364c34 Latest Latest
Warning

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

Go to latest
Published: Jan 18, 2023 License: AGPL-3.0 Imports: 24 Imported by: 0

Documentation

Index

Constants

View Source
const ArikawaDocumentationBase = "https://pkg.go.dev/github.com/diamondburned/arikawa/v3"

ArikawaDocumentationBase ...

Variables

View Source
var ConfigOptions = map[string]ConfigOption{

	"prefix": {
		Description:  "The prefix used for bot commands. Case-insensitive.",
		Type:         StringOptionType,
		DefaultValue: ".",
	},
	"activity": {
		Description:  "The activity shown in the bot's status.",
		Type:         StringOptionType,
		DefaultValue: "",
	},
	"activity_type": {
		Description:  "The activity type shown in the bot's status. Valid options are: `playing`, `listening`, `watching`",
		Type:         StringOptionType,
		DefaultValue: "playing",
		ValidValues:  []interface{}{"playing", "listening", "watching"},
	},
	"status": {
		Description:  "The bot's status. Valid options are: `online`, `idle`, `dnd`",
		Type:         StringOptionType,
		DefaultValue: "online",
		ValidValues:  []interface{}{"online", "idle", "dnd"},
	},

	"welcome_channel": {
		Description:  "The channel new joins are announced in, and where they are welcomed if approved.",
		Type:         SnowflakeOptionType,
		DefaultValue: 0,
	},
	"welcome_message": {
		Description: "The message used to welcome someone. Accepted variables are:\n- `{{.Guild}}`: the [guild]({docs}/discord#Guild) the user is welcomed in\n- `{{.Member}}`: the [member]({docs}/discord#Member) that is being welcomed\n- `{{.Approver}}`: the [member]({docs}/discord#Member) that approved the user\n\nThis message is sent to `welcome_channel`.",

		Type:         StringOptionType,
		DefaultValue: "Welcome to {{.Guild.Name}}, {{.Member.User.Mention}}!",
	},
	"deny_message": {
		Description: "The message sent in `welcome_channel` when a user is denied. If empty, denials will not be posted publicly.\nAccepted variables are:\n- `{{.Guild}}`: the [guild]({docs}/discord#Guild) the user is denied in\n- `{{.User}}`: the [user]({docs}/discord#User) that was denied\n- `{{.Denier}}`: the [member]({docs}/discord#Member) that denied the user\n- `{{.Reason}}`: the reason the user was denied, or \"No reason specified\" if no reason was given.",

		Type:         StringOptionType,
		DefaultValue: "{{.User.Mention}} ({{.User.Tag}}) was denied entry to the server by {{displayName .Denier}}.\nReason: {{.Reason}}",
	},

	"application_category": {
		Description:  "The category where application channels are created.",
		Type:         SnowflakeOptionType,
		DefaultValue: 0,
	},
	"finished_application_category": {
		Description:  "The category that holds finished applications until they are closed.",
		Type:         SnowflakeOptionType,
		DefaultValue: 0,
	},
	"transcript_channel": {
		Description:  "The channel where application transcripts are saved.",
		Type:         SnowflakeOptionType,
		DefaultValue: 0,
	},
	"discussion_channel": {
		Description:  "The channel where newly finished applications are announced.",
		Type:         SnowflakeOptionType,
		DefaultValue: 0,
	},
	"application_channel_message": {
		Description:  "The message that is posted in the applications channel. `{guild}` is replaced with the guild name.",
		Type:         StringOptionType,
		DefaultValue: "Thank you for joining {guild}!\nWe hope you enjoy your stay.",
	},
	"open_application_message": {
		Description:  "The message that is posted when an application is opened. `{guild}` is replaced with the guild name.",
		Type:         StringOptionType,
		DefaultValue: "Thank you for beginning your application for {guild}.",
	},
	"application_finished_message": {
		Description:  "The message that is posted when an application finishes.",
		Type:         StringOptionType,
		DefaultValue: "Application finished! Please continue to add proof if it included more than one screenshot, and otherwise, please be patient until a mod can review your answers.",
	},
	"long_answer_minimum": {
		Description:  "Minimum number of words needed to advance questions where long answers are required.",
		Type:         IntOptionType,
		DefaultValue: 3,
	},
	"long_answer_message": {
		Description:  "Message sent when someone's answer is too short. `{num}` is replaced with the number of words required.",
		Type:         StringOptionType,
		DefaultValue: "Sorry, but your answer is too short! Please resend it, and make sure it's at least {num} words long.",
	},

	"verified_role": {
		Description:  "The role given to a member when they are approved.",
		Type:         SnowflakeOptionType,
		DefaultValue: 0,
	},
	"adult_role": {
		Description:  "The role given to an adult member when they are approved.\n\nIf either this or `minor_role` is invalid, this step will be skipped and the valid role will be given.\nIf both this and `minor_role` are invalid, only `verified_role` will be given when a member is approved.",
		Type:         SnowflakeOptionType,
		DefaultValue: 0,
	},
	"minor_role": {
		Description:  "The role given to a minor member when they are approved.\n\nIf either this or `adult_role` is invalid, this step will be skipped and the valid role will be given.\nIf both this and `adult_role` are invalid, only `verified_role` will be given when a member is approved.",
		Type:         SnowflakeOptionType,
		DefaultValue: 0,
	},
	"keep_application_visible": {
		Description:  "Whether to keep the application channel visible to a member once they are approved.\n(If they are denied, the channel is hidden immediately)",
		Type:         BoolOptionType,
		DefaultValue: false,
	},
	"kick_on_deny": {
		Description:  "Whether to kick a user immediately after they are denied with the `{prefix}deny` command. See also: `confirm_deny`, `dm_on_deny`.",
		Type:         BoolOptionType,
		DefaultValue: false,
	},
	"dm_on_deny": {
		Description:  "Whether to DM a user if they are denied with the `{prefix}deny` command. See also: `confirm_deny`, `kick_on_deny`.",
		Type:         BoolOptionType,
		DefaultValue: false,
	},
	"confirm_deny": {
		Description:  "Whether to show a confirmation prompt for the `{prefix}deny` command. See also: `dm_on_deny`, `kick_on_deny`.",
		Type:         BoolOptionType,
		DefaultValue: false,
	},

	"join_leave_log": {
		Description:  "The channel to log members joining and leaving in (for mods).",
		Type:         SnowflakeOptionType,
		DefaultValue: 0,
	},
	"invite_channel": {
		Description:  "The channel to create invites in.",
		Type:         SnowflakeOptionType,
		DefaultValue: 0,
	},
	"username_role_log": {
		Description:  "The channel to log name and role changes in.",
		Type:         SnowflakeOptionType,
		DefaultValue: 0,
	},
	"message_log": {
		Description:  "The channel to log message updates and deletes in.",
		Type:         SnowflakeOptionType,
		DefaultValue: 0,
	},

	"mod_log": {
		Description:  "The channel to log moderator actions in.",
		Type:         SnowflakeOptionType,
		DefaultValue: 0,
	},
	"mute_role": {
		Description:  "The role to give to people with the `{prefix}mute` command.",
		Type:         SnowflakeOptionType,
		DefaultValue: 0,
	},
}

ConfigOptions are all configuration options

View Source
var DefaultPermissions = map[string]PermissionLevel{
	"ping":        EveryoneLevel,
	"help":        UserLevel,
	"config":      OwnerLevel,
	"permissions": OwnerLevel,
	"app":         StaffLevel,
	"verify":      HelperLevel,
	"close":       HelperLevel,
	"deny":        HelperLevel,
	"logs":        HelperLevel,
	"userinfo":    UserLevel,
	"unverified":  StaffLevel,
	"level":       UserLevel,
	"levelcfg":    StaffLevel,
	"leaderboard": UserLevel,
	"restart":     HelperLevel,
	"invites":     StaffLevel,
	"open":        HelperLevel,
	"hello":       EveryoneLevel,
	"valid":       EveryoneLevel,
	"transcript":  StaffLevel,
	"remindme":    EveryoneLevel,
	"warn":        HelperLevel,
	"mute":        HelperLevel,
	"hardmute":    HelperLevel,
	"unmute":      HelperLevel,
	"kick":        StaffLevel,
	"ban":         StaffLevel,
	"unban":       StaffLevel,
	"modlogs":     HelperLevel,
	"stats":       HelperLevel,
	"charinfo":    HelperLevel,
}

DefaultPermissions ...

View Source
var (
	ErrInvalidConfigOption = errors.New("invalid configuration option")
)

Configuration errors

View Source
var OverridesMu sync.RWMutex

Functions

This section is empty.

Types

type AppQuestion

type AppQuestion struct {
	Index      int64
	TrackID    int64
	ID         int64
	Question   string
	LongAnswer bool
}

AppQuestion is a single application question.

type AppResponse

type AppResponse struct {
	ApplicationID xid.ID
	MessageID     discord.MessageID
	UserID        discord.UserID
	Username      string
	Discriminator string
	Content       string

	FromBot   bool
	FromStaff bool
}

AppResponse ...

type Application

type Application struct {
	ID        xid.ID
	UserID    discord.UserID
	ChannelID discord.ChannelID

	// Can be null before a track is chosen + if the track is deleted
	TrackID *int64
	// Question index
	Question int

	// Whether the user has completed the automated interview section
	Completed bool
	// Whether the user was verified--null if not decided yet
	Verified *bool
	// If Verified is false, the reason why the user was denied
	DenyReason *string
	// Moderator who verified or denied the user
	Moderator *discord.UserID

	// Whether the interview has been closed (channel deleted)
	Closed     bool
	ClosedTime *time.Time

	TranscriptChannel *discord.ChannelID
	TranscriptMessage *discord.MessageID

	// The scheduled event used to notify when the app times out
	ScheduledEventID *int64
	ScheduledCloseID *int64
}

Application is a user's application.

type ApplicationTrack

type ApplicationTrack struct {
	ID          int64
	Name        string
	Description string
	// RawEmoji is stored as a?:name:id
	RawEmoji string `db:"emoji"`
}

ApplicationTrack is a single list of questions and associated name.

func (ApplicationTrack) Emoji

func (t ApplicationTrack) Emoji() discord.Emoji

Emoji returns the emoji struct version of the stored emoji.

type CommandOverrides

type CommandOverrides map[string]PermissionLevel

CommandOverrides is a map of command permission level overrides.

Command permission levels: - 1: @everyone - 2: normal users - 3: chat moderators/helpers - 4: staff - 5: owner

func (CommandOverrides) For

For returns the permission level for the given command.

type Config

type Config map[string]interface{}

Config is a server's configuration.

func (Config) Get

func (c Config) Get(name string) ConfigSetting

Get gets the given configuration setting. *This method panics if an invalid option name is given.*

func (Config) Set

func (c Config) Set(name string, val interface{}) error

Set sets the given option name to the given value. Passing a nil pointer will delete the value, making it fall back to the default value.

type ConfigOption

type ConfigOption struct {
	Description  string
	Type         ConfigOptionType
	DefaultValue interface{}
	ValidValues  []interface{}
}

ConfigOption is a single configuration option definition

type ConfigOptionType

type ConfigOptionType int

ConfigOptionType is the configuration option's type (string, bool, float, int)

const (
	InvalidOptionType ConfigOptionType = iota
	StringOptionType
	BoolOptionType
	IntOptionType
	FloatOptionType
	SnowflakeOptionType
)

Option type constants

func (ConfigOptionType) String

func (t ConfigOptionType) String() string

type ConfigSetting

type ConfigSetting struct {
	// contains filtered or unexported fields
}

ConfigSetting ...

func (ConfigSetting) ToBool

func (s ConfigSetting) ToBool() bool

ToBool returns the ConfigSetting as a bool

func (ConfigSetting) ToChannelID

func (s ConfigSetting) ToChannelID() discord.ChannelID

ToChannelID returns the ConfigSetting as a discord.ChannelID

func (ConfigSetting) ToFloat

func (s ConfigSetting) ToFloat() float64

ToFloat returns the ConfigSetting as a float64

func (ConfigSetting) ToInt

func (s ConfigSetting) ToInt() int64

ToInt returns the ConfigSetting as an int64

func (ConfigSetting) ToInterface

func (s ConfigSetting) ToInterface() interface{}

ToInterface returns the ConfigSetting as an interface

func (ConfigSetting) ToRoleID

func (s ConfigSetting) ToRoleID() discord.RoleID

ToRoleID returns the ConfigSetting as a discord.RoleID

func (ConfigSetting) ToSnowflake

func (s ConfigSetting) ToSnowflake() discord.Snowflake

ToSnowflake returns the ConfigSetting as a discord.Snowflake

func (ConfigSetting) ToString

func (s ConfigSetting) ToString() string

ToString returns the ConfigSetting as a string

func (ConfigSetting) ToUint

func (s ConfigSetting) ToUint() uint64

ToUint returns the ConfigSetting as a uint64

func (ConfigSetting) ToUserID

func (s ConfigSetting) ToUserID() discord.UserID

ToUserID returns the ConfigSetting as a discord.UserID

type DB

type DB struct {
	*pgxpool.Pool

	BotConfig common.BotConfig
	Config    Config
	Perms     PermissionConfig
	Overrides CommandOverrides
}

DB ...

func New

func New(conf common.BotConfig) (*DB, error)

New returns a new DB

func (*DB) AddApplicationTrack

func (db *DB) AddApplicationTrack(t ApplicationTrack) (*ApplicationTrack, error)

AddApplicationTrack adds an application track to the database.

func (*DB) AddQuestion

func (db *DB) AddQuestion(trackID int64, question string) (err error)

AddQuestion ...

func (*DB) AddResponse

func (db *DB) AddResponse(appID xid.ID, resp AppResponse) error

AddResponse adds or updates a response to an application.

func (*DB) AllInvites

func (db *DB) AllInvites() (invs map[string]string, err error)

func (*DB) AllUserApplications

func (db *DB) AllUserApplications(userID discord.UserID) (as []Application, err error)

AllUserApplications returns all of this user's applications, sorted by ID descending.

func (*DB) ApplicationTrack

func (db *DB) ApplicationTrack(id int64) (*ApplicationTrack, error)

ApplicationTrack ...

func (*DB) ApplicationTracks

func (db *DB) ApplicationTracks() (tracks []ApplicationTrack, err error)

ApplicationTracks returns all application tracks sorted by ID.

func (*DB) ChannelApplication

func (db *DB) ChannelApplication(chID discord.ChannelID) (*Application, error)

ChannelApplication ...

func (*DB) ClearInviteName

func (db *DB) ClearInviteName(code string) error

func (*DB) CloseApplication

func (db *DB) CloseApplication(id xid.ID) error

CloseApplication closes the given application.

func (*DB) CompleteApp

func (db *DB) CompleteApp(appID xid.ID) error

CompleteApp ...

func (*DB) CreateApplication

func (db *DB) CreateApplication(userID discord.UserID, chID discord.ChannelID) (a Application, err error)

CreateApplication ...

func (*DB) DeleteMessage

func (db *DB) DeleteMessage(id discord.MessageID) (err 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) InsertMessage

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

InsertMessage inserts a message

func (*DB) InsertModLog

func (db *DB) InsertModLog(ctx context.Context, entry ModLogEntry) (ModLogEntry, error)

func (*DB) InviteName

func (db *DB) InviteName(code string) (name string)

func (*DB) ModLogFor

func (db *DB) ModLogFor(guildID discord.GuildID, userID discord.UserID) (es []ModLogEntry, err error)

func (*DB) Prefixer

func (db *DB) Prefixer(m discord.Message) int

Prefixer ...

func (*DB) Questions

func (db *DB) Questions(id int64) (qs []AppQuestion, err error)

Questions gets all questions for an interview track.

func (*DB) ResetApplication

func (db *DB) ResetApplication(appID xid.ID) error

func (*DB) SetCloseID

func (db *DB) SetCloseID(appID xid.ID, eventID int64) error

func (*DB) SetEventID

func (db *DB) SetEventID(appID xid.ID, eventID int64) error

func (*DB) SetInviteName

func (db *DB) SetInviteName(code, name string) error

func (*DB) SetQuestionIndex

func (db *DB) SetQuestionIndex(appID xid.ID, index int) error

SetQuestionIndex ...

func (*DB) SetTrack

func (db *DB) SetTrack(appID xid.ID, trackID int64) error

SetTrack ...

func (*DB) SetTranscript

func (db *DB) SetTranscript(appID xid.ID, chID discord.ChannelID, msgID discord.MessageID) error

SetTranscript ...

func (*DB) SetVerified

func (db *DB) SetVerified(appID xid.ID, mod discord.UserID, verified bool, denyReason *string) error

SetVerified ...

func (*DB) SyncConfig

func (db *DB) SyncConfig() error

SyncConfig synchronizes configuration with the database.

func (*DB) SyncOverrides

func (db *DB) SyncOverrides() error

SyncOverrides synchronizes command overrides with the database.

func (*DB) SyncPerms

func (db *DB) SyncPerms() error

SyncPerms synchronizes role/user permissions with the database.

func (*DB) UpdateApplicationTrack

func (db *DB) UpdateApplicationTrack(t ApplicationTrack) error

UpdateApplicationTrack updates the given application track.

func (*DB) UpdateModLogMessage

func (db *DB) UpdateModLogMessage(id int64, chID discord.ChannelID, msgID discord.MessageID) (e ModLogEntry, err error)

func (*DB) UpdateModLogReason

func (db *DB) UpdateModLogReason(id int64, reason string) (e ModLogEntry, err error)

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

func (db *DB) UserApplication(userID discord.UserID) (*Application, error)

UserApplication returns an open application for the given user.

func (*DB) UserStringGet

func (db *DB) UserStringGet(ctx context.Context, userID discord.UserID, key string) (string, error)

func (*DB) UserStringSet

func (db *DB) UserStringSet(userID discord.UserID, key, val string) error

func (*DB) UserTime

func (db *DB) UserTime(ctx context.Context, userID discord.UserID) *time.Location

type Message

type Message struct {
	ID        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
}

Message is a single message

type ModLogEntry

type ModLogEntry struct {
	ID      int64
	GuildID discord.GuildID

	UserID discord.UserID
	ModID  discord.UserID

	ActionType string
	Reason     string

	Time time.Time

	ChannelID *discord.ChannelID
	MessageID *discord.MessageID
}

func (ModLogEntry) Embed

func (m ModLogEntry) Embed(s *state.State) discord.Embed

type PermissionConfig

type PermissionConfig struct {
	BotOwners []discord.UserID `json:"-"`

	User   []PermissionOverride `json:"user"`
	Helper []PermissionOverride `json:"helper"`
	Staff  []PermissionOverride `json:"staff"`
	Owner  []PermissionOverride `json:"owner"`
}

PermissionConfig ...

func (PermissionConfig) Level

Level returns the permission level of the given member.

type PermissionLevel

type PermissionLevel int

PermissionLevel is command permission levels

const (
	InvalidLevel  PermissionLevel = 0
	EveryoneLevel PermissionLevel = 1
	UserLevel     PermissionLevel = 2
	HelperLevel   PermissionLevel = 3
	StaffLevel    PermissionLevel = 4
	OwnerLevel    PermissionLevel = 5
	DisabledLevel PermissionLevel = 6
)

Permission level constants

func (PermissionLevel) String

func (p PermissionLevel) String() string

type PermissionOverride

type PermissionOverride struct {
	ID   discord.Snowflake `json:"id"`
	Type PermissionType    `json:"type"`
}

PermissionOverride ...

func (PermissionOverride) Has

Has ...

type PermissionType

type PermissionType int

PermissionType is command permission types

const (
	UserPermission PermissionType = 0
	RolePermission PermissionType = 1
)

Permission type constants

Jump to

Keyboard shortcuts

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