Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adminchannel: rework topic-mask commands #2601

Merged
merged 4 commits into from
Mar 20, 2024
Merged
Changes from 2 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
36 changes: 23 additions & 13 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 @@ -366,24 +365,35 @@ def topic(bot, trigger):
@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
"""Set or get the topic mask to use for the current channel.

Within the topic mask, {} is used to allow substituting in chunks of text.
This mask is used when running the 'topic' command. `{}` is used to allow
interpolating chunks of text within the topic mask.

This mask is used when running the 'topic' command.
If called without arguments, prints the channel's current topic mask.
"""
bot.db.set_channel_value(trigger.sender, 'topic_mask', trigger.group(2))
new_mask = trigger.group(2)

if new_mask is None:
mask = bot.db.get_channel_value(
trigger.sender, 'topic_mask', default_mask(trigger))
bot.reply('Current topic mask: {}'.format(mask))
return

bot.db.set_channel_value(trigger.sender, 'topic_mask', new_mask)
message = (
'Topic mask set. '
'Use `{prefix}topic <args>` to set topic '
'and `{prefix}showmask` to see current mask.'
'Use `{prefix}topic <args>` to set topic, '
'`{prefix}tmask` without arguments to see the current mask, '
'and `{prefix}cleartmask` to clear the topic mask.'
).format(prefix=bot.settings.core.help_prefix)
bot.reply(message)


@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)))
@plugin.command('cleartmask')
dgw marked this conversation as resolved.
Show resolved Hide resolved
def clear_mask(bot, trigger):
"""Clear the topic mask for the current channel."""
bot.db.delete_channel_value(trigger.sender, 'topic_mask')
bot.reply('Cleared topic mask.')
Loading