Compare commits
7
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d64a532a81 | ||
|
|
136377d81a | ||
|
|
0218676e2d | ||
|
|
e333f084b5 | ||
|
|
f285367511 | ||
|
|
177c820821 | ||
|
|
ffb8b963fa |
No files matched your search
@@ -93,9 +93,10 @@ func (r *Repo) GetSettings(ctx context.Context, guildID int64) (*Settings, error
|
|||||||
err := r.db.QueryRowContext(ctx, q, guildID).Scan(&s.Enabled, &ch, &logCh, &panel, &s.PanelTitle, &s.PanelDescription, &s.MaxOpenPerUser)
|
err := r.db.QueryRowContext(ctx, q, guildID).Scan(&s.Enabled, &ch, &logCh, &panel, &s.PanelTitle, &s.PanelDescription, &s.MaxOpenPerUser)
|
||||||
switch {
|
switch {
|
||||||
case errors.Is(err, sql.ErrNoRows):
|
case errors.Is(err, sql.ErrNoRows):
|
||||||
|
// Modules start off until the server sets them up.
|
||||||
return &Settings{
|
return &Settings{
|
||||||
GuildID: guildID,
|
GuildID: guildID,
|
||||||
Enabled: true,
|
Enabled: false,
|
||||||
PanelTitle: DefaultPanelTitle,
|
PanelTitle: DefaultPanelTitle,
|
||||||
PanelDescription: DefaultPanelDescription,
|
PanelDescription: DefaultPanelDescription,
|
||||||
MaxOpenPerUser: DefaultMaxOpenPerUser,
|
MaxOpenPerUser: DefaultMaxOpenPerUser,
|
||||||
@@ -109,11 +110,12 @@ func (r *Repo) GetSettings(ctx context.Context, guildID int64) (*Settings, error
|
|||||||
}
|
}
|
||||||
|
|
||||||
// SetChannels saves where tickets live and where transcripts go. A zero log
|
// SetChannels saves where tickets live and where transcripts go. A zero log
|
||||||
// channel clears it.
|
// channel clears it. Setting tickets up for the first time turns them on
|
||||||
|
// (they start off); after that, the on/off switch is left alone.
|
||||||
func (r *Repo) SetChannels(ctx context.Context, guildID, channelID, logChannelID int64) error {
|
func (r *Repo) SetChannels(ctx context.Context, guildID, channelID, logChannelID int64) error {
|
||||||
const q = `
|
const q = `
|
||||||
INSERT INTO ticket_settings (guild_id, channel_id, log_channel_id)
|
INSERT INTO ticket_settings (guild_id, channel_id, log_channel_id, enabled)
|
||||||
VALUES ($1, $2, $3)
|
VALUES ($1, $2, $3, TRUE)
|
||||||
ON CONFLICT (guild_id) DO UPDATE SET
|
ON CONFLICT (guild_id) DO UPDATE SET
|
||||||
channel_id = EXCLUDED.channel_id,
|
channel_id = EXCLUDED.channel_id,
|
||||||
log_channel_id = EXCLUDED.log_channel_id`
|
log_channel_id = EXCLUDED.log_channel_id`
|
||||||
|
|||||||
@@ -102,10 +102,13 @@ func (r *Repo) GetNotificationChannel(ctx context.Context, guildID int64) (int64
|
|||||||
return chID.Int64, true, nil
|
return chID.Int64, true, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SetNotificationChannel sets where live alerts go. Setting it for the first
|
||||||
|
// time turns alerts on (they start off); after that, the on/off switch is
|
||||||
|
// left alone.
|
||||||
func (r *Repo) SetNotificationChannel(ctx context.Context, guildID, channelID int64) error {
|
func (r *Repo) SetNotificationChannel(ctx context.Context, guildID, channelID int64) error {
|
||||||
const q = `
|
const q = `
|
||||||
INSERT INTO twitch_config (guild_id, twitch_channel_id)
|
INSERT INTO twitch_config (guild_id, twitch_channel_id, enabled)
|
||||||
VALUES ($1, $2)
|
VALUES ($1, $2, TRUE)
|
||||||
ON CONFLICT (guild_id)
|
ON CONFLICT (guild_id)
|
||||||
DO UPDATE SET twitch_channel_id = EXCLUDED.twitch_channel_id
|
DO UPDATE SET twitch_channel_id = EXCLUDED.twitch_channel_id
|
||||||
`
|
`
|
||||||
@@ -114,15 +117,14 @@ func (r *Repo) SetNotificationChannel(ctx context.Context, guildID, channelID in
|
|||||||
}
|
}
|
||||||
|
|
||||||
// IsEnabled reports whether Twitch notifications are enabled for guildID.
|
// IsEnabled reports whether Twitch notifications are enabled for guildID.
|
||||||
// A guild with no twitch_config row yet defaults to enabled, matching the
|
// A guild with no twitch_config row yet is off: modules start off until
|
||||||
// column's own DEFAULT TRUE - "never configured" and "explicitly on" are
|
// the server sets them up.
|
||||||
// the same state until someone actually flips it off.
|
|
||||||
func (r *Repo) IsEnabled(ctx context.Context, guildID int64) (bool, error) {
|
func (r *Repo) IsEnabled(ctx context.Context, guildID int64) (bool, error) {
|
||||||
const q = `SELECT enabled FROM twitch_config WHERE guild_id = $1`
|
const q = `SELECT enabled FROM twitch_config WHERE guild_id = $1`
|
||||||
var enabled bool
|
var enabled bool
|
||||||
err := r.db.QueryRowContext(ctx, q, guildID).Scan(&enabled)
|
err := r.db.QueryRowContext(ctx, q, guildID).Scan(&enabled)
|
||||||
if err == sql.ErrNoRows {
|
if err == sql.ErrNoRows {
|
||||||
return true, nil
|
return false, nil
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, err
|
return false, err
|
||||||
|
|||||||
+2
-2
@@ -46,7 +46,7 @@ CREATE TABLE IF NOT EXISTS levelup (
|
|||||||
CREATE TABLE IF NOT EXISTS twitch_config (
|
CREATE TABLE IF NOT EXISTS twitch_config (
|
||||||
guild_id BIGINT PRIMARY KEY,
|
guild_id BIGINT PRIMARY KEY,
|
||||||
twitch_channel_id BIGINT,
|
twitch_channel_id BIGINT,
|
||||||
enabled BOOLEAN NOT NULL DEFAULT TRUE
|
enabled BOOLEAN NOT NULL DEFAULT FALSE
|
||||||
);
|
);
|
||||||
|
|
||||||
CREATE TABLE IF NOT EXISTS rps (
|
CREATE TABLE IF NOT EXISTS rps (
|
||||||
@@ -180,7 +180,7 @@ CREATE TABLE IF NOT EXISTS music_commands (
|
|||||||
-- Tickets (mirror of velox-dashboard-api migration 000016_tickets)
|
-- Tickets (mirror of velox-dashboard-api migration 000016_tickets)
|
||||||
CREATE TABLE IF NOT EXISTS ticket_settings (
|
CREATE TABLE IF NOT EXISTS ticket_settings (
|
||||||
guild_id BIGINT PRIMARY KEY,
|
guild_id BIGINT PRIMARY KEY,
|
||||||
enabled BOOLEAN NOT NULL DEFAULT TRUE,
|
enabled BOOLEAN NOT NULL DEFAULT FALSE,
|
||||||
channel_id BIGINT,
|
channel_id BIGINT,
|
||||||
log_channel_id BIGINT,
|
log_channel_id BIGINT,
|
||||||
panel_message_id BIGINT,
|
panel_message_id BIGINT,
|
||||||
|
|||||||
Reference in new issue
Block a user