Added Stop command
improved init command improved error handler
This commit is contained in:
parent
62e7283f47
commit
1592192b01
@ -41,4 +41,8 @@ var Commands = []*discordgo.ApplicationCommand{
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
Name: "stop",
|
||||||
|
Description: "stop bot",
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,8 +1,10 @@
|
|||||||
package handlers
|
package handlers
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"github.com/bwmarrin/discordgo"
|
"github.com/bwmarrin/discordgo"
|
||||||
"kleincordBot/services"
|
"kleincordBot/services"
|
||||||
|
"log"
|
||||||
)
|
)
|
||||||
|
|
||||||
func ReadBackCommand(data discordgo.ApplicationCommandInteractionData, s *discordgo.Session, i *discordgo.InteractionCreate) {
|
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)
|
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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@ -1 +0,0 @@
|
|||||||
package handlers
|
|
||||||
@ -11,11 +11,14 @@ func CommandRouter(s *discordgo.Session, i *discordgo.InteractionCreate) {
|
|||||||
switch data.Name {
|
switch data.Name {
|
||||||
case "init":
|
case "init":
|
||||||
services.AddServer(i.GuildID, s)
|
services.AddServer(i.GuildID, s)
|
||||||
|
handlers.InitCommand(s, i)
|
||||||
case "test1":
|
case "test1":
|
||||||
handlers.Test1Command(s, i)
|
handlers.Test1Command(s, i)
|
||||||
case "read_back":
|
case "read_back":
|
||||||
handlers.ReadBackCommand(data, s, i)
|
handlers.ReadBackCommand(data, s, i)
|
||||||
case "delete":
|
case "delete":
|
||||||
handlers.DeleteCommand(data, s, i)
|
handlers.DeleteCommand(data, s, i)
|
||||||
|
case "stop":
|
||||||
|
handlers.StopCommand(s, i)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,16 +1,19 @@
|
|||||||
package services
|
package services
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"github.com/bwmarrin/discordgo"
|
"github.com/bwmarrin/discordgo"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
func HandleError(err error, s *discordgo.Session) {
|
func HandleError(err error, s *discordgo.Session) {
|
||||||
s.ChannelMessageSendComplex(strconv.Itoa(1236038688627101749), &discordgo.MessageSend{
|
_, err = s.ChannelMessageSendComplex(strconv.Itoa(1236038688627101749), &discordgo.MessageSend{
|
||||||
Content: "@here",
|
Content: "@here",
|
||||||
Embed: &discordgo.MessageEmbed{
|
Embed: &discordgo.MessageEmbed{
|
||||||
Title: "Error",
|
Title: "Error",
|
||||||
Color: 0xff0000,
|
Color: 0xff0000,
|
||||||
|
Timestamp: time.Now().Format(time.RFC3339),
|
||||||
Fields: []*discordgo.MessageEmbedField{
|
Fields: []*discordgo.MessageEmbedField{
|
||||||
{
|
{
|
||||||
Value: "```" + err.Error() + "```",
|
Value: "```" + err.Error() + "```",
|
||||||
@ -18,4 +21,7 @@ func HandleError(err error, s *discordgo.Session) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println(err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user