Add info command

master
ALI Hamza 2021-09-07 21:35:56 +07:00
parent 87b08cb2c5
commit d088e909c3
Signed by: hamza
GPG Key ID: 22473A32291F8CB6
2 changed files with 49 additions and 2 deletions

@ -0,0 +1,40 @@
package main
import (
"bytes"
"fmt"
"runtime"
"time"
"github.com/diamondburned/arikawa/v3/api"
"github.com/diamondburned/arikawa/v3/discord"
"github.com/diamondburned/arikawa/v3/gateway"
"github.com/dustin/go-humanize"
)
var started = time.Now().Unix()
func (b *botState) handleInfo(e *gateway.InteractionCreateEvent) {
stats := runtime.MemStats{}
runtime.ReadMemStats(&stats)
buf := &bytes.Buffer{}
fmt.Fprintf(buf, "Go: %s\n", runtime.Version())
fmt.Fprintf(buf, "Uptime: <t:%d:R>\n", started)
fmt.Fprintf(buf, "Memory: %s / %s (alloc / sys)\n", humanize.Bytes(stats.Alloc), humanize.Bytes(stats.Sys))
fmt.Fprintf(buf, "Source: %s\n", "[link](https://gitea.teamortix.com/hamza/discodoc)")
fmt.Fprintf(buf, "Concurrent Tasks: %s\n", humanize.Comma(int64(runtime.NumGoroutine())))
b.state.RespondInteraction(e.ID, e.Token, api.InteractionResponse{
Type: api.MessageInteractionWithSource,
Data: &api.InteractionResponseData{
Flags: api.EphemeralResponse,
Embeds: &[]discord.Embed{{
Title: "DiscoDocs",
Description: buf.String(),
Color: accentColor,
}},
},
})
}

@ -26,10 +26,13 @@ func (b *botState) OnCommand(e *gateway.InteractionCreateEvent) {
e.User = &e.Member.User
}
if e.Data.Name == "docs" {
switch e.Data.Name {
case "docs":
b.handleDocs(e)
return
case "info":
b.handleInfo(e)
}
if data, ok := interactionMap[e.Data.CustomID]; ok {
b.onDocsComponent(e, data)
return
@ -126,4 +129,8 @@ var commands = []api.CreateCommandData{
},
},
},
{
Name: "info",
Description: "Generic bot information",
},
}