diff --git a/plugins/SedRegex/config.py b/plugins/SedRegex/config.py index 42b53c978..0d06e5150 100644 --- a/plugins/SedRegex/config.py +++ b/plugins/SedRegex/config.py @@ -57,6 +57,17 @@ conf.registerChannelValue(SedRegex, 'enable', conf.registerChannelValue(SedRegex, 'ignoreRegex', registry.Boolean(True, _("""Should Perl/sed regex replacing ignore messages which look like valid regex?"""))) +conf.registerChannelValue(SedRegex, 'format', + registry.String(_('$nick meant to say: $replacement'), _("""Sets the format + string for a message edited by the original + author. Required fields: $nick (nick of the + author), $replacement (edited message)"""))) +conf.registerChannelValue(SedRegex.format, 'other', + registry.String(_('$otherNick thinks $nick meant to say: $replacement'), _(""" + Sets the format string for a message edited by + another author. Required fields: $nick (nick + of the original author), $otherNick (nick of + the editor), $replacement (edited message)"""))) conf.registerGlobalValue(SedRegex, 'processTimeout', registry.PositiveFloat(0.5, _("""Sets the timeout when processing a single regexp. The default should be adequate unless diff --git a/plugins/SedRegex/plugin.py b/plugins/SedRegex/plugin.py index 79062f908..a34e6a413 100644 --- a/plugins/SedRegex/plugin.py +++ b/plugins/SedRegex/plugin.py @@ -222,10 +222,6 @@ class SedRegex(callbacks.PluginRegexp): if self.registryValue('ignoreRegex', msg.channel, irc.network) and m.tagged(TAG_IS_REGEX): self.log.debug("Skipping message %s because it is tagged as isRegex", m.args[1]) continue - if m.nick == msg.nick: - messageprefix = msg.nick - else: - messageprefix = '%s thinks %s' % (msg.nick, m.nick) try: replace_result = pattern.search(text) @@ -239,8 +235,15 @@ class SedRegex(callbacks.PluginRegexp): subst = axe_spaces(subst) - return _("%s meant to say: %s") % \ - (messageprefix, subst) + if m.nick == msg.nick: + fmt = self.registryValue('format', msg.channel, irc.network) + env = {'replacement': subst} + else: + fmt = self.registryValue('format.other', msg.channel, irc.network) + env = {'otherNick': msg.nick, 'replacement': subst} + + return ircutils.standardSubstitute(irc, m, fmt, env) + except Exception as e: self.log.warning(_("SedRegex error: %s"), e, exc_info=True) raise diff --git a/plugins/SedRegex/test.py b/plugins/SedRegex/test.py index aa5134e8d..78c6eb202 100644 --- a/plugins/SedRegex/test.py +++ b/plugins/SedRegex/test.py @@ -279,6 +279,23 @@ class SedRegexTestCase(ChannelPluginTestCase): with conf.supybot.protocols.irc.strictRfc.context(True): self.assertSnarfNoResponse('%s: s/123/321/' % ircutils.nickFromHostmask(frm), frm=self.__class__.other2) + def testFmtString(self): + fmt = "<$nick>: $replacement" + with conf.supybot.plugins.sedregex.format.context(fmt): + self.feedMsg('frog') + self.feedMsg('s/frog/frogged/') + m = self.getMsg(' ') + self.assertIn('<%s>: frogged' % self.nick, str(m)) + + def testFmtStringOtherPerson(self): + fmt = "(edited by $otherNick) <$nick>: $replacement" + with conf.supybot.plugins.sedregex.format.other.context(fmt): + self.feedMsg('frog', frm=self.__class__.other) + self.feedMsg('s/frog/frogged/', frm=self.__class__.other2) + m = self.getMsg(' ') + self.assertIn('(edited by %s) <%s>: frogged' % (ircutils.nickFromHostmask(self.__class__.other2), + ircutils.nickFromHostmask(self.__class__.other)), str(m)) + # TODO: test ignores # vim:set shiftwidth=4 tabstop=4 expandtab textwidth=79: