use of net.essentialsx.discord.listeners.DiscordCommandDispatcher in project Essentials by drtshock.
the class JDADiscordService method updateConsoleRelay.
public void updateConsoleRelay() {
final String consoleDef = getSettings().getConsoleChannelDef();
final Matcher matcher = WebhookClientBuilder.WEBHOOK_PATTERN.matcher(consoleDef);
final long webhookId;
final String webhookToken;
if (matcher.matches()) {
webhookId = Long.parseUnsignedLong(matcher.group(1));
webhookToken = matcher.group(2);
if (commandDispatcher != null) {
jda.removeEventListener(commandDispatcher);
commandDispatcher = null;
}
} else {
final TextChannel channel = getChannel(consoleDef, false);
if (channel != null) {
if (getSettings().isConsoleCommandRelay()) {
if (commandDispatcher == null) {
commandDispatcher = new DiscordCommandDispatcher(this);
jda.addEventListener(commandDispatcher);
}
commandDispatcher.setChannelId(channel.getId());
} else if (commandDispatcher != null) {
jda.removeEventListener(commandDispatcher);
commandDispatcher = null;
}
if (channel.getId().equals(lastConsoleId)) {
return;
}
final Webhook webhook = DiscordUtil.getOrCreateWebhook(channel, DiscordUtil.CONSOLE_RELAY_NAME).join();
if (webhook == null) {
logger.info(tl("discordErrorLoggerNoPerms"));
return;
}
webhookId = webhook.getIdLong();
webhookToken = webhook.getToken();
lastConsoleId = channel.getId();
} else if (!getSettings().getConsoleChannelDef().equals("none") && !getSettings().getConsoleChannelDef().startsWith("0")) {
logger.info(tl("discordErrorLoggerInvalidChannel"));
shutdownConsoleRelay(true);
return;
} else {
// It's either not configured at all or knowingly disabled.
shutdownConsoleRelay(true);
return;
}
}
shutdownConsoleRelay(false);
consoleWebhook = DiscordUtil.getWebhookClient(webhookId, webhookToken, jda.getHttpClient());
if (injector == null) {
injector = new ConsoleInjector(this);
injector.start();
}
}
use of net.essentialsx.discord.listeners.DiscordCommandDispatcher in project Essentials by EssentialsX.
the class JDADiscordService method updateConsoleRelay.
public void updateConsoleRelay() {
final String consoleDef = getSettings().getConsoleChannelDef();
final Matcher matcher = WebhookClientBuilder.WEBHOOK_PATTERN.matcher(consoleDef);
final long webhookId;
final String webhookToken;
if (matcher.matches()) {
webhookId = Long.parseUnsignedLong(matcher.group(1));
webhookToken = matcher.group(2);
if (commandDispatcher != null) {
jda.removeEventListener(commandDispatcher);
commandDispatcher = null;
}
} else {
final TextChannel channel = getChannel(consoleDef, false);
if (channel != null) {
if (getSettings().isConsoleCommandRelay()) {
if (commandDispatcher == null) {
commandDispatcher = new DiscordCommandDispatcher(this);
jda.addEventListener(commandDispatcher);
}
commandDispatcher.setChannelId(channel.getId());
} else if (commandDispatcher != null) {
jda.removeEventListener(commandDispatcher);
commandDispatcher = null;
}
if (channel.getId().equals(lastConsoleId)) {
return;
}
final Webhook webhook = DiscordUtil.getOrCreateWebhook(channel, DiscordUtil.CONSOLE_RELAY_NAME).join();
if (webhook == null) {
logger.info(tl("discordErrorLoggerNoPerms"));
return;
}
webhookId = webhook.getIdLong();
webhookToken = webhook.getToken();
lastConsoleId = channel.getId();
} else if (!getSettings().getConsoleChannelDef().equals("none") && !getSettings().getConsoleChannelDef().startsWith("0")) {
logger.info(tl("discordErrorLoggerInvalidChannel"));
shutdownConsoleRelay(true);
return;
} else {
// It's either not configured at all or knowingly disabled.
shutdownConsoleRelay(true);
return;
}
}
shutdownConsoleRelay(false);
consoleWebhook = DiscordUtil.getWebhookClient(webhookId, webhookToken, jda.getHttpClient());
if (injector == null) {
injector = new ConsoleInjector(this);
injector.start();
}
}
Aggregations