Search in sources :

Example 1 with CommandClientBuilder

use of com.jagrosh.jdautilities.command.CommandClientBuilder in project GordoBot by Pedroleal19.

the class Main method main.

public static void main(String[] args) throws LoginException, IOException, IllegalArgumentException, RateLimitedException {
    fileConfig fc = new fileConfig();
    String token = fc.fileConfig();
    String ownerId = fc.ownerId();
    EventWaiter waiter = new EventWaiter();
    CommandClientBuilder client = new CommandClientBuilder();
    client.setPrefix("gordo ");
    // ADICIONAR FUNÇÃO DE PROCURAR PELA OWNERID NA CONFIG.TXT, POR AGORA TO COM PREGUIÇA
    client.setOwnerId(ownerId);
    client.addCommands(new HelloWorld(), new kick(), new ban(), new teste(), new help(), new say(), new sobre());
    client.setHelpWord("%JDAOldHelp%");
    client.useHelpBuilder(false);
    client.setGame(Game.playing("e comendo biscoito"));
    try {
        new JDABuilder(AccountType.BOT).setToken(token).addEventListener(waiter).addEventListener(client.build()).setGame(Game.playing("REINICIANDO")).setStatus(OnlineStatus.IDLE).buildAsync();
    } catch (Exception e) {
        System.out.println("PROBLEMAS NA CONEXÃO // ERRO PROVAVEL NO TOKEN // VOCÊ COLOCOU O TOKEN CORRETAMENTE?" + "\n" + "Script encerrado");
        return;
    }
}
Also used : EventWaiter(com.jagrosh.jdautilities.commons.waiter.EventWaiter) CommandClientBuilder(com.jagrosh.jdautilities.command.CommandClientBuilder) LoginException(javax.security.auth.login.LoginException) RateLimitedException(net.dv8tion.jda.core.exceptions.RateLimitedException) IOException(java.io.IOException)

Example 2 with CommandClientBuilder

use of com.jagrosh.jdautilities.command.CommandClientBuilder in project MMDBot by MinecraftModDevelopment.

the class TheCommander method start.

