mirror of
https://github.com/cnaude/PurpleIRC-spigot.git
synced 2024-11-06 02:19:33 +01:00
New discord-chat tokens %NICKNAME%, %EFFNAME%, %COLOR%
This commit is contained in:
parent
8198c9082f
commit
55f65256a0
@ -42,9 +42,13 @@ public class DiscordListener {
|
|||||||
public void onDiscordGuildMessageReceivedEvent(DiscordGuildMessageReceivedEvent event) {
|
public void onDiscordGuildMessageReceivedEvent(DiscordGuildMessageReceivedEvent event) {
|
||||||
for (PurpleBot ircBot : plugin.ircBots.values()) {
|
for (PurpleBot ircBot : plugin.ircBots.values()) {
|
||||||
ircBot.discordChat(event.getMessage().getAuthor().getName(),
|
ircBot.discordChat(event.getMessage().getAuthor().getName(),
|
||||||
|
event.getMember().getNickname(),
|
||||||
|
event.getMember().getEffectiveName(),
|
||||||
|
event.getMember().getColor(),
|
||||||
event.getChannel().getName(),
|
event.getChannel().getName(),
|
||||||
event.getMessage().getContent());
|
event.getMessage().getContent());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -47,6 +47,7 @@ import com.massivecraft.factions.entity.Faction;
|
|||||||
import com.massivecraft.factions.entity.MPlayer;
|
import com.massivecraft.factions.entity.MPlayer;
|
||||||
import com.nyancraft.reportrts.data.Ticket;
|
import com.nyancraft.reportrts.data.Ticket;
|
||||||
import com.titankingdoms.dev.titanchat.core.participant.Participant;
|
import com.titankingdoms.dev.titanchat.core.participant.Participant;
|
||||||
|
import java.awt.Color;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.InetAddress;
|
import java.net.InetAddress;
|
||||||
@ -1566,20 +1567,21 @@ public final class PurpleBot {
|
|||||||
* Called from Discord ProcessChatEvent
|
* Called from Discord ProcessChatEvent
|
||||||
*
|
*
|
||||||
* @param username
|
* @param username
|
||||||
|
* @param nickname
|
||||||
* @param discordChannel
|
* @param discordChannel
|
||||||
|
* @param color
|
||||||
|
* @param effectiveName
|
||||||
* @param message
|
* @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()) {
|
if (!this.isConnected()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
for (String channelName : botChannels) {
|
for (String channelName : botChannels) {
|
||||||
if (isMessageEnabled(channelName, TemplateName.DISCORD_CHAT)
|
if (isMessageEnabled(channelName, TemplateName.DISCORD_CHAT) || isMessageEnabled(channelName, "discord-" + discordChannel + "-chat")) {
|
||||||
|| isMessageEnabled(channelName, "discord-" + discordChannel + "-chat")) {
|
String template = plugin.getMessageTemplate(botNick, channelName, TemplateName.DISCORD_CHAT);
|
||||||
asyncIRCMessage(channelName, plugin.tokenizer
|
asyncIRCMessage(channelName, plugin.tokenizer
|
||||||
.gameChatToIRCTokenizer(username, plugin.getMessageTemplate(
|
.discordChatToIRCTokenizer(template, username, nickname, effectiveName, color, discordChannel, message)
|
||||||
botNick, channelName, TemplateName.DISCORD_CHAT), message)
|
|
||||||
.replace("%CHANNEL%", discordChannel)
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -24,6 +24,8 @@ import com.dthielke.herochat.ChannelManager;
|
|||||||
import com.gmail.nossr50.util.player.UserManager;
|
import com.gmail.nossr50.util.player.UserManager;
|
||||||
import com.nyancraft.reportrts.data.Ticket;
|
import com.nyancraft.reportrts.data.Ticket;
|
||||||
import com.palmergames.bukkit.TownyChat.channels.Channel;
|
import com.palmergames.bukkit.TownyChat.channels.Channel;
|
||||||
|
import github.scarsz.discordsrv.DiscordSRV;
|
||||||
|
import java.awt.Color;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
@ -121,8 +123,8 @@ public class ChatTokenizer {
|
|||||||
public String ircNickChangeTokenizer(User user, String oldNick, String newNick, String channelName, PurpleBot ircBot) {
|
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 template = plugin.getMessageTemplate(ircBot.botNick, channelName, TemplateName.IRC_NICK_CHANGE);
|
||||||
String message = template.replace("%NEWNICK%", newNick)
|
String message = template.replace("%NEWNICK%", newNick)
|
||||||
.replace("%OLDNICK%", oldNick)
|
.replace("%OLDNICK%", oldNick)
|
||||||
.replace("%CHANNEL%", channelName);
|
.replace("%CHANNEL%", channelName);
|
||||||
message = plugin.colorConverter.ircColorsToGame(ircUserTokenizer(message, user, ircBot));
|
message = plugin.colorConverter.ircColorsToGame(ircUserTokenizer(message, user, ircBot));
|
||||||
|
|
||||||
return plugin.colorConverter.ircColorsToGame(message);
|
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)
|
* Game chat to game (private messages)
|
||||||
*
|
*
|
||||||
|
Loading…
Reference in New Issue
Block a user