2024-05-03 17:39:11 +02:00
|
|
|
package main
|
|
|
|
|
|
|
|
|
|
import (
|
2024-05-03 21:00:32 +02:00
|
|
|
"fmt"
|
2024-05-03 17:39:11 +02:00
|
|
|
"github.com/bwmarrin/discordgo"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func MessageHandler(s *discordgo.Session, m *discordgo.MessageCreate) {
|
|
|
|
|
|
|
|
|
|
if m.Author.ID == s.State.User.ID {
|
|
|
|
|
return
|
|
|
|
|
}
|
2024-05-03 21:00:32 +02:00
|
|
|
switch m.Content {
|
|
|
|
|
case "test":
|
|
|
|
|
var serverListString string
|
|
|
|
|
for i, server := range ServerList {
|
|
|
|
|
serverListString = serverListString + fmt.Sprintf("\n %d) ", i+1) + server.Name
|
2024-05-03 18:07:31 +02:00
|
|
|
}
|
2024-05-03 21:00:32 +02:00
|
|
|
s.ChannelMessageSendEmbed(m.ChannelID, &discordgo.MessageEmbed{
|
|
|
|
|
Title: "Servers",
|
|
|
|
|
Fields: []*discordgo.MessageEmbedField{
|
|
|
|
|
{
|
|
|
|
|
Value: serverListString,
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
Type: discordgo.EmbedTypeArticle,
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
case "!test":
|
|
|
|
|
s.ChannelMessageSendEmbed(m.ChannelID, &discordgo.MessageEmbed{
|
|
|
|
|
Title: "Servers",
|
|
|
|
|
Fields: []*discordgo.MessageEmbedField{
|
|
|
|
|
{
|
|
|
|
|
Value: "test",
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
Type: discordgo.EmbedTypeArticle,
|
|
|
|
|
})
|
2024-05-03 17:39:11 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func CommandHandler(s *discordgo.Session, i *discordgo.InteractionCreate) {
|
|
|
|
|
data := i.ApplicationCommandData()
|
|
|
|
|
switch data.Name {
|
|
|
|
|
case "init":
|
|
|
|
|
AddServer(i.GuildID, s)
|
|
|
|
|
case "test1":
|
|
|
|
|
err := s.InteractionRespond(
|
|
|
|
|
i.Interaction,
|
|
|
|
|
&discordgo.InteractionResponse{
|
|
|
|
|
Type: discordgo.InteractionResponseChannelMessageWithSource,
|
2024-05-03 21:00:32 +02:00
|
|
|
Data: &discordgo.InteractionResponseData{},
|
2024-05-03 17:39:11 +02:00
|
|
|
},
|
|
|
|
|
)
|
|
|
|
|
if err != nil {
|
|
|
|
|
// Handle the error
|
|
|
|
|
}
|
|
|
|
|
case "read_back":
|
|
|
|
|
err := s.InteractionRespond(
|
|
|
|
|
i.Interaction,
|
|
|
|
|
&discordgo.InteractionResponse{
|
|
|
|
|
Type: discordgo.InteractionResponseChannelMessageWithSource,
|
|
|
|
|
Data: &discordgo.InteractionResponseData{
|
|
|
|
|
Content: data.Options[0].Value.(string),
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
)
|
|
|
|
|
if err != nil {
|
|
|
|
|
// Handle the error
|
|
|
|
|
}
|
|
|
|
|
case "delete":
|
2024-05-03 18:07:31 +02:00
|
|
|
deleteMessages(data, s, i)
|
2024-05-03 17:39:11 +02:00
|
|
|
}
|
|
|
|
|
}
|