kleincordBot/handlers/basicCommands.go
darius 1592192b01 Added Stop command
improved init command
improved error handler
2024-05-03 22:37:29 +02:00

80 lines
1.9 KiB
Go

package handlers
import (
"fmt"
"github.com/bwmarrin/discordgo"
"kleincordBot/services"
"log"
)
func ReadBackCommand(data discordgo.ApplicationCommandInteractionData, s *discordgo.Session, i *discordgo.InteractionCreate) {
err := s.InteractionRespond(
i.Interaction,
&discordgo.InteractionResponse{
Type: discordgo.InteractionResponseChannelMessageWithSource,
Data: &discordgo.InteractionResponseData{
Content: data.Options[0].Value.(string),
},
},
)
if err != nil {
services.HandleError(err, s)
}
}
func Test1Command(s *discordgo.Session, i *discordgo.InteractionCreate) {
err := s.InteractionRespond(
i.Interaction,
&discordgo.InteractionResponse{
Type: discordgo.InteractionResponseChannelMessageWithSource,
Data: &discordgo.InteractionResponseData{},
},
)
if err != nil {
services.HandleError(err, s)
}
}
func StopCommand(s *discordgo.Session, i *discordgo.InteractionCreate) {
s.InteractionRespond(
i.Interaction,
&discordgo.InteractionResponse{
Type: discordgo.InteractionResponseChannelMessageWithSource,
Data: &discordgo.InteractionResponseData{
Content: "bye",
},
},
)
log.Fatalf("stop command")
}
func InitCommand(s *discordgo.Session, i *discordgo.InteractionCreate) {
var serverListString string
for i, server := range services.ServerList {
serverListString = serverListString + fmt.Sprintf("\n %d) ", i+1) + server.Name
}
err := s.InteractionRespond(
i.Interaction,
&discordgo.InteractionResponse{
Type: discordgo.InteractionResponseChannelMessageWithSource,
Data: &discordgo.InteractionResponseData{
Embeds: []*discordgo.MessageEmbed{
{
Title: "Servers",
Fields: []*discordgo.MessageEmbedField{
{
Value: serverListString,
},
},
Type: discordgo.EmbedTypeArticle,
},
},
},
},
)
if err != nil {
services.HandleError(err, s)
}
}