Improve registered commands caching
All checks were successful
continuous-integration/drone/push Build is passing
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:
@@ -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!");
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user