Add %ATTACHMENTURLS% for Discord to IRC bridge messages.

This commit is contained in:
Chris Naude 2023-09-10 15:26:45 -07:00
parent 683c2efe40
commit f4e2857631
5 changed files with 46 additions and 22 deletions

14
pom.xml
View File

@ -6,7 +6,7 @@
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<!-- Bukkit API Version, change if out dated -->
<bukkit.version>1.18</bukkit.version>
<bukkit.version>1.20-R0.1-SNAPSHOT</bukkit.version>
<build.number>SNAPSHOT</build.number>
</properties>
@ -450,14 +450,14 @@
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>31.0.1-jre</version>
<version>32.1.2-jre</version>
</dependency>
<!-- Testing only -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.1</version>
<version>4.13.2</version>
<type>jar</type>
<scope>test</scope>
</dependency>
@ -491,17 +491,17 @@
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.9.0-SNAPSHOT</version>
<version>3.11.0</version>
<configuration>
<source>11</source>
<target>11</target>
<source>17</source>
<target>17</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.3.0-SNAPSHOT</version>
<version>3.5.0</version>
<executions>
<execution>
<phase>package</phase>

View File

@ -22,6 +22,9 @@ import github.scarsz.discordsrv.DiscordSRV;
import github.scarsz.discordsrv.api.ListenerPriority;
import github.scarsz.discordsrv.api.Subscribe;
import github.scarsz.discordsrv.api.events.DiscordGuildMessageReceivedEvent;
import github.scarsz.discordsrv.dependencies.jda.api.entities.Message.Attachment;
import java.util.ArrayList;
import java.util.List;
/**
*
@ -58,7 +61,8 @@ public class DiscordListener {
event.getMember().getEffectiveName(),
event.getMember().getColor(),
event.getChannel().getName(),
event.getMessage().getContentDisplay());
event.getMessage().getContentDisplay(),
event.getMessage().getAttachments());
}
}

View File

@ -45,6 +45,7 @@ import com.massivecraft.factions.entity.Faction;
import com.massivecraft.factions.entity.MPlayer;
import com.nyancraft.reportrts.data.Ticket;
import com.titankingdoms.dev.titanchat.core.participant.Participant;
import github.scarsz.discordsrv.dependencies.jda.api.entities.Message.Attachment;
import java.awt.Color;
import java.io.File;
import java.io.IOException;
@ -66,7 +67,6 @@ import java.util.concurrent.locks.ReentrantReadWriteLock;
import me.botsko.prism.actionlibs.QueryParameters;
import me.botsko.prism.events.BlockStateChange;
import org.bukkit.Achievement;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.GameMode;
import org.bukkit.Location;
@ -1360,7 +1360,7 @@ public final class PurpleBot {
}
if (plugin.ventureChatEnabled) {
plugin.logDebug("Calling VentureChatEvent: " + event.getMessage());
plugin.getServer().getScheduler().runTask(plugin, () -> plugin.getServer().getPluginManager().callEvent(new VentureChatEvent(event, this, channelName)));
plugin.getServer().getScheduler().runTask(plugin, () -> plugin.getServer().getPluginManager().callEvent(new VentureChatEvent(event, this, channelName)));
}
if (isMessageEnabled(channelName, TemplateName.GAME_CHAT)) {
asyncIRCMessage(channelName, plugin.tokenizer
@ -1513,16 +1513,29 @@ public final class PurpleBot {
* @param color
* @param effectiveName
* @param message
* @param attachments
*/
public void discordChat(String username, String nickname, String effectiveName, Color color, String discordChannel, String message) {
public void discordChat(
String username,
String nickname,
String effectiveName,
Color color,
String discordChannel,
String message,
List<Attachment> attachments) {
if (!this.isConnected()) {
return;
}
List<String> aList = new ArrayList<>();
for (Attachment a : attachments) {
aList.add(a.getUrl());
}
String attUrls = String.join(", ", aList);
for (String channelName : botChannels) {
if (isMessageEnabled(channelName, TemplateName.DISCORD_CHAT) || isMessageEnabled(channelName, "discord-" + discordChannel + "-chat")) {
String template = plugin.getMessageTemplate(botNick, channelName, TemplateName.DISCORD_CHAT);
asyncIRCMessage(channelName, plugin.tokenizer
.discordChatToIRCTokenizer(template, username, nickname, effectiveName, color, discordChannel, message)
.discordChatToIRCTokenizer(template, username, nickname, effectiveName, color, discordChannel, message, attUrls)
);
}
}
@ -2779,9 +2792,9 @@ public final class PurpleBot {
}
}
}
// https://github.com/cnaude/PurpleIRC-spigot/issues/49
if (message == null){
if (message == null) {
return;
}

View File

@ -23,12 +23,9 @@ import com.cnaude.purpleirc.TemplateName;
import com.gmail.nossr50.util.player.UserManager;
import com.nyancraft.reportrts.data.Ticket;
import com.palmergames.bukkit.TownyChat.channels.Channel;
import github.scarsz.discordsrv.DiscordSRV;
import java.awt.Color;
import java.util.Set;
import java.util.UUID;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Location;
@ -36,7 +33,6 @@ import org.bukkit.block.Block;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.pircbotx.User;
import github.scarsz.discordsrv.objects.MessageFormat;
/**
* Main class containing all message template token expanding methods
@ -493,11 +489,20 @@ public class ChatTokenizer {
* @param color
* @param discordChannel
* @param template
*
* @param message
* @param attUrls
* @return
*/
public String discordChatToIRCTokenizer(String template, String username, String nickname, String effectiveName, Color color, String discordChannel, String message) {
public String discordChatToIRCTokenizer(
String template,
String username,
String nickname,
String effectiveName,
Color color,
String discordChannel,
String message,
String attUrls
) {
// String hex = color != null ? Integer.toHexString(color.getRGB()).toUpperCase() : "99AAB5";
// if (hex.length() == 8) {
// hex = hex.substring(2);
@ -517,6 +522,7 @@ public class ChatTokenizer {
.replace("%CHANNEL%", discordChannel)
.replace("%MESSAGE%", plugin.colorConverter.gameColorsToIrc(message))
.replace("%RAWMESSAGE%", ChatColor.stripColor(message))
.replace("%ATTACHMENTURLS%", attUrls)
);
}

View File

@ -69,7 +69,8 @@ chat-ping-fix: false
# %TOWNYCHANNELTAG% - Towny channel tag name
# %TOWNYMSGCOLOR% - Towny message color
# %JOBS% - Player jobs
# %JOBSSHORT% - Player jobs shortened
# %JOBSSHORT% - Player jobs
# %ATTACHMENTURLS% - Discord attachment URLs
# Prism custom tokens:
# prism-rollback:
# %COMMAND%
@ -153,7 +154,7 @@ message-format:
# AdminPrivateChat message from IRC to game
irc-a-chat: '[AdminChat] [&4IRC&r] %MESSAGE%'
# Messages from Discord (Valid tokens: %NAME%, %NICKNAME%, %EFFNAME%, %COLOR%, %CHANNEL%, %MESSAGE%, %RAWMESSAGE%)
discord-chat: '[Discord]<%NAME%> %MESSAGE%'
discord-chat: '[Discord]<%NAME%> %MESSAGE% %ATTACHMENTURLS%'
# Messages from IRC to Discord
irc-discord-chat: '[IRC]<%NAME%> %MESSAGE%'
# Actions from IRC to Discord