mirror of
https://github.com/Mikaela/Limnoria.git
synced 2025-01-25 19:44:13 +01:00
SedRegex: Implement changing of sed response per channel (#1556)
Fixes #1433 Co-authored-by: Val Lorentz <progval+github@progval.net> Co-authored-by: James Lu <hello@jlu5.com>
This commit is contained in:
parent
5ab7c8a749
commit
91accc0458
@ -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
|
||||
|
@ -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
|
||||
|
@ -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:
|
||||
|
Loading…
Reference in New Issue
Block a user