Skip to content
This repository has been archived by the owner on Jul 27, 2019. It is now read-only.

Commit

Permalink
Add irc-chat-response
Browse files Browse the repository at this point in the history
  • Loading branch information
cnaude committed Sep 13, 2014
1 parent a7f6b57 commit 5a41fb8
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 20 deletions.
44 changes: 28 additions & 16 deletions src/main/java/com/cnaude/purpleirc/PurpleBot.java
Expand Up @@ -617,7 +617,7 @@ private void loadConfig() {
if (channelCmdNotifyRecipients.isEmpty()) {
plugin.logInfo(" No command recipients defined.");
}

// build command notify ignore list
for (String command : config.getStringList("command-notify.ignore")) {
if (!channelCmdNotifyIgnore.contains(command)) {
Expand Down Expand Up @@ -1270,7 +1270,7 @@ public void consoleBroadcast(String message) {
}
}
}

/**
*
* @param message
Expand All @@ -1286,7 +1286,7 @@ public void redditStreamBroadcast(String message) {
} else {
plugin.logDebug("Checking if " + TemplateName.REDDIT_MESSAGES + " is enabled... NOPE");
}

}
}

Expand Down Expand Up @@ -2108,7 +2108,8 @@ public String filterMessage(String message, String myChannel) {
* @param message
* @param override
*/
public void broadcastChat(User user, org.pircbotx.Channel channel, String message, boolean override) {
public void broadcastChat(User user, org.pircbotx.Channel channel, String target, String message, boolean override, boolean ctcpResponse) {
boolean messageSent = false;
String myChannel = channel.getName();
if (plugin.dynmapHook != null) {
plugin.logDebug("Checking if " + TemplateName.IRC_DYNMAP_WEB_CHAT + " is enabled ...");
Expand All @@ -2119,6 +2120,7 @@ public void broadcastChat(User user, org.pircbotx.Channel channel, String messag
String rawDWMessage = filterMessage(
plugin.tokenizer.ircChatToGameTokenizer(this, user, channel, template, message), myChannel);
plugin.dynmapHook.sendMessage(user.getNick(), rawDWMessage);
messageSent = true;
} else {
plugin.logDebug("Nope, " + TemplateName.IRC_DYNMAP_WEB_CHAT + " is NOT enabled...");
}
Expand All @@ -2135,38 +2137,37 @@ public void broadcastChat(User user, org.pircbotx.Channel channel, String messag
String rawTCMessage = filterMessage(
plugin.tokenizer.ircChatToTownyChatTokenizer(this, user, channel, tmpl, message, tChannel), myChannel);
plugin.tcHook.sendMessage(tChannel, rawTCMessage);
messageSent = true;
}
}
} else {
plugin.logDebug("Nope, " + TemplateName.IRC_TOWNY_CHAT + " is NOT enabled...");
}
}

plugin.logDebug("Checking if " + TemplateName.IRC_CHAT
+ " is enabled before broadcasting chat from IRC");
plugin.logDebug("Checking if " + TemplateName.IRC_CHAT + " is enabled before broadcasting chat from IRC");
if (enabledMessages.get(myChannel).contains(TemplateName.IRC_CHAT) || override) {
plugin.logDebug("Yup we can broadcast due to " + TemplateName.IRC_CHAT + " enabled");
String newMessage = filterMessage(
plugin.tokenizer.ircChatToGameTokenizer(this, user, channel, plugin.getMsgTemplate(
botNick, TemplateName.IRC_CHAT), message), myChannel);
if (!newMessage.isEmpty()) {
plugin.getServer().broadcast(newMessage, "irc.message.chat");
messageSent = true;
}
} else {
plugin.logDebug("NOPE we can't broadcast due to " + TemplateName.IRC_CHAT
+ " disabled");
plugin.logDebug("NOPE we can't broadcast due to " + TemplateName.IRC_CHAT + " disabled");
}

if (enabledMessages.get(myChannel).contains(TemplateName.IRC_CONSOLE_CHAT)) {
String tmpl = plugin.getMsgTemplate(botNick, TemplateName.IRC_CONSOLE_CHAT);
plugin.logDebug("broadcastChat [Console]: " + tmpl);
plugin.getServer().getConsoleSender().sendMessage(plugin.tokenizer.ircChatToGameTokenizer(
this, user, channel, plugin.getMsgTemplate(botNick,
TemplateName.IRC_CONSOLE_CHAT), message));
this, user, channel, plugin.getMsgTemplate(botNick, TemplateName.IRC_CONSOLE_CHAT), message));
messageSent = true;
}

