-
Notifications
You must be signed in to change notification settings - Fork 1
/
ping.go
53 lines (47 loc) · 1005 Bytes
/
ping.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package bot
import (
"fmt"
"github.com/pauloo27/aryzona/internal/command"
"github.com/pauloo27/aryzona/internal/discord"
"github.com/pauloo27/aryzona/internal/discord/model"
"github.com/pauloo27/aryzona/internal/i18n"
)
var PingCommand = command.Command{
Name: "ping",
Handler: func(ctx *command.Context) command.Result {
t := ctx.T.(*i18n.CommandPing)
latency := formatAPILatency(ctx.Bot)
if latency == "0" {
latency = t.StillCalculating.Str(":hourglass_flowing_sand:")
}
return ctx.SuccessEmbed(
model.NewEmbed().
WithTitle(t.Title.Str(":ping_pong:")).
WithFooter(t.Footer.Str()).
WithField(
t.APILatency.Str(),
latency,
),
)
},
}
func formatAPILatency(bot discord.BotAdapter) string {
latency := bot.Latency()
if latency == 0 {
return "0"
}
ms := latency.Milliseconds()
var icon string
if ms < 50 {
icon = "🟢"
} else if ms < 100 {
icon = "🟡"
} else {
icon = "🔴"
}
return fmt.Sprintf(
"%s %d ms",
icon,
ms,
)
}