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

Commit

Permalink
Add irc-a-chat message type. Allows messages in channel to be sent di…
Browse files Browse the repository at this point in the history
…rectly to AdminPrivateChat
  • Loading branch information
cnaude committed Feb 23, 2015
1 parent 0400182 commit 6834234
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 2 deletions.
49 changes: 47 additions & 2 deletions src/main/java/com/cnaude/purpleirc/PurpleBot.java
Expand Up @@ -51,7 +51,6 @@
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Set;
import me.botsko.prism.actionlibs.QueryParameters;
import me.botsko.prism.events.BlockStateChange;
import org.bukkit.Achievement;
Expand Down Expand Up @@ -2221,6 +2220,9 @@ public String filterMessage(String message, String myChannel) {
public void broadcastChat(User user, org.pircbotx.Channel channel, String target, String message, boolean override, boolean ctcpResponse) {
boolean messageSent = false;
String myChannel = channel.getName();
/*
Send messages to Dynmap if enabled
*/
if (plugin.dynmapHook != null) {
plugin.logDebug("Checking if " + TemplateName.IRC_DYNMAP_WEB_CHAT + " is enabled ...");
if (enabledMessages.get(myChannel).contains(TemplateName.IRC_DYNMAP_WEB_CHAT)) {
Expand All @@ -2229,12 +2231,18 @@ public void broadcastChat(User user, org.pircbotx.Channel channel, String target
String template = plugin.getMsgTemplate(botNick, TemplateName.IRC_DYNMAP_WEB_CHAT);
String rawDWMessage = filterMessage(
plugin.tokenizer.ircChatToGameTokenizer(this, user, channel, template, message), myChannel);
plugin.dynmapHook.sendMessage(user.getNick(), rawDWMessage);
String nickTmpl = plugin.getMsgTemplate(botNick, TemplateName.IRC_DYNMAP_NICK);
String rawNick = nickTmpl.replace("%NICK%", user.getNick());
plugin.dynmapHook.sendMessage(rawNick, rawDWMessage);
messageSent = true;
} else {
plugin.logDebug("Nope, " + TemplateName.IRC_DYNMAP_WEB_CHAT + " is NOT enabled...");
}
}

/*
Send messages to TownyChat if enabled
*/
if (plugin.tcHook != null) {
plugin.logDebug("Checking if " + TemplateName.IRC_TOWNY_CHAT + " is enabled ...");
if (enabledMessages.get(myChannel).contains(TemplateName.IRC_TOWNY_CHAT)) {
Expand All @@ -2255,6 +2263,9 @@ public void broadcastChat(User user, org.pircbotx.Channel channel, String target
}
}

/*
Send messages to players if enabled
*/
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");
Expand All @@ -2269,6 +2280,9 @@ public void broadcastChat(User user, org.pircbotx.Channel channel, String target
plugin.logDebug("NOPE we can't broadcast due to " + TemplateName.IRC_CHAT + " disabled");
}

/*
Send messages to console if enabled
*/
if (enabledMessages.get(myChannel).contains(TemplateName.IRC_CONSOLE_CHAT)) {
String tmpl = plugin.getMsgTemplate(botNick, TemplateName.IRC_CONSOLE_CHAT);
plugin.logDebug("broadcastChat [Console]: " + tmpl);
Expand All @@ -2277,6 +2291,9 @@ public void broadcastChat(User user, org.pircbotx.Channel channel, String target
messageSent = true;
}

/*
Send messages to Herochat if enabled
*/
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);
Expand All @@ -2296,6 +2313,10 @@ public void broadcastChat(User user, org.pircbotx.Channel channel, String target
} else {
plugin.logDebug("NOPE we can't broadcast to HeroChat due to " + TemplateName.IRC_HERO_CHAT + " disabled");
}

/*
Send messages to Essentials if enabled
*/
if (plugin.isPluginEnabled("Essentials")) {
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) {
Expand All @@ -2312,6 +2333,29 @@ public void broadcastChat(User user, org.pircbotx.Channel channel, String target
+ " disabled");
}
}

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

/*
Notify IRC user that message was sent.
*/
if (enabledMessages.get(myChannel).contains(TemplateName.IRC_CHAT_RESPONSE) && messageSent && target != null) {
// Let the sender know the message was sent
String responseTemplate = plugin.getMsgTemplate(botNick, TemplateName.IRC_CHAT_RESPONSE);
Expand All @@ -2323,6 +2367,7 @@ public void broadcastChat(User user, org.pircbotx.Channel channel, String target
}
}
}

}

// Broadcast chat messages from IRC to specific hero channel
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/com/cnaude/purpleirc/TemplateName.java
Expand Up @@ -38,6 +38,8 @@ public class TemplateName {
public final static String DYNMAP_WEB_CHAT = "dynmap-web-chat";
public final static String IRC_DYNMAP_WEB_CHAT = "irc-dynmap-web-chat";
public final static String IRC_ACTION_DYNMAP_WEB_CHAT = "irc-action-dynmap-web-chat";
public final static String IRC_DYNMAP_NICK = "irc-dynmap-nick";
public final static String IRC_DYNMAP_ACTION_NICK = "irc-dynmap-action-nick";

public final static String CLEVER_SEND = "clever-send";

Expand Down Expand Up @@ -125,5 +127,6 @@ public class TemplateName {

public final static String IRC_A_RESPONSE = "irc-a-response";
public final static String GAME_A_CHAT = "game-a-chat";
public final static String IRC_A_CHAT = "irc-a-chat";

}
2 changes: 2 additions & 0 deletions src/main/resources/SampleBot.yml
Expand Up @@ -181,6 +181,8 @@ channels:
#- reddit-messages
# AdminPrivateChat messages
#- game-a-chat
# AdminPrivateChat messages IRC to game
#- irc-a-chat
# Hero channel destination for IRC messages
hero-channel: admin
# Towny channel destination for IRC messages
Expand Down
2 changes: 2 additions & 0 deletions src/main/resources/config.yml
Expand Up @@ -121,6 +121,8 @@ message-format:
irc-a-response: ' &6-> &7[AdminChat]: %MESSAGE%'
# AdinPrivateChat message from game to IRC
game-a-chat: '[%WORLD%] <%NAME%> -> [AdminChat]: %MESSAGE%'
# AdminPrivateChat message from IRC to game
irc-a-chat: '[&4IRC&r] %MESSAGE%'
# Message template for Clevernotch bot to IRC messages
clever-send: '[&4BOT]<%NAME%> %MESSAGE%'
# Message templates for mcMMO to IRC messages
Expand Down

0 comments on commit 6834234

Please sign in to comment.