diff --git a/commands/util.go b/commands/util.go index 3fe4959f..d70f533f 100644 --- a/commands/util.go +++ b/commands/util.go @@ -3,7 +3,6 @@ package commands import ( "ChatWire/cfg" "ChatWire/commands/moderator" - "ChatWire/constants" "ChatWire/cwlog" "ChatWire/disc" "ChatWire/fact" @@ -11,7 +10,7 @@ import ( "ChatWire/sclean" "ChatWire/support" "fmt" - "log" + "os" "strings" "sync" "time" @@ -140,17 +139,15 @@ func DeregisterCommands() { return } if *glob.DoDeregisterCommands && disc.DS != nil { - cmds, _ := disc.DS.ApplicationCommands(cfg.Global.Discord.Application, cfg.Global.Discord.Guild) - for _, v := range cmds { - cwlog.DoLogCW("Deregistered command: %s", v.Name) - err := disc.DS.ApplicationCommandDelete(disc.DS.State.User.ID, cfg.Global.Discord.Guild, v.ID) - if err != nil { - cwlog.DoLogCW(err.Error()) - } - - time.Sleep(constants.ApplicationCommandSleep) + cwlog.DoLogCW("Bulk deregistering commands!") + _, err := disc.DS.ApplicationCommandBulkOverwrite(cfg.Global.Discord.Application, cfg.Global.Discord.Guild, []*discordgo.ApplicationCommand{}) + if err != nil { + fact.LogGameCMS(true, cfg.Local.Channel.ChatChannel, "Deregister commands failed: "+err.Error()) + return } - cwlog.DoLogCW("Deregister commands complete.") + fact.LogGameCMS(true, cfg.Local.Channel.ChatChannel, "Deregister commands complete.") + time.Sleep(time.Second * 5) + os.Exit(0) } } @@ -166,11 +163,10 @@ func RegisterCommands() { /* Bypasses init loop compile error. */ CL = cmds - //Bypass register, very slow - //TODO: Cache info and correct for changes when needed - if *glob.DoRegisterCommands { + cwlog.DoLogCW("Bulk registering commands!") + cmdList := []*discordgo.ApplicationCommand{} for i, o := range CL { if o.Disabled { @@ -180,7 +176,6 @@ func RegisterCommands() { cwlog.DoLogCW("Command has no name or description, skipping") continue } - time.Sleep(constants.ApplicationCommandSleep) if strings.EqualFold(o.AppCmd.Name, "config-server") { LinkConfigData(i, false) @@ -224,16 +219,21 @@ func RegisterCommands() { tempAppCmd.Options = append(tempAppCmd.Options, tmpOption) } - - _, err := disc.DS.ApplicationCommandCreate(cfg.Global.Discord.Application, cfg.Global.Discord.Guild, tempAppCmd) - if err != nil { - log.Println("Failed to create command: ", - CL[i].AppCmd.Name, ": ", err) - continue + cmdList = append(cmdList, tempAppCmd) + } + created, err := disc.DS.ApplicationCommandBulkOverwrite(cfg.Global.Discord.Application, cfg.Global.Discord.Guild, cmdList) + if err != nil { + fact.LogGameCMS(true, cfg.Local.Channel.ChatChannel, "Register commands failed: "+err.Error()) + return + } + cList := "" + for _, ctmp := range created { + if cList != "" { + cList = cList + ", " } - cwlog.DoLogCW("Registered command: %s", CL[i].AppCmd.Name) + cList = cList + ctmp.Name } - cwlog.DoLogCW("Register commands complete.") + fact.LogGameCMS(true, cfg.Local.Channel.ChatChannel, "Register commands complete: "+cList) } } diff --git a/constants/consts.go b/constants/consts.go index 275a3840..1a6b0195 100755 --- a/constants/consts.go +++ b/constants/consts.go @@ -4,7 +4,7 @@ import "time" const ( ProgName = "ChatWire" - Version = "2648-1101.2024-1228" + Version = "2648-1101.2024-0358p" CWEpoch = 1653239822390688174 SeenDivisor = 60 SeenEpoch = 1546326000 @@ -85,11 +85,10 @@ const ( WatchdogInterval = time.Second /* Throttle Discord chat */ - CMSRate = 500 * time.Millisecond //Time we spend waiting for buffer to fill up once active - CMSRestTime = 2000 * time.Millisecond //Time to sleep after sending a message - CMSPollRate = 100 * time.Millisecond //Time between polls - MaxDiscordAttempts = 95 - ApplicationCommandSleep = time.Second * 3 + CMSRate = 500 * time.Millisecond //Time we spend waiting for buffer to fill up once active + CMSRestTime = 2000 * time.Millisecond //Time to sleep after sending a message + CMSPollRate = 100 * time.Millisecond //Time between polls + MaxDiscordAttempts = 95 ) /* Factorio map preset names */ diff --git a/main.go b/main.go index 87805bf7..d95c1e4c 100755 --- a/main.go +++ b/main.go @@ -28,7 +28,7 @@ import ( func main() { glob.DoRegisterCommands = flag.Bool("regCommands", false, "Register discord commands") - glob.DoDeregisterCommands = flag.Bool("deregCommands", false, "Deregister discord commands") + glob.DoDeregisterCommands = flag.Bool("deregCommands", false, "Deregister discord commands and quit.") glob.LocalTestMode = flag.Bool("localTest", false, "Turn off public/auth mode for testing") glob.NoAutoLaunch = flag.Bool("noAutoLaunch", false, "Turn off auto-launch") cleanDB := flag.Bool("cleanDB", false, "Clean/minimize player database and exit.")