Merge pull request #102 from CafogenMod/cloudev
implement tools for editing users with permissions via irc for the new p...
This commit is contained in:
commit
5d0754f21c
|
@ -32,7 +32,7 @@
|
|||
},
|
||||
"permissions": {
|
||||
"admins": {
|
||||
"perms": ["addfactoid", "delfactoid", "ignore", "botcontrol"],
|
||||
"perms": ["addfactoid", "delfactoid", "ignore", "botcontrol", "permissions_users"],
|
||||
"users": ["examplea!user@example.com", "exampleb!user@example.com"]
|
||||
},
|
||||
"moderators": {
|
||||
|
|
|
@ -5,6 +5,99 @@ import json
|
|||
import time
|
||||
import subprocess
|
||||
|
||||
@hook.command(autohelp=False, permissions=["permissions_users"])
|
||||
def permissions(inp, bot=None, notice=None):
|
||||
"permissions [group] -- lists the users and their permission level who have permissions."
|
||||
permissions = bot.config.get("permissions", [])
|
||||
groups = []
|
||||
if inp:
|
||||
for k in permissions:
|
||||
if inp == k:
|
||||
groups.append(k)
|
||||
else:
|
||||
for k in permissions:
|
||||
groups.append(k)
|
||||
if not groups:
|
||||
notice("%s is not a group with permissions" % inp)
|
||||
return None
|
||||
|
||||
for v in groups:
|
||||
members = ""
|
||||
for value in permissions[v]["users"]:
|
||||
members = members + ", " + value
|
||||
if members:
|
||||
notice("the members in the %s group are.." % v)
|
||||
notice(members)
|
||||
else:
|
||||
notice("there are no members in the %s group" % v)
|
||||
|
||||
|
||||
@hook.command(permissions=["permissions_users"])
|
||||
def deluser(inp, bot=None, notice=None):
|
||||
"deluser [user] [group] -- removes elevated permissions from [user]. " \
|
||||
"If [group] is specified, they will only be removed from [group]."
|
||||
permissions = bot.config.get("permissions", [])
|
||||
inp = inp.split(" ")
|
||||
groups = []
|
||||
try:
|
||||
specgroup = inp[1]
|
||||
except IndexError:
|
||||
specgroup = None
|
||||
for k in permissions:
|
||||
groups.append(k)
|
||||
else:
|
||||
for k in permissions:
|
||||
if specgroup == k:
|
||||
groups.append(k)
|
||||
if not groups:
|
||||
notice("%s is not a group with permissions" % inp[1])
|
||||
return None
|
||||
|
||||
removed = 0
|
||||
for v in groups:
|
||||
users = permissions[v]["users"]
|
||||
for value in users:
|
||||
if inp[0] == value:
|
||||
users.remove(inp[0])
|
||||
removed = 1
|
||||
notice("%s has been removed from the group %s" % (inp[0], v))
|
||||
json.dump(bot.config, open('config', 'w'), sort_keys=True, indent=2)
|
||||
if specgroup:
|
||||
if removed == 0:
|
||||
notice("%s is not in the group %s" % (inp[0], specgroup))
|
||||
else:
|
||||
if removed == 0:
|
||||
notice("%s is not in any groups" % inp[0])
|
||||
|
||||
@hook.command(permissions=["permissions_users"])
|
||||
def adduser(inp, bot=None, notice=None):
|
||||
"adduser [user] [group] -- adds elevated permissions to [user]. " \
|
||||
"[group] must be specified."
|
||||
permissions = bot.config.get("permissions", [])
|
||||
inp = inp.split(" ")
|
||||
try:
|
||||
user = inp[0]
|
||||
targetgroup = inp[1]
|
||||
except IndexError:
|
||||
notice("the group must be specified")
|
||||
return None
|
||||
if not re.search('.+!.+@.+', user):
|
||||
notice("the user must be in the form of \"nick!user@host\"")
|
||||
return None
|
||||
try:
|
||||
users = permissions[targetgroup]["users"]
|
||||
except KeyError:
|
||||
notice("no such group as %s" % targetgroup)
|
||||
return None
|
||||
if user in users:
|
||||
notice("%s is already in %s" % (user, targetgroup))
|
||||
return None
|
||||
|
||||
users.append(user)
|
||||
notice("%s has been added to the group %s" % (user, targetgroup))
|
||||
users.sort()
|
||||
json.dump(bot.config, open('config', 'w'), sort_keys=True, indent=2)
|
||||
|
||||
|
||||
@hook.command("quit", autohelp=False, permissions=["botcontrol"])
|
||||
@hook.command(autohelp=False, permissions=["botcontrol"])
|
||||
|
|
Reference in New Issue