From 681745d35753c3129127a94edb1938a952170599 Mon Sep 17 00:00:00 2001 From: neersighted Date: Sun, 1 Apr 2012 22:37:32 -0700 Subject: [PATCH] Added json/persist to ignore.py, added in-chat admin adding --- plugins/admin.py | 50 ++++++++++++++++++++++++++++++------ plugins/ignore.py | 65 +++++++++++++++++------------------------------ 2 files changed, 66 insertions(+), 49 deletions(-) diff --git a/plugins/admin.py b/plugins/admin.py index 0568abd..2190101 100755 --- a/plugins/admin.py +++ b/plugins/admin.py @@ -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 -- Make 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 -- Make 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): diff --git a/plugins/ignore.py b/plugins/ignore.py index c2476d7..b6b2110 100755 --- a/plugins/ignore.py +++ b/plugins/ignore.py @@ -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 -- Makes the bot ignore ." - target = inp - - if is_ignored(target): +def ignore(inp, notice=None, bot=None, config=None): + ".ignore -- Makes the bot ignore ." + 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 -- Makes the bot listen to ." - target = inp - - if is_ignored(target): - unignore_target(target) +def unignore(inp, notice=None, bot=None, config=None): + ".unignore -- Makes the bot listen to ." + 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