Command rework
This commit is contained in:
@@ -113,3 +113,31 @@ func (r *Repo) SetNotificationChannel(ctx context.Context, guildID, channelID in
|
||||
return err
|
||||
}
|
||||
|
||||
// IsEnabled reports whether Twitch notifications are enabled for guildID.
|
||||
// A guild with no twitch_config row yet defaults to enabled, matching the
|
||||
// column's own DEFAULT TRUE - "never configured" and "explicitly on" are
|
||||
// the same state until someone actually flips it off.
|
||||
func (r *Repo) IsEnabled(ctx context.Context, guildID int64) (bool, error) {
|
||||
const q = `SELECT enabled FROM twitch_config WHERE guild_id = $1`
|
||||
var enabled bool
|
||||
err := r.db.QueryRowContext(ctx, q, guildID).Scan(&enabled)
|
||||
if err == sql.ErrNoRows {
|
||||
return true, nil
|
||||
}
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
return enabled, nil
|
||||
}
|
||||
|
||||
func (r *Repo) SetEnabled(ctx context.Context, guildID int64, enabled bool) error {
|
||||
const q = `
|
||||
INSERT INTO twitch_config (guild_id, enabled)
|
||||
VALUES ($1, $2)
|
||||
ON CONFLICT (guild_id)
|
||||
DO UPDATE SET enabled = EXCLUDED.enabled
|
||||
`
|
||||
_, err := r.db.ExecContext(ctx, q, guildID, enabled)
|
||||
return err
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user