From d088e909c30e2d3afa2a030b912b6c4ae164794d Mon Sep 17 00:00:00 2001 From: Hamza Ali Date: Tue, 7 Sep 2021 21:35:56 +0700 Subject: [PATCH] Add info command --- info.go | 40 ++++++++++++++++++++++++++++++++++++++++ main.go | 11 +++++++++-- 2 files changed, 49 insertions(+), 2 deletions(-) create mode 100644 info.go diff --git a/info.go b/info.go new file mode 100644 index 0000000..3603dfe --- /dev/null +++ b/info.go @@ -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: \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, + }}, + }, + }) +} diff --git a/main.go b/main.go index 861969d..f93bd80 100644 --- a/main.go +++ b/main.go @@ -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", + }, }