mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-11-05 02:29:22 +01:00
ChannelLogger: Log away messages
This commit is contained in:
parent
ebaa346619
commit
bc0c5bdeed
@ -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.""")))
|
||||
|
@ -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]
|
||||
|
@ -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 <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:
|
||||
|
Loading…
Reference in New Issue
Block a user