New discord-chat tokens %NICKNAME%, %EFFNAME%, %COLOR%

This commit is contained in:
cnaude 2017-09-14 18:42:35 -07:00
parent 8198c9082f
commit 55f65256a0
3 changed files with 55 additions and 10 deletions

View File

@ -42,9 +42,13 @@ public class DiscordListener {
public void onDiscordGuildMessageReceivedEvent(DiscordGuildMessageReceivedEvent event) {
for (PurpleBot ircBot : plugin.ircBots.values()) {
ircBot.discordChat(event.getMessage().getAuthor().getName(),
event.getMember().getNickname(),
event.getMember().getEffectiveName(),
event.getMember().getColor(),
event.getChannel().getName(),
event.getMessage().getContent());
}
}
}

View File

@ -47,6 +47,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 java.awt.Color;
import java.io.File;
import java.io.IOException;
import java.net.InetAddress;
@ -1566,20 +1567,21 @@ public final class PurpleBot {
* Called from Discord ProcessChatEvent
*
* @param username
* @param nickname
* @param discordChannel
* @param color
* @param effectiveName
* @param message
*/
public void discordChat(String username, String discordChannel, String message) {
public void discordChat(String username, String nickname, String effectiveName, Color color, String discordChannel, String message) {
if (!this.isConnected()) {
return;
}
for (String channelName : botChannels) {
if (isMessageEnabled(channelName, TemplateName.DISCORD_CHAT)
|| isMessageEnabled(channelName, "discord-" + discordChannel + "-chat")) {
if (isMessageEnabled(channelName, TemplateName.DISCORD_CHAT) || isMessageEnabled(channelName, "discord-" + discordChannel + "-chat")) {
String template = plugin.getMessageTemplate(botNick, channelName, TemplateName.DISCORD_CHAT);
asyncIRCMessage(channelName, plugin.tokenizer
.gameChatToIRCTokenizer(username, plugin.getMessageTemplate(
botNick, channelName, TemplateName.DISCORD_CHAT), message)
.replace("%CHANNEL%", discordChannel)
.discordChatToIRCTokenizer(template, username, nickname, effectiveName, color, discordChannel, message)
);
}
}

View File

@ -24,6 +24,8 @@ import com.dthielke.herochat.ChannelManager;
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 org.bukkit.Bukkit;
@ -108,7 +110,7 @@ public class ChatTokenizer {
.replace("%SERVER%", server)
.replace("%AWAY%", away);
}
/**
*
* @param user
@ -121,10 +123,10 @@ public class ChatTokenizer {
public String ircNickChangeTokenizer(User user, String oldNick, String newNick, String channelName, PurpleBot ircBot) {
String template = plugin.getMessageTemplate(ircBot.botNick, channelName, TemplateName.IRC_NICK_CHANGE);
String message = template.replace("%NEWNICK%", newNick)
.replace("%OLDNICK%", oldNick)
.replace("%CHANNEL%", channelName);
.replace("%OLDNICK%", oldNick)
.replace("%CHANNEL%", channelName);
message = plugin.colorConverter.ircColorsToGame(ircUserTokenizer(message, user, ircBot));
return plugin.colorConverter.ircColorsToGame(message);
}
@ -482,6 +484,43 @@ public class ChatTokenizer {
);
}
/**
* Game chat to IRC
*
* @param username
* @param nickname
* @param effectiveName
* @param color
* @param discordChannel
* @param template
*
* @param message
* @return
*/
public String discordChatToIRCTokenizer(String template, String username, String nickname, String effectiveName, Color color, String discordChannel, String message) {
String hex = Integer.toHexString(color.getRGB()).toUpperCase();
if (hex.length() == 8) {
hex = hex.substring(2);
}
plugin.logError("HEX: " + hex);
if (nickname == null) {
nickname = "";
}
if (effectiveName == null) {
effectiveName = "";
}
String colorCode = ChatColor.translateAlternateColorCodes('&', DiscordSRV.getPlugin().getColors().get(hex));
return plugin.colorConverter.gameColorsToIrc(template
.replace("%NAME%", username)
.replace("%NICKNAME%", nickname)
.replace("%EFFNAME%", effectiveName)
.replace("%COLOR%", colorCode)
.replace("%CHANNEL%", discordChannel)
.replace("%MESSAGE%", plugin.colorConverter.gameColorsToIrc(message))
.replace("%RAWMESSAGE%", ChatColor.stripColor(message))
);
}
/**
* Game chat to game (private messages)
*