From d2d691bf94b59a5909520e8ec280ed840a05b2f4 Mon Sep 17 00:00:00 2001 From: 5HT2 Date: Sun, 26 May 2024 04:08:01 +0100 Subject: [PATCH] plugins: (sys-stat) Fix bug causing command to hang after one run --- plugins/sys-stats/sys-stats.go | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/plugins/sys-stats/sys-stats.go b/plugins/sys-stats/sys-stats.go index 92f895e..d4a0253 100644 --- a/plugins/sys-stats/sys-stats.go +++ b/plugins/sys-stats/sys-stats.go @@ -2,6 +2,12 @@ package main import ( "fmt" + "log" + "os" + "os/exec" + "strings" + "time" + "github.com/5HT2/taro-bot/bot" "github.com/5HT2/taro-bot/cmd" "github.com/5HT2/taro-bot/plugins" @@ -9,11 +15,6 @@ import ( "github.com/mackerelio/go-osstat/cpu" "github.com/mackerelio/go-osstat/memory" "github.com/mackerelio/go-osstat/uptime" - "log" - "os" - "os/exec" - "strings" - "time" ) var ( @@ -43,11 +44,11 @@ func SysStatsCommand(c bot.Command) error { // If we have a running fetch command in this guild, cancel it if quit, ok := runningFetches[c.E.GuildID.String()]; ok { quit <- true + } else { + // Start a new quit channel + runningFetches[c.E.GuildID.String()] = make(chan bool) } - // Start a new quit channel - runningFetches[c.E.GuildID.String()] = make(chan bool) - // Determine displayed shell based on shell := "$" if err := cmd.HasPermission(c, cmd.PermOperator); err == nil {