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

coretasks: .blocks hostmask -> .blocks host #2344

Merged
merged 1 commit into from
Aug 27, 2022
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
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