Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 42 additions & 23 deletions sopel/builtins/adminchannel.py
Original file line number Diff line number Diff line change
Expand Up @@ -331,9 +331,8 @@ def topic(bot, trigger):
return
channel = trigger.sender.lower()

mask = None
mask = bot.db.get_channel_value(channel, 'topic_mask')
mask = mask or default_mask(trigger)
mask = bot.db.get_channel_value(
channel, 'topic_mask', default_mask(trigger))
mask = mask.replace('%s', '{}')
narg = len(re.findall('{}', mask))

Expand Down Expand Up @@ -362,28 +361,48 @@ def topic(bot, trigger):
bot.write(('TOPIC', channel + ' :' + topic))


@plugin.require_chanmsg
@plugin.require_privilege(plugin.OP, ERROR_MESSAGE_NO_PRIV)
@plugin.command('tmask')
def set_mask(bot, trigger):
"""Set the topic mask to use for the current channel
@plugin.commands('tmask set', 'tmask get', 'tmask clear', 'tmask')
@plugin.example('.tmask clear', user_help=True)
@plugin.example('.tmask get', user_help=True)
@plugin.example('.tmask set My {} topic mask!', user_help=True)
def topic_mask_management(bot, trigger):
"""Set, get, or clear the current channel's topic mask.

Recognized subcommands are 'set', 'get', and 'clear'. A plain 'tmask'
command with no arguments is equivalent to 'tmask get'.

This mask is used by the 'topic' command. `{}` allows interpolating a chunk
of text within the topic mask template.
"""
command, _, subcommand = trigger.group(1).partition(' ')

Within the topic mask, {} is used to allow substituting in chunks of text.
if not subcommand or subcommand == 'get':
mask = bot.db.get_channel_value(
trigger.sender, 'topic_mask', default_mask(trigger))
bot.reply('Current topic mask: {}'.format(mask))
return

This mask is used when running the 'topic' command.
"""
bot.db.set_channel_value(trigger.sender, 'topic_mask', trigger.group(2))
message = (
'Topic mask set. '
'Use `{prefix}topic <args>` to set topic '
'and `{prefix}showmask` to see current mask.'
).format(prefix=bot.settings.core.help_prefix)
bot.reply(message)
if subcommand == 'set':
if not trigger.group(2):
message = (
'I need a non-empty topic mask to set. '
'To delete the saved topic mask, use `{prefix}tmask clear`.'
).format(prefix=bot.settings.core.help_prefix)
bot.reply(message)
return

bot.db.set_channel_value(trigger.sender, 'topic_mask', trigger.group(2))
message = (
'Topic mask set. '
'Use `{prefix}topic <args>` to set topic, '
'`{prefix}tmask get` to see the current mask, '
'and `{prefix}tmask clear` to delete the saved topic mask.'
).format(prefix=bot.settings.core.help_prefix)
bot.reply(message)
return

@plugin.require_chanmsg
@plugin.require_privilege(plugin.OP, ERROR_MESSAGE_NO_PRIV)
@plugin.command('showmask')
def show_mask(bot, trigger):
"""Show the topic mask for the current channel."""
bot.say(bot.db.get_channel_value(trigger.sender, 'topic_mask', default_mask(trigger)))
if subcommand == 'clear':
bot.db.delete_channel_value(trigger.sender, 'topic_mask')
bot.reply('Cleared topic mask.')
return