Fixed formatting and changed string construction.
This commit is contained in:
parent
4069dd21a3
commit
b08bc570d1
1 changed files with 65 additions and 70 deletions
135
plugins/admin.py
135
plugins/admin.py
|
@ -5,21 +5,22 @@ import json
|
||||||
import time
|
import time
|
||||||
import subprocess
|
import subprocess
|
||||||
|
|
||||||
|
|
||||||
@hook.command(autohelp=False, permissions=["permissions_users"])
|
@hook.command(autohelp=False, permissions=["permissions_users"])
|
||||||
def permissions(inp, bot=None, notice=None):
|
def permissions(inp, bot=None, notice=None):
|
||||||
"permissions [group] -- lists the users and their permission level who have permissions."
|
"""permissions [group] -- lists the users and their permission level who have permissions."""
|
||||||
permissions = bot.config.get("permissions", [])
|
permissions = bot.config.get("permissions", [])
|
||||||
groups = []
|
groups = []
|
||||||
if inp:
|
if inp:
|
||||||
for k in permissions:
|
for k in permissions:
|
||||||
if inp == k:
|
if inp == k:
|
||||||
groups.append(k)
|
groups.append(k)
|
||||||
else:
|
else:
|
||||||
for k in permissions:
|
for k in permissions:
|
||||||
groups.append(k)
|
groups.append(k)
|
||||||
if not groups:
|
if not groups:
|
||||||
notice("%s is not a group with permissions" % inp)
|
notice("%s is not a group with permissions" % inp)
|
||||||
return None
|
return None
|
||||||
|
|
||||||
for v in groups:
|
for v in groups:
|
||||||
members = ""
|
members = ""
|
||||||
|
@ -34,64 +35,65 @@ def permissions(inp, bot=None, notice=None):
|
||||||
|
|
||||||
@hook.command(permissions=["permissions_users"])
|
@hook.command(permissions=["permissions_users"])
|
||||||
def deluser(inp, bot=None, notice=None):
|
def deluser(inp, bot=None, notice=None):
|
||||||
"deluser [user] [group] -- removes elevated permissions from [user]. " \
|
"""deluser [user] [group] -- removes elevated permissions from [user].
|
||||||
"If [group] is specified, they will only be removed from [group]."
|
If [group] is specified, they will only be removed from [group]."""
|
||||||
permissions = bot.config.get("permissions", [])
|
permissions = bot.config.get("permissions", [])
|
||||||
inp = inp.split(" ")
|
inp = inp.split(" ")
|
||||||
groups = []
|
groups = []
|
||||||
try:
|
try:
|
||||||
specgroup = inp[1]
|
specgroup = inp[1]
|
||||||
except IndexError:
|
except IndexError:
|
||||||
specgroup = None
|
specgroup = None
|
||||||
for k in permissions:
|
for k in permissions:
|
||||||
groups.append(k)
|
groups.append(k)
|
||||||
else:
|
else:
|
||||||
for k in permissions:
|
for k in permissions:
|
||||||
if specgroup == k:
|
if specgroup == k:
|
||||||
groups.append(k)
|
groups.append(k)
|
||||||
if not groups:
|
if not groups:
|
||||||
notice("%s is not a group with permissions" % inp[1])
|
notice("%s is not a group with permissions" % inp[1])
|
||||||
return None
|
return None
|
||||||
|
|
||||||
removed = 0
|
removed = 0
|
||||||
for v in groups:
|
for v in groups:
|
||||||
users = permissions[v]["users"]
|
users = permissions[v]["users"]
|
||||||
for value in users:
|
for value in users:
|
||||||
if inp[0] == value:
|
if inp[0] == value:
|
||||||
users.remove(inp[0])
|
users.remove(inp[0])
|
||||||
removed = 1
|
removed = 1
|
||||||
notice("%s has been removed from the group %s" % (inp[0], v))
|
notice("%s has been removed from the group %s" % (inp[0], v))
|
||||||
json.dump(bot.config, open('config', 'w'), sort_keys=True, indent=2)
|
json.dump(bot.config, open('config', 'w'), sort_keys=True, indent=2)
|
||||||
if specgroup:
|
if specgroup:
|
||||||
if removed == 0:
|
if removed == 0:
|
||||||
notice("%s is not in the group %s" % (inp[0], specgroup))
|
notice("%s is not in the group %s" % (inp[0], specgroup))
|
||||||
else:
|
else:
|
||||||
if removed == 0:
|
if removed == 0:
|
||||||
notice("%s is not in any groups" % inp[0])
|
notice("%s is not in any groups" % inp[0])
|
||||||
|
|
||||||
|
|
||||||
@hook.command(permissions=["permissions_users"])
|
@hook.command(permissions=["permissions_users"])
|
||||||
def adduser(inp, bot=None, notice=None):
|
def adduser(inp, bot=None, notice=None):
|
||||||
"adduser [user] [group] -- adds elevated permissions to [user]. " \
|
"""adduser [user] [group] -- adds elevated permissions to [user].
|
||||||
"[group] must be specified."
|
[group] must be specified."""
|
||||||
permissions = bot.config.get("permissions", [])
|
permissions = bot.config.get("permissions", [])
|
||||||
inp = inp.split(" ")
|
inp = inp.split(" ")
|
||||||
try:
|
try:
|
||||||
user = inp[0]
|
user = inp[0]
|
||||||
targetgroup = inp[1]
|
targetgroup = inp[1]
|
||||||
except IndexError:
|
except IndexError:
|
||||||
notice("the group must be specified")
|
notice("the group must be specified")
|
||||||
return None
|
return None
|
||||||
if not re.search('.+!.+@.+', user):
|
if not re.search('.+!.+@.+', user):
|
||||||
notice("the user must be in the form of \"nick!user@host\"")
|
notice("the user must be in the form of \"nick!user@host\"")
|
||||||
return None
|
return None
|
||||||
try:
|
try:
|
||||||
users = permissions[targetgroup]["users"]
|
users = permissions[targetgroup]["users"]
|
||||||
except KeyError:
|
except KeyError:
|
||||||
notice("no such group as %s" % targetgroup)
|
notice("no such group as %s" % targetgroup)
|
||||||
return None
|
return None
|
||||||
if user in users:
|
if user in users:
|
||||||
notice("%s is already in %s" % (user, targetgroup))
|
notice("%s is already in %s" % (user, targetgroup))
|
||||||
return None
|
return None
|
||||||
|
|
||||||
users.append(user)
|
users.append(user)
|
||||||
notice("%s has been added to the group %s" % (user, targetgroup))
|
notice("%s has been added to the group %s" % (user, targetgroup))
|
||||||
|
@ -102,7 +104,7 @@ def adduser(inp, bot=None, notice=None):
|
||||||
@hook.command("quit", autohelp=False, permissions=["botcontrol"])
|
@hook.command("quit", autohelp=False, permissions=["botcontrol"])
|
||||||
@hook.command(autohelp=False, permissions=["botcontrol"])
|
@hook.command(autohelp=False, permissions=["botcontrol"])
|
||||||
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."""
|
||||||
if inp:
|
if inp:
|
||||||
conn.cmd("QUIT", ["Killed by %s (%s)" % (nick, inp)])
|
conn.cmd("QUIT", ["Killed by %s (%s)" % (nick, inp)])
|
||||||
else:
|
else:
|
||||||
|
@ -113,7 +115,7 @@ def stop(inp, nick=None, conn=None):
|
||||||
|
|
||||||
@hook.command(autohelp=False, permissions=["botcontrol"])
|
@hook.command(autohelp=False, permissions=["botcontrol"])
|
||||||
def restart(inp, nick=None, conn=None):
|
def restart(inp, nick=None, conn=None):
|
||||||
"restart [reason] -- Restarts the bot with [reason] as its quit message."
|
"""restart [reason] -- Restarts the bot with [reason] as its quit message."""
|
||||||
if inp:
|
if inp:
|
||||||
conn.cmd("QUIT", ["Restarted by %s (%s)" % (nick, inp)])
|
conn.cmd("QUIT", ["Restarted by %s (%s)" % (nick, inp)])
|
||||||
else:
|
else:
|
||||||
|
@ -124,22 +126,22 @@ def restart(inp, nick=None, conn=None):
|
||||||
|
|
||||||
@hook.command(autohelp=False, permissions=["botcontrol"])
|
@hook.command(autohelp=False, permissions=["botcontrol"])
|
||||||
def clearlogs(inp, input=None):
|
def clearlogs(inp, input=None):
|
||||||
"clearlogs -- Clears the bots log(s)."
|
"""clearlogs -- Clears the bots log(s)."""
|
||||||
subprocess.call(["./cloudbot", "clear"])
|
subprocess.call(["./cloudbot", "clear"])
|
||||||
|
|
||||||
|
|
||||||
@hook.command(permissions=["botcontrol"])
|
@hook.command(permissions=["botcontrol"])
|
||||||
def join(inp, conn=None, notice=None):
|
def join(inp, conn=None, notice=None):
|
||||||
"join <channel> -- Joins <channel>."
|
"""join <channel> -- Joins <channel>."""
|
||||||
notice("Attempting to join %s..." % inp)
|
notice("Attempting to join %s..." % inp)
|
||||||
conn.join(inp)
|
conn.join(inp)
|
||||||
|
|
||||||
|
|
||||||
@hook.command(autohelp=False, permissions=["botcontrol"])
|
@hook.command(autohelp=False, permissions=["botcontrol"])
|
||||||
def part(inp, conn=None, chan=None, notice=None):
|
def part(inp, conn=None, chan=None, notice=None):
|
||||||
"part <channel> -- Leaves <channel>." \
|
"""part <channel> -- Leaves <channel>.
|
||||||
"If [channel] is blank the bot will leave the " \
|
If [channel] is blank the bot will leave the
|
||||||
"channel the command was used in."
|
channel the command was used in."""
|
||||||
if inp:
|
if inp:
|
||||||
target = inp
|
target = inp
|
||||||
else:
|
else:
|
||||||
|
@ -150,9 +152,9 @@ def part(inp, conn=None, chan=None, notice=None):
|
||||||
|
|
||||||
@hook.command(autohelp=False, permissions=["botcontrol"])
|
@hook.command(autohelp=False, permissions=["botcontrol"])
|
||||||
def cycle(inp, conn=None, chan=None, notice=None):
|
def cycle(inp, conn=None, chan=None, notice=None):
|
||||||
"cycle <channel> -- Cycles <channel>." \
|
"""cycle <channel> -- Cycles <channel>.
|
||||||
"If [channel] is blank the bot will cycle the " \
|
If [channel] is blank the bot will cycle the
|
||||||
"channel the command was used in."
|
channel the command was used in."""
|
||||||
if inp:
|
if inp:
|
||||||
target = inp
|
target = inp
|
||||||
else:
|
else:
|
||||||
|
@ -163,8 +165,8 @@ def cycle(inp, conn=None, chan=None, notice=None):
|
||||||
|
|
||||||
|
|
||||||
@hook.command(permissions=["botcontrol"])
|
@hook.command(permissions=["botcontrol"])
|
||||||
def nick(inp, input=None, notice=None, conn=None):
|
def nick(inp, notice=None, conn=None):
|
||||||
"nick <nick> -- Changes the bots nickname to <nick>."
|
"""nick <nick> -- Changes the bots nickname to <nick>."""
|
||||||
if not re.match("^[A-Za-z0-9_|.-\]\[]*$", inp.lower()):
|
if not re.match("^[A-Za-z0-9_|.-\]\[]*$", inp.lower()):
|
||||||
notice("Invalid username!")
|
notice("Invalid username!")
|
||||||
return
|
return
|
||||||
|
@ -174,38 +176,31 @@ def nick(inp, input=None, notice=None, conn=None):
|
||||||
|
|
||||||
@hook.command(permissions=["botcontrol"])
|
@hook.command(permissions=["botcontrol"])
|
||||||
def raw(inp, conn=None, notice=None):
|
def raw(inp, conn=None, notice=None):
|
||||||
"raw <command> -- Sends a RAW IRC command."
|
"""raw <command> -- Sends a RAW IRC command."""
|
||||||
notice("Raw command sent.")
|
notice("Raw command sent.")
|
||||||
conn.send(inp)
|
conn.send(inp)
|
||||||
|
|
||||||
|
|
||||||
@hook.command(permissions=["botcontrol"])
|
@hook.command(permissions=["botcontrol"])
|
||||||
def say(inp, conn=None, chan=None, notice=None):
|
def say(inp, conn=None, chan=None):
|
||||||
"say [channel] <message> -- Makes the bot say <message> in [channel]. " \
|
"""say [channel] <message> -- Makes the bot say <message> in [channel].
|
||||||
"If [channel] is blank the bot will say the <message> in the channel " \
|
If [channel] is blank the bot will say the <message> in the channel
|
||||||
"the command was used in."
|
the command was used in."""
|
||||||
inp = inp.split(" ")
|
inp = inp.split(" ")
|
||||||
|
message = " ".join(inp[1:])
|
||||||
if inp[0][0] == "#":
|
if inp[0][0] == "#":
|
||||||
message = ""
|
|
||||||
for x in inp[1:]:
|
|
||||||
message = message + x + " "
|
|
||||||
message = message[:-1]
|
|
||||||
out = "PRIVMSG %s :%s" % (inp[0], message)
|
out = "PRIVMSG %s :%s" % (inp[0], message)
|
||||||
else:
|
else:
|
||||||
message = ""
|
|
||||||
for x in inp[0:]:
|
|
||||||
message = message + x + " "
|
|
||||||
message = message[:-1]
|
|
||||||
out = "PRIVMSG %s :%s" % (chan, message)
|
out = "PRIVMSG %s :%s" % (chan, message)
|
||||||
conn.send(out)
|
conn.send(out)
|
||||||
|
|
||||||
|
|
||||||
@hook.command("act", permissions=["botcontrol"])
|
@hook.command("act", permissions=["botcontrol"])
|
||||||
@hook.command(permissions=["botcontrol"])
|
@hook.command(permissions=["botcontrol"])
|
||||||
def me(inp, conn=None, chan=None, notice=None):
|
def me(inp, conn=None, chan=None):
|
||||||
"me [channel] <action> -- Makes the bot act out <action> in [channel]. " \
|
"""me [channel] <action> -- Makes the bot act out <action> in [channel].
|
||||||
"If [channel] is blank the bot will act the <action> in the channel the " \
|
If [channel] is blank the bot will act the <action> in the channel the
|
||||||
"command was used in."
|
command was used in."""
|
||||||
inp = inp.split(" ")
|
inp = inp.split(" ")
|
||||||
if inp[0][0] == "#":
|
if inp[0][0] == "#":
|
||||||
message = ""
|
message = ""
|
||||||
|
|
Reference in a new issue