|
14 | 14 | import java.util.logging.Logger;
|
15 | 15 |
|
16 | 16 | import org.pircbotx.PircBotX;
|
| 17 | +import org.pircbotx.exception.DaoException; |
17 | 18 | import org.pircbotx.hooks.ListenerAdapter;
|
18 | 19 | import org.pircbotx.hooks.events.DisconnectEvent;
|
19 | 20 | import org.pircbotx.hooks.events.InviteEvent;
|
@@ -92,6 +93,23 @@ public void onMessage(MessageEvent event) {
|
92 | 93 | public void onPrivateMessage(PrivateMessageEvent event) {
|
93 | 94 | String sender = event.getUser().getNick();
|
94 | 95 | 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 | + } |
95 | 113 | for (MessageListener l : this.msgListeners) {
|
96 | 114 | if (this.nick.equals(l.target)) {
|
97 | 115 | if (l.sender.equals(CHAT_ESTABLISHER) || sender.equals(l.sender)) {
|
|
0 commit comments