Admin/Owner: Use standard substitution for part/quit messages

This commit is contained in:
James Lu 2015-02-05 20:26:14 -08:00
parent a46f12beeb
commit b243c83e41
5 changed files with 12 additions and 9 deletions

View File

@ -45,9 +45,10 @@ def configure(advanced):
Admin = conf.registerPlugin('Admin') Admin = conf.registerPlugin('Admin')
conf.registerChannelValue(Admin, 'partMsg', conf.registerChannelValue(Admin, 'partMsg',
registry.String('%version%', _("""Determines what part message should be registry.String('$version', _("""Determines what part message should be
used by default. If the part command is called without a part message, used by default. If the part command is called without a part message,
this will be used. If this value is empty, then no part message will this will be used. If this value is empty, then no part message will
be used (they are optional in the IRC protocol)."""))) be used (they are optional in the IRC protocol). The standard
substitutions ($version, $nick, etc.) are all handled appropriately.""")))
# vim:set shiftwidth=4 softtabstop=4 expandtab textwidth=79: # vim:set shiftwidth=4 softtabstop=4 expandtab textwidth=79:

View File

@ -255,7 +255,7 @@ class Admin(callbacks.Plugin):
if channel not in irc.state.channels: if channel not in irc.state.channels:
irc.error(_('I\'m not in %s.') % channel, Raise=True) irc.error(_('I\'m not in %s.') % channel, Raise=True)
reason = (reason or self.registryValue("partMsg", channel)) reason = (reason or self.registryValue("partMsg", channel))
reason = reason.replace("%version%", "Supybot %s" % conf.version) reason = ircutils.standardSubstitute(irc, msg, reason)
irc.queueMsg(ircmsgs.part(channel, reason)) irc.queueMsg(ircmsgs.part(channel, reason))
if msg.nick in irc.state.channels[channel].users: if msg.nick in irc.state.channels[channel].users:
irc.noReply() irc.noReply()

View File

@ -46,10 +46,11 @@ conf.registerGlobalValue(Owner, 'public',
registry.Boolean(True, """Determines whether this plugin is publicly registry.Boolean(True, """Determines whether this plugin is publicly
visible.""")) visible."""))
conf.registerGlobalValue(Owner, 'quitMsg', conf.registerGlobalValue(Owner, 'quitMsg',
registry.String('%version%', """Determines what quit message will be used by default. registry.String('$version', """Determines what quit message will be used by default.
If the quit command is called without a quit message, this will be used. If If the quit command is called without a quit message, this will be used. If
this value is empty, the nick of the person giving the quit command will be this value is empty, the nick of the person giving the quit command will be
used. %version% is automatically expanded to the bot's current version.""")) used. The standard substitutions ($version, $nick, etc.) are all handled
appropriately."""))
conf.registerGroup(conf.supybot.commands, 'renames', orderAlphabetically=True) conf.registerGroup(conf.supybot.commands, 'renames', orderAlphabetically=True)

View File

@ -344,11 +344,11 @@ class Owner(callbacks.Plugin):
Exits the bot with the QUIT message <text>. If <text> is not given, Exits the bot with the QUIT message <text>. If <text> is not given,
the default quit message (supybot.plugins.Owner.quitMsg) will be used. the default quit message (supybot.plugins.Owner.quitMsg) will be used.
If there is no default quitMsg set, your nick will be used. %version% If there is no default quitMsg set, your nick will be used. The standard
is automatically expanded to the bot's current version. substitutions ($version, $nick, etc.) are all handled appropriately.
""" """
text = text or self.registryValue('quitMsg') or msg.nick text = text or self.registryValue('quitMsg') or msg.nick
text = text.replace("%version%", "Supybot %s" % conf.version) text = ircutils.standardSubstitute(irc, msg, text)
irc.noReply() irc.noReply()
m = ircmsgs.quit(text) m = ircmsgs.quit(text)
world.upkeep() world.upkeep()

View File

@ -49,7 +49,7 @@ from cStringIO import StringIO as sio
from . import utils from . import utils
from . import minisix from . import minisix
from .version import version
def debug(s, *args): def debug(s, *args):
"""Prints a debug string. Most likely replaced by our logging debug.""" """Prints a debug string. Most likely replaced by our logging debug."""
@ -713,6 +713,7 @@ def standardSubstitute(irc, msg, text, env=None):
'm': localtime[4], 'min': localtime[4], 'minute': localtime[4], 'm': localtime[4], 'min': localtime[4], 'minute': localtime[4],
's': localtime[5], 'sec': localtime[5], 'second': localtime[5], 's': localtime[5], 'sec': localtime[5], 'second': localtime[5],
'tz': time.strftime('%Z', localtime), 'tz': time.strftime('%Z', localtime),
'version': 'Supybot %s' % version,
}) })
if msg.reply_env: if msg.reply_env:
vars.update(msg.reply_env) vars.update(msg.reply_env)