continued porting to disgo...
This commit is contained in:
33
cmd_ping.go
33
cmd_ping.go
@@ -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,
|
||||
}
|
||||
*/
|
||||
|
Reference in New Issue
Block a user