Skip to content

Commit

Permalink
Merge pull request #272 from AarKro/bug/#271-on-join-role-fix-depende…
Browse files Browse the repository at this point in the history
…ncy-upgrade

fixed onjoinrole, updated dependencies
  • Loading branch information
Pacmens authored Sep 29, 2021
2 parents 2eacb20 + b7b66bf commit 9c50e60
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 17 deletions.
6 changes: 3 additions & 3 deletions core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
<dependency>
<groupId>com.discord4j</groupId>
<artifactId>discord4j-core</artifactId>
<version>3.1.5</version>
<version>3.2.0</version>
</dependency>
<dependency>
<groupId>com.sedmelluq</groupId>
Expand All @@ -40,12 +40,12 @@
<dependency>
<groupId>com.google.apis</groupId>
<artifactId>google-api-services-youtube</artifactId>
<version>v3-rev20200618-1.30.9</version>
<version>v3-rev20210915-1.32.1</version>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.2.3</version>
<version>1.2.6</version>
</dependency>
<dependency>
<groupId>hera</groupId>
Expand Down
5 changes: 4 additions & 1 deletion core/src/main/java/hera/core/Core.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();

Expand Down Expand Up @@ -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()))
Expand Down
11 changes: 6 additions & 5 deletions core/src/main/java/hera/core/api/handlers/YouTubeApiHandler.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;

Expand Down Expand Up @@ -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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public static Mono<Void> executeFromReaction(ReactionAddEvent event, MessageChan
return Mono.empty();
}

private static HashMap<String, Double> countReactions(Set<Reaction> reactions) {
private static HashMap<String, Double> countReactions(List<Reaction> reactions) {
HashMap<String, Double> out = new HashMap<>();
for (Reaction reaction : reactions) {
if (reaction.selfReacted()) { //only consider options the bot set
Expand Down
15 changes: 8 additions & 7 deletions core/src/main/java/hera/core/messages/MessageHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<Message> 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<Message> 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();
}
}

0 comments on commit 9c50e60

Please sign in to comment.