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 # Plugin made by iloveportalz0r, TheNoodle, Lukeroge and neersighted
from util import hook from util import hook
import os import os
import sys
import subprocess
import time
import re import re
import sys
import json
import time
import subprocess
@hook.command(autohelp=False) @hook.command(autohelp=False)
def admins(inp, bot=None): def admins(inp, notice=None, bot=None):
".admins -- Lists the bot's admins." ".admins -- Lists bot's admins."
admins = bot.config["admins"] adminlist = bot.config["admins"]
return ", ".join(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) @hook.command(autohelp=False)
def channels(inp, conn=None): def channels(inp, conn=None):
".channels -- Lists the channels that the bot is in." ".channels -- Lists the channels that the bot is in."
return "I am in these channels: %s" % ", ".join(conn.channels) return "I am in these channels: %s" % ", ".join(conn.channels)
@hook.command("quit", autohelp=False, adminonly=True)
@hook.command(autohelp=False, adminonly=True) @hook.command(autohelp=False, adminonly=True)
def stop(inp, nick=None, conn=None): def stop(inp, nick=None, conn=None):
".stop [reason] -- Kills the bot with [reason] as its quit message." ".stop [reason] -- Kills the bot with [reason] as its quit message."
@ -28,7 +62,7 @@ def stop(inp, nick=None, conn=None):
else: else:
conn.cmd("QUIT", ["Killed by %s." % nick]) conn.cmd("QUIT", ["Killed by %s." % nick])
time.sleep(5) time.sleep(5)
os.execl(["./cloudbot", "stop"]) os.execl("./cloudbot", "stop")
@hook.command(autohelp=False, adminonly=True) @hook.command(autohelp=False, adminonly=True)
def restart(inp, nick=None, conn=None): def restart(inp, nick=None, conn=None):

View file

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