mirror of
https://github.com/cnaude/PurpleIRC-spigot.git
synced 2025-02-16 03:21:25 +01:00
Translate custom prefix colors.
This commit is contained in:
parent
7f710de6eb
commit
c40c4d5a74
@ -16,12 +16,6 @@
|
|||||||
*/
|
*/
|
||||||
package com.cnaude.purpleirc;
|
package com.cnaude.purpleirc;
|
||||||
|
|
||||||
import com.cnaude.purpleirc.IRCCommand;
|
|
||||||
import com.cnaude.purpleirc.IRCCommandSender;
|
|
||||||
import com.cnaude.purpleirc.IRCConsoleCommandSender;
|
|
||||||
import com.cnaude.purpleirc.PurpleBot;
|
|
||||||
import com.cnaude.purpleirc.PurpleIRC;
|
|
||||||
import com.cnaude.purpleirc.TemplateName;
|
|
||||||
import com.cnaude.purpleirc.Utilities.CaseInsensitiveMap;
|
import com.cnaude.purpleirc.Utilities.CaseInsensitiveMap;
|
||||||
import com.google.common.base.Joiner;
|
import com.google.common.base.Joiner;
|
||||||
import java.text.Collator;
|
import java.text.Collator;
|
||||||
|
@ -140,6 +140,7 @@ public final class PurpleBot {
|
|||||||
public CaseInsensitiveMap<Collection<String>> muteList;
|
public CaseInsensitiveMap<Collection<String>> muteList;
|
||||||
public CaseInsensitiveMap<Collection<String>> enabledMessages;
|
public CaseInsensitiveMap<Collection<String>> enabledMessages;
|
||||||
public CaseInsensitiveMap<String> userPrefixes;
|
public CaseInsensitiveMap<String> userPrefixes;
|
||||||
|
public CaseInsensitiveMap<CaseInsensitiveMap<String>> firstOccurenceReplacements;
|
||||||
public String defaultCustomPrefix;
|
public String defaultCustomPrefix;
|
||||||
public CaseInsensitiveMap<CaseInsensitiveMap<CaseInsensitiveMap<String>>> commandMap;
|
public CaseInsensitiveMap<CaseInsensitiveMap<CaseInsensitiveMap<String>>> commandMap;
|
||||||
public CaseInsensitiveMap<CaseInsensitiveMap<List<String>>> extraCommandMap;
|
public CaseInsensitiveMap<CaseInsensitiveMap<List<String>>> extraCommandMap;
|
||||||
@ -176,6 +177,7 @@ public final class PurpleBot {
|
|||||||
this.extraCommandMap = new CaseInsensitiveMap<>();
|
this.extraCommandMap = new CaseInsensitiveMap<>();
|
||||||
this.joinNoticeCooldownMap = new CaseInsensitiveMap<>();
|
this.joinNoticeCooldownMap = new CaseInsensitiveMap<>();
|
||||||
this.enabledMessages = new CaseInsensitiveMap<>();
|
this.enabledMessages = new CaseInsensitiveMap<>();
|
||||||
|
this.firstOccurenceReplacements = new CaseInsensitiveMap<>();
|
||||||
this.userPrefixes = new CaseInsensitiveMap<>();
|
this.userPrefixes = new CaseInsensitiveMap<>();
|
||||||
this.muteList = new CaseInsensitiveMap<>();
|
this.muteList = new CaseInsensitiveMap<>();
|
||||||
this.worldList = new CaseInsensitiveMap<>();
|
this.worldList = new CaseInsensitiveMap<>();
|
||||||
@ -669,6 +671,7 @@ public final class PurpleBot {
|
|||||||
muteList.clear();
|
muteList.clear();
|
||||||
enabledMessages.clear();
|
enabledMessages.clear();
|
||||||
userPrefixes.clear();
|
userPrefixes.clear();
|
||||||
|
firstOccurenceReplacements.clear();
|
||||||
worldList.clear();
|
worldList.clear();
|
||||||
commandMap.clear();
|
commandMap.clear();
|
||||||
extraCommandMap.clear();
|
extraCommandMap.clear();
|
||||||
@ -682,11 +685,22 @@ public final class PurpleBot {
|
|||||||
for (String s : config.getStringList("custom-prefixes")) {
|
for (String s : config.getStringList("custom-prefixes")) {
|
||||||
String pair[] = s.split(" ", 2);
|
String pair[] = s.split(" ", 2);
|
||||||
if (pair.length > 0) {
|
if (pair.length > 0) {
|
||||||
userPrefixes.put(pair[0], pair[1]);
|
String token = ChatColor.translateAlternateColorCodes('&', pair[1]);
|
||||||
plugin.logDebug("CustomPrefix: " + pair[0] + " => " + pair[1]);
|
userPrefixes.put(pair[0], token);
|
||||||
|
plugin.logDebug("CustomPrefix: " + pair[0] + " => " + token);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
defaultCustomPrefix = ChatColor.translateAlternateColorCodes('&',config.getString("custom-prefix-default", "[IRC]"));
|
||||||
|
|
||||||
|
for (String s : config.getStringList("replace-first-occurrences")) {
|
||||||
|
String pair[] = s.split(" ", 3);
|
||||||
|
if (pair.length > 2) {
|
||||||
|
CaseInsensitiveMap rfo = new CaseInsensitiveMap<>();
|
||||||
|
rfo.put(pair[1], pair[2]);
|
||||||
|
firstOccurenceReplacements.put(pair[0], rfo);
|
||||||
|
plugin.logDebug("ReplaceFirstOccurence: " + pair[0] + " => " + pair[1] + " => " + pair[2]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
defaultCustomPrefix = config.getString("custom-prefix-default", "[IRC]");
|
|
||||||
|
|
||||||
// build command notify recipient list
|
// build command notify recipient list
|
||||||
for (String recipient : config.getStringList("command-notify.recipients")) {
|
for (String recipient : config.getStringList("command-notify.recipients")) {
|
||||||
@ -2270,6 +2284,14 @@ public final class PurpleBot {
|
|||||||
return message;
|
return message;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected String replaceFirstOccurences(String message) {
|
||||||
|
String newMessage = message;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
return newMessage;
|
||||||
|
}
|
||||||
|
|
||||||
// Broadcast chat messages from IRC
|
// Broadcast chat messages from IRC
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
|
@ -75,27 +75,26 @@ public class ChatTokenizer {
|
|||||||
if (away == null) {
|
if (away == null) {
|
||||||
away = "";
|
away = "";
|
||||||
}
|
}
|
||||||
|
plugin.logDebug("customPrefix before: " + customPrefix);
|
||||||
if (!ircBot.userPrefixes.isEmpty()) {
|
if (!ircBot.userPrefixes.isEmpty()) {
|
||||||
for (String key : ircBot.userPrefixes.keySet()) {
|
for (String key : ircBot.userPrefixes.keySet()) {
|
||||||
plugin.logDebug("Does " + key + " match " + user.getNick() + "?");
|
|
||||||
if (ircBot.userPrefixes.containsKey(user.getNick())) {
|
if (ircBot.userPrefixes.containsKey(user.getNick())) {
|
||||||
plugin.logDebug("YES");
|
plugin.logDebug("Comparing [" + key + "] to [" + user.getNick() + "] MATCH!");
|
||||||
customPrefix = ircBot.userPrefixes.get(key);
|
customPrefix = ircBot.userPrefixes.get(key);
|
||||||
break;
|
break;
|
||||||
} else {
|
} else {
|
||||||
plugin.logDebug("NO");
|
plugin.logDebug("Comparing [" + key + "] to [" + user.getNick() + "] NOPE!");
|
||||||
}
|
}
|
||||||
plugin.logDebug("Does " + key + " match " + user.getHostmask() + "?");
|
|
||||||
if (ircBot.checkUserMask(user, key)) {
|
if (ircBot.checkUserMask(user, key)) {
|
||||||
customPrefix = ircBot.userPrefixes.get(key);
|
customPrefix = ircBot.userPrefixes.get(key);
|
||||||
plugin.logDebug("YES");
|
plugin.logDebug("Comparing [" + key + "] to [" + user.getHostmask() + "] MATCH");
|
||||||
break;
|
break;
|
||||||
} else {
|
} else {
|
||||||
plugin.logDebug("NO");
|
plugin.logDebug("Comparing [" + key + "] to [" + user.getHostmask() + "] NOPE!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
plugin.logDebug("customPrefix: " + customPrefix);
|
plugin.logDebug("customPrefix after: " + customPrefix);
|
||||||
return template.replace("%HOST%", host)
|
return template.replace("%HOST%", host)
|
||||||
.replace("%CUSTOMPREFIX%", customPrefix)
|
.replace("%CUSTOMPREFIX%", customPrefix)
|
||||||
.replace("%NAME%", ircNick)
|
.replace("%NAME%", ircNick)
|
||||||
|
@ -69,10 +69,14 @@ channel-auto-join-delay: 20
|
|||||||
# If your irc-chat message has a %CUSTOMPREFIX% then these custom prefixes can replace them.
|
# If your irc-chat message has a %CUSTOMPREFIX% then these custom prefixes can replace them.
|
||||||
# Can match either nick or hostmask
|
# Can match either nick or hostmask
|
||||||
custom-prefixes:
|
custom-prefixes:
|
||||||
- 'AwesomeNick [AwesomePrefix]'
|
- 'AwesomeNick [AwesomePrefix]'
|
||||||
- '*!*sarah@example.com [Owner]'
|
- '*!*sarah@example.com [Owner]'
|
||||||
# Default if no match is found
|
# Default if no match is found
|
||||||
custom-prefix-default: '[IRC]'
|
custom-prefix-default: '[IRC]'
|
||||||
|
# Similar to custom-prefixe above. Search and replace first occurrence of : and replace with &r:
|
||||||
|
replace-first-occurrences:
|
||||||
|
- 'AwesomeNick : &r:'
|
||||||
|
- '*!*sarah@example.com : &r:'
|
||||||
# channels - List the channels your bot will join here
|
# channels - List the channels your bot will join here
|
||||||
channels:
|
channels:
|
||||||
# Channel name must be surrounded by sing quotes to be YAML compliant.
|
# Channel name must be surrounded by sing quotes to be YAML compliant.
|
||||||
|
Loading…
Reference in New Issue
Block a user