plugin.logDebug("Checking if " + TemplateName.IRC_HERO_CHAT
+ " is enabled before broadcasting chat from IRC to HeroChat");
plugin.logDebug("Checking if " + TemplateName.IRC_HERO_CHAT + " is enabled before broadcasting chat from IRC to HeroChat");
if (enabledMessages.get(myChannel).contains(TemplateName.IRC_HERO_CHAT)) {
String hChannel = heroChannel.get(myChannel);
String tmpl = plugin.getIRCHeroChatChannelTemplate(botNick, hChannel);
Expand All @@ -2175,32 +2176,43 @@ public void broadcastChat(User user, org.pircbotx.Channel channel, String messag
plugin.tokenizer.ircChatToHeroChatTokenizer(this, user, channel, tmpl, message, Herochat.getChannelManager(), hChannel), myChannel);
if (!rawHCMessage.isEmpty()) {
Herochat.getChannelManager().getChannel(hChannel).sendRawMessage(rawHCMessage);
messageSent = true;
if (logIrcToHeroChat.containsKey(myChannel)) {
if (logIrcToHeroChat.get(myChannel)) {
plugin.getServer().getConsoleSender().sendMessage(rawHCMessage);
}
}
}
} else {
plugin.logDebug("NOPE we can't broadcast to HeroChat due to "
+ TemplateName.IRC_HERO_CHAT + " disabled");
plugin.logDebug("NOPE we can't broadcast to HeroChat due to " + TemplateName.IRC_HERO_CHAT + " disabled");
}
if (plugin.isPluginEnabled("Essentials")) {
plugin.logDebug("Checking if " + TemplateName.IRC_ESS_HELPOP
+ " is enabled before broadcasting chat from IRC");
plugin.logDebug("Checking if " + TemplateName.IRC_ESS_HELPOP + " is enabled before broadcasting chat from IRC");
if (enabledMessages.get(myChannel).contains(TemplateName.IRC_ESS_HELPOP) || override) {
plugin.logDebug("Yup we can broadcast due to " + TemplateName.IRC_ESS_HELPOP + " enabled");
String newMessage = filterMessage(
plugin.tokenizer.ircChatToGameTokenizer(this, user, channel, plugin.getMsgTemplate(
botNick, TemplateName.IRC_ESS_HELPOP), message), myChannel);
if (!newMessage.isEmpty()) {
plugin.getServer().broadcast(newMessage, "essentials.helpop.receive");
messageSent = true;
}
} else {
plugin.logDebug("NOPE we can't broadcast due to " + TemplateName.IRC_ESS_HELPOP
+ " disabled");
}
}
if (messageSent && target != null) {
// Let the sender know the message was sent
String responseTemplate = plugin.getMsgTemplate(botNick, TemplateName.IRC_CHAT_RESPONSE);
if (!responseTemplate.isEmpty()) {
if (ctcpResponse) {
asyncCTCPMessage(target, plugin.tokenizer.targetChatResponseTokenizer(target, message, responseTemplate));
} else {
asyncIRCMessage(target, plugin.tokenizer.targetChatResponseTokenizer(target, message, responseTemplate));
}
}
}
}

// Broadcast chat messages from IRC to specific hero channel
Expand Down
1 change: 1 addition & 0 deletions src/main/java/com/cnaude/purpleirc/TemplateName.java
Expand Up @@ -61,6 +61,7 @@ public class TemplateName {
public final static String IRC_HCHAT_RESPONSE = "irc-hchat-response";
public final static String IRC_PCHAT = "irc-pchat";
public final static String IRC_PCHAT_RESPONSE = "irc-pchat-response";
public final static String IRC_CHAT_RESPONSE = "irc-chat-response";
public final static String IRC_KICK = "irc-kick";
public final static String IRC_JOIN = "irc-join";
public final static String IRC_PART = "irc-part";
Expand Down
Expand Up @@ -98,10 +98,10 @@ public void processMessage(PurpleBot ircBot, User user, Channel channel, String
sendMessage(ircBot, target, getCommands(ircBot.commandMap, myChannel), ctcpResponse);
break;
case "@chat":
ircBot.broadcastChat(user, channel, commandArgs, false);
ircBot.broadcastChat(user, channel, target, commandArgs, false, ctcpResponse);
break;
case "@ochat":
ircBot.broadcastChat(user, channel, commandArgs, true);
ircBot.broadcastChat(user, channel, target, commandArgs, true, ctcpResponse);
break;
case "@hchat":
ircBot.broadcastHeroChat(user, channel, target, commandArgs);
Expand Down Expand Up @@ -162,7 +162,7 @@ public void processMessage(PurpleBot ircBot, User user, Channel channel, String
}
if (ircBot.enabledMessages.get(myChannel).contains(TemplateName.INVALID_IRC_COMMAND)) {
plugin.logDebug("Invalid IRC command dispatched for broadcast...");
ircBot.broadcastChat(user, channel, message, false);
ircBot.broadcastChat(user, channel, null, message, false, false);
}
}
} else {
Expand All @@ -175,7 +175,7 @@ public void processMessage(PurpleBot ircBot, User user, Channel channel, String
return;
}
plugin.logDebug("Message dispatched for broadcast...");
ircBot.broadcastChat(user, channel, message, false);
ircBot.broadcastChat(user, channel, null, message, false, false);
}
}

Expand Down
1 change: 1 addition & 0 deletions src/main/resources/config.yml
Expand Up @@ -91,6 +91,7 @@ message-format:
# Message templates for IRC to game messages
irc-action: '[&4IRC&r] ***%NAME% %MESSAGE%'
irc-chat: '[&4IRC&r]<%NAME%> %MESSAGE%'
irc-chat-response: ' &6-> &7%TARGET%: %MESSAGE%'
irc-pchat: '&dPrivate message: [&4IRC&r]<%NAME%> %MESSAGE%'
# Notification to user when sending a private message to a player
irc-pchat-response: ' &6-> &7%TARGET%: %MESSAGE%'
Expand Down

0 comments on commit 5a41fb8

Please sign in to comment.