mirror of
https://github.com/cnaude/PurpleIRC-spigot.git
synced 2024-11-29 05:26:19 +01:00
Add %CUSTOMPREFIX%
This commit is contained in:
parent
cb0c3b9778
commit
07558aef55
@ -54,19 +54,22 @@ public class MessageListener extends ListenerAdapter {
|
|||||||
User user = event.getUser();
|
User user = event.getUser();
|
||||||
|
|
||||||
plugin.logDebug("Message caught <" + user.getNick() + ">: " + message);
|
plugin.logDebug("Message caught <" + user.getNick() + ">: " + message);
|
||||||
|
try {
|
||||||
if (plugin.shortifyHook != null && ircBot.isShortifyEnabled(channel.getName())) {
|
if (plugin.shortifyHook != null && ircBot.isShortifyEnabled(channel.getName())) {
|
||||||
plugin.logDebug("Shortifying message (before): " + message);
|
plugin.logDebug("Shortifying message (before): " + message);
|
||||||
message = plugin.shortifyHook.shorten(message);
|
message = plugin.shortifyHook.shorten(message);
|
||||||
plugin.logDebug("Shortifying message (after): " + message);
|
plugin.logDebug("Shortifying message (after): " + message);
|
||||||
} else {
|
} else {
|
||||||
plugin.logDebug("Shortify: false");
|
plugin.logDebug("Shortify: false");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ircBot.isValidChannel(channel.getName())) {
|
if (ircBot.isValidChannel(channel.getName())) {
|
||||||
plugin.ircMessageHandler.processMessage(ircBot, user, channel, message, false);
|
plugin.ircMessageHandler.processMessage(ircBot, user, channel, message, false);
|
||||||
} else {
|
} else {
|
||||||
plugin.logDebug("Channel " + channel.getName() + " is not valid.");
|
plugin.logDebug("Channel " + channel.getName() + " is not valid.");
|
||||||
|
}
|
||||||
|
} catch (Exception ex) {
|
||||||
|
plugin.logError("onMessage: " + ex.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -139,6 +139,8 @@ public final class PurpleBot {
|
|||||||
public CaseInsensitiveMap<Collection<String>> worldList;
|
public CaseInsensitiveMap<Collection<String>> worldList;
|
||||||
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 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;
|
||||||
public CaseInsensitiveMap<Long> joinNoticeCooldownMap;
|
public CaseInsensitiveMap<Long> joinNoticeCooldownMap;
|
||||||
@ -174,6 +176,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.userPrefixes = new CaseInsensitiveMap<>();
|
||||||
this.muteList = new CaseInsensitiveMap<>();
|
this.muteList = new CaseInsensitiveMap<>();
|
||||||
this.worldList = new CaseInsensitiveMap<>();
|
this.worldList = new CaseInsensitiveMap<>();
|
||||||
this.opsList = new CaseInsensitiveMap<>();
|
this.opsList = new CaseInsensitiveMap<>();
|
||||||
@ -315,21 +318,6 @@ public final class PurpleBot {
|
|||||||
ircListeners.add(new ServerResponseListener(plugin, this));
|
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() {
|
public void autoJoinChannels() {
|
||||||
plugin.getServer().getScheduler().runTaskLaterAsynchronously(plugin, new Runnable() {
|
plugin.getServer().getScheduler().runTaskLaterAsynchronously(plugin, new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
@ -680,6 +668,7 @@ public final class PurpleBot {
|
|||||||
voicesList.clear();
|
voicesList.clear();
|
||||||
muteList.clear();
|
muteList.clear();
|
||||||
enabledMessages.clear();
|
enabledMessages.clear();
|
||||||
|
userPrefixes.clear();
|
||||||
worldList.clear();
|
worldList.clear();
|
||||||
commandMap.clear();
|
commandMap.clear();
|
||||||
extraCommandMap.clear();
|
extraCommandMap.clear();
|
||||||
@ -689,6 +678,15 @@ public final class PurpleBot {
|
|||||||
|
|
||||||
channelCmdNotifyMode = config.getString("command-notify.mode", "msg");
|
channelCmdNotifyMode = config.getString("command-notify.mode", "msg");
|
||||||
plugin.logDebug(" channelCmdNotifyMode => " + channelCmdNotifyMode);
|
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
|
// build command notify recipient list
|
||||||
for (String recipient : config.getStringList("command-notify.recipients")) {
|
for (String recipient : config.getStringList("command-notify.recipients")) {
|
||||||
@ -831,7 +829,7 @@ public final class PurpleBot {
|
|||||||
enabledMessages.put(channelName, c);
|
enabledMessages.put(channelName, c);
|
||||||
if (enabledMessages.isEmpty()) {
|
if (enabledMessages.isEmpty()) {
|
||||||
plugin.logInfo("There are no enabled messages!");
|
plugin.logInfo("There are no enabled messages!");
|
||||||
}
|
}
|
||||||
|
|
||||||
// build valid world list
|
// build valid world list
|
||||||
Collection<String> w = new ArrayList<>();
|
Collection<String> w = new ArrayList<>();
|
||||||
|
@ -55,16 +55,17 @@ public class ChatTokenizer {
|
|||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public String chatIRCTokenizer(PurpleBot ircBot, User user, org.pircbotx.Channel channel, String template) {
|
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("%NICKPREFIX%", ircBot.getNickPrefix(user, channel))
|
||||||
.replace("%CHANNEL%", channel.getName()));
|
.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 host = user.getHostmask();
|
||||||
String server = user.getServer();
|
String server = user.getServer();
|
||||||
String away = user.getAwayMessage();
|
String away = user.getAwayMessage();
|
||||||
String ircNick = user.getNick();
|
String ircNick = user.getNick();
|
||||||
|
String customPrefix = ircBot.defaultCustomPrefix;
|
||||||
if (host == null) {
|
if (host == null) {
|
||||||
host = "";
|
host = "";
|
||||||
}
|
}
|
||||||
@ -74,13 +75,35 @@ public class ChatTokenizer {
|
|||||||
if (away == null) {
|
if (away == null) {
|
||||||
away = "";
|
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)
|
return template.replace("%HOST%", host)
|
||||||
|
.replace("%CUSTOMPREFIX%", customPrefix)
|
||||||
.replace("%NAME%", ircNick)
|
.replace("%NAME%", ircNick)
|
||||||
.replace("%SERVER%", server)
|
.replace("%SERVER%", server)
|
||||||
.replace("%AWAY%", away);
|
.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 host = kicker.getHostmask();
|
||||||
String server = kicker.getServer();
|
String server = kicker.getServer();
|
||||||
String away = kicker.getAwayMessage();
|
String away = kicker.getAwayMessage();
|
||||||
@ -94,7 +117,7 @@ public class ChatTokenizer {
|
|||||||
if (away == null) {
|
if (away == null) {
|
||||||
away = "";
|
away = "";
|
||||||
}
|
}
|
||||||
return ircUserTokenizer(template, recipient)
|
return ircUserTokenizer(template, recipient, ircBot)
|
||||||
.replace("%KICKERHOST%", host)
|
.replace("%KICKERHOST%", host)
|
||||||
.replace("%KICKER%", ircNick)
|
.replace("%KICKER%", ircNick)
|
||||||
.replace("%KICKERSERVER%", server)
|
.replace("%KICKERSERVER%", server)
|
||||||
@ -122,7 +145,7 @@ public class ChatTokenizer {
|
|||||||
} else {
|
} else {
|
||||||
tmpl = playerTokenizer(ircNick, template);
|
tmpl = playerTokenizer(ircNick, template);
|
||||||
}
|
}
|
||||||
return plugin.colorConverter.ircColorsToGame(ircUserTokenizer(tmpl, user)
|
return plugin.colorConverter.ircColorsToGame(ircUserTokenizer(tmpl, user, ircBot)
|
||||||
.replace("%HEROCHANNEL%", hChannel)
|
.replace("%HEROCHANNEL%", hChannel)
|
||||||
.replace("%HERONICK%", channelManager.getChannel(hChannel).getNick())
|
.replace("%HERONICK%", channelManager.getChannel(hChannel).getNick())
|
||||||
.replace("%HEROCOLOR%", channelManager.getChannel(hChannel).getColor().toString())
|
.replace("%HEROCOLOR%", channelManager.getChannel(hChannel).getColor().toString())
|
||||||
@ -150,7 +173,7 @@ public class ChatTokenizer {
|
|||||||
plugin.logDebug("ircChatToGameTokenizer: null player: " + ircNick);
|
plugin.logDebug("ircChatToGameTokenizer: null player: " + ircNick);
|
||||||
tmpl = playerTokenizer(ircNick, template);
|
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("%NICKPREFIX%", ircBot.getNickPrefix(user, channel))
|
||||||
.replace("%MESSAGE%", message)
|
.replace("%MESSAGE%", message)
|
||||||
.replace("%CHANNEL%", channel.getName()));
|
.replace("%CHANNEL%", channel.getName()));
|
||||||
@ -177,7 +200,7 @@ public class ChatTokenizer {
|
|||||||
} else {
|
} else {
|
||||||
tmpl = playerTokenizer(ircNick, template);
|
tmpl = playerTokenizer(ircNick, template);
|
||||||
}
|
}
|
||||||
return plugin.colorConverter.ircColorsToGame(ircUserTokenizer(tmpl, user)
|
return plugin.colorConverter.ircColorsToGame(ircUserTokenizer(tmpl, user, ircBot)
|
||||||
.replace("%HEROCHANNEL%", hChannel)
|
.replace("%HEROCHANNEL%", hChannel)
|
||||||
.replace("%HERONICK%", channelManager.getChannel(hChannel).getNick())
|
.replace("%HERONICK%", channelManager.getChannel(hChannel).getNick())
|
||||||
.replace("%HEROCOLOR%", channelManager.getChannel(hChannel).getColor().toString())
|
.replace("%HEROCOLOR%", channelManager.getChannel(hChannel).getColor().toString())
|
||||||
@ -206,7 +229,7 @@ public class ChatTokenizer {
|
|||||||
} else {
|
} else {
|
||||||
tmpl = playerTokenizer(ircNick, template);
|
tmpl = playerTokenizer(ircNick, template);
|
||||||
}
|
}
|
||||||
return plugin.colorConverter.ircColorsToGame(ircUserTokenizer(tmpl, user)
|
return plugin.colorConverter.ircColorsToGame(ircUserTokenizer(tmpl, user, ircBot)
|
||||||
.replace("%TOWNYCHANNEL%", tChannel)
|
.replace("%TOWNYCHANNEL%", tChannel)
|
||||||
.replace("%NICKPREFIX%", ircBot.getNickPrefix(user, channel))
|
.replace("%NICKPREFIX%", ircBot.getNickPrefix(user, channel))
|
||||||
.replace("%MESSAGE%", message)
|
.replace("%MESSAGE%", message)
|
||||||
@ -225,7 +248,7 @@ public class ChatTokenizer {
|
|||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public String ircKickTokenizer(PurpleBot ircBot, User recipient, User kicker, String reason, org.pircbotx.Channel channel, String template) {
|
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("%NICKPREFIX%", ircBot.getNickPrefix(kicker, channel))
|
||||||
.replace("%REASON%", reason)
|
.replace("%REASON%", reason)
|
||||||
.replace("%CHANNEL%", channel.getName()));
|
.replace("%CHANNEL%", channel.getName()));
|
||||||
@ -245,7 +268,7 @@ public class ChatTokenizer {
|
|||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public String ircKickToHeroChatTokenizer(PurpleBot ircBot, User recipient, User kicker, String reason, org.pircbotx.Channel channel, String template, ChannelManager channelManager, String hChannel) {
|
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("%HEROCHANNEL%", hChannel)
|
||||||
.replace("%HERONICK%", channelManager.getChannel(hChannel).getNick())
|
.replace("%HERONICK%", channelManager.getChannel(hChannel).getNick())
|
||||||
.replace("%HEROCOLOR%", channelManager.getChannel(hChannel).getColor().toString())
|
.replace("%HEROCOLOR%", channelManager.getChannel(hChannel).getColor().toString())
|
||||||
@ -265,7 +288,7 @@ public class ChatTokenizer {
|
|||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public String ircModeTokenizer(PurpleBot ircBot, User user, String mode, org.pircbotx.Channel channel, String template) {
|
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("%MODE%", mode)
|
||||||
.replace("%NICKPREFIX%", ircBot.getNickPrefix(user, channel))
|
.replace("%NICKPREFIX%", ircBot.getNickPrefix(user, channel))
|
||||||
.replace("%CHANNEL%", channel.getName()));
|
.replace("%CHANNEL%", channel.getName()));
|
||||||
@ -283,7 +306,7 @@ public class ChatTokenizer {
|
|||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public String ircNoticeTokenizer(PurpleBot ircBot, User user, String message, String notice, org.pircbotx.Channel channel, String template) {
|
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("%NICKPREFIX%", ircBot.getNickPrefix(user, channel))
|
||||||
.replace("%MESSAGE%", message)
|
.replace("%MESSAGE%", message)
|
||||||
.replace("%NOTICE%", notice)
|
.replace("%NOTICE%", notice)
|
||||||
|
@ -66,6 +66,13 @@ part-invalid-channels: false
|
|||||||
part-invalid-channels-message: 'I should not be here! Bye!'
|
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 in server ticks (20 ticks = 1 second)
|
||||||
channel-auto-join-delay: 20
|
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 - 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