ChannelLogger: Log away messages

This commit is contained in:
Valentin Lorentz 2021-10-07 21:34:04 +02:00
parent ebaa346619
commit bc0c5bdeed
3 changed files with 105 additions and 1 deletions

View File

@ -50,7 +50,11 @@ conf.registerGlobalValue(ChannelLogger, 'flushImmediately',
flushed anytime they're written to, rather than being buffered by the flushed anytime they're written to, rather than being buffered by the
operating system."""))) operating system.""")))
conf.registerChannelValue(ChannelLogger, 'showJoinParts', 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', conf.registerChannelValue(ChannelLogger, 'stripFormatting',
registry.Boolean(True, _("""Determines whether formatting characters (such registry.Boolean(True, _("""Determines whether formatting characters (such
as bolding, color, etc.) are removed when writing the logs to disk."""))) as bolding, color, etc.) are removed when writing the logs to disk.""")))

View File

@ -226,6 +226,20 @@ class ChannelLogger(callbacks.Plugin):
if irc.isChannel(channel): if irc.isChannel(channel):
self.doLog(irc, channel, '-%s- %s\n', msg.nick, text) 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): def doNick(self, irc, msg):
oldNick = msg.nick oldNick = msg.nick
newNick = msg.args[0] newNick = msg.args[0]

View File

@ -180,5 +180,91 @@ class ChannelLoggerTestCase(ChannelPluginTestCase):
timestamp_re + '-foo- test message\n' 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 <foo!bar@baz> has joined #foo\n' +
timestamp_re + r'\*\*\* foo <foo!bar@baz> 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 <foo!bar@baz> 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 <foo!bar@baz> has joined #foo\n$'
)
# vim:set shiftwidth=4 softtabstop=4 expandtab textwidth=79: # vim:set shiftwidth=4 softtabstop=4 expandtab textwidth=79: