Skip to content

Commit 085e7ad

Browse files
committed
Add IRCv3 tags to other events
We're already parsing these tags, but we were only putting them into MessageEvent and PrivateMessageEvent. This just updates all the other events to also store the tags. I'm using this in combination with the `account-tag` capability to associate user accounts to each of these events without needing to do a whois. This is so much more efficient.
1 parent 12f5639 commit 085e7ad

9 files changed

+76
-20
lines changed

src/main/java/org/pircbotx/InputParser.java

+12-12
Original file line numberDiff line numberDiff line change
@@ -613,7 +613,7 @@ else if (request.startsWith("DCC ")) {
613613
sourceUser = createUserIfNull(sourceUser, source);
614614

615615
bot.getUserChannelDao().addUserToChannel(sourceUser, channel);
616-
configuration.getListenerManager().onEvent(new JoinEvent(bot, channel, source, sourceUser));
616+
configuration.getListenerManager().onEvent(new JoinEvent(bot, channel, source, sourceUser, tags));
617617
} else if (command.equals("PART")) {
618618
// Someone is parting from a channel.
619619
UserChannelDaoSnapshot daoSnapshot;
@@ -635,7 +635,7 @@ else if (request.startsWith("DCC ")) {
635635
else
636636
//Just remove the user from memory
637637
bot.getUserChannelDao().removeUserFromChannel(sourceUser, channel);
638-
configuration.getListenerManager().onEvent(new PartEvent(bot, daoSnapshot, channelSnapshot, channel.getName(), source, sourceSnapshot, message));
638+
configuration.getListenerManager().onEvent(new PartEvent(bot, daoSnapshot, channelSnapshot, channel.getName(), source, sourceSnapshot, message, tags));
639639
} else if (command.equals("NICK")) {
640640
// Somebody is changing their nick.
641641
sourceUser = createUserIfNull(sourceUser, source);
@@ -644,7 +644,7 @@ else if (request.startsWith("DCC ")) {
644644
if (source.getNick().equals(bot.getNick()))
645645
// Update our nick if it was us that changed nick.
646646
bot.setNick(newNick);
647-
configuration.getListenerManager().onEvent(new NickChangeEvent(bot, source.getNick(), newNick, source, sourceUser));
647+
configuration.getListenerManager().onEvent(new NickChangeEvent(bot, source.getNick(), newNick, source, sourceUser, tags));
648648
} else if (command.equals("NOTICE")) {
649649
// Someone is sending a notice.
650650
configuration.getListenerManager().onEvent(new NoticeEvent(bot, source, sourceUser, channel, target, message, tags));
@@ -664,7 +664,7 @@ else if (request.startsWith("DCC ")) {
664664
if (!source.getNick().equals(bot.getNick()))
665665
//Someone else
666666
bot.getUserChannelDao().removeUser(sourceUser);
667-
configuration.getListenerManager().onEvent(new QuitEvent(bot, daoSnapshot, source, sourceSnapshot, reason));
667+
configuration.getListenerManager().onEvent(new QuitEvent(bot, daoSnapshot, source, sourceSnapshot, reason, tags));
668668
} else if (command.equals("KICK")) {
669669
// Somebody has been kicked from a channel.
670670
UserHostmask recipientHostmask = bot.getConfiguration().getBotFactory().createUserHostmask(bot, message);
@@ -676,7 +676,7 @@ else if (request.startsWith("DCC ")) {
676676
else
677677
//Someone else
678678
bot.getUserChannelDao().removeUserFromChannel(recipient, channel);
679-
configuration.getListenerManager().onEvent(new KickEvent(bot, channel, source, sourceUser, recipientHostmask, recipient, parsedLine.get(2)));
679+
configuration.getListenerManager().onEvent(new KickEvent(bot, channel, source, sourceUser, recipientHostmask, recipient, parsedLine.get(2), tags));
680680
} else if (command.equals("MODE")) {
681681
// Somebody is changing the mode on a channel or user (Use long form since mode isn't after a : )
682682
String mode = line.substring(line.indexOf(target, 2) + target.length() + 1);
@@ -687,7 +687,7 @@ else if (request.startsWith("DCC ")) {
687687
//User sourceModeUser = sourceUser;
688688
//if (sourceModeUser == null)
689689
// sourceModeUser = bot.getUserChannelDao().getUser(source);
690-
processMode(source, sourceUser, target, mode);
690+
processMode(source, sourceUser, target, mode, tags);
691691
} else if (command.equals("TOPIC")) {
692692
// Someone is changing the topic.
693693
long currentTime = System.currentTimeMillis();
@@ -696,7 +696,7 @@ else if (request.startsWith("DCC ")) {
696696
channel.setTopicSetter(source);
697697
channel.setTopicTimestamp(currentTime);
698698

699-
configuration.getListenerManager().onEvent(new TopicEvent(bot, channel, oldTopic, message, source, currentTime, true));
699+
configuration.getListenerManager().onEvent(new TopicEvent(bot, channel, oldTopic, message, source, currentTime, true, tags));
700700
} else if (command.equals("INVITE")) {
701701
// Somebody is inviting somebody else into a channel.
702702
configuration.getListenerManager().onEvent(new InviteEvent(bot, source, sourceUser, message));
@@ -794,7 +794,7 @@ public void processServerResponse(int code, String rawResponse, List<String> par
794794
channel.setTopicTimestamp(date * 1000);
795795
channel.setTopicSetter(setBy);
796796

797-
configuration.getListenerManager().onEvent(new TopicEvent(bot, channel, null, channel.getTopic(), setBy, date, false));
797+
configuration.getListenerManager().onEvent(new TopicEvent(bot, channel, null, channel.getTopic(), setBy, date, false, ImmutableMap.of()));
798798
} else if (code == RPL_WHOREPLY) {
799799
//EXAMPLE: 352 PircBotX #aChannel ~someName 74.56.56.56.my.Hostmask wolfe.freenode.net someNick H :0 Full Name
800800
//Part of a WHO reply on information on individual users
@@ -872,7 +872,7 @@ public void processServerResponse(int code, String rawResponse, List<String> par
872872
String mode = StringUtils.join(modeParsed, ' ');
873873

874874
channel.setMode(mode, modeParsed);
875-
configuration.getListenerManager().onEvent(new ModeEvent(bot, channel, null, null, mode, modeParsed));
875+
configuration.getListenerManager().onEvent(new ModeEvent(bot, channel, null, null, mode, modeParsed, ImmutableMap.of()));
876876
} else if (code == 329) {
877877
//EXAMPLE: 329 lordquackstar #botters 1199140245
878878
//Tells when channel was created. From /JOIN
@@ -1089,7 +1089,7 @@ else if (code == RPL_MOTD) {
10891089
* @param target The channel or nick that the mode operation applies to.
10901090
* @param mode The mode that has been set.
10911091
*/
1092-
public void processMode(UserHostmask userHostmask, User user, String target, String mode) {
1092+
public void processMode(UserHostmask userHostmask, User user, String target, String mode, ImmutableMap<String, String> tags) {
10931093
if (configuration.getChannelPrefixes().indexOf(target.charAt(0)) >= 0) {
10941094
// The mode of a channel is being changed.
10951095
Channel channel = bot.getUserChannelDao().getChannel(target);
@@ -1112,12 +1112,12 @@ else if (curModeChar == '-')
11121112
modeHandler.handleMode(bot, channel, userHostmask, user, params, adding, true);
11131113
}
11141114
}
1115-
configuration.getListenerManager().onEvent(new ModeEvent(bot, channel, userHostmask, user, mode, modeParsed));
1115+
configuration.getListenerManager().onEvent(new ModeEvent(bot, channel, userHostmask, user, mode, modeParsed, tags));
11161116
} else {
11171117
// The mode of a user is being changed.
11181118
UserHostmask targetHostmask = bot.getConfiguration().getBotFactory().createUserHostmask(bot, target);
11191119
User targetUser = bot.getUserChannelDao().getUser(target);
1120-
configuration.getListenerManager().onEvent(new UserModeEvent(bot, userHostmask, user, targetHostmask, targetUser, mode));
1120+
configuration.getListenerManager().onEvent(new UserModeEvent(bot, userHostmask, user, targetHostmask, targetUser, mode, tags));
11211121
}
11221122
}
11231123

src/main/java/org/pircbotx/hooks/events/JoinEvent.java

+7-1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
*/
1818
package org.pircbotx.hooks.events;
1919

20+
import com.google.common.collect.ImmutableMap;
2021
import javax.annotation.Nullable;
2122
import org.pircbotx.Channel;
2223
import org.pircbotx.User;
@@ -57,12 +58,17 @@ public class JoinEvent extends Event implements GenericChannelUserEvent {
5758
@Getter(onMethod = @__({
5859
@Override}))
5960
protected final UserHostmask userHostmask;
61+
/**
62+
* The IrcV3 tags
63+
*/
64+
protected final ImmutableMap<String, String> tags;
6065

61-
public JoinEvent(PircBotX bot, @NonNull Channel channel, @NonNull UserHostmask userHostmask, User user) {
66+
public JoinEvent(PircBotX bot, @NonNull Channel channel, @NonNull UserHostmask userHostmask, User user, ImmutableMap<String, String> tags) {
6267
super(bot);
6368
this.channel = channel;
6469
this.user = user;
6570
this.userHostmask = userHostmask;
71+
this.tags = tags;
6672
}
6773

6874
/**

src/main/java/org/pircbotx/hooks/events/KickEvent.java

+8-1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
*/
1818
package org.pircbotx.hooks.events;
1919

20+
import com.google.common.collect.ImmutableMap;
2021
import javax.annotation.Nullable;
2122
import org.pircbotx.Channel;
2223
import org.pircbotx.User;
@@ -74,16 +75,22 @@ public class KickEvent extends Event implements GenericChannelModeRecipientEvent
7475
* The reason given by the user who performed the kick.
7576
*/
7677
protected final String reason;
78+
/**
79+
* The IrcV3 tags
80+
*/
81+
protected final ImmutableMap<String, String> tags;
7782

7883
public KickEvent(PircBotX bot, @NonNull Channel channel, @NonNull UserHostmask userHostmask, User user,
79-
@NonNull UserHostmask recipientHostmask, User recipient, @NonNull String reason) {
84+
@NonNull UserHostmask recipientHostmask, User recipient, @NonNull String reason,
85+
ImmutableMap<String, String> tags) {
8086
super(bot);
8187
this.channel = channel;
8288
this.userHostmask = userHostmask;
8389
this.user = user;
8490
this.recipientHostmask = recipientHostmask;
8591
this.recipient = recipient;
8692
this.reason = reason;
93+
this.tags = tags;
8794
}
8895

8996
/**

src/main/java/org/pircbotx/hooks/events/ModeEvent.java

+8-1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
*/
1818
package org.pircbotx.hooks.events;
1919

20+
import com.google.common.collect.ImmutableMap;
2021
import com.google.common.collect.ImmutableList;
2122
import javax.annotation.Nullable;
2223
import org.pircbotx.Channel;
@@ -69,15 +70,21 @@ public class ModeEvent extends Event implements GenericChannelUserEvent {
6970
*/
7071
protected final String mode;
7172
protected final ImmutableList<String> modeParsed;
73+
/**
74+
* The IrcV3 tags
75+
*/
76+
protected final ImmutableMap<String, String> tags;
7277

7378
public ModeEvent(PircBotX bot, @NonNull Channel channel, UserHostmask userHostmask,
74-
User user, @NonNull String mode, @NonNull ImmutableList<String> modeParsed) {
79+
User user, @NonNull String mode, @NonNull ImmutableList<String> modeParsed,
80+
ImmutableMap<String, String> tags) {
7581
super(bot);
7682
this.channel = channel;
7783
this.userHostmask = userHostmask;
7884
this.user = user;
7985
this.mode = mode;
8086
this.modeParsed = modeParsed;
87+
this.tags = tags;
8188
}
8289

8390
/**

src/main/java/org/pircbotx/hooks/events/NickChangeEvent.java

+7-1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
*/
1818
package org.pircbotx.hooks.events;
1919

20+
import com.google.common.collect.ImmutableMap;
2021
import javax.annotation.Nullable;
2122
import org.pircbotx.User;
2223
import lombok.Data;
@@ -58,14 +59,19 @@ public class NickChangeEvent extends Event implements GenericUserEvent {
5859
@Override,
5960
@Nullable}))
6061
protected final User user;
62+
/**
63+
* The IrcV3 tags
64+
*/
65+
protected final ImmutableMap<String, String> tags;
6166

6267
public NickChangeEvent(PircBotX bot, @NonNull String oldNick, @NonNull String newNick,
63-
@NonNull UserHostmask userHostmask, User user) {
68+
@NonNull UserHostmask userHostmask, User user, ImmutableMap<String, String> tags) {
6469
super(bot);
6570
this.oldNick = oldNick;
6671
this.newNick = newNick;
6772
this.userHostmask = userHostmask;
6873
this.user = user;
74+
this.tags = tags;
6975
}
7076

7177
/**

src/main/java/org/pircbotx/hooks/events/PartEvent.java

+8-1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
*/
1818
package org.pircbotx.hooks.events;
1919

20+
import com.google.common.collect.ImmutableMap;
2021
import org.pircbotx.PircBotX;
2122
import org.pircbotx.UserHostmask;
2223
import org.pircbotx.hooks.Event;
@@ -71,15 +72,21 @@ public class PartEvent extends Event implements GenericChannelUserEvent, Generic
7172
*/
7273
protected final String reason;
7374

75+
/**
76+
* The IrcV3 tags
77+
*/
78+
protected final ImmutableMap<String, String> tags;
79+
7480
public PartEvent(PircBotX bot, UserChannelDaoSnapshot daoSnapshot, ChannelSnapshot channel, @NonNull String channelName,
75-
@NonNull UserHostmask userHostmask, UserSnapshot user, @NonNull String reason) {
81+
@NonNull UserHostmask userHostmask, UserSnapshot user, @NonNull String reason, ImmutableMap<String, String> tags) {
7682
super(bot);
7783
this.userChannelDaoSnapshot = daoSnapshot;
7884
this.channel = channel;
7985
this.channelName = channelName;
8086
this.userHostmask = userHostmask;
8187
this.user = user;
8288
this.reason = reason;
89+
this.tags = tags;
8390
}
8491

8592
/**

src/main/java/org/pircbotx/hooks/events/QuitEvent.java

+9-1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
*/
1818
package org.pircbotx.hooks.events;
1919

20+
import com.google.common.collect.ImmutableMap;
21+
2022
import org.pircbotx.PircBotX;
2123
import org.pircbotx.UserHostmask;
2224
import org.pircbotx.hooks.Event;
@@ -56,14 +58,20 @@ public class QuitEvent extends Event implements GenericUserEvent, GenericSnapsho
5658
* The reason the user quit from the server.
5759
*/
5860
protected final String reason;
61+
/**
62+
* The IrcV3 tags
63+
*/
64+
protected final ImmutableMap<String, String> tags;
5965

6066
public QuitEvent(PircBotX bot, UserChannelDaoSnapshot userChannelDaoSnapshot,
61-
@NonNull UserHostmask userHostmask, UserSnapshot user, @NonNull String reason) {
67+
@NonNull UserHostmask userHostmask, UserSnapshot user, @NonNull String reason,
68+
ImmutableMap<String, String> tags) {
6269
super(bot);
6370
this.userChannelDaoSnapshot = userChannelDaoSnapshot;
6471
this.userHostmask = userHostmask;
6572
this.user = user;
6673
this.reason = reason;
74+
this.tags = tags;
6775
}
6876

6977
/**

src/main/java/org/pircbotx/hooks/events/TopicEvent.java

+9-1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
*/
1818
package org.pircbotx.hooks.events;
1919

20+
import com.google.common.collect.ImmutableMap;
21+
2022
import org.pircbotx.Channel;
2123
import org.pircbotx.PircBotX;
2224
import org.pircbotx.UserHostmask;
@@ -64,15 +66,21 @@ public class TopicEvent extends Event implements GenericChannelEvent {
6466
* When the topic was set (milliseconds since the epoch).
6567
*/
6668
protected final long date;
69+
/**
70+
* The IrcV3 tags
71+
*/
72+
protected final ImmutableMap<String, String> tags;
6773

68-
public TopicEvent(PircBotX bot, @NonNull Channel channel, String oldTopic, @NonNull String topic, @NonNull UserHostmask user, long date, boolean changed) {
74+
public TopicEvent(PircBotX bot, @NonNull Channel channel, String oldTopic, @NonNull String topic, @NonNull UserHostmask user, long date, boolean changed,
75+
ImmutableMap<String, String> tags) {
6976
super(bot);
7077
this.channel = channel;
7178
this.oldTopic = oldTopic;
7279
this.topic = topic;
7380
this.user = user;
7481
this.changed = changed;
7582
this.date = date;
83+
this.tags = tags;
7684
}
7785

7886
/**

src/main/java/org/pircbotx/hooks/events/UserModeEvent.java

+8-1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
*/
1818
package org.pircbotx.hooks.events;
1919

20+
import com.google.common.collect.ImmutableMap;
2021
import javax.annotation.Nullable;
2122
import org.pircbotx.User;
2223
import lombok.Data;
@@ -64,15 +65,21 @@ public class UserModeEvent extends Event implements GenericUserModeEvent {
6465
* The mode that has been set.
6566
*/
6667
protected final String mode;
68+
/**
69+
* The IrcV3 tags
70+
*/
71+
protected final ImmutableMap<String, String> tags;
6772

6873
public UserModeEvent(PircBotX bot, @NonNull UserHostmask userHostmask, User user,
69-
@NonNull UserHostmask recipientHostmask, User recipient, @NonNull String mode) {
74+
@NonNull UserHostmask recipientHostmask, User recipient, @NonNull String mode,
75+
ImmutableMap<String, String> tags) {
7076
super(bot);
7177
this.userHostmask = user;
7278
this.user = user;
7379
this.recipientHostmask = recipientHostmask;
7480
this.recipient = recipient;
7581
this.mode = mode;
82+
this.tags = tags;
7683
}
7784

7885
/**

0 commit comments

Comments
 (0)