Merge pull request #1041 from GLolol/admin/configurable-partmsg

Admin/Owner: substitute $version in quit and part messages (also make part messages configurable)
This commit is contained in:
Valentin Lorentz 2015-02-27 13:15:25 +01:00
commit 9076194009
6 changed files with 23 additions and 9 deletions

View File

@ -43,8 +43,12 @@ def configure(advanced):
Admin = conf.registerPlugin('Admin')
# This is where your configuration variables (if any) should go. For example:
# conf.registerGlobalValue(Admin, 'someConfigVariableName',
# registry.Boolean(False, """Help for someConfigVariableName."""))
conf.registerChannelValue(Admin, 'partMsg',
registry.String('$version', _("""Determines what part message should be
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
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:

View File

@ -238,7 +238,9 @@ class Admin(callbacks.Plugin):
Tells the bot to part the list of channels you give it. <channel> is
only necessary if you want the bot to part a channel other than the
current channel. If <reason> is specified, use it as the part
message.
message. Otherwise, the default part message specified in
supybot.plugins.Admin.partMsg will be used. No part message will be
used if no default is configured.
"""
if channel is None:
if irc.isChannel(msg.args[0]):
@ -252,7 +254,9 @@ class Admin(callbacks.Plugin):
pass
if channel not in irc.state.channels:
irc.error(_('I\'m not in %s.') % channel, Raise=True)
irc.queueMsg(ircmsgs.part(channel, reason or msg.nick))
reason = (reason or self.registryValue("partMsg", channel))
reason = ircutils.standardSubstitute(irc, msg, reason)
irc.queueMsg(ircmsgs.part(channel, reason))
if msg.nick in irc.state.channels[channel].users:
irc.noReply()
else:

View File

@ -46,10 +46,11 @@ conf.registerGlobalValue(Owner, 'public',
registry.Boolean(True, """Determines whether this plugin is publicly
visible."""))
conf.registerGlobalValue(Owner, 'quitMsg',
registry.String('', """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
this value is empty, the nick of the person giving the quit command will be
used."""))
used. The standard substitutions ($version, $nick, etc.) are all handled
appropriately."""))
conf.registerGroup(conf.supybot.commands, 'renames', orderAlphabetically=True)

View File

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

View File

@ -69,6 +69,7 @@ import supybot.i18n as i18n
import supybot.utils as utils
import supybot.registry as registry
import supybot.questions as questions
import supybot.ircutils as ircutils
from supybot.version import version
@ -104,6 +105,7 @@ def main():
for irc in world.ircs:
quitmsg = conf.supybot.plugins.Owner.quitMsg() or \
'Ctrl-C at console.'
quitmsg = ircutils.standardSubstitute(irc, None, quitmsg)
irc.queueMsg(ircmsgs.quit(quitmsg))
irc.die()
except SystemExit as e:

View File

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