@Override
public void start() {
    instance = this;
    EventListeners.clear();
    try {
        final var configPath = runPath.resolve("configs").resolve("general_config.conf");
        final HoconConfigurationLoader loader = HoconConfigurationLoader.builder().emitComments(true).prettyPrinting(true).defaultOptions(ConfigurationOptions.defaults().serializers(ADDED_SERIALIZERS)).path(configPath).build();
        final var cPair = ConfigurateUtils.loadConfig(loader, configPath, c -> generalConfig = c, Configuration.class, Configuration.EMPTY);
        config = cPair.second();
        generalConfig = cPair.first().get();
    } catch (ConfigurateException e) {
        LOGGER.error("Exception while trying to load general config", e);
        throw new RuntimeException(e);
    }
    MessageAction.setDefaultMentionRepliedUser(false);
    MessageAction.setDefaultMentions(Collections.emptySet());
    if (generalConfig.bot().getOwners().isEmpty()) {
        LOGGER.warn("Please provide at least one bot owner!");
        throw new RuntimeException();
    }
    final var coOwners = generalConfig.bot().getOwners().subList(1, generalConfig.bot().getOwners().size());
    commandClient = new CommandClientBuilder().setOwnerId(generalConfig.bot().getOwners().get(0)).setCoOwnerIds(coOwners.toArray(String[]::new)).forceGuildOnly(generalConfig.bot().guild()).useHelpBuilder(false).setManualUpsert(false).setActivity(null).build();
    EventListeners.COMMANDS_LISTENER.addListener((EventListener) commandClient);
    {
        // Command register
        ReflectionsUtils.getFieldsAnnotatedWith(RegisterSlashCommand.class).stream().peek(f -> f.setAccessible(true)).map(io.github.matyrobbrt.curseforgeapi.util.Utils.rethrowFunction(f -> f.get(null))).filter(SlashCommand.class::isInstance).map(SlashCommand.class::cast).forEach(commandClient::addSlashCommand);
    }
    try {
        final var builder = JDABuilder.create(dotenv.get("BOT_TOKEN"), INTENTS).disableCache(CacheFlag.VOICE_STATE).disableCache(CacheFlag.ACTIVITY).disableCache(CacheFlag.CLIENT_STATUS).disableCache(CacheFlag.ONLINE_STATUS).setEnabledIntents(INTENTS);
        EventListeners.register(builder::addEventListeners);
        jda = builder.build().awaitReady();
    } catch (final LoginException exception) {
        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) {
        LOGGER.error("Error awaiting caching.", e);
        System.exit(1);
    }
    try {
        final var cfKey = dotenv.get("CF_API_KEY", "");
        if (!cfKey.isBlank()) {
            final var api = CurseForgeAPI.builder().apiKey(cfKey).build();
            final var cfProjects = new CFProjects(runPath.resolve("cf_projects.json"));
            this.curseForgeManager = new CurseForgeManager(api, cfProjects);
            CURSE_FORGE_UPDATE_SCHEDULER.scheduleAtFixedRate(cfProjects, 0, 10, TimeUnit.MINUTES);
            CurseForgeCommand.REFRESH_GAMES_TASK.run();
        } else {
            LOGGER.warn("Could not find a valid CurseForge API Key! Some features might not work as expected.");
        }
    } catch (LoginException e) {
        LOGGER.error("Error while authenticating to the CurseForge API. Please provide a valid token, or don't provide any value!", e);
        System.exit(1);
    }
}
Also used : LoginException(javax.security.auth.login.LoginException) CommentedConfigurationNode(org.spongepowered.configurate.CommentedConfigurationNode) TypeSerializerCollection(org.spongepowered.configurate.serialize.TypeSerializerCollection) JDA(net.dv8tion.jda.api.JDA) CommandClient(com.jagrosh.jdautilities.command.CommandClient) BotRegistry(com.mcmoddev.mmdbot.core.bot.BotRegistry) AllowedMentions(net.dv8tion.jda.api.utils.AllowedMentions) LoggerFactory(org.slf4j.LoggerFactory) ConfigurateException(org.spongepowered.configurate.ConfigurateException) ConfigurationReference(org.spongepowered.configurate.reference.ConfigurationReference) BotUserData(com.mcmoddev.mmdbot.dashboard.util.BotUserData) GatewayIntent(net.dv8tion.jda.api.requests.GatewayIntent) ConfigurationOptions(org.spongepowered.configurate.ConfigurationOptions) ConfigurateUtils(com.mcmoddev.mmdbot.core.util.ConfigurateUtils) Dotenv(io.github.cdimascio.dotenv.Dotenv) SlashCommand(com.jagrosh.jdautilities.command.SlashCommand) DotenvLoader(com.mcmoddev.mmdbot.core.util.DotenvLoader) JDABuilder(net.dv8tion.jda.api.JDABuilder) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) MessageAction(net.dv8tion.jda.api.requests.restaction.MessageAction) CacheFlag(net.dv8tion.jda.api.utils.cache.CacheFlag) CurseForgeCommand(com.mcmoddev.mmdbot.commander.commands.curseforge.CurseForgeCommand) CurseForgeManager(com.mcmoddev.mmdbot.commander.cfwebhooks.CurseForgeManager) Path(java.nio.file.Path) Nullable(javax.annotation.Nullable) EventListeners(com.mcmoddev.mmdbot.commander.util.EventListeners) Logger(org.slf4j.Logger) Configuration(com.mcmoddev.mmdbot.commander.config.Configuration) RegisterBotType(com.mcmoddev.mmdbot.core.bot.RegisterBotType) RegisterSlashCommand(com.mcmoddev.mmdbot.commander.annotation.RegisterSlashCommand) Set(java.util.Set) IOException(java.io.IOException) Executors(java.util.concurrent.Executors) TimeUnit(java.util.concurrent.TimeUnit) CommandClientBuilder(com.jagrosh.jdautilities.command.CommandClientBuilder) CFProjects(com.mcmoddev.mmdbot.commander.cfwebhooks.CFProjects) EventListener(net.dv8tion.jda.api.hooks.EventListener) Utils(com.mcmoddev.mmdbot.core.util.Utils) Bot(com.mcmoddev.mmdbot.core.bot.Bot) BotType(com.mcmoddev.mmdbot.core.bot.BotType) HoconConfigurationLoader(org.spongepowered.configurate.hocon.HoconConfigurationLoader) CurseForgeAPI(io.github.matyrobbrt.curseforgeapi.CurseForgeAPI) Optional(java.util.Optional) ReflectionsUtils(com.mcmoddev.mmdbot.core.util.ReflectionsUtils) Collections(java.util.Collections) CurseForgeManager(com.mcmoddev.mmdbot.commander.cfwebhooks.CurseForgeManager) RegisterSlashCommand(com.mcmoddev.mmdbot.commander.annotation.RegisterSlashCommand) ConfigurateException(org.spongepowered.configurate.ConfigurateException) CommandClientBuilder(com.jagrosh.jdautilities.command.CommandClientBuilder) SlashCommand(com.jagrosh.jdautilities.command.SlashCommand) RegisterSlashCommand(com.mcmoddev.mmdbot.commander.annotation.RegisterSlashCommand) HoconConfigurationLoader(org.spongepowered.configurate.hocon.HoconConfigurationLoader) LoginException(javax.security.auth.login.LoginException) CFProjects(com.mcmoddev.mmdbot.commander.cfwebhooks.CFProjects)

