Files
backend/bot/commands/greet.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

44 lines
981 B
Go

package commands
import (
"fmt"
"gitea.konchin.com/go2025/backend/bot"
"github.com/bwmarrin/discordgo"
)
type GreetCommand struct {
bot *bot.Bot
}
func NewGreetCommand(bot *bot.Bot) bot.Command {
return &GreetCommand{bot: bot}
}
func (self *GreetCommand) ApplicationCommand() *discordgo.ApplicationCommand {
return &discordgo.ApplicationCommand{
Name: "greet",
Description: "Get a friendly greeting",
}
}
func (self *GreetCommand) Handler() bot.CommandHandler {
return func(s *discordgo.Session, i *discordgo.InteractionCreate) {
var username string
if i.Member != nil {
username = i.Member.User.Username
} else if i.User != nil {
username = i.User.Username
} else {
username = "Unknown"
}
s.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{
Type: discordgo.InteractionResponseChannelMessageWithSource,
Data: &discordgo.InteractionResponseData{
Content: fmt.Sprintf("Ciallo, %s!", username),
},
})
}
}