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

62 lines
2 KiB
Python
Raw Normal View History

import json
2012-03-24 04:42:08 +01:00
from util import hook
2012-04-02 18:17:55 +02:00
2012-03-24 04:42:08 +01:00
@hook.sieve
def ignoresieve(bot, input, func, type, args):
2012-04-02 22:16:38 +02:00
""" blocks input from ignored channels/nicks/hosts """
ignorelist = bot.config["plugins"]["ignore"]["ignored"]
2012-03-24 04:42:08 +01:00
# don't block input to event hooks
if type == "event":
return input
2012-04-03 02:09:30 +02:00
if input.chan.lower() in ignorelist or\
input.nick.lower() in ignorelist or\
input.mask.lower() in ignorelist:
2012-03-24 04:42:08 +01:00
if input.command == "PRIVMSG" and input.lastparam[1:] == "unignore":
return input
else:
return None
return input
@hook.command(autohelp=False)
def ignored(inp, notice=None, bot=None):
2012-05-16 05:07:27 +02:00
"ignored -- Lists ignored channels/nicks/hosts."
ignorelist = bot.config["plugins"]["ignore"]["ignored"]
2012-03-24 04:42:08 +01:00
if ignorelist:
notice("Ignored channels/nicks/hosts are: %s" % ", ".join(ignorelist))
2012-03-24 04:42:08 +01:00
else:
notice("No channels/nicks/hosts are currently ignored.")
return
2012-03-24 04:42:08 +01:00
@hook.command(adminonly=True)
def ignore(inp, notice=None, bot=None, config=None):
2012-05-16 05:07:27 +02:00
"ignore <channel|nick|host> -- Makes the bot ignore <channel|nick|host>."
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
2012-03-24 04:42:08 +01:00
@hook.command(adminonly=True)
def unignore(inp, notice=None, bot=None, config=None):
2012-05-16 05:07:27 +02:00
"unignore <channel|nick|host> -- Makes the bot listen to"\
2012-04-02 18:17:55 +02:00
" <channel|nick|host>."
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