kleincordBot/handlers/basicCommands.go

90 lines
2.1 KiB
Go
Raw Normal View History

2024-05-03 21:31:24 +02:00
package handlers
import (
"fmt"
2024-05-03 21:31:24 +02:00
"github.com/bwmarrin/discordgo"
"kleincordBot/services"
"log"
2024-05-04 13:36:37 +02:00
"os"
2024-05-04 13:23:57 +02:00
"time"
2024-05-03 21:31:24 +02:00
)
2024-05-04 13:23:57 +02:00
var LogChannelID string
2024-05-03 21:31:24 +02:00
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 {
2024-05-03 22:05:35 +02:00
services.HandleError(err, s)
2024-05-03 21:31:24 +02:00
}
}
func Test1Command(s *discordgo.Session, i *discordgo.InteractionCreate) {
err := s.InteractionRespond(
i.Interaction,
&discordgo.InteractionResponse{
Type: discordgo.InteractionResponseChannelMessageWithSource,
Data: &discordgo.InteractionResponseData{},
},
)
if err != nil {
2024-05-03 22:05:35 +02:00
services.HandleError(err, s)
2024-05-03 21:31:24 +02:00
}
}
func StopCommand(s *discordgo.Session, i *discordgo.InteractionCreate) {
s.InteractionRespond(
i.Interaction,
&discordgo.InteractionResponse{
Type: discordgo.InteractionResponseChannelMessageWithSource,
Data: &discordgo.InteractionResponseData{
Content: "bye",
},
},
)
2024-05-04 13:23:57 +02:00
s.ChannelMessageSendEmbed(
LogChannelID,
&discordgo.MessageEmbed{
2024-05-04 13:36:37 +02:00
Title: "stopped " + os.Getenv("ENVIRONMENT") + " with command",
2024-05-04 13:23:57 +02:00
Timestamp: time.Now().Format(time.RFC3339),
})
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)
}
}