Refactor: migrate discordbot
All checks were successful
All checks were successful
This commit is contained in:
43
bot/commands/greet.go
Normal file
43
bot/commands/greet.go
Normal file
@@ -0,0 +1,43 @@
|
||||
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),
|
||||
},
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user