Search in sources :

Example 1 with WebhookMessageBuilder

use of net.dv8tion.jda.webhook.WebhookMessageBuilder in project Rubicon by Rubicon-Bot.

the class PortalListener method onGuildMessageReceived.

@Override
public void onGuildMessageReceived(GuildMessageReceivedEvent e) {
    if (!e.getAuthor().isBot()) {
        if (e.getChannel().getId().equals(RubiconBot.getMySQL().getPortalValue(e.getGuild(), "channelid"))) {
            String status = RubiconBot.getMySQL().getGuildValue(e.getGuild(), "portal");
            if (status.contains("open")) {
                TextChannel otherChannel = e.getJDA().getTextChannelById(RubiconBot.getMySQL().getPortalValue(e.getJDA().getGuildById(RubiconBot.getMySQL().getPortalValue(e.getGuild(), "partnerid")), "channelid"));
                try {
                    Webhook webhook = null;
                    for (Webhook hook : otherChannel.getWebhooks().complete()) {
                        if (hook.getName().equals("rubicon-portal-hook")) {
                            webhook = hook;
                            break;
                        }
                    }
                    if (webhook == null) {
                        webhook = otherChannel.createWebhook("rubicon-portal-hook").complete();
                    }
                    WebhookClientBuilder clientBuilder = webhook.newClient();
                    WebhookClient client = clientBuilder.build();
                    WebhookMessageBuilder builder = new WebhookMessageBuilder();
                    builder.setContent(e.getMessage().getContentDisplay().replace("@here", "@ here").replace("@everyone", "@ everyone"));
                    builder.setAvatarUrl(e.getAuthor().getAvatarUrl());
                    builder.setUsername(e.getAuthor().getName());
                    WebhookMessage message = builder.build();
                    client.send(message);
                    client.close();
                /*EmbedBuilder builder = new EmbedBuilder();
                        builder.setAuthor(e.getAuthor().getName(), null, e.getAuthor().getEffectiveAvatarUrl());
                        builder.setDescription(e.getMessage().getContent());
                        otherChannel.sendMessage(builder.build()).queue();*/
                } catch (NullPointerException fuck) {
                    fuck.printStackTrace();
                }
            }
        }
    }
}
Also used : WebhookMessage(net.dv8tion.jda.webhook.WebhookMessage) WebhookClientBuilder(net.dv8tion.jda.webhook.WebhookClientBuilder) TextChannel(net.dv8tion.jda.core.entities.TextChannel) WebhookClient(net.dv8tion.jda.webhook.WebhookClient) WebhookMessageBuilder(net.dv8tion.jda.webhook.WebhookMessageBuilder) Webhook(net.dv8tion.jda.core.entities.Webhook)

Aggregations

TextChannel (net.dv8tion.jda.core.entities.TextChannel)1 Webhook (net.dv8tion.jda.core.entities.Webhook)1 WebhookClient (net.dv8tion.jda.webhook.WebhookClient)1 WebhookClientBuilder (net.dv8tion.jda.webhook.WebhookClientBuilder)1 WebhookMessage (net.dv8tion.jda.webhook.WebhookMessage)1 WebhookMessageBuilder (net.dv8tion.jda.webhook.WebhookMessageBuilder)1