continued porting to disgo...

This commit is contained in:
2024-04-09 23:21:08 +02:00
parent 01ac1ec363
commit b7f126efba
10 changed files with 284 additions and 379 deletions

View File

@@ -1,28 +1,28 @@
package main
/*
import (
"fmt"
"net/http"
"time"
"github.com/bwmarrin/discordgo"
"github.com/disgoorg/disgo/discord"
"github.com/disgoorg/disgo/events"
"github.com/sirupsen/logrus"
)
var cmd_ping Command = Command{
Definition: discordgo.ApplicationCommand{
Definition: discord.SlashCommandCreate{
Name: "ping",
Description: "Returns the ping of the bot",
},
Interact: func(s *discordgo.Session, i *discordgo.InteractionCreate) {
Interact: func(e *events.ApplicationCommandInteractionCreate) {
start := time.Now()
client := http.Client{
Timeout: 5 * time.Second,
}
resp, err := client.Get("https://discord.com/api/" + discordgo.APIVersion + "/gateway/bot")
resp, err := client.Get("https://discord.com/api/v9/gateway/bot")
if err != nil {
logrus.Error(err)
return
@@ -30,23 +30,26 @@ var cmd_ping Command = Command{
defer resp.Body.Close()
ping := time.Since(start)
var ping_color string
var pingColor string
if ping.Milliseconds() < 200 {
ping_color = "green"
pingColor = "green"
} else if ping.Milliseconds() < 400 {
ping_color = "yellow"
pingColor = "yellow"
} else {
ping_color = "red"
pingColor = "red"
}
err = respondEmbed(i.Interaction, discordgo.MessageEmbed{
Title: s.State.User.Username + " ping",
Description: fmt.Sprintf("# %.2fms", ping.Seconds()*1000),
Type: discordgo.EmbedTypeArticle,
Color: hexToDecimal(color[ping_color])}, true)
app, err := e.Client().Rest().GetCurrentApplication()
if err != nil {
logrus.Error(err)
}
err = e.CreateMessage(discord.NewMessageCreateBuilder().
SetEmbeds(discord.NewEmbedBuilder().
SetTitle(app.Bot.Username + " ping").
SetDescription(fmt.Sprintf("# %.2fms", ping.Seconds()*1000)).
SetColor(hexToDecimal(color[pingColor])).Build()).SetEphemeral(true).Build())
if err != nil {
logrus.Error(err)
}
},
AllowDM: true,
}
*/