use of com.jagrosh.jdautilities.command.CommandClient 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);
}
}
use of com.jagrosh.jdautilities.command.CommandClient in project clancy by brendonmiranda.
the class JDAConfiguration method load.
@Bean
public JDA load(PlayCmd playCmd, StopCmd stopCmd, PauseCmd pauseCmd, ResumeCmd resumeCmd, SkipCmd skipCmd, NowPlayingCmd nowPlayingCmd, JoinCmd joinCmd) throws LoginException {
JDA jda = JDABuilder.createDefault(token).build();
CommandClient cmdListener = new CommandClientBuilder().setPrefix(prefix).setOwnerId(Long.toString(owner)).addSlashCommands(playCmd, stopCmd, pauseCmd, resumeCmd, skipCmd, nowPlayingCmd, joinCmd).setActivity(listening("type /join")).build();
// todo: set watching activity
jda.addEventListener(cmdListener, eventWaiter());
return jda;
}
Aggregations