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,25 +1,59 @@
# Plugin made by iloveportalz0r, TheNoodle, Lukeroge and neersighted
from util import hook
import os
import sys
import subprocess
import time
import re
import sys
import json
import time
import subprocess
@hook.command(autohelp=False)
def admins(inp, bot=None):
".admins -- Lists the bot's admins."
admins = bot.config["admins"]
return ", ".join(admins)
def admins(inp, notice=None, bot=None):
".admins -- Lists bot's admins."
adminlist = bot.config["admins"]
if adminlist:
notice("Admins are: %s." % ", ".join(adminlist))
else:
notice("No users are admins!")
return
@hook.command(adminonly=True)
def admin(inp, notice=None, bot=None, config=None):
".admin <nick|host> -- Make <nick|host> an admin."
target = inp.lower()
adminlist = bot.config["admins"]
if target in adminlist:
notice("%s is already an admin." % target)
else:
notice("%s is now an admin." % target)
adminlist.append(target)
adminlist.sort()
json.dump(bot.config, open('config', 'w'), sort_keys=True, indent=2)
return
@hook.command(adminonly=True)
def unadmin(inp, notice=None, bot=None, config=None):
".unadmin <nick|host> -- Make <nick|host> a non-admin."
target = inp.lower()
adminlist = bot.config["admins"]
if target in adminlist:
notice("%s is no longer an admin." % target)
adminlist.remove(target)
adminlist.sort()
json.dump(bot.config, open('config', 'w'), sort_keys=True, indent=2)
else:
notice("%s is not an admin." % target)
return
@hook.command(autohelp=False)
def channels(inp, conn=None):
".channels -- Lists the channels that the bot is in."
return "I am in these channels: %s" % ", ".join(conn.channels)
@hook.command("quit", autohelp=False, adminonly=True)
@hook.command(autohelp=False, adminonly=True)
def stop(inp, nick=None, conn=None):
".stop [reason] -- Kills the bot with [reason] as its quit message."
@ -28,7 +62,7 @@ def stop(inp, nick=None, conn=None):
else:
conn.cmd("QUIT", ["Killed by %s." % nick])
time.sleep(5)
os.execl(["./cloudbot", "stop"])
os.execl("./cloudbot", "stop")
@hook.command(autohelp=False, adminonly=True)
def restart(inp, nick=None, conn=None):

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