Skip to content

Commit

Permalink
coretasks: .blocks hostmask -> .blocks host
Browse files Browse the repository at this point in the history
These are not, and AFAICT never have been, actual host*masks*. Having
the subcommand name and code variables refer to them as (host)masks has
been a point of confusion for, literally, years.

This is just the first step toward making the ignore/block system work
more intuitively, but you know what they say about journeys of a
thousand miles...

For full context, thought processes, tentative future plans, and so on:
See #1355.
  • Loading branch information
dgw committed Aug 24, 2022
1 parent a4f185d commit da82135
Showing 1 changed file with 16 additions and 16 deletions.
32 changes: 16 additions & 16 deletions sopel/coretasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -1272,26 +1272,26 @@ def blocks(bot, trigger):
"success_del": "Successfully deleted block: %s",
"success_add": "Successfully added block: %s",
"no_nick": "No matching nick block found for: %s",
"no_host": "No matching hostmask block found for: %s",
"invalid": "Invalid format for %s a block. Try: .blocks add (nick|hostmask) sopel",
"no_host": "No matching host block found for: %s",
"invalid": "Invalid format for %s a block. Try: .blocks add (nick|host) sopel",
"invalid_display": "Invalid input for displaying blocks.",
"nonelisted": "No %s listed in the blocklist.",
'huh': "I could not figure out what you wanted to do.",
}

masks = set(s for s in bot.config.core.host_blocks if s != '')
hosts = set(s for s in bot.config.core.host_blocks if s != '')
nicks = set(bot.make_identifier(nick)
for nick in bot.config.core.nick_blocks
if nick != '')
text = trigger.group().split()

if len(text) == 3 and text[1] == "list":
if text[2] == "hostmask":
if len(masks) > 0:
blocked = ', '.join(str(mask) for mask in masks)
bot.say("Blocked hostmasks: {}".format(blocked))
if text[2] == "host":
if len(hosts) > 0:
blocked = ', '.join(str(host) for host in hosts)
bot.say("Blocked hosts: {}".format(blocked))
else:
bot.reply(STRINGS['nonelisted'] % ('hostmasks'))
bot.reply(STRINGS['nonelisted'] % ('hosts'))
elif text[2] == "nick":
if len(nicks) > 0:
blocked = ', '.join(str(nick) for nick in nicks)
Expand All @@ -1306,9 +1306,9 @@ def blocks(bot, trigger):
nicks.add(text[3])
bot.config.core.nick_blocks = nicks
bot.config.save()
elif text[2] == "hostmask":
masks.add(text[3].lower())
bot.config.core.host_blocks = list(masks)
elif text[2] == "host":
hosts.add(text[3].lower())
bot.config.core.host_blocks = list(hosts)
else:
bot.reply(STRINGS['invalid'] % ("adding"))
return
Expand All @@ -1325,13 +1325,13 @@ def blocks(bot, trigger):
bot.config.core.nick_blocks = [str(n) for n in nicks]
bot.config.save()
bot.reply(STRINGS['success_del'] % (text[3]))
elif text[2] == "hostmask":
mask = text[3].lower()
if mask not in masks:
elif text[2] == "host":
host = text[3].lower()
if host not in hosts:
bot.reply(STRINGS['no_host'] % (text[3]))
return
masks.remove(mask)
bot.config.core.host_blocks = [str(m) for m in masks]
hosts.remove(host)
bot.config.core.host_blocks = [str(m) for m in hosts]
bot.config.save()
bot.reply(STRINGS['success_del'] % (text[3]))
else:
Expand Down

0 comments on commit da82135

Please sign in to comment.