Skip to content

Commit

Permalink
Merge pull request #2344 from sopel-irc/blocks-hostmask-rename
Browse files Browse the repository at this point in the history
coretasks: `.blocks hostmask` -> `.blocks host`
  • Loading branch information
dgw authored Aug 27, 2022
2 parents a4f185d + da82135 commit 8453be4
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 8453be4

Please sign in to comment.