Implement command force-refresh arg
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Bea 2022-11-20 18:54:13 +01:00
parent 3578de17c8
commit 3474593dc9
2 changed files with 19 additions and 10 deletions

View File

@ -10,7 +10,8 @@ java -jar HidekoBot.jar <botToken> [additional parameters]
Where `HidekoBot.jar` is the executable archive and `<botToken>` is your bot token passed as an argument. Where `HidekoBot.jar` is the executable archive and `<botToken>` is your bot token passed as an argument.
Additionally available parameters are: Additionally available parameters are:
- **verbose**: log every message that the bot receives. Very spammy and performance heavy. - **verbose**: log every message that the bot receives. Very spammy and performance heavy.
- **refresh**: force refresh the bot's commands.
*Note: Java 16 or later is required.* *Note: Java 16 or later is required.*

View File

@ -7,6 +7,7 @@ import net.dv8tion.jda.api.entities.Activity;
import net.dv8tion.jda.api.requests.GatewayIntent; import net.dv8tion.jda.api.requests.GatewayIntent;
import sun.misc.Signal; import sun.misc.Signal;
import wtf.beatrice.hidekobot.listeners.MessageListener; import wtf.beatrice.hidekobot.listeners.MessageListener;
import wtf.beatrice.hidekobot.listeners.SlashCommandCompleter;
import wtf.beatrice.hidekobot.listeners.SlashCommandListener; import wtf.beatrice.hidekobot.listeners.SlashCommandListener;
import wtf.beatrice.hidekobot.utils.Logger; import wtf.beatrice.hidekobot.utils.Logger;
import wtf.beatrice.hidekobot.utils.SlashCommandsUtil; import wtf.beatrice.hidekobot.utils.SlashCommandsUtil;
@ -64,16 +65,8 @@ public class HidekoBot
String botUserId = jda.getSelfUser().getId(); String botUserId = jda.getSelfUser().getId();
Configuration.setBotApplicationId(botUserId); Configuration.setBotApplicationId(botUserId);
// register listeners boolean forceUpdateCommands = false;
jda.addEventListener(new MessageListener());
jda.addEventListener(new SlashCommandListener());
// update slash commands (delayed)
Executors.newSingleThreadScheduledExecutor().schedule(SlashCommandsUtil::updateSlashCommands, 1, TimeUnit.SECONDS);
// set the bot's status
jda.getPresence().setStatus(OnlineStatus.ONLINE);
jda.getPresence().setActivity(Activity.playing("Hatsune Miku: Project DIVA"));
// if there is more than 1 arg, then iterate through them because we have additional things to do. // if there is more than 1 arg, then iterate through them because we have additional things to do.
// we are doing this at the end because we might need the API to be already initialized for some things. // we are doing this at the end because we might need the API to be already initialized for some things.
@ -81,8 +74,23 @@ public class HidekoBot
List<String> argsList = new ArrayList<>(Arrays.asList(args).subList(1, args.length)); List<String> argsList = new ArrayList<>(Arrays.asList(args).subList(1, args.length));
if(argsList.contains("verbose")) Configuration.setVerbose(true); if(argsList.contains("verbose")) Configuration.setVerbose(true);
if(argsList.contains("refresh")) forceUpdateCommands = true;
} }
// register listeners
jda.addEventListener(new MessageListener());
jda.addEventListener(new SlashCommandListener());
jda.addEventListener(new SlashCommandCompleter());
// update slash commands (delayed)
final boolean finalForceUpdateCommands = forceUpdateCommands;
Executors.newSingleThreadScheduledExecutor().schedule(() ->
SlashCommandsUtil.updateSlashCommands(finalForceUpdateCommands), 1, TimeUnit.SECONDS);
// set the bot's status
jda.getPresence().setStatus(OnlineStatus.ONLINE);
jda.getPresence().setActivity(Activity.playing("Hatsune Miku: Project DIVA"));
// print the bot logo. // print the bot logo.
logger.log("\n\n" + logger.getLogo() + "\nv" + version + " - bot is ready!\n", 2); logger.log("\n\n" + logger.getLogo() + "\nv" + version + " - bot is ready!\n", 2);