This repository has been archived on 2023-04-13. You can view files and clone it, but cannot push or open issues or pull requests.
CloudBot/plugins/ignore.py

72 lines
2.2 KiB
Python
Raw Normal View History

import json
2012-03-24 04:42:08 +01:00
from util import hook
from fnmatch import fnmatch
2012-03-24 04:42:08 +01:00
2012-04-02 18:17:55 +02:00
2012-03-24 04:42:08 +01:00
@hook.sieve
2013-08-01 11:17:13 +02:00
def ignore_sieve(bot, input, func, type, args):
""" blocks input from ignored channels/hosts """
ignorelist = bot.config["plugins"]["ignore"]["ignored"]
mask = input.mask.lower()
2012-03-24 04:42:08 +01:00
# don't block input to event hooks
if type == "event":
return input
if ignorelist:
for pattern in ignorelist:
2013-08-01 11:17:13 +02:00
if pattern.startswith("#") and pattern in ignorelist:
if input.command == "PRIVMSG" and input.lastparam[1:] == "unignore":
return input
else:
return None
2013-08-01 11:17:13 +02:00
elif fnmatch(mask, pattern):
if input.command == "PRIVMSG" and input.lastparam[1:] == "unignore":
return input
else:
return None
2012-03-24 04:42:08 +01:00
return input
@hook.command(autohelp=False)
def ignored(inp, notice=None, bot=None):
"ignored -- Lists ignored channels/users."
ignorelist = bot.config["plugins"]["ignore"]["ignored"]
2012-03-24 04:42:08 +01:00
if ignorelist:
notice("Ignored channels/users are: %s" % ", ".join(ignorelist))
2012-03-24 04:42:08 +01:00
else:
notice("No masks are currently ignored.")
return
2012-03-24 04:42:08 +01:00
@hook.command(permissions=["ignore"])
def ignore(inp, notice=None, bot=None, config=None):
"ignore <channel|nick|host> -- Makes the bot ignore <channel|user>."
2012-04-03 02:09:30 +02:00
target = inp.lower()
ignorelist = bot.config["plugins"]["ignore"]["ignored"]
if target in ignorelist:
2012-03-24 04:42:08 +01:00
notice("%s is already ignored." % target)
else:
notice("%s has been ignored." % target)
ignorelist.append(target)
ignorelist.sort()
json.dump(bot.config, open('config', 'w'), sort_keys=True, indent=2)
2012-04-02 05:57:00 +02:00
return
2012-03-24 04:42:08 +01:00
2012-04-02 18:17:55 +02:00
@hook.command(permissions=["ignore"])
def unignore(inp, notice=None, bot=None, config=None):
"unignore <channel|user> -- Makes the bot listen to"\
" <channel|user>."
2012-04-03 02:09:30 +02:00
target = inp.lower()
ignorelist = bot.config["plugins"]["ignore"]["ignored"]
if target in ignorelist:
2012-03-24 04:42:08 +01:00
notice("%s has been unignored." % target)
ignorelist.remove(target)
ignorelist.sort()
json.dump(bot.config, open('config', 'w'), sort_keys=True, indent=2)
2012-03-24 04:42:08 +01:00
else:
notice("%s is not ignored." % target)
2012-04-02 05:57:00 +02:00
return