first commit
This commit is contained in:
48
bot/handlers_challenge.go
Normal file
48
bot/handlers_challenge.go
Normal file
@@ -0,0 +1,48 @@
|
||||
package bot
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"github.com/bwmarrin/discordgo"
|
||||
)
|
||||
|
||||
func (b *Bot) handleResetChallenge(ctx context.Context, s *discordgo.Session, i *discordgo.InteractionCreate) {
|
||||
if !b.isAdmin(i) {
|
||||
respondEphemeral(s, i, "You need the **Manage Server** permission to use this command.")
|
||||
return
|
||||
}
|
||||
name, _ := optString(i.ApplicationCommandData().Options, "name")
|
||||
if err := b.db.ResetChallenge(ctx, i.GuildID, name); err != nil {
|
||||
respondEphemeral(s, i, "Error resetting challenge.")
|
||||
return
|
||||
}
|
||||
_ = b.db.DeleteSetting(ctx, i.GuildID, "challenge_goal_km")
|
||||
respond(s, i, "🔄 Challenge reset! Previous totals have been archived. Start logging your rides!")
|
||||
}
|
||||
|
||||
func (b *Bot) handleSetChallengeName(ctx context.Context, s *discordgo.Session, i *discordgo.InteractionCreate) {
|
||||
if !b.isAdmin(i) {
|
||||
respondEphemeral(s, i, "You need the **Manage Server** permission to use this command.")
|
||||
return
|
||||
}
|
||||
name := i.ApplicationCommandData().Options[0].StringValue()
|
||||
if err := b.db.SetSetting(ctx, i.GuildID, "challenge_name", name); err != nil {
|
||||
respondEphemeral(s, i, "Error saving challenge name.")
|
||||
return
|
||||
}
|
||||
respondEphemeral(s, i, fmt.Sprintf("✅ Challenge name set to **%s**.", name))
|
||||
}
|
||||
|
||||
func (b *Bot) handleSetGoal(ctx context.Context, s *discordgo.Session, i *discordgo.InteractionCreate) {
|
||||
if !b.isAdmin(i) {
|
||||
respondEphemeral(s, i, "You need the **Manage Server** permission to use this command.")
|
||||
return
|
||||
}
|
||||
km := i.ApplicationCommandData().Options[0].FloatValue()
|
||||
if err := b.db.SetSetting(ctx, i.GuildID, "challenge_goal_km", fmt.Sprintf("%.2f", km)); err != nil {
|
||||
respondEphemeral(s, i, "Error saving goal.")
|
||||
return
|
||||
}
|
||||
respond(s, i, fmt.Sprintf("🎯 Goal set to **%.1f km**! Let's ride!", km))
|
||||
}
|
||||
Reference in New Issue
Block a user