diff --git a/config.example.toml b/config.example.toml index 4aa850b..5d052d7 100644 --- a/config.example.toml +++ b/config.example.toml @@ -4,7 +4,11 @@ token = "token" # the bot token debug_guilds = [994710566612500550] # server IDs to create slash commands in. Omit for all guilds. disabled_commands = ["i do not exist"] # A list of full command names to disable (e.g. " foo.bar if ext.split(".")[-1].startswith("__"): log.info("Skipping loading %s - starts with double underscore." % ext) @@ -194,7 +196,25 @@ async def delete_message(ctx: discord.ApplicationContext, message: discord.Messa async def check_is_enabled(ctx: commands.Context | discord.ApplicationContext) -> bool: disabled = CONFIG["jimmy"].get("disabled_commands", []) if ctx.command.qualified_name in disabled: - raise commands.DisabledCommand("%s is disabled via this instance's configuration file.") + raise commands.DisabledCommand( + "%s is disabled via this instance's configuration file." % ( + ctx.command.qualified_name + ) + ) + return True + + +@bot.before_invoke +async def add_delays(ctx: commands.Context | discord.ApplicationContext) -> bool: + blocked = CONFIG["jimmy"].get("delay", {}) + if str(ctx.author.id) in blocked: + range_start, range_end = blocked[str(ctx.author.id)] + range_start = max(0.01, range_start) + range_end = min(2.89, range_end) + n = random.randint(round(range_start * 100), round(range_end * 100)) / 100 + log.warning("Delaying user %s by %.2f seconds.", ctx.author, n) + await asyncio.sleep(n) + log.info("Artificial delay for %s lifted", ctx.author) return True @@ -202,4 +222,15 @@ if not CONFIG["jimmy"].get("token"): log.critical("No token specified in config.toml. Exiting. (hint: set jimmy.token in config.toml)") sys.exit(1) +__disabled = CONFIG["jimmy"].get("disabled_commands", []) +__disabled_mode = CONFIG["jimmy"].get("disabled_mode", "disabled").lower() +if __disabled: + if __disabled_mode == "delete": + for __command__name in __disabled: + _cmd = bot.get_application_command(__command__name) + if not _cmd: + log.warning("Unknown command %r - cannot remove.", __command__name) + else: + bot.remove_application_command(_cmd) + bot.run(CONFIG["jimmy"]["token"])