Skip to content

Commit

Permalink
Added support for discord -> ingame emojis
Browse files Browse the repository at this point in the history
  • Loading branch information
jacoballen1 committed May 1, 2020
1 parent 3859028 commit 393e973
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,6 @@ public interface EmojiService {
Map<String, Character> getEmojis();

String toEmoji(String message, String chatColor);

String toEmojiWithoutColor(String message);
}
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ subprojects {
implementation apache_http_core
implementation apache_http_mime
implementation apache_http_nio
implementation emoji_java
implementation jackson_annotations
implementation jackson_core
implementation jackson_databind
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@
package org.anvilpowered.catalyst.common.discord;

import com.google.inject.Inject;
import com.vdurmont.emoji.EmojiParser;
import net.dv8tion.jda.api.Permission;
import net.dv8tion.jda.api.entities.Message;
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
import net.dv8tion.jda.api.hooks.ListenerAdapter;
import org.anvilpowered.anvil.api.data.registry.Registry;
Expand Down Expand Up @@ -67,15 +69,15 @@ public void onMessageReceived(MessageReceivedEvent event) {
}

if (event.getChannel().getId().equals(registry.getOrDefault(CatalystKeys.MAIN_CHANNEL))) {
String message = EmojiParser.parseToAliases(event.getMessage().getContentDisplay());
if (event.getMember().hasPermission(Permission.ADMINISTRATOR)
&& event.getMessage().toString().contains("!cmd")) {
String command = event.getMessage().getContentRaw().replace("!cmd ", "");
executeCommandService.executeDiscordCommand(command);
return;
} else {
String message = event.getMessage().getContentDisplay();
if (registry.getOrDefault(CatalystKeys.EMOJI_ENABLE)) {
for (String key : emojiService.getEmojis().keySet()) {
for (String key : registry.getOrDefault(CatalystKeys.EMOJI_MAP).keySet()) {
message = message.replace(key, emojiService.getEmojis().get(key).toString());
}
}
Expand All @@ -90,11 +92,11 @@ public void onMessageReceived(MessageReceivedEvent event) {
.sendTo((TCommandSource) p)
);
}
loggerService.info("[Discord] " + event.getMember().getEffectiveName() + " : " + event.getMessage().getContentDisplay());
loggerService.info("[Discord] " + event.getMember().getEffectiveName() + " : " + EmojiParser.parseToAliases(event.getMessage().getContentDisplay()));
}

if (event.getChannel().getId().equals(registry.getOrDefault(CatalystKeys.STAFF_CHANNEL))) {
String message = event.getMessage().getContentDisplay();
String message = EmojiParser.parseToAliases(event.getMessage().getContentDisplay());
if (registry.getOrDefault(CatalystKeys.EMOJI_ENABLE)) {
for (String key : emojiService.getEmojis().keySet()) {
message = message.replace(key, emojiService.getEmojis().get(key).toString());
Expand All @@ -112,7 +114,7 @@ public void onMessageReceived(MessageReceivedEvent event) {
.sendTo((TCommandSource) p);
}
});
loggerService.info("[Discord][STAFF] " + event.getMember().getEffectiveName() + " : " + event.getMessage().getContentDisplay());
loggerService.info("[Discord][STAFF] " + event.getMember().getEffectiveName() + " : " + EmojiParser.parseToAliases(event.getMessage().getContentDisplay()));
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import org.anvilpowered.catalyst.api.listener.DiscordChatListener;
import org.anvilpowered.catalyst.api.listener.StaffChatListener;
import org.anvilpowered.catalyst.api.plugin.PluginMessages;
import org.anvilpowered.catalyst.api.service.EmojiService;
import org.anvilpowered.catalyst.api.service.EventService;
import org.anvilpowered.catalyst.api.service.LoggerService;

Expand Down Expand Up @@ -68,18 +69,27 @@ public class CommonStaffChatListener<
@Inject
private LoggerService<TString> loggerService;

@Inject
private EmojiService emojiService;

@Override
public void onStaffChatEvent(TPlayer player, UUID playerUUID, String message) {
if (registry.getOrDefault(CatalystKeys.EMOJI_ENABLE)
&& permissionService.hasPermission((TSubject) player,
registry.getOrDefault(CatalystKeys.EMOJI_PERMISSION))) {
message = emojiService.toEmoji(message, "&d");
}
String finalMessage = message;
userService.getOnlinePlayers().forEach(p -> {
if (permissionService.hasPermission((TSubject) p, registry.getOrDefault(CatalystKeys.STAFFCHAT_PERMISSION))) {
textService.send(pluginMessages.getStaffChatMessageFormatted(userService.getUserName((TUser) player), textService.of(message)), (TCommandSource) p);
textService.send(pluginMessages.getStaffChatMessageFormatted(userService.getUserName((TUser) player), textService.deserialize(finalMessage)), (TCommandSource) p);
}
});
loggerService.info("[STAFF] " + userService.getUserName(playerUUID).join() + " : " + message);

loggerService.info("[STAFF] " + userService.getUserName(playerUUID).join() + " : " + finalMessage);
staffChatEvent.setSender(player);
staffChatEvent.setRawMessage(message);
staffChatEvent.setMessage(textService.of(message));
staffChatEvent.setRawMessage(finalMessage);
staffChatEvent.setMessage(textService.of(finalMessage));
eventService.fire((TEvent) staffChatEvent);
discordChatListener.onStaffChatEvent(staffChatEvent);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,12 @@ public String toEmoji(String message, String chatColor) {
}
return message;
}

@Override
public String toEmojiWithoutColor(String message) {
for (String key : getEmojis().keySet()) {
message = message.replace(key, "" + getEmojis().get(key));
}
return message;
}
}
1 change: 1 addition & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ bson=org.mongodb:bson:3.10.1
bungee=net.md-5:bungeecord-api:1.14-SNAPSHOT
configurate_core=org.spongepowered:configurate-core:3.6
configurate_hocon=org.spongepowered:configurate-hocon:3.6
emoji_java=com.vdurmont:emoji-java:5.1.1
guava=com.google.guava:guava:28.1-jre
guice=com.google.inject:guice:4.1.0
guice_extensions=com.google.inject.extensions:guice-assistedinject:3.0
Expand Down
1 change: 1 addition & 0 deletions velocity/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ shadowJar {
include dependency(apache_http_core)
include dependency(apache_http_mime)
include dependency(apache_http_nio)
include dependency(emoji_java)
include dependency(jackson_annotations)
include dependency(jackson_core)
include dependency(jackson_databind)
Expand Down

0 comments on commit 393e973

Please sign in to comment.