Improve registered commands caching
All checks were successful
continuous-integration/drone/push Build is passing

Discord's API is slow in updating and registering new commands, so we set up a runnable to periodically check.
This commit is contained in:
2022-11-21 16:24:09 +01:00
parent b015fddf3c
commit 163619a7f8
4 changed files with 37 additions and 8 deletions

View File

@@ -0,0 +1,25 @@
package wtf.beatrice.hidekobot.runnables;
import net.dv8tion.jda.api.JDA;
import wtf.beatrice.hidekobot.Configuration;
import wtf.beatrice.hidekobot.HidekoBot;
import wtf.beatrice.hidekobot.utils.Logger;
public class CommandsUpdateTask implements Runnable {
private final Logger logger;
public CommandsUpdateTask()
{
logger = new Logger(getClass());
}
@Override
public void run() {
if(Configuration.isVerbose()) logger.log("Refreshing commands cache...");
JDA instance = HidekoBot.getAPI();
if(instance == null) return;
Configuration.setRegisteredCommands(instance.retrieveCommands().complete());
if(Configuration.isVerbose()) logger.log("Commands cache refreshed!");
}
}