diff --git a/commands/commands.go b/commands/commands.go index fdc8629..e50ac7b 100644 --- a/commands/commands.go +++ b/commands/commands.go @@ -41,4 +41,8 @@ var Commands = []*discordgo.ApplicationCommand{ }, }, }, + { + Name: "stop", + Description: "stop bot", + }, } diff --git a/handlers/basicCommands.go b/handlers/basicCommands.go index e16e1a6..ab44809 100644 --- a/handlers/basicCommands.go +++ b/handlers/basicCommands.go @@ -1,8 +1,10 @@ package handlers import ( + "fmt" "github.com/bwmarrin/discordgo" "kleincordBot/services" + "log" ) func ReadBackCommand(data discordgo.ApplicationCommandInteractionData, s *discordgo.Session, i *discordgo.InteractionCreate) { @@ -32,3 +34,46 @@ func Test1Command(s *discordgo.Session, i *discordgo.InteractionCreate) { 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) + } +} diff --git a/handlers/handlers.go b/handlers/handlers.go deleted file mode 100644 index 5ac8282..0000000 --- a/handlers/handlers.go +++ /dev/null @@ -1 +0,0 @@ -package handlers diff --git a/routers/commandRouter.go b/routers/commandRouter.go index 293fe18..224e3d4 100644 --- a/routers/commandRouter.go +++ b/routers/commandRouter.go @@ -11,11 +11,14 @@ func CommandRouter(s *discordgo.Session, i *discordgo.InteractionCreate) { switch data.Name { case "init": services.AddServer(i.GuildID, s) + handlers.InitCommand(s, i) case "test1": handlers.Test1Command(s, i) case "read_back": handlers.ReadBackCommand(data, s, i) case "delete": handlers.DeleteCommand(data, s, i) + case "stop": + handlers.StopCommand(s, i) } } diff --git a/services/Error.go b/services/Error.go index 609976e..9fd95c0 100644 --- a/services/Error.go +++ b/services/Error.go @@ -1,16 +1,19 @@ package services import ( + "fmt" "github.com/bwmarrin/discordgo" "strconv" + "time" ) func HandleError(err error, s *discordgo.Session) { - s.ChannelMessageSendComplex(strconv.Itoa(1236038688627101749), &discordgo.MessageSend{ + _, err = s.ChannelMessageSendComplex(strconv.Itoa(1236038688627101749), &discordgo.MessageSend{ Content: "@here", Embed: &discordgo.MessageEmbed{ - Title: "Error", - Color: 0xff0000, + Title: "Error", + Color: 0xff0000, + Timestamp: time.Now().Format(time.RFC3339), Fields: []*discordgo.MessageEmbedField{ { Value: "```" + err.Error() + "```", @@ -18,4 +21,7 @@ func HandleError(err error, s *discordgo.Session) { }, }, }) + if err != nil { + fmt.Println(err) + } }