Added json/persist to ignore.py, added in-chat admin adding

This commit is contained in:
neersighted 2012-04-01 22:37:32 -07:00
parent 5af42f128a
commit 681745d357
2 changed files with 66 additions and 49 deletions

View file

@ -1,36 +1,14 @@
import json
from util import hook
ignorelist = []
def ignore_target(target):
""" ignores someone """
target = target.lower()
ignorelist.append(target)
def unignore_target(target):
""" unignores someone """
target = target.lower()
ignorelist.remove(target)
def is_ignored(target):
""" checks of someone is ignored """
target = target.lower()
if target in ignorelist:
return True
else:
return False
@hook.sieve
def ignoresieve(bot, input, func, type, args):
""" blocks input from ignored channels/users """
""" blocks input from ignored channels/nicks """
ignorelist = bot.config["plugins"]["ignore"]["ignored"]
# don't block input to event hooks
if type == "event":
return input
if is_ignored(input.chan) or is_ignored(input.nick) or is_ignored(input.host) or is_ignored(input.mask):
if input.chan in ignorelist or input.nick in ignorelist or input.host in ignorelist or input.mask in ignorelist:
if input.command == "PRIVMSG" and input.lastparam[1:] == "unignore":
return input
else:
@ -40,34 +18,39 @@ def ignoresieve(bot, input, func, type, args):
@hook.command(autohelp=False)
def ignored(inp, notice=None, bot=None):
".ignored -- Lists ignored channels/users/hosts."
".ignored -- Lists ignored channels/nicks/hosts."
ignorelist = bot.config["plugins"]["ignore"]["ignored"]
if ignorelist:
notice("Ignored channels/users/hosts are: %s" % ", ".join(ignorelist))
notice("Ignored channels/nicks/hosts are: %s" % ", ".join(ignorelist))
else:
notice("No channels/users/hosts are currently ignored.")
notice("No channels/nicks/hosts are currently ignored.")
return
@hook.command(adminonly=True)
def ignore(inp, input=None, notice=None):
".ignore <channel|user|host> -- Makes the bot ignore <channel|user|host>."
target = inp
if is_ignored(target):
def ignore(inp, notice=None, bot=None, config=None):
".ignore <channel|nick|host> -- Makes the bot ignore <channel|nick|host>."
target = inp.lower()
ignorelist = bot.config["plugins"]["ignore"]["ignored"]
if target in ignorelist:
notice("%s is already ignored." % target)
else:
ignore_target(target)
notice("%s has been ignored." % target)
ignorelist.append(target)
ignorelist.sort()
json.dump(bot.config, open('config', 'w'), sort_keys=True, indent=2)
return
@hook.command(adminonly=True)
def unignore(inp, input=None, notice=None):
".unignore <channel|user|host> -- Makes the bot listen to <channel|user|host>."
target = inp
if is_ignored(target):
unignore_target(target)
def unignore(inp, notice=None, bot=None, config=None):
".unignore <channel|nick|host> -- Makes the bot listen to <channel|nick|host>."
target = inp.lower()
ignorelist = bot.config["plugins"]["ignore"]["ignored"]
if target in ignorelist:
notice("%s has been unignored." % target)
ignorelist.remove(target)
ignorelist.sort()
json.dump(bot.config, open('config', 'w'), sort_keys=True, indent=2)
else:
notice("%s is not ignored." % target)
return