Skip to content

Commit

Permalink
Merge pull request #216 from jimklimov/JENKINS-72587
Browse files Browse the repository at this point in the history
PircListener.java: when we react onPrivateMessage()…
  • Loading branch information
jimklimov authored Jan 22, 2024
2 parents 58f265e + 032996d commit 40cc686
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/main/java/hudson/plugins/ircbot/v2/PircListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import java.util.logging.Logger;

import org.pircbotx.PircBotX;
import org.pircbotx.exception.DaoException;
import org.pircbotx.hooks.ListenerAdapter;
import org.pircbotx.hooks.events.DisconnectEvent;
import org.pircbotx.hooks.events.InviteEvent;
Expand Down Expand Up @@ -92,6 +93,23 @@ public void onMessage(MessageEvent event) {
public void onPrivateMessage(PrivateMessageEvent event) {
String sender = event.getUser().getNick();
String message = event.getMessage();
if (!sender.equals(CHAT_ESTABLISHER)) {
// Ensure that later the ...getChannel(sender) in IRCConnection.send()
// would not throw exceptions about unknown channel, but would actually
// send a response to this sender. The "bot" here is a PircBotX layer,
// not our instant-messaging-plugin Bot class instance. We get() the
// UserChannelDao a few times here to avoid the hassle of spelling out
// a parameterized class temporary instance.
synchronized (PircListener.class) {
try {
if (null == event.getBot().getUserChannelDao().getChannel(sender)) {
event.getBot().getUserChannelDao().createChannel(sender);
}
} catch (DaoException ignored) {
event.getBot().getUserChannelDao().createChannel(sender);
}
}

Check warning on line 111 in src/main/java/hudson/plugins/ircbot/v2/PircListener.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered lines

Lines 96-111 are not covered by tests
}
for (MessageListener l : this.msgListeners) {
if (this.nick.equals(l.target)) {
if (l.sender.equals(CHAT_ESTABLISHER) || sender.equals(l.sender)) {
Expand Down

0 comments on commit 40cc686

Please sign in to comment.