Search in sources :

Example 1 with MessageType

use of net.essentialsx.api.v2.services.discord.MessageType in project Essentials by EssentialsX.

the class JDADiscordService method updateTypesRelay.

public void updateTypesRelay() {
    if (!getSettings().isShowAvatar() && !getSettings().isShowName() && !getSettings().isShowDisplayName()) {
        for (WebhookClient webhook : channelIdToWebhook.values()) {
            webhook.close();
        }
        typeToChannelId.clear();
        channelIdToWebhook.clear();
        return;
    }
    for (MessageType type : MessageType.DefaultTypes.values()) {
        if (!type.isPlayer()) {
            continue;
        }
        final TextChannel channel = getChannel(type.getKey(), true);
        if (channel.getId().equals(typeToChannelId.get(type))) {
            continue;
        }
        final Webhook webhook = DiscordUtil.getOrCreateWebhook(channel, DiscordUtil.ADVANCED_RELAY_NAME).join();
        if (webhook == null) {
            final WebhookClient current = channelIdToWebhook.get(channel.getId());
            if (current != null) {
                current.close();
            }
            channelIdToWebhook.remove(channel.getId());
            continue;
        }
        typeToChannelId.put(type, channel.getId());
        channelIdToWebhook.put(channel.getId(), DiscordUtil.getWebhookClient(webhook.getIdLong(), webhook.getToken(), jda.getHttpClient()));
    }
}
Also used : TextChannel(net.dv8tion.jda.api.entities.TextChannel) WebhookClient(club.minnced.discord.webhook.WebhookClient) Webhook(net.dv8tion.jda.api.entities.Webhook) MessageType(net.essentialsx.api.v2.services.discord.MessageType)

Example 2 with MessageType

use of net.essentialsx.api.v2.services.discord.MessageType in project Essentials by drtshock.

the class JDADiscordService method updateTypesRelay.

public void updateTypesRelay() {
    if (!getSettings().isShowAvatar() && !getSettings().isShowName() && !getSettings().isShowDisplayName()) {
        for (WebhookClient webhook : channelIdToWebhook.values()) {
            webhook.close();
        }
        typeToChannelId.clear();
        channelIdToWebhook.clear();
        return;
    }
    for (MessageType type : MessageType.DefaultTypes.values()) {
        if (!type.isPlayer()) {
            continue;
        }
        final TextChannel channel = getChannel(type.getKey(), true);
        if (channel.getId().equals(typeToChannelId.get(type))) {
            continue;
        }
        final Webhook webhook = DiscordUtil.getOrCreateWebhook(channel, DiscordUtil.ADVANCED_RELAY_NAME).join();
        if (webhook == null) {
            final WebhookClient current = channelIdToWebhook.get(channel.getId());
            if (current != null) {
                current.close();
            }
            channelIdToWebhook.remove(channel.getId());
            continue;
        }
        typeToChannelId.put(type, channel.getId());
        channelIdToWebhook.put(channel.getId(), DiscordUtil.getWebhookClient(webhook.getIdLong(), webhook.getToken(), jda.getHttpClient()));
    }
}
Also used : TextChannel(net.dv8tion.jda.api.entities.TextChannel) WebhookClient(club.minnced.discord.webhook.WebhookClient) Webhook(net.dv8tion.jda.api.entities.Webhook) MessageType(net.essentialsx.api.v2.services.discord.MessageType)

Aggregations

WebhookClient (club.minnced.discord.webhook.WebhookClient)2 TextChannel (net.dv8tion.jda.api.entities.TextChannel)2 Webhook (net.dv8tion.jda.api.entities.Webhook)2 MessageType (net.essentialsx.api.v2.services.discord.MessageType)2