diff --git a/README.md b/README.md index 946b7a1..fdac6d8 100644 --- a/README.md +++ b/README.md @@ -21,16 +21,16 @@ Set some environment variables before launching, or add a `.env` file. If database environment variables are provided, the bot will save configuration to an external database. Otherwise, it will save configuration to a local sqlite database at `/var/go-discord-archiver/local.db` -| Variable | Value(s) | -| :---------------- | :------------------------------------------------------------------------------------- | -| ADMINISTRATOR_IDS | Comma separated IDs of users allowed to use administrator commands | -| DB_NAME | Database name for database | -| DB_HOST | Hostname for database | -| DB_PASSWORD | Password for database user | -| DB_USER | Username for database user | -| LOG_LEVEL | `trace`, `debug`, `info`, `warn`, `error` | -| COOKIE | Archive.org login cookie, get this from a web browser's Dev Tools visiting Archive.org | -| TOKEN | The Discord token the bot should use | +| Variable | Value(s) | +| :------------------ | :------------------------------------------------------------------------------------- | +| DB_NAME | Database name for database | +| DB_HOST | Hostname for database | +| DB_PASSWORD | Password for database user | +| DB_USER | Username for database user | +| REREGISTER_COMMANDS | Delete and re-register commands. Only use when command names are changed, unset after | +| LOG_LEVEL | `trace`, `debug`, `info`, `warn`, `error` | +| COOKIE | Archive.org login cookie, get this from a web browser's Dev Tools visiting Archive.org | +| TOKEN | The Discord token the bot should use | ## Usage diff --git a/bot/discord_handlers.go b/bot/discord_handlers.go index 7c61ba6..130ab30 100644 --- a/bot/discord_handlers.go +++ b/bot/discord_handlers.go @@ -15,11 +15,19 @@ func (bot *ArchiverBot) BotReadyHandler(s *discordgo.Session, r *discordgo.Ready // Use this to clean up commands if IDs have changed // TODO remove later if unnecessary - // log.Debug("removing all commands") - // bot.deleteAllCommands() - // var err error - // globals.RegisteredCommands, err = bot.DG.ApplicationCommandBulkOverwrite(bot.DG.State.User.ID, "", globals.Commands) - log.Debug("registering slash commands") + if bot.Config.ReregisterAllCommands { + envVar := getTagValue(ArchiverBotConfig{}, "ReregisterAllCommands", "env") + log.Warn(envVar + " is enabled, commands will be re-registered on every startup " + + "(not advised, existing commands break for users and you will get rate-limited)") + log.Info("re-registering slash commands") + bot.deleteAllCommands() + _, err := bot.DG.ApplicationCommandBulkOverwrite(bot.DG.State.User.ID, "", globals.Commands) + if err != nil { + log.Errorf("error re-registering commands, err: %s", err) + } + } else { + log.Debug("updating registered slash commands") + } registeredCommands, err := bot.DG.ApplicationCommands(bot.DG.State.User.ID, "") if err != nil { log.Errorf("unable to look up registered application commands, err: %s", err) diff --git a/bot/types.go b/bot/types.go index 00bcd19..1fdd11f 100644 --- a/bot/types.go +++ b/bot/types.go @@ -49,14 +49,14 @@ type ArchiverBot struct { // ArchiverBotConfig is attached to ArchiverBot so config settings can be // accessed easily type ArchiverBotConfig struct { - AdminIds []string `env:"ADMINISTRATOR_IDS"` - DBHost string `env:"DB_HOST"` - DBName string `env:"DB_NAME"` - DBPassword string `env:"DB_PASSWORD"` - DBUser string `env:"DB_USER"` - LogLevel string `env:"LOG_LEVEL"` - Token string `env:"TOKEN"` - Cookie string `env:"COOKIE"` + DBHost string `env:"DB_HOST"` + DBName string `env:"DB_NAME"` + DBPassword string `env:"DB_PASSWORD"` + DBUser string `env:"DB_USER"` + ReregisterAllCommands bool `env:"REREGISTER_COMMANMDS"` + LogLevel string `env:"LOG_LEVEL"` + Token string `env:"TOKEN"` + Cookie string `env:"COOKIE"` } // Servers