Add %CUSTOMPREFIX%

This commit is contained in:
cnaude 2015-02-27 20:00:00 -07:00
parent cb0c3b9778
commit 07558aef55
4 changed files with 71 additions and 40 deletions

View File

@ -54,7 +54,7 @@ public class MessageListener extends ListenerAdapter {
User user = event.getUser();
plugin.logDebug("Message caught <" + user.getNick() + ">: " + message);
try {
if (plugin.shortifyHook != null && ircBot.isShortifyEnabled(channel.getName())) {
plugin.logDebug("Shortifying message (before): " + message);
message = plugin.shortifyHook.shorten(message);
@ -68,5 +68,8 @@ public class MessageListener extends ListenerAdapter {
} else {
plugin.logDebug("Channel " + channel.getName() + " is not valid.");
}
} catch (Exception ex) {
plugin.logError("onMessage: " + ex.getMessage());
}
}
}

View File

@ -139,6 +139,8 @@ public final class PurpleBot {
public CaseInsensitiveMap<Collection<String>> worldList;
public CaseInsensitiveMap<Collection<String>> muteList;
public CaseInsensitiveMap<Collection<String>> enabledMessages;
public CaseInsensitiveMap<String> userPrefixes;
public String defaultCustomPrefix;
public CaseInsensitiveMap<CaseInsensitiveMap<CaseInsensitiveMap<String>>> commandMap;
public CaseInsensitiveMap<CaseInsensitiveMap<List<String>>> extraCommandMap;
public CaseInsensitiveMap<Long> joinNoticeCooldownMap;
@ -174,6 +176,7 @@ public final class PurpleBot {
this.extraCommandMap = new CaseInsensitiveMap<>();
this.joinNoticeCooldownMap = new CaseInsensitiveMap<>();
this.enabledMessages = new CaseInsensitiveMap<>();
this.userPrefixes = new CaseInsensitiveMap<>();
this.muteList = new CaseInsensitiveMap<>();
this.worldList = new CaseInsensitiveMap<>();
this.opsList = new CaseInsensitiveMap<>();
@ -315,21 +318,6 @@ public final class PurpleBot {
ircListeners.add(new ServerResponseListener(plugin, this));
}
/*
private void addAutoJoinChannels(Configuration.Builder configBuilder) {
for (String channelName : botChannels) {
if (channelAutoJoin.containsKey(channelName)) {
if (channelAutoJoin.get(channelName)) {
if (channelPassword.get(channelName).isEmpty()) {
configBuilder.addAutoJoinChannel(channelName);
} else {
configBuilder.addAutoJoinChannel(channelName, channelPassword.get(channelName));
}
}
}
}
}
*/
public void autoJoinChannels() {
plugin.getServer().getScheduler().runTaskLaterAsynchronously(plugin, new Runnable() {
@Override
@ -680,6 +668,7 @@ public final class PurpleBot {
voicesList.clear();
muteList.clear();
enabledMessages.clear();
userPrefixes.clear();
worldList.clear();
commandMap.clear();
extraCommandMap.clear();
@ -690,6 +679,15 @@ public final class PurpleBot {
channelCmdNotifyMode = config.getString("command-notify.mode", "msg");
plugin.logDebug(" channelCmdNotifyMode => " + channelCmdNotifyMode);
for (String s : config.getStringList("custom-prefixes")) {
String pair[] = s.split(" ", 2);
if (pair.length > 0) {
userPrefixes.put(pair[0], pair[1]);
plugin.logDebug("CustomPrefix: " + pair[0] + " => " + pair[1]);
}
}
defaultCustomPrefix = config.getString("custom-prefix-deault", "[IRC]");
// build command notify recipient list
for (String recipient : config.getStringList("command-notify.recipients")) {
if (!channelCmdNotifyRecipients.contains(recipient)) {

View File

@ -55,16 +55,17 @@ public class ChatTokenizer {
* @return
*/
public String chatIRCTokenizer(PurpleBot ircBot, User user, org.pircbotx.Channel channel, String template) {
return plugin.colorConverter.ircColorsToGame(ircUserTokenizer(template, user)
return plugin.colorConverter.ircColorsToGame(ircUserTokenizer(template, user, ircBot)
.replace("%NICKPREFIX%", ircBot.getNickPrefix(user, channel))
.replace("%CHANNEL%", channel.getName()));
}
public String ircUserTokenizer(String template, User user) {
public String ircUserTokenizer(String template, User user, PurpleBot ircBot) {
String host = user.getHostmask();
String server = user.getServer();
String away = user.getAwayMessage();
String ircNick = user.getNick();
String customPrefix = ircBot.defaultCustomPrefix;
if (host == null) {
host = "";
}
@ -74,13 +75,35 @@ public class ChatTokenizer {
if (away == null) {
away = "";
}
if (!ircBot.userPrefixes.isEmpty()) {
for (String key : ircBot.userPrefixes.keySet()) {
plugin.logDebug("Does " + key + " match " + user.getNick() + "?");
if (ircBot.userPrefixes.containsKey(user.getNick())) {
plugin.logDebug("YES");
customPrefix = ircBot.userPrefixes.get(key);
break;
} else {
plugin.logDebug("NO");
}
plugin.logDebug("Does " + key + " match " + user.getHostmask() + "?");
if (ircBot.checkUserMask(user, key)) {
customPrefix = ircBot.userPrefixes.get(key);
plugin.logDebug("YES");
break;
} else {
plugin.logDebug("NO");
}
}
}
plugin.logDebug("customPrefix: " + customPrefix);
return template.replace("%HOST%", host)
.replace("%CUSTOMPREFIX%", customPrefix)
.replace("%NAME%", ircNick)
.replace("%SERVER%", server)
.replace("%AWAY%", away);
}
public String ircUserTokenizer(String template, User recipient, User kicker) {
public String ircUserTokenizer(String template, User recipient, User kicker, PurpleBot ircBot) {
String host = kicker.getHostmask();
String server = kicker.getServer();
String away = kicker.getAwayMessage();
@ -94,7 +117,7 @@ public class ChatTokenizer {
if (away == null) {
away = "";
}
return ircUserTokenizer(template, recipient)
return ircUserTokenizer(template, recipient, ircBot)
.replace("%KICKERHOST%", host)
.replace("%KICKER%", ircNick)
.replace("%KICKERSERVER%", server)
@ -122,7 +145,7 @@ public class ChatTokenizer {
} else {
tmpl = playerTokenizer(ircNick, template);
}
return plugin.colorConverter.ircColorsToGame(ircUserTokenizer(tmpl, user)
return plugin.colorConverter.ircColorsToGame(ircUserTokenizer(tmpl, user, ircBot)
.replace("%HEROCHANNEL%", hChannel)
.replace("%HERONICK%", channelManager.getChannel(hChannel).getNick())
.replace("%HEROCOLOR%", channelManager.getChannel(hChannel).getColor().toString())
@ -150,7 +173,7 @@ public class ChatTokenizer {
plugin.logDebug("ircChatToGameTokenizer: null player: " + ircNick);
tmpl = playerTokenizer(ircNick, template);
}
return plugin.colorConverter.ircColorsToGame(ircUserTokenizer(tmpl, user)
return plugin.colorConverter.ircColorsToGame(ircUserTokenizer(tmpl, user, ircBot)
.replace("%NICKPREFIX%", ircBot.getNickPrefix(user, channel))
.replace("%MESSAGE%", message)
.replace("%CHANNEL%", channel.getName()));
@ -177,7 +200,7 @@ public class ChatTokenizer {
} else {
tmpl = playerTokenizer(ircNick, template);
}
return plugin.colorConverter.ircColorsToGame(ircUserTokenizer(tmpl, user)
return plugin.colorConverter.ircColorsToGame(ircUserTokenizer(tmpl, user, ircBot)
.replace("%HEROCHANNEL%", hChannel)
.replace("%HERONICK%", channelManager.getChannel(hChannel).getNick())
.replace("%HEROCOLOR%", channelManager.getChannel(hChannel).getColor().toString())
@ -206,7 +229,7 @@ public class ChatTokenizer {
} else {
tmpl = playerTokenizer(ircNick, template);
}
return plugin.colorConverter.ircColorsToGame(ircUserTokenizer(tmpl, user)
return plugin.colorConverter.ircColorsToGame(ircUserTokenizer(tmpl, user, ircBot)
.replace("%TOWNYCHANNEL%", tChannel)
.replace("%NICKPREFIX%", ircBot.getNickPrefix(user, channel))
.replace("%MESSAGE%", message)
@ -225,7 +248,7 @@ public class ChatTokenizer {
* @return
*/
public String ircKickTokenizer(PurpleBot ircBot, User recipient, User kicker, String reason, org.pircbotx.Channel channel, String template) {
return plugin.colorConverter.ircColorsToGame(ircUserTokenizer(template, recipient, kicker)
return plugin.colorConverter.ircColorsToGame(ircUserTokenizer(template, recipient, kicker, ircBot)
.replace("%NICKPREFIX%", ircBot.getNickPrefix(kicker, channel))
.replace("%REASON%", reason)
.replace("%CHANNEL%", channel.getName()));
@ -245,7 +268,7 @@ public class ChatTokenizer {
* @return
*/
public String ircKickToHeroChatTokenizer(PurpleBot ircBot, User recipient, User kicker, String reason, org.pircbotx.Channel channel, String template, ChannelManager channelManager, String hChannel) {
return plugin.colorConverter.ircColorsToGame(ircUserTokenizer(template, recipient, kicker)
return plugin.colorConverter.ircColorsToGame(ircUserTokenizer(template, recipient, kicker, ircBot)
.replace("%HEROCHANNEL%", hChannel)
.replace("%HERONICK%", channelManager.getChannel(hChannel).getNick())
.replace("%HEROCOLOR%", channelManager.getChannel(hChannel).getColor().toString())
@ -265,7 +288,7 @@ public class ChatTokenizer {
* @return
*/
public String ircModeTokenizer(PurpleBot ircBot, User user, String mode, org.pircbotx.Channel channel, String template) {
return plugin.colorConverter.ircColorsToGame(ircUserTokenizer(template, user)
return plugin.colorConverter.ircColorsToGame(ircUserTokenizer(template, user, ircBot)
.replace("%MODE%", mode)
.replace("%NICKPREFIX%", ircBot.getNickPrefix(user, channel))
.replace("%CHANNEL%", channel.getName()));
@ -283,7 +306,7 @@ public class ChatTokenizer {
* @return
*/
public String ircNoticeTokenizer(PurpleBot ircBot, User user, String message, String notice, org.pircbotx.Channel channel, String template) {
return plugin.colorConverter.ircColorsToGame(ircUserTokenizer(template, user)
return plugin.colorConverter.ircColorsToGame(ircUserTokenizer(template, user, ircBot)
.replace("%NICKPREFIX%", ircBot.getNickPrefix(user, channel))
.replace("%MESSAGE%", message)
.replace("%NOTICE%", notice)

View File

@ -66,6 +66,13 @@ part-invalid-channels: false
part-invalid-channels-message: 'I should not be here! Bye!'
# Channel auto join delay in server ticks (20 ticks = 1 second)
channel-auto-join-delay: 20
# If your irc-chat message has a %CUSTOMPREFIX% the these custom prefixes can replace them.
# Can match either nick or hostmask
custom-prefixes:
- 'AwesomeNick [AwesomePrefix]'
- '*!*sarah@example.com [Owner]'
# Default if no match is found
custom-prefix-deault: '[IRC]'
# channels - List the channels your bot will join here
channels:
# Channel name must be surrounded by sing quotes to be YAML compliant.