Skip to content

Commit 032996d

Browse files
committed
PircListener.java: when we react onPrivateMessage(), make sure the sender is assigned a channel in the UserChannelDao cache [JENKINS-72587]
Signed-off-by: Jim Klimov <jimklimov+jenkinsci@gmail.com>
1 parent 58f265e commit 032996d

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

src/main/java/hudson/plugins/ircbot/v2/PircListener.java

+18
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import java.util.logging.Logger;
1515

1616
import org.pircbotx.PircBotX;
17+
import org.pircbotx.exception.DaoException;
1718
import org.pircbotx.hooks.ListenerAdapter;
1819
import org.pircbotx.hooks.events.DisconnectEvent;
1920
import org.pircbotx.hooks.events.InviteEvent;
@@ -92,6 +93,23 @@ public void onMessage(MessageEvent event) {
9293
public void onPrivateMessage(PrivateMessageEvent event) {
9394
String sender = event.getUser().getNick();
9495
String message = event.getMessage();
96+
if (!sender.equals(CHAT_ESTABLISHER)) {
97+
// Ensure that later the ...getChannel(sender) in IRCConnection.send()
98+
// would not throw exceptions about unknown channel, but would actually
99+
// send a response to this sender. The "bot" here is a PircBotX layer,
100+
// not our instant-messaging-plugin Bot class instance. We get() the
101+
// UserChannelDao a few times here to avoid the hassle of spelling out
102+
// a parameterized class temporary instance.
103+
synchronized (PircListener.class) {
104+
try {
105+
if (null == event.getBot().getUserChannelDao().getChannel(sender)) {
106+
event.getBot().getUserChannelDao().createChannel(sender);
107+
}
108+
} catch (DaoException ignored) {
109+
event.getBot().getUserChannelDao().createChannel(sender);
110+
}
111+
}
112+
}
95113
for (MessageListener l : this.msgListeners) {
96114
if (this.nick.equals(l.target)) {
97115
if (l.sender.equals(CHAT_ESTABLISHER) || sender.equals(l.sender)) {

0 commit comments

Comments
 (0)