use of com.mcmoddev.mmdbot.utilities.ThreadedEventListener in project MMDBot by MinecraftModDevelopment.
the class CommandModule method setupCommandModule.
/**
* Setup and load the bots command module.
*/
public static void setupCommandModule() {
commandClient = new CommandClientBuilder().setOwnerId(MMDBot.getConfig().getOwnerID()).setPrefix(MMDBot.getConfig().getMainPrefix()).setAlternativePrefix(MMDBot.getConfig().getAlternativePrefix()).useHelpBuilder(false).setManualUpsert(true).build();
addSlashCommand(new CmdHelp(), new CmdGuild(), new CmdAbout(), new CmdUser(), new CmdRoles(), new CmdCatFacts(), new CmdSearch("google", "https://www.google.com/search?q=", "goog"), new CmdSearch("bing", "https://www.bing.com/search?q="), new CmdSearch("duckduckgo", "https://duckduckgo.com/?q=", "ddg"), new CmdSearch("lmgtfy", "https://lmgtfy.com/?q=", "let-me-google-that-for-you"), new CmdToggleMcServerPings(), new CmdToggleEventPings(), new CmdForgeVersion(), new CmdMinecraftVersion(), new CmdFabricVersion(), new CmdMute(), new CmdUnmute(), new CmdCommunityChannel(), new CmdOldChannels(), new CmdAvatar(), new CmdRename(), // TODO Setup DB storage for tricks and polish them off/add permission restrictions for when needed.
new CmdShutdown(), new CmdRestart(), new CmdQuote(), new CmdRolePanel(), new CmdWarning(), new CmdTrick(), new CmdInvite(), new CmdDictionary(), new CmdEvaluate(), new CmdRawTrick());
// addSlashCommand(Tricks.getTricks().stream().map(CmdRunTrickSeparated::new).toArray(SlashCommand[]::new));
commandClient.addCommand(new CmdRefreshScamLinks());
commandClient.addCommand(new CmdReact());
commandClient.addCommand(new CmdGist());
commandClient.addCommand(new CmdEvaluate());
commandClient.addCommand(new CmdAddTrick.Prefix());
commandClient.addCommand(new CmdEditTrick.Prefix());
addContextMenu(new ContextMenuGist());
addContextMenu(new ContextMenuAddQuote());
addContextMenu(new ContextMenuUserInfo());
if (MMDBot.getConfig().prefixTricksEnabled()) {
Tricks.getTricks().stream().map(CmdRunTrick.Prefix::new).forEach(commandClient::addCommand);
}
if (MMDBot.getConfig().isCommandModuleEnabled()) {
// Wrap the command and button listener in another thread, so that if a runtime exception
// occurs while executing a command, the event thread will not be stopped
// Commands and buttons are separated so that they do not interfere with each other
MMDBot.getJDA().addEventListener(new ThreadedEventListener((EventListener) commandClient, COMMAND_LISTENER_THREAD_POOL));
MMDBot.getJDA().addEventListener(buttonListener(CmdRoles.getListener()));
MMDBot.getJDA().addEventListener(buttonListener(CmdHelp.getListener()));
MMDBot.getJDA().addEventListener(buttonListener(CmdListTricks.getListListener()));
MMDBot.getJDA().addEventListener(buttonListener(CmdQuote.ListQuotes.getQuoteListener()));
MMDBot.getJDA().addEventListener(buttonListener(CmdInvite.ListCmd.getButtonListener()));
MMDBot.getJDA().addEventListener(buttonListener(CmdDictionary.listener));
MMDBot.getJDA().addEventListener(buttonListener(new DismissListener()));
MMDBot.LOGGER.warn("Command module enabled and loaded.");
} else {
MMDBot.LOGGER.warn("Command module disabled via config, commands will not work at this time!");
}
}
use of com.mcmoddev.mmdbot.utilities.ThreadedEventListener in project MMDBot by MinecraftModDevelopment.
the class MMDBot method start.
@Override
public void start() {
instance = this;
JSONDataMigrator.checkAndMigrate(database);
if (config.isNewlyGenerated()) {
MMDBot.LOGGER.warn("A new config file at {} has been generated. Please configure the bot and try again.", config.getConfig().getNioPath());
System.exit(0);
} else if (config.getToken().isEmpty()) {
MMDBot.LOGGER.error("No token is specified in the config. Please configure the bot and try again");
System.exit(0);
} else if (config.getOwnerID().isEmpty()) {
MMDBot.LOGGER.error("No owner ID is specified in the config. Please configure the bot and try again");
System.exit(0);
} else if (config.getGuildID() == 0L) {
MMDBot.LOGGER.error("No guild ID is configured. Please configure the bot and try again.");
System.exit(0);
}
try {
jda.set(JDABuilder.create(config.getToken(), MMDBot.INTENTS).disableCache(CacheFlag.VOICE_STATE).disableCache(CacheFlag.ACTIVITY).disableCache(CacheFlag.CLIENT_STATUS).disableCache(CacheFlag.ONLINE_STATUS).addEventListeners(new ThreadedEventListener(new MiscEvents(), GENERAL_EVENT_THREAD_POOL)).build().awaitReady());
CommandModule.setupCommandModule();
LoggingModule.setupLoggingModule();
jda.get().getPresence().setActivity(Activity.of(config.getActivityType(), config.getActivityName()));
} catch (final LoginException exception) {
MMDBot.LOGGER.error("Error logging in the bot! Please give the bot a valid token in the config file.", exception);
System.exit(1);
} catch (InterruptedException e) {
MMDBot.LOGGER.error("Error awaiting caching.", e);
System.exit(1);
}
}
Aggregations