Added multi-user admining

This commit is contained in:
neersighted 2012-04-02 17:40:52 -07:00
parent d07f28885d
commit fed5c17468

View file

@ -11,9 +11,8 @@ import subprocess
@hook.command(autohelp=False) @hook.command(autohelp=False)
def admins(inp, notice=None, bot=None): def admins(inp, notice=None, bot=None):
".admins -- Lists bot's admins." ".admins -- Lists bot's admins."
adminlist = bot.config["admins"] if bot.config["admins"]:
if adminlist: notice("Admins are: %s." % ", ".join(bot.config["admins"]))
notice("Admins are: %s." % ", ".join(adminlist))
else: else:
notice("No users are admins!") notice("No users are admins!")
return return
@ -21,31 +20,33 @@ def admins(inp, notice=None, bot=None):
@hook.command(adminonly=True) @hook.command(adminonly=True)
def addadmin(inp, notice=None, bot=None, config=None): def addadmin(inp, notice=None, bot=None, config=None):
".addadmin <nick|host> -- Make <nick|host> an admin." ".addadmin <nick|host> -- Make <nick|host> an admin. " \
target = inp.lower().split()[0] "(you can add multiple admins at once)"
adminlist = bot.config["admins"] targets = inp.lower().split()
if target in adminlist: for target in targets:
notice("%s is already an admin." % target) if target in bot.config["admins"]:
else: notice("%s is already an admin." % target)
notice("%s is now an admin." % target) else:
adminlist.append(target) notice("%s is now an admin." % target)
adminlist.sort() bot.config["admins"].append(target)
json.dump(bot.config, open('config', 'w'), sort_keys=True, indent=2) bot.config["admins"].sort()
json.dump(bot.config, open('config', 'w'), sort_keys=True, indent=2)
return return
@hook.command(adminonly=True) @hook.command(adminonly=True)
def deladmin(inp, notice=None, bot=None, config=None): def deladmin(inp, notice=None, bot=None, config=None):
".deladmin <nick|host> -- Make <nick|host> a non-admin." ".deladmin <nick|host> -- Make <nick|host> a non-admin." \
target = inp.lower().split()[0] "(you can delete multiple admins at once)"
adminlist = bot.config["admins"] targets = inp.lower().split()
if target in adminlist: for target in targets:
notice("%s is no longer an admin." % target) if target in bot.config["admins"]:
adminlist.remove(target) notice("%s is no longer an admin." % target)
adminlist.sort() bot.config["admins"].remove(target)
json.dump(bot.config, open('config', 'w'), sort_keys=True, indent=2) bot.config["admins"].sort()
else: json.dump(bot.config, open('config', 'w'), sort_keys=True, indent=2)
notice("%s is not an admin." % target) else:
notice("%s is not an admin." % target)
return return