mirror of
https://github.com/cnaude/PurpleIRC-spigot.git
synced 2025-02-13 10:01:29 +01:00
Translate custom prefix colors.
This commit is contained in:
parent
7f710de6eb
commit
c40c4d5a74
@ -16,12 +16,6 @@
|
||||
*/
|
||||
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.google.common.base.Joiner;
|
||||
import java.text.Collator;
|
||||
|
@ -140,6 +140,7 @@ public final class PurpleBot {
|
||||
public CaseInsensitiveMap<Collection<String>> muteList;
|
||||
public CaseInsensitiveMap<Collection<String>> enabledMessages;
|
||||
public CaseInsensitiveMap<String> userPrefixes;
|
||||
public CaseInsensitiveMap<CaseInsensitiveMap<String>> firstOccurenceReplacements;
|
||||
public String defaultCustomPrefix;
|
||||
public CaseInsensitiveMap<CaseInsensitiveMap<CaseInsensitiveMap<String>>> commandMap;
|
||||
public CaseInsensitiveMap<CaseInsensitiveMap<List<String>>> extraCommandMap;
|
||||
@ -176,6 +177,7 @@ public final class PurpleBot {
|
||||
this.extraCommandMap = new CaseInsensitiveMap<>();
|
||||
this.joinNoticeCooldownMap = new CaseInsensitiveMap<>();
|
||||
this.enabledMessages = new CaseInsensitiveMap<>();
|
||||
this.firstOccurenceReplacements = new CaseInsensitiveMap<>();
|
||||
this.userPrefixes = new CaseInsensitiveMap<>();
|
||||
this.muteList = new CaseInsensitiveMap<>();
|
||||
this.worldList = new CaseInsensitiveMap<>();
|
||||
@ -669,6 +671,7 @@ public final class PurpleBot {
|
||||
muteList.clear();
|
||||
enabledMessages.clear();
|
||||
userPrefixes.clear();
|
||||
firstOccurenceReplacements.clear();
|
||||
worldList.clear();
|
||||
commandMap.clear();
|
||||
extraCommandMap.clear();
|
||||
@ -682,11 +685,22 @@ public final class PurpleBot {
|
||||
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]);
|
||||
String token = ChatColor.translateAlternateColorCodes('&', 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
|
||||
for (String recipient : config.getStringList("command-notify.recipients")) {
|
||||
@ -2270,6 +2284,14 @@ public final class PurpleBot {
|
||||
return message;
|
||||
}
|
||||
|
||||
protected String replaceFirstOccurences(String message) {
|
||||
String newMessage = message;
|
||||
|
||||
|
||||
|
||||
return newMessage;
|
||||
}
|
||||
|
||||
// Broadcast chat messages from IRC
|
||||
/**
|
||||
*
|
||||
|
@ -75,27 +75,26 @@ public class ChatTokenizer {
|
||||
if (away == null) {
|
||||
away = "";
|
||||
}
|
||||
plugin.logDebug("customPrefix before: " + customPrefix);
|
||||
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");
|
||||
plugin.logDebug("Comparing [" + key + "] to [" + user.getNick() + "] MATCH!");
|
||||
customPrefix = ircBot.userPrefixes.get(key);
|
||||
break;
|
||||
} else {
|
||||
plugin.logDebug("NO");
|
||||
plugin.logDebug("Comparing [" + key + "] to [" + user.getNick() + "] NOPE!");
|
||||
}
|
||||
plugin.logDebug("Does " + key + " match " + user.getHostmask() + "?");
|
||||
if (ircBot.checkUserMask(user, key)) {
|
||||
customPrefix = ircBot.userPrefixes.get(key);
|
||||
plugin.logDebug("YES");
|
||||
plugin.logDebug("Comparing [" + key + "] to [" + user.getHostmask() + "] MATCH");
|
||||
break;
|
||||
} 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)
|
||||
.replace("%CUSTOMPREFIX%", customPrefix)
|
||||
.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.
|
||||
# Can match either nick or hostmask
|
||||
custom-prefixes:
|
||||
- 'AwesomeNick [AwesomePrefix]'
|
||||
- '*!*sarah@example.com [Owner]'
|
||||
- 'AwesomeNick [AwesomePrefix]'
|
||||
- '*!*sarah@example.com [Owner]'
|
||||
# Default if no match is found
|
||||
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:
|
||||
# Channel name must be surrounded by sing quotes to be YAML compliant.
|
||||
|
Loading…
Reference in New Issue
Block a user