Files
backend/bot/commands/echo.go
Yi-Ting Shih 47f09b733a
All checks were successful
Go test / run-go-vet (push) Successful in 20s
Go test / check-swagger-up-to-date (push) Successful in 9s
Go test / run-go-test (push) Successful in 47s
Go test / cleanup-go-test (push) Successful in 4s
Go test / release-image (push) Successful in 3m35s
Refactor: migrate discordbot
2025-12-13 04:58:12 +08:00

54 lines
1.3 KiB
Go

package commands
import (
"gitea.konchin.com/go2025/backend/bot"
"github.com/bwmarrin/discordgo"
)
type EchoCommand struct {
bot *bot.Bot
}
func NewEchoCommand(bot *bot.Bot) bot.Command {
return &EchoCommand{bot: bot}
}
func (self *EchoCommand) ApplicationCommand() *discordgo.ApplicationCommand {
return &discordgo.ApplicationCommand{
Name: "echo",
Description: "Bot repeats what you say",
Options: []*discordgo.ApplicationCommandOption{
{
Type: discordgo.ApplicationCommandOptionString,
Name: "message",
Description: "Message to echo",
Required: true,
},
},
}
}
func (self *EchoCommand) Handler() bot.CommandHandler {
return func(s *discordgo.Session, i *discordgo.InteractionCreate) {
options := i.ApplicationCommandData().Options
if len(options) == 0 {
s.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{
Type: discordgo.InteractionResponseChannelMessageWithSource,
Data: &discordgo.InteractionResponseData{
Content: "No message provided!",
},
})
return
}
message := options[0].StringValue()
s.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{
Type: discordgo.InteractionResponseChannelMessageWithSource,
Data: &discordgo.InteractionResponseData{
Content: message,
},
})
}
}