Skip to content

Commit 5a49c24

Browse files
committed
Better support of irc NOTICE
-Notices sent to irc channels can be relayed to irc -Individual minecraft events can be shown as notices by using attributes
1 parent 5a5530a commit 5a49c24

File tree

4 files changed

+53
-5
lines changed

4 files changed

+53
-5
lines changed

Diff for: config.yml

+8
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ settings:
108108
quit: '[%srcChannel%] * Quits: %sender% (%message%)'
109109
kick: '[%srcChannel%] * %sender% was kicked by %moderator% (%message%)'
110110
nick: '[%srcChannel%] * %sender% is now known as %message%'
111+
notice: '[%srcChannel%] [NOTICE %sender%] %message%'
111112
generic: '%message%'
112113
mode: '[%srcChannel%] * %moderator% sets mode %message%'
113114
from-plain:
@@ -138,6 +139,7 @@ settings:
138139
# quit: '%grey%[%srcChannel%]%blue% * Quits: %sender%'
139140
# kick: '%grey%[%srcChannel%]%darkgreen% * %sender% was kicked by %ircModPrefix%%moderator%'
140141
# nick: '%grey%[%srcChannel%]%darkgreen% * %sender% is now known as %message%'
142+
# notice: '%grey%[%srcChannel%]%foreground% [%purple%NOTICE%foreground% %ircPrefix%%sender%] %message%'
141143
# generic: '%grey%%message%'
142144
# mode: '%grey%[%srcChannel%]%darkgreen% * %moderator% sets mode %message%'
143145
#from-plain:
@@ -280,13 +282,19 @@ default-attributes:
280282
generic: true
281283
death: true
282284
mode: false
285+
notice: false
283286

284287
#Admin commands and /admins! can only be sent through a path where admin is set to true
285288
admin: false
286289

287290
#True: Colors will be converted. False: Colors will be stripped.
288291
colors: true
289292

293+
# List of event types that should be sent as NOTICE on irc
294+
notices:
295+
admin: true
296+
private: true
297+
290298

291299
# ******************* COLOR CONVERSION MAP *******************
292300
# Here you can assign 3-tuples with names, IRC colors and Minecraft colors.

Diff for: src/com/ensifera/animosity/craftirc/CraftIRC.java

+7-1
Original file line numberDiff line numberDiff line change
@@ -197,9 +197,11 @@ public void onEnable() {
197197
//Ugly but there is no better way with this non-bukkit config
198198
this.configuration.getString("settings.formatting.from-game.players-list", "Online (%playerCount%/%maxPlayers%): %message%");
199199
this.configuration.getString("settings.formatting.from-game.players-nobody", "Nobody is minecrafting right now.");
200+
this.configuration.getBoolean("default-attributes.notices.admin", true);
201+
this.configuration.getBoolean("default-attributes.notices.private", true);
200202

201203

202-
if (this.configuration.getNode("default-attributes").getBoolean("disable", false)) {
204+
if (this.configuration.getBoolean("default-attributes.disable", false)) {
203205
this.logDerp("All communication paths disabled because the 'disable' attribute was found. Check the config.");
204206
} else {
205207
this.log("Enabled.");
@@ -789,6 +791,10 @@ boolean delivery(RelayedMessage msg, List<EndPoint> knownDestinations, String us
789791
continue;
790792
}
791793
msg.setField("target", targetTag);
794+
795+
//Whether the event should be sent as a NOTICE on irc endpoints or not (Ignored in others)
796+
msg.setFlag("notice", this.cPathAttribute(sourceTag, targetTag, "notices." + msg.getEvent()));
797+
792798
//Check against path filters
793799
if (this.matchesFilter(msg, this.cPathFilters(sourceTag, targetTag))) {
794800
if (knownDestinations != null) {

Diff for: src/com/ensifera/animosity/craftirc/IRCChannelPoint.java

+15-4
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,21 @@ public Security getSecurity() {
5555
return SecuredEndPoint.Security.UNSECURED;
5656
}
5757

58+
private void send(String target, String message, boolean isNotice) {
59+
if (isNotice) {
60+
this.bot.sendNotice(target, message);
61+
} else {
62+
this.bot.sendMessage(target, message);
63+
}
64+
}
65+
5866
@Override
5967
public void messageIn(RelayedMessage msg) {
6068
String message = msg.getMessage(this);
6169
if (!this.allowColors) {
6270
message = Colors.removeFormattingAndColors(message);
6371
}
72+
boolean isNotice = msg.getFlag("notice");
6473
if (message.length() > maxlen) {
6574
String[] messages;
6675
final StringBuilder builder = new StringBuilder(message.length());
@@ -80,30 +89,32 @@ public void messageIn(RelayedMessage msg) {
8089
}
8190
messages = builder.toString().split("\n");
8291
for (final String messagePart : messages) {
83-
this.bot.sendMessage(this.channel, messagePart);
92+
this.send(this.channel, messagePart, isNotice);
8493
}
8594
} else {
86-
this.bot.sendMessage(this.channel, message);
95+
this.send(this.channel, message, isNotice);
8796
}
8897
}
8998

99+
90100
@Override
91101
public boolean userMessageIn(String username, RelayedMessage msg) {
92102
if (this.bot.getChannelPrefixes().contains(username.substring(0, 1))) {
93103
return false;
94104
}
95-
this.bot.sendNotice(username, msg.getMessage(this));
105+
this.send(username, msg.getMessage(this), msg.getFlag("notice"));
96106
return true;
97107
}
98108

99109
@Override
100110
public boolean adminMessageIn(RelayedMessage msg) {
101111
boolean success = false;
102112
final String message = msg.getMessage(this);
113+
boolean isNotice = msg.getFlag("notice");
103114
for (final String nick : this.listDisplayUsers()) {
104115
if (this.bot.getPlugin().cBotAdminPrefixes(this.bot.getId()).contains(nick.substring(0, 1))) {
105116
success = true;
106-
this.bot.sendNotice(nick.substring(1), message);
117+
this.send(nick.substring(1), message, isNotice);
107118
}
108119
}
109120
return success;

Diff for: src/com/ensifera/animosity/craftirc/Minebot.java

+23
Original file line numberDiff line numberDiff line change
@@ -525,6 +525,29 @@ public void onMessage(String channel, String sender, String login, String hostna
525525
}
526526
}
527527

528+
@Override
529+
protected void onNotice(String sender, String login, String hostname, String target, String notice) {
530+
target = target.toLowerCase();
531+
final RelayedMessage msg = this.plugin.newMsg(this.channels.get(target), null, "notice");
532+
if (msg == null) {
533+
return;
534+
}
535+
if (this.plugin.cUseMapAsWhitelist(this.botId) && !this.plugin.cNicknameIsInIrcMap(this.botId, sender)) {
536+
return;
537+
}
538+
msg.setField("sender", this.plugin.cIrcDisplayName(this.botId, sender));
539+
msg.setField("realSender", sender);
540+
msg.setField("srcChannel", target);
541+
msg.setField("message", notice);
542+
msg.setField("ircPrefix", this.getHighestUserPrefix(this.getUser(sender, target)));
543+
msg.setField("username", login);
544+
msg.setField("hostname", hostname);
545+
msg.doNotColor("message");
546+
msg.doNotColor("username");
547+
msg.doNotColor("hostname");
548+
msg.post();
549+
}
550+
528551
@Override
529552
public void onAction(String sender, String login, String hostname, String target, String action) {
530553
target = target.toLowerCase();

0 commit comments

Comments
 (0)