Example 3 with CommandClientBuilder

use of com.jagrosh.jdautilities.command.CommandClientBuilder in project GeyserDiscordBot by GeyserMC.

the class GeyserBot method main.

public static void main(String[] args) throws IOException, LoginException {
    // Load properties into the PropertiesManager
    Properties prop = new Properties();
    prop.load(new FileInputStream("bot.properties"));
    PropertiesManager.loadProperties(prop);
    // Setup sentry.io
    if (PropertiesManager.getSentryDsn() != null) {
        LOGGER.info("Loading sentry.io...");
        Sentry.init(options -> {
            options.setDsn(PropertiesManager.getSentryDsn());
            options.setEnvironment(PropertiesManager.getSentryEnv());
            LOGGER.info("Sentry.io loaded");
        });
    }
    // Connect to github
    github = new GitHubBuilder().withOAuthToken(PropertiesManager.getGithubToken()).build();
    // Initialize the waiter
    EventWaiter waiter = new EventWaiter();
    // Load filters
    SwearHandler.loadFilters();
    // Load the db
    StorageType storageType = StorageType.getByName(PropertiesManager.getDatabaseType());
    if (storageType == StorageType.UNKNOWN) {
        LOGGER.error("Invalid database type! '" + PropertiesManager.getDatabaseType() + "'");
        System.exit(1);
    }
    try {
        storageManager = storageType.getStorageManager().getDeclaredConstructor().newInstance();
        storageManager.setupStorage();
    } catch (InstantiationException | IllegalAccessException | NoSuchMethodException | InvocationTargetException e) {
        LOGGER.error("Unable to create database link!");
        System.exit(1);
    }
    // Setup the main client
    CommandClientBuilder client = new CommandClientBuilder();
    client.setActivity(null);
    // No owner
    client.setOwnerId("0");
    client.setPrefix(PropertiesManager.getPrefix());
    client.useHelpBuilder(false);
    client.addCommands(COMMANDS.toArray(new Command[0]));
    client.addSlashCommands(SLASH_COMMANDS.toArray(new SlashCommand[0]));
    client.setListener(new CommandErrorHandler());
    client.setCommandPreProcessBiFunction((event, command) -> !SwearHandler.filteredMessages.contains(event.getMessage().getIdLong()));
    // Setup the tag client
    CommandClientBuilder tagClient = new CommandClientBuilder();
    tagClient.setActivity(null);
    // No owner
    tagClient.setOwnerId("0");
    String tagPrefix = PropertiesManager.getPrefix() + PropertiesManager.getPrefix();
    tagClient.setPrefix(tagPrefix);
    tagClient.setPrefixes(new String[] { "!tag " });
    tagClient.useHelpBuilder(false);
    tagClient.addCommands(TagsManager.getTags().toArray(new Command[0]));
    tagClient.setListener(new TagsListener());
    tagClient.setCommandPreProcessBiFunction((event, command) -> !SwearHandler.filteredMessages.contains(event.getMessage().getIdLong()));
    tagClient.setManualUpsert(true);
    // Disable pings on replies
    MessageAction.setDefaultMentionRepliedUser(false);
    // Setup the thread pool
    generalThreadPool = Executors.newScheduledThreadPool(5);
    // Register JDA
    try {
        jda = JDABuilder.createDefault(PropertiesManager.getToken()).setChunkingFilter(ChunkingFilter.ALL).setMemberCachePolicy(MemberCachePolicy.ALL).enableIntents(GatewayIntent.GUILD_MEMBERS).enableIntents(GatewayIntent.GUILD_PRESENCES).enableCache(CacheFlag.ACTIVITY).enableCache(CacheFlag.ROLE_TAGS).setStatus(OnlineStatus.ONLINE).setActivity(Activity.playing("Booting...")).setEnableShutdownHook(true).setEventManager(new SentryEventManager()).addEventListeners(waiter, new LogHandler(), new SwearHandler(), new PersistentRoleHandler(), new FileHandler(), new LevelHandler(), new DumpHandler(), new ErrorAnalyzer(), new ShutdownHandler(), new VoiceGroupHandler(), new BadLinksHandler(), client.build(), tagClient.build()).build();
    } catch (IllegalArgumentException exception) {
        LOGGER.error("Failed to initialize JDA!", exception);
        System.exit(1);
    }
    // Register listeners
    jda.addEventListener();
    // Setup the http server
    if (PropertiesManager.enableWeb()) {
        try {
            httpServer = new Server();
            httpServer.start();
        } catch (Exception e) {
            // TODO
            e.printStackTrace();
        }
    }
    // Setup the update check scheduler
    UpdateManager.setup();
    // Setup the health check scheduler
    HealthCheckerManager.setup();
    // Setup the rss feed check scheduler
    RssFeedManager.setup();
    // Setup all slow mode handlers
    generalThreadPool.schedule(() -> {
        for (Guild guild : jda.getGuilds()) {
            for (SlowModeInfo info : storageManager.getSlowModeChannels(guild)) {
                jda.addEventListener(new SlowmodeHandler(info.getChannel(), info.getDelay()));
            }
        }
    }, 5, TimeUnit.SECONDS);
    // Start the bStats tracking thread
    generalThreadPool.scheduleAtFixedRate(() -> {
        JSONArray servers = new JSONArray(RestClient.get("https://bstats.org/api/v1/plugins/5273/charts/servers/data"));
        JSONArray players = new JSONArray(RestClient.get("https://bstats.org/api/v1/plugins/5273/charts/players/data"));
        int serverCount = servers.getJSONArray(servers.length() - 1).getInt(1);
        int playerCount = players.getJSONArray(players.length() - 1).getInt(1);
        jda.getPresence().setActivity(Activity.playing(BotHelpers.coolFormat(serverCount) + " servers, " + BotHelpers.coolFormat(playerCount) + " players"));
    }, 5, 60 * 5, TimeUnit.SECONDS);
}
Also used : SlowmodeHandler(org.geysermc.discordbot.listeners.SlowmodeHandler) SentryEventManager(org.geysermc.discordbot.util.SentryEventManager) SwearHandler(org.geysermc.discordbot.listeners.SwearHandler) Server(org.geysermc.discordbot.http.Server) GitHubBuilder(org.kohsuke.github.GitHubBuilder) Properties(java.util.Properties) Guild(net.dv8tion.jda.api.entities.Guild) ErrorAnalyzer(org.geysermc.discordbot.listeners.ErrorAnalyzer) SlashCommand(com.jagrosh.jdautilities.command.SlashCommand) LogHandler(org.geysermc.discordbot.listeners.LogHandler) LevelHandler(org.geysermc.discordbot.listeners.LevelHandler) SlowModeInfo(org.geysermc.discordbot.storage.SlowModeInfo) ShutdownHandler(org.geysermc.discordbot.listeners.ShutdownHandler) TagsListener(org.geysermc.discordbot.tags.TagsListener) StorageType(org.geysermc.discordbot.storage.StorageType) CommandErrorHandler(org.geysermc.discordbot.listeners.CommandErrorHandler) JSONArray(org.json.JSONArray) EventWaiter(com.jagrosh.jdautilities.commons.waiter.EventWaiter) DumpHandler(org.geysermc.discordbot.listeners.DumpHandler) FileInputStream(java.io.FileInputStream) InvocationTargetException(java.lang.reflect.InvocationTargetException) CommandClientBuilder(com.jagrosh.jdautilities.command.CommandClientBuilder) LoginException(javax.security.auth.login.LoginException) InvocationTargetException(java.lang.reflect.InvocationTargetException) IOException(java.io.IOException) FileHandler(org.geysermc.discordbot.listeners.FileHandler) PersistentRoleHandler(org.geysermc.discordbot.listeners.PersistentRoleHandler) BadLinksHandler(org.geysermc.discordbot.listeners.BadLinksHandler) SlashCommand(com.jagrosh.jdautilities.command.SlashCommand) Command(com.jagrosh.jdautilities.command.Command) VoiceGroupHandler(org.geysermc.discordbot.listeners.VoiceGroupHandler)

