diff --git a/plugins/ChannelLogger/config.py b/plugins/ChannelLogger/config.py index ce5f75755..beec1a816 100644 --- a/plugins/ChannelLogger/config.py +++ b/plugins/ChannelLogger/config.py @@ -50,7 +50,11 @@ conf.registerGlobalValue(ChannelLogger, 'flushImmediately', flushed anytime they're written to, rather than being buffered by the operating system."""))) conf.registerChannelValue(ChannelLogger, 'showJoinParts', - registry.Boolean(True, _("""Determines wether joins and parts are logged"""))) + registry.Boolean(True, _("""Determines whether joins and parts are logged"""))) +conf.registerChannelValue(ChannelLogger, 'showAway', + registry.Boolean(True, _("""Determines whether users going away and coming + back should be logged. This is only supported on networks implementing the + 'away-notify' IRCv3 capability."""))) conf.registerChannelValue(ChannelLogger, 'stripFormatting', registry.Boolean(True, _("""Determines whether formatting characters (such as bolding, color, etc.) are removed when writing the logs to disk."""))) diff --git a/plugins/ChannelLogger/plugin.py b/plugins/ChannelLogger/plugin.py index b974a388f..e61c6500e 100644 --- a/plugins/ChannelLogger/plugin.py +++ b/plugins/ChannelLogger/plugin.py @@ -226,6 +226,20 @@ class ChannelLogger(callbacks.Plugin): if irc.isChannel(channel): self.doLog(irc, channel, '-%s- %s\n', msg.nick, text) + def doAway(self, irc, msg): + # https://ircv3.net/specs/extensions/away-notify + if msg.args: + away_message = msg.args[-1] + for channel in msg.tagged('channels'): + if self.registryValue('showAway', channel, irc.network): + self.doLog(irc, channel, + '*** %s is now away: %s\n', msg.nick, away_message) + else: + for channel in msg.tagged('channels'): + if self.registryValue('showAway', channel, irc.network): + self.doLog(irc, channel, + '*** %s is back\n', msg.nick) + def doNick(self, irc, msg): oldNick = msg.nick newNick = msg.args[0] diff --git a/plugins/ChannelLogger/test.py b/plugins/ChannelLogger/test.py index 9e8b378f4..698993149 100644 --- a/plugins/ChannelLogger/test.py +++ b/plugins/ChannelLogger/test.py @@ -180,5 +180,91 @@ class ChannelLoggerTestCase(ChannelPluginTestCase): timestamp_re + '-foo- test message\n' ) + @patch_open + def testLogJoinQuit(self, mock_open): + log_file = io.StringIO() + mock_open.return_value = log_file + + self.irc.feedMsg( + ircmsgs.join('#foo', prefix='foo!bar@baz') + ) + + self.irc.feedMsg( + ircmsgs.quit('bye', prefix='foo!bar@baz') + ) + + self.assertRegex( + log_file.getvalue(), + timestamp_re + r'\*\*\* foo has joined #foo\n' + + timestamp_re + r'\*\*\* foo has quit IRC \(bye\)\n' + ) + + @patch_open + def testNoLogJoinQuit(self, mock_open): + log_file = io.StringIO() + mock_open.return_value = log_file + + with conf.supybot.plugins.ChannelLogger.showJoinParts.context(False): + self.irc.feedMsg( + ircmsgs.join('#foo', prefix='foo!bar@baz') + ) + self.irc.feedMsg( + ircmsgs.quit('bye', prefix='foo!bar@baz') + ) + + self.assertRegex( + log_file.getvalue(), + '^$' + ) + + @patch_open + def testLogAway(self, mock_open): + log_file = io.StringIO() + mock_open.return_value = log_file + + self.irc.feedMsg( + ircmsgs.join('#foo', prefix='foo!bar@baz') + ) + + self.irc.feedMsg( + ircmsgs.IrcMsg(command='AWAY', args=('be right back',), + prefix='foo!bar@baz') + ) + + self.irc.feedMsg( + ircmsgs.IrcMsg(command='AWAY', args=(), prefix='foo!bar@baz') + ) + + self.assertRegex( + log_file.getvalue(), + timestamp_re + r'\*\*\* foo has joined #foo\n' + + timestamp_re + r'\*\*\* foo is now away: be right back\n' + + timestamp_re + r'\*\*\* foo is back\n' + ) + + @patch_open + def testNoLogAway(self, mock_open): + log_file = io.StringIO() + mock_open.return_value = log_file + + self.irc.feedMsg( + ircmsgs.join('#foo', prefix='foo!bar@baz') + ) + + with conf.supybot.plugins.ChannelLogger.showAway.context(False): + self.irc.feedMsg( + ircmsgs.IrcMsg(command='AWAY', args=('be right back',), + prefix='foo!bar@baz') + ) + + self.irc.feedMsg( + ircmsgs.IrcMsg(command='AWAY', args=(), prefix='foo!bar@baz') + ) + + self.assertRegex( + log_file.getvalue(), + timestamp_re + r'\*\*\* foo has joined #foo\n$' + ) + # vim:set shiftwidth=4 softtabstop=4 expandtab textwidth=79: