Search in sources :

Example 1 with ThreadedEventListener

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!");
    }
}
Also used : CmdGuild(com.mcmoddev.mmdbot.modules.commands.community.information.CmdGuild) ContextMenuUserInfo(com.mcmoddev.mmdbot.modules.commands.community.contextmenu.user.ContextMenuUserInfo) CmdQuote(com.mcmoddev.mmdbot.modules.commands.community.server.quotes.CmdQuote) CmdEditTrick(com.mcmoddev.mmdbot.modules.commands.community.server.tricks.CmdEditTrick) CmdReact(com.mcmoddev.mmdbot.modules.commands.moderation.CmdReact) CmdEvaluate(com.mcmoddev.mmdbot.modules.commands.community.CmdEvaluate) ContextMenuAddQuote(com.mcmoddev.mmdbot.modules.commands.community.contextmenu.message.ContextMenuAddQuote) CmdFabricVersion(com.mcmoddev.mmdbot.modules.commands.community.development.CmdFabricVersion) CmdCatFacts(com.mcmoddev.mmdbot.modules.commands.community.information.CmdCatFacts) CmdToggleMcServerPings(com.mcmoddev.mmdbot.modules.commands.community.server.CmdToggleMcServerPings) CmdInvite(com.mcmoddev.mmdbot.modules.commands.community.information.CmdInvite) CmdShutdown(com.mcmoddev.mmdbot.modules.commands.bot.management.CmdShutdown) CmdAbout(com.mcmoddev.mmdbot.modules.commands.bot.info.CmdAbout) CmdRename(com.mcmoddev.mmdbot.modules.commands.bot.management.CmdRename) CmdRoles(com.mcmoddev.mmdbot.modules.commands.community.server.CmdRoles) ContextMenuGist(com.mcmoddev.mmdbot.modules.commands.community.contextmenu.message.ContextMenuGist) CmdRolePanel(com.mcmoddev.mmdbot.modules.commands.moderation.CmdRolePanel) CmdRawTrick(com.mcmoddev.mmdbot.modules.commands.community.server.tricks.CmdRawTrick) CmdGist(com.mcmoddev.mmdbot.modules.commands.community.development.CmdGist) ThreadedEventListener(com.mcmoddev.mmdbot.utilities.ThreadedEventListener) EventListener(net.dv8tion.jda.api.hooks.EventListener) ThreadedEventListener(com.mcmoddev.mmdbot.utilities.ThreadedEventListener) CmdAvatar(com.mcmoddev.mmdbot.modules.commands.bot.management.CmdAvatar) CmdAddTrick(com.mcmoddev.mmdbot.modules.commands.community.server.tricks.CmdAddTrick) CmdHelp(com.mcmoddev.mmdbot.modules.commands.bot.info.CmdHelp) CmdOldChannels(com.mcmoddev.mmdbot.modules.commands.moderation.CmdOldChannels) CmdToggleEventPings(com.mcmoddev.mmdbot.modules.commands.community.server.CmdToggleEventPings) CmdMinecraftVersion(com.mcmoddev.mmdbot.modules.commands.community.development.CmdMinecraftVersion) CmdRestart(com.mcmoddev.mmdbot.modules.commands.bot.management.CmdRestart) CmdForgeVersion(com.mcmoddev.mmdbot.modules.commands.community.development.CmdForgeVersion) CmdRefreshScamLinks(com.mcmoddev.mmdbot.modules.commands.bot.management.CmdRefreshScamLinks) CmdUnmute(com.mcmoddev.mmdbot.modules.commands.moderation.CmdUnmute) CmdDictionary(com.mcmoddev.mmdbot.modules.commands.community.information.CmdDictionary) CmdWarning(com.mcmoddev.mmdbot.modules.commands.moderation.CmdWarning) CommandClientBuilder(com.jagrosh.jdautilities.command.CommandClientBuilder) CmdUser(com.mcmoddev.mmdbot.modules.commands.community.information.CmdUser) CmdMute(com.mcmoddev.mmdbot.modules.commands.moderation.CmdMute) CmdSearch(com.mcmoddev.mmdbot.modules.commands.community.information.CmdSearch) CmdCommunityChannel(com.mcmoddev.mmdbot.modules.commands.moderation.CmdCommunityChannel) CmdTrick(com.mcmoddev.mmdbot.modules.commands.community.server.tricks.CmdTrick) CmdRunTrick(com.mcmoddev.mmdbot.modules.commands.community.server.tricks.CmdRunTrick)

Example 2 with ThreadedEventListener

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);
    }
}
Also used : MiscEvents(com.mcmoddev.mmdbot.modules.logging.misc.MiscEvents) LoginException(javax.security.auth.login.LoginException) ThreadedEventListener(com.mcmoddev.mmdbot.utilities.ThreadedEventListener)

Aggregations

ThreadedEventListener (com.mcmoddev.mmdbot.utilities.ThreadedEventListener)2 CommandClientBuilder (com.jagrosh.jdautilities.command.CommandClientBuilder)1 CmdAbout (com.mcmoddev.mmdbot.modules.commands.bot.info.CmdAbout)1 CmdHelp (com.mcmoddev.mmdbot.modules.commands.bot.info.CmdHelp)1 CmdAvatar (com.mcmoddev.mmdbot.modules.commands.bot.management.CmdAvatar)1 CmdRefreshScamLinks (com.mcmoddev.mmdbot.modules.commands.bot.management.CmdRefreshScamLinks)1 CmdRename (com.mcmoddev.mmdbot.modules.commands.bot.management.CmdRename)1 CmdRestart (com.mcmoddev.mmdbot.modules.commands.bot.management.CmdRestart)1 CmdShutdown (com.mcmoddev.mmdbot.modules.commands.bot.management.CmdShutdown)1 CmdEvaluate (com.mcmoddev.mmdbot.modules.commands.community.CmdEvaluate)1 ContextMenuAddQuote (com.mcmoddev.mmdbot.modules.commands.community.contextmenu.message.ContextMenuAddQuote)1 ContextMenuGist (com.mcmoddev.mmdbot.modules.commands.community.contextmenu.message.ContextMenuGist)1 ContextMenuUserInfo (com.mcmoddev.mmdbot.modules.commands.community.contextmenu.user.ContextMenuUserInfo)1 CmdFabricVersion (com.mcmoddev.mmdbot.modules.commands.community.development.CmdFabricVersion)1 CmdForgeVersion (com.mcmoddev.mmdbot.modules.commands.community.development.CmdForgeVersion)1 CmdGist (com.mcmoddev.mmdbot.modules.commands.community.development.CmdGist)1 CmdMinecraftVersion (com.mcmoddev.mmdbot.modules.commands.community.development.CmdMinecraftVersion)1 CmdCatFacts (com.mcmoddev.mmdbot.modules.commands.community.information.CmdCatFacts)1 CmdDictionary (com.mcmoddev.mmdbot.modules.commands.community.information.CmdDictionary)1 CmdGuild (com.mcmoddev.mmdbot.modules.commands.community.information.CmdGuild)1