Example 4 with CommandClientBuilder

use of com.jagrosh.jdautilities.command.CommandClientBuilder in project MusicBot by jagrosh.

the class JMusicBot method startBot.

private static void startBot() {
    // create prompt to handle startup
    Prompt prompt = new Prompt("JMusicBot");
    // startup checks
    OtherUtil.checkVersion(prompt);
    OtherUtil.checkJavaVersion(prompt);
    // load config
    BotConfig config = new BotConfig(prompt);
    config.load();
    if (!config.isValid())
        return;
    LOG.info("Loaded config from " + config.getConfigLocation());
    // set up the listener
    EventWaiter waiter = new EventWaiter();
    SettingsManager settings = new SettingsManager();
    Bot bot = new Bot(waiter, config, settings);
    AboutCommand aboutCommand = new AboutCommand(Color.BLUE.brighter(), "a music bot that is [easy to host yourself!](https://github.com/jagrosh/MusicBot) (v" + OtherUtil.getCurrentVersion() + ")", new String[] { "High-quality music playback", "FairQueue™ Technology", "Easy to host yourself" }, RECOMMENDED_PERMS);
    aboutCommand.setIsAuthor(false);
    // 🎶
    aboutCommand.setReplacementCharacter("\uD83C\uDFB6");
    // set up the command client
    CommandClientBuilder cb = new CommandClientBuilder().setPrefix(config.getPrefix()).setAlternativePrefix(config.getAltPrefix()).setOwnerId(Long.toString(config.getOwnerId())).setEmojis(config.getSuccess(), config.getWarning(), config.getError()).setHelpWord(config.getHelp()).setLinkedCacheSize(200).setGuildSettingsManager(settings).addCommands(aboutCommand, new PingCommand(), new SettingsCmd(bot), new LyricsCmd(bot), new NowplayingCmd(bot), new PlayCmd(bot), new PlaylistsCmd(bot), new QueueCmd(bot), new RemoveCmd(bot), new SearchCmd(bot), new SCSearchCmd(bot), new ShuffleCmd(bot), new SkipCmd(bot), new ForceRemoveCmd(bot), new ForceskipCmd(bot), new MoveTrackCmd(bot), new PauseCmd(bot), new PlaynextCmd(bot), new RepeatCmd(bot), new SkiptoCmd(bot), new StopCmd(bot), new VolumeCmd(bot), new PrefixCmd(bot), new SetdjCmd(bot), new SkipratioCmd(bot), new SettcCmd(bot), new SetvcCmd(bot), new AutoplaylistCmd(bot), new DebugCmd(bot), new PlaylistCmd(bot), new SetavatarCmd(bot), new SetgameCmd(bot), new SetnameCmd(bot), new SetstatusCmd(bot), new ShutdownCmd(bot));
    if (config.useEval())
        cb.addCommand(new EvalCmd(bot));
    boolean nogame = false;
    if (config.getStatus() != OnlineStatus.UNKNOWN)
        cb.setStatus(config.getStatus());
    if (config.getGame() == null)
        cb.useDefaultGame();
    else if (config.getGame().getName().equalsIgnoreCase("none")) {
        cb.setActivity(null);
        nogame = true;
    } else
        cb.setActivity(config.getGame());
    if (!prompt.isNoGUI()) {
        try {
            GUI gui = new GUI(bot);
            bot.setGUI(gui);
            gui.init();
        } catch (Exception e) {
            LOG.error("Could not start GUI. If you are " + "running on a server or in a location where you cannot display a " + "window, please run in nogui mode using the -Dnogui=true flag.");
        }
    }
    // attempt to log in and start
    try {
        JDA jda = JDABuilder.create(config.getToken(), Arrays.asList(INTENTS)).enableCache(CacheFlag.MEMBER_OVERRIDES, CacheFlag.VOICE_STATE).disableCache(CacheFlag.ACTIVITY, CacheFlag.CLIENT_STATUS, CacheFlag.EMOTE, CacheFlag.ONLINE_STATUS).setActivity(nogame ? null : Activity.playing("loading...")).setStatus(config.getStatus() == OnlineStatus.INVISIBLE || config.getStatus() == OnlineStatus.OFFLINE ? OnlineStatus.INVISIBLE : OnlineStatus.DO_NOT_DISTURB).addEventListeners(cb.build(), waiter, new Listener(bot)).setBulkDeleteSplittingEnabled(true).build();
        bot.setJDA(jda);
    } catch (LoginException ex) {
        prompt.alert(Prompt.Level.ERROR, "JMusicBot", ex + "\nPlease make sure you are " + "editing the correct config.txt file, and that you have used the " + "correct token (not the 'secret'!)\nConfig Location: " + config.getConfigLocation());
        System.exit(1);
    } catch (IllegalArgumentException ex) {
        prompt.alert(Prompt.Level.ERROR, "JMusicBot", "Some aspect of the configuration is " + "invalid: " + ex + "\nConfig Location: " + config.getConfigLocation());
        System.exit(1);
    }
}
Also used : GUI(com.jagrosh.jmusicbot.gui.GUI) CommandClientBuilder(com.jagrosh.jdautilities.command.CommandClientBuilder) LoginException(javax.security.auth.login.LoginException) SettingsManager(com.jagrosh.jmusicbot.settings.SettingsManager) EventWaiter(com.jagrosh.jdautilities.commons.waiter.EventWaiter) LoginException(javax.security.auth.login.LoginException) Prompt(com.jagrosh.jmusicbot.entities.Prompt)

