From b7b66bf1db37f59a20bc0efdcfad09b37b8dd610 Mon Sep 17 00:00:00 2001 From: Pacmens Date: Wed, 29 Sep 2021 11:54:17 +0200 Subject: [PATCH] fixed onjoinrole, updated dependencies --- core/pom.xml | 6 +++--- core/src/main/java/hera/core/Core.java | 5 ++++- .../hera/core/api/handlers/YouTubeApiHandler.java | 11 ++++++----- .../hera/core/commands/miscellaneous/Vote.java | 2 +- .../java/hera/core/messages/MessageHandler.java | 15 ++++++++------- 5 files changed, 22 insertions(+), 17 deletions(-) diff --git a/core/pom.xml b/core/pom.xml index b5a8f88..de66894 100644 --- a/core/pom.xml +++ b/core/pom.xml @@ -30,7 +30,7 @@ com.discord4j discord4j-core - 3.1.5 + 3.2.0 com.sedmelluq @@ -40,12 +40,12 @@ com.google.apis google-api-services-youtube - v3-rev20200618-1.30.9 + v3-rev20210915-1.32.1 ch.qos.logback logback-classic - 1.2.3 + 1.2.6 hera diff --git a/core/src/main/java/hera/core/Core.java b/core/src/main/java/hera/core/Core.java index 9a1d874..53e181f 100644 --- a/core/src/main/java/hera/core/Core.java +++ b/core/src/main/java/hera/core/Core.java @@ -10,6 +10,7 @@ import discord4j.core.event.domain.message.MessageCreateEvent; import discord4j.core.event.domain.message.MessageDeleteEvent; import discord4j.core.event.domain.message.ReactionAddEvent; +import discord4j.gateway.intent.IntentSet; import hera.core.api.handlers.YouTubeApiHandler; import hera.core.commands.Commands; import hera.core.events.reactions.GuildReactionListener; @@ -68,9 +69,10 @@ public static void startup(String dbUser, String dbPassword, String dbUrl) { //final DiscordClient client = new DiscordClientBuilder(loginTokens.get(0).getToken()).build(); final DiscordClient client = DiscordClient.create(loginTokens.get(0).getToken()); - final GatewayDiscordClient gateway = client.login().block(); + final GatewayDiscordClient gateway = client.gateway().setEnabledIntents(IntentSet.all()).login().block(); HeraUtil.setClient(gateway); + HeraCommunicationInterface hci = new HeraCommunicationInterface(gateway); hci.startupHCI(); @@ -126,6 +128,7 @@ public static void startup(String dbUser, String dbPassword, String dbUrl) { ) ); + // log when a user leaves a guild gateway.on(MemberLeaveEvent.class) .doOnNext(event -> STATS.logUserGuildLeave(event.getUser().getId().asLong(), event.getGuildId().asLong())) diff --git a/core/src/main/java/hera/core/api/handlers/YouTubeApiHandler.java b/core/src/main/java/hera/core/api/handlers/YouTubeApiHandler.java index b119f9d..8e929f9 100644 --- a/core/src/main/java/hera/core/api/handlers/YouTubeApiHandler.java +++ b/core/src/main/java/hera/core/api/handlers/YouTubeApiHandler.java @@ -1,7 +1,7 @@ package hera.core.api.handlers; +import com.google.api.client.googleapis.util.Utils; import com.google.api.client.http.javanet.NetHttpTransport; -import com.google.api.client.json.jackson2.JacksonFactory; import com.google.api.services.youtube.YouTube; import com.google.api.services.youtube.model.SearchListResponse; import com.google.api.services.youtube.model.SearchResult; @@ -11,6 +11,8 @@ import org.slf4j.LoggerFactory; import java.io.IOException; +import java.util.ArrayList; +import java.util.Arrays; import java.util.Collections; import java.util.List; @@ -39,17 +41,16 @@ public static void initialise() { applicationName = appNames.get(0).getToken(); apiToken = apiTokens.get(0).getToken(); - - youtube = new YouTube.Builder(new NetHttpTransport(), new JacksonFactory(), request -> { + youtube = new YouTube.Builder(new NetHttpTransport(), Utils.getDefaultJsonFactory(), request -> { }).setApplicationName(applicationName).build(); } public static String getYoutubeVideoFromKeyword(String keyword) { try { - YouTube.Search.List search = youtube.search().list("id,snippet"); + YouTube.Search.List search = youtube.search().list(Arrays.asList("id", "snippet")); search.setKey(apiToken); search.setQ(keyword); - search.setType("video"); + search.setType(Collections.singletonList("video")); search.setFields("items(id/kind,id/videoId,snippet/title,snippet/thumbnails/default/url)"); search.setMaxResults((long) 1); diff --git a/core/src/main/java/hera/core/commands/miscellaneous/Vote.java b/core/src/main/java/hera/core/commands/miscellaneous/Vote.java index 6f4895f..fea8759 100644 --- a/core/src/main/java/hera/core/commands/miscellaneous/Vote.java +++ b/core/src/main/java/hera/core/commands/miscellaneous/Vote.java @@ -85,7 +85,7 @@ public static Mono executeFromReaction(ReactionAddEvent event, MessageChan return Mono.empty(); } - private static HashMap countReactions(Set reactions) { + private static HashMap countReactions(List reactions) { HashMap out = new HashMap<>(); for (Reaction reaction : reactions) { if (reaction.selfReacted()) { //only consider options the bot set diff --git a/core/src/main/java/hera/core/messages/MessageHandler.java b/core/src/main/java/hera/core/messages/MessageHandler.java index 137bd0b..2c4b874 100644 --- a/core/src/main/java/hera/core/messages/MessageHandler.java +++ b/core/src/main/java/hera/core/messages/MessageHandler.java @@ -3,22 +3,23 @@ import discord4j.core.object.entity.Message; import discord4j.core.object.entity.channel.MessageChannel; import discord4j.core.spec.EmbedCreateSpec; +import discord4j.core.spec.MessageCreateSpec; +import discord4j.core.spec.MessageEditSpec; import reactor.core.publisher.Mono; public class MessageHandler { public static Mono send(MessageChannel channel, MessageSpec messageSpec) { - return channel.createMessage(mcs -> mcs.setEmbed(embedCreateSpec -> fillEmbedSpec(embedCreateSpec, messageSpec))); + return channel.createMessage(MessageCreateSpec.builder().addEmbed(fillEmbedSpec(messageSpec)).build()); } public static Mono edit(Message message, MessageSpec messageSpec) { - return message.edit(mes -> mes.setEmbed(embedCreateSpec -> fillEmbedSpec(embedCreateSpec, messageSpec))); + return message.edit(MessageEditSpec.builder().addEmbed(fillEmbedSpec(messageSpec)).build()); } - private static void fillEmbedSpec(EmbedCreateSpec embedSpec, MessageSpec messageSpec) { - if (messageSpec.getTitle() != null) embedSpec.setTitle(messageSpec.getTitle()); - if (messageSpec.getDescription() != null) embedSpec.setDescription(messageSpec.getDescription()); - if (messageSpec.getFooterText() != null) embedSpec.setFooter(messageSpec.getFooterText(), null); - if (messageSpec.getColor() != null) embedSpec.setColor(messageSpec.getColor()); + private static EmbedCreateSpec fillEmbedSpec(MessageSpec messageSpec) { + EmbedCreateSpec.Builder embedSpecBuilder = EmbedCreateSpec.builder().title(messageSpec.getTitle()).description(messageSpec.getDescription()).footer(messageSpec.getFooterText(), null); + if (messageSpec.getColor() != null) embedSpecBuilder.color(messageSpec.getColor()); + return embedSpecBuilder.build(); } }