75 lines
2.1 KiB
Go
75 lines
2.1 KiB
Go
package discord
|
|
|
|
import (
|
|
"fmt"
|
|
"git.jojodev.com/Minecraft/canopeas/database"
|
|
"git.jojodev.com/Minecraft/canopeas/discord/track"
|
|
"github.com/bwmarrin/discordgo"
|
|
"github.com/rs/zerolog/log"
|
|
"strings"
|
|
)
|
|
|
|
var trackCommand = &discordgo.ApplicationCommand{
|
|
Name: "track",
|
|
Description: "Track words",
|
|
Options: []*discordgo.ApplicationCommandOption{
|
|
{
|
|
Type: discordgo.ApplicationCommandOptionSubCommand,
|
|
Name: "add",
|
|
Description: "Add a tracked word",
|
|
Options: []*discordgo.ApplicationCommandOption{
|
|
{
|
|
Type: discordgo.ApplicationCommandOptionString,
|
|
Name: "word",
|
|
Description: "The word to track",
|
|
Required: true,
|
|
},
|
|
},
|
|
},
|
|
{
|
|
Type: discordgo.ApplicationCommandOptionSubCommand,
|
|
Name: "remove",
|
|
Description: "Remove a tracked word",
|
|
Options: []*discordgo.ApplicationCommandOption{
|
|
{
|
|
Type: discordgo.ApplicationCommandOptionString,
|
|
Name: "word",
|
|
Description: "The tracked word to remove",
|
|
Required: true,
|
|
},
|
|
},
|
|
},
|
|
},
|
|
}
|
|
|
|
var (
|
|
trackCommandHandler = func(t track.Tracker, d *database.Database) func(*discordgo.Session, *discordgo.InteractionCreate) {
|
|
return func(s *discordgo.Session, i *discordgo.InteractionCreate) {
|
|
var action string
|
|
word := strings.ToLower(i.ApplicationCommandData().Options[0].Options[0].StringValue())
|
|
switch i.ApplicationCommandData().Options[0].Name {
|
|
case "add":
|
|
action = "added"
|
|
t.Add(word, i.User.ID)
|
|
case "remove":
|
|
action = "removed"
|
|
t.Remove(word, i.User.ID)
|
|
default:
|
|
log.Error().Msg("Track command did a woopsie")
|
|
}
|
|
if err := d.SetTrack(word, t[word]); err != nil {
|
|
log.Err(err).Msg("")
|
|
}
|
|
if err := s.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{
|
|
Type: discordgo.InteractionResponseChannelMessageWithSource,
|
|
Data: &discordgo.InteractionResponseData{
|
|
Content: fmt.Sprintf("Successfully %s tracking for %q", action, word),
|
|
Flags: uint64(discordgo.MessageFlagsEphemeral),
|
|
},
|
|
}); err != nil {
|
|
log.Err(err).Msg("")
|
|
}
|
|
}
|
|
}
|
|
)
|