Example 5 with CommandClientBuilder

use of com.jagrosh.jdautilities.command.CommandClientBuilder 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)

Aggregations

CommandClientBuilder (com.jagrosh.jdautilities.command.CommandClientBuilder)8 EventWaiter (com.jagrosh.jdautilities.commons.waiter.EventWaiter)5 LoginException (javax.security.auth.login.LoginException)4 IOException (java.io.IOException)3 CommandClient (com.jagrosh.jdautilities.command.CommandClient)2 SlashCommand (com.jagrosh.jdautilities.command.SlashCommand)2 Prompt (com.jagrosh.jmusicbot.entities.Prompt)2 GUI (com.jagrosh.jmusicbot.gui.GUI)2 SettingsManager (com.jagrosh.jmusicbot.settings.SettingsManager)2 Command (com.jagrosh.jdautilities.command.Command)1 RegisterSlashCommand (com.mcmoddev.mmdbot.commander.annotation.RegisterSlashCommand)1 CFProjects (com.mcmoddev.mmdbot.commander.cfwebhooks.CFProjects)1 CurseForgeManager (com.mcmoddev.mmdbot.commander.cfwebhooks.CurseForgeManager)1 CurseForgeCommand (com.mcmoddev.mmdbot.commander.commands.curseforge.CurseForgeCommand)1 Configuration (com.mcmoddev.mmdbot.commander.config.Configuration)1 EventListeners (com.mcmoddev.mmdbot.commander.util.EventListeners)1 Bot (com.mcmoddev.mmdbot.core.bot.Bot)1 BotRegistry (com.mcmoddev.mmdbot.core.bot.BotRegistry)1 BotType (com.mcmoddev.mmdbot.core.bot.BotType)1 RegisterBotType (com.mcmoddev.mmdbot.core.bot.RegisterBotType)1