2011-11-20 10:23:31 +01:00
|
|
|
from util import hook
|
2013-11-12 07:06:06 +01:00
|
|
|
import os
|
|
|
|
import sys
|
2012-04-02 07:37:32 +02:00
|
|
|
import re
|
|
|
|
import json
|
2012-02-29 06:09:40 +01:00
|
|
|
import time
|
2012-04-02 07:37:32 +02:00
|
|
|
import subprocess
|
2012-02-29 06:09:40 +01:00
|
|
|
|
2013-09-04 12:30:48 +02:00
|
|
|
|
2013-08-06 00:01:37 +02:00
|
|
|
@hook.command(autohelp=False, permissions=["permissions_users"])
|
|
|
|
def permissions(inp, bot=None, notice=None):
|
2013-09-04 12:30:48 +02:00
|
|
|
"""permissions [group] -- lists the users and their permission level who have permissions."""
|
2013-08-06 00:01:37 +02:00
|
|
|
permissions = bot.config.get("permissions", [])
|
|
|
|
groups = []
|
|
|
|
if inp:
|
|
|
|
for k in permissions:
|
2013-09-04 12:30:48 +02:00
|
|
|
if inp == k:
|
|
|
|
groups.append(k)
|
2013-08-06 00:01:37 +02:00
|
|
|
else:
|
2013-09-04 12:30:48 +02:00
|
|
|
for k in permissions:
|
|
|
|
groups.append(k)
|
2013-08-06 00:01:37 +02:00
|
|
|
if not groups:
|
2013-09-05 03:46:49 +02:00
|
|
|
notice("{} is not a group with permissions".format(inp))
|
2013-09-04 12:30:48 +02:00
|
|
|
return None
|
2013-08-06 00:01:37 +02:00
|
|
|
|
|
|
|
for v in groups:
|
|
|
|
members = ""
|
|
|
|
for value in permissions[v]["users"]:
|
2013-08-06 00:40:59 +02:00
|
|
|
members = members + value + ", "
|
2013-08-06 00:01:37 +02:00
|
|
|
if members:
|
2013-09-05 03:46:49 +02:00
|
|
|
notice("the members in the {} group are..".format(v))
|
2013-08-06 00:40:59 +02:00
|
|
|
notice(members[:-2])
|
2013-08-06 00:01:37 +02:00
|
|
|
else:
|
2013-09-05 03:46:49 +02:00
|
|
|
notice("there are no members in the {} group".format(v))
|
2013-08-06 00:01:37 +02:00
|
|
|
|
|
|
|
|
|
|
|
@hook.command(permissions=["permissions_users"])
|
|
|
|
def deluser(inp, bot=None, notice=None):
|
2013-09-04 12:30:48 +02:00
|
|
|
"""deluser [user] [group] -- removes elevated permissions from [user].
|
|
|
|
If [group] is specified, they will only be removed from [group]."""
|
2013-08-06 00:01:37 +02:00
|
|
|
permissions = bot.config.get("permissions", [])
|
|
|
|
inp = inp.split(" ")
|
|
|
|
groups = []
|
|
|
|
try:
|
2013-09-04 12:30:48 +02:00
|
|
|
specgroup = inp[1]
|
2013-08-06 00:01:37 +02:00
|
|
|
except IndexError:
|
2013-09-04 12:30:48 +02:00
|
|
|
specgroup = None
|
|
|
|
for k in permissions:
|
|
|
|
groups.append(k)
|
2013-08-06 00:01:37 +02:00
|
|
|
else:
|
2013-09-04 12:30:48 +02:00
|
|
|
for k in permissions:
|
|
|
|
if specgroup == k:
|
|
|
|
groups.append(k)
|
2013-08-06 00:01:37 +02:00
|
|
|
if not groups:
|
2013-09-05 03:46:49 +02:00
|
|
|
notice("{} is not a group with permissions".format(inp[1]))
|
2013-09-04 12:30:48 +02:00
|
|
|
return None
|
2013-08-06 00:01:37 +02:00
|
|
|
|
|
|
|
removed = 0
|
|
|
|
for v in groups:
|
2013-09-04 12:30:48 +02:00
|
|
|
users = permissions[v]["users"]
|
|
|
|
for value in users:
|
|
|
|
if inp[0] == value:
|
|
|
|
users.remove(inp[0])
|
|
|
|
removed = 1
|
2013-09-05 03:46:49 +02:00
|
|
|
notice("{} has been removed from the group {}".format(inp[0], v))
|
2013-09-04 12:30:48 +02:00
|
|
|
json.dump(bot.config, open('config', 'w'), sort_keys=True, indent=2)
|
2013-08-06 00:01:37 +02:00
|
|
|
if specgroup:
|
2013-09-04 12:30:48 +02:00
|
|
|
if removed == 0:
|
2013-09-05 03:46:49 +02:00
|
|
|
notice("{} is not in the group {}".format(inp[0], specgroup))
|
2013-08-06 00:01:37 +02:00
|
|
|
else:
|
2013-09-04 12:30:48 +02:00
|
|
|
if removed == 0:
|
2013-09-05 03:46:49 +02:00
|
|
|
notice("{} is not in any groups".format(inp[0]))
|
2013-09-04 12:30:48 +02:00
|
|
|
|
2013-08-06 00:01:37 +02:00
|
|
|
|
|
|
|
@hook.command(permissions=["permissions_users"])
|
|
|
|
def adduser(inp, bot=None, notice=None):
|
2013-09-04 12:30:48 +02:00
|
|
|
"""adduser [user] [group] -- adds elevated permissions to [user].
|
|
|
|
[group] must be specified."""
|
2013-08-06 00:01:37 +02:00
|
|
|
permissions = bot.config.get("permissions", [])
|
|
|
|
inp = inp.split(" ")
|
|
|
|
try:
|
2013-09-04 12:30:48 +02:00
|
|
|
user = inp[0]
|
|
|
|
targetgroup = inp[1]
|
2013-08-06 00:01:37 +02:00
|
|
|
except IndexError:
|
2013-09-04 12:30:48 +02:00
|
|
|
notice("the group must be specified")
|
|
|
|
return None
|
2013-08-06 00:01:37 +02:00
|
|
|
if not re.search('.+!.+@.+', user):
|
2013-09-04 12:30:48 +02:00
|
|
|
notice("the user must be in the form of \"nick!user@host\"")
|
|
|
|
return None
|
2013-08-06 00:01:37 +02:00
|
|
|
try:
|
|
|
|
users = permissions[targetgroup]["users"]
|
|
|
|
except KeyError:
|
2013-09-05 03:46:49 +02:00
|
|
|
notice("no such group as {}".format(targetgroup))
|
2013-09-04 12:30:48 +02:00
|
|
|
return None
|
2013-08-06 00:01:37 +02:00
|
|
|
if user in users:
|
2013-09-05 03:46:49 +02:00
|
|
|
notice("{} is already in {}".format(user, targetgroup))
|
2013-09-04 12:30:48 +02:00
|
|
|
return None
|
2013-08-06 00:01:37 +02:00
|
|
|
|
|
|
|
users.append(user)
|
2013-09-05 03:46:49 +02:00
|
|
|
notice("{} has been added to the group {}".format(user, targetgroup))
|
2013-08-06 00:01:37 +02:00
|
|
|
users.sort()
|
|
|
|
json.dump(bot.config, open('config', 'w'), sort_keys=True, indent=2)
|
|
|
|
|
2012-03-12 07:24:52 +01:00
|
|
|
|
2013-08-01 09:03:40 +02:00
|
|
|
@hook.command("quit", autohelp=False, permissions=["botcontrol"])
|
|
|
|
@hook.command(autohelp=False, permissions=["botcontrol"])
|
2012-03-23 06:08:58 +01:00
|
|
|
def stop(inp, nick=None, conn=None):
|
2013-09-04 12:30:48 +02:00
|
|
|
"""stop [reason] -- Kills the bot with [reason] as its quit message."""
|
2012-02-26 07:47:13 +01:00
|
|
|
if inp:
|
2013-09-05 03:46:49 +02:00
|
|
|
conn.cmd("QUIT", ["Killed by {} ({})".format(nick, inp)])
|
2012-02-26 07:47:13 +01:00
|
|
|
else:
|
2013-09-05 03:46:49 +02:00
|
|
|
conn.cmd("QUIT", ["Killed by {}.".format(nick)])
|
2012-03-01 22:52:09 +01:00
|
|
|
time.sleep(5)
|
2012-04-02 21:32:42 +02:00
|
|
|
os.execl("./cloudbot", "cloudbot", "stop")
|
2012-04-02 18:17:55 +02:00
|
|
|
|
2012-04-02 22:17:47 +02:00
|
|
|
|
2013-08-01 09:03:40 +02:00
|
|
|
@hook.command(autohelp=False, permissions=["botcontrol"])
|
2013-09-12 13:49:00 +02:00
|
|
|
def restart(inp, nick=None, conn=None, bot=None):
|
2013-09-04 12:30:48 +02:00
|
|
|
"""restart [reason] -- Restarts the bot with [reason] as its quit message."""
|
2013-09-12 13:49:00 +02:00
|
|
|
for botcon in bot.conns:
|
|
|
|
if inp:
|
|
|
|
bot.conns[botcon].cmd("QUIT", ["Restarted by {} ({})".format(nick, inp)])
|
|
|
|
else:
|
|
|
|
bot.conns[botcon].cmd("QUIT", ["Restarted by {}.".format(nick)])
|
2012-03-01 22:52:09 +01:00
|
|
|
time.sleep(5)
|
2013-09-12 13:49:00 +02:00
|
|
|
#os.execl("./cloudbot", "cloudbot", "restart")
|
|
|
|
args = sys.argv[:]
|
|
|
|
args.insert(0, sys.executable)
|
|
|
|
os.execv(sys.executable, args)
|
2012-03-12 12:25:38 +01:00
|
|
|
|
2013-11-12 07:06:06 +01:00
|
|
|
|
2013-08-01 09:03:40 +02:00
|
|
|
@hook.command(autohelp=False, permissions=["botcontrol"])
|
2012-03-23 06:08:58 +01:00
|
|
|
def clearlogs(inp, input=None):
|
2013-09-04 12:30:48 +02:00
|
|
|
"""clearlogs -- Clears the bots log(s)."""
|
2012-03-27 23:44:07 +02:00
|
|
|
subprocess.call(["./cloudbot", "clear"])
|
2012-02-29 21:00:10 +01:00
|
|
|
|
|
|
|
|
2013-08-01 09:03:40 +02:00
|
|
|
@hook.command(permissions=["botcontrol"])
|
2012-03-25 04:15:11 +02:00
|
|
|
def join(inp, conn=None, notice=None):
|
2013-09-04 12:30:48 +02:00
|
|
|
"""join <channel> -- Joins <channel>."""
|
2013-09-05 03:46:49 +02:00
|
|
|
notice("Attempting to join {}...".format(inp))
|
2012-03-27 23:27:18 +02:00
|
|
|
conn.join(inp)
|
2011-11-20 10:23:31 +01:00
|
|
|
|
2012-02-26 07:47:13 +01:00
|
|
|
|
2013-08-01 09:03:40 +02:00
|
|
|
@hook.command(autohelp=False, permissions=["botcontrol"])
|
2012-04-02 22:14:38 +02:00
|
|
|
def part(inp, conn=None, chan=None, notice=None):
|
2013-09-04 12:30:48 +02:00
|
|
|
"""part <channel> -- Leaves <channel>.
|
|
|
|
If [channel] is blank the bot will leave the
|
|
|
|
channel the command was used in."""
|
2012-04-02 22:14:38 +02:00
|
|
|
if inp:
|
|
|
|
target = inp
|
|
|
|
else:
|
|
|
|
target = chan
|
2013-09-05 03:46:49 +02:00
|
|
|
notice("Attempting to leave {}...".format(target))
|
2012-04-02 22:14:38 +02:00
|
|
|
conn.part(target)
|
2011-11-20 10:23:31 +01:00
|
|
|
|
2012-02-29 06:15:35 +01:00
|
|
|
|
2013-08-01 09:03:40 +02:00
|
|
|
@hook.command(autohelp=False, permissions=["botcontrol"])
|
2012-04-02 22:14:38 +02:00
|
|
|
def cycle(inp, conn=None, chan=None, notice=None):
|
2013-09-04 12:30:48 +02:00
|
|
|
"""cycle <channel> -- Cycles <channel>.
|
|
|
|
If [channel] is blank the bot will cycle the
|
|
|
|
channel the command was used in."""
|
2012-04-02 22:14:38 +02:00
|
|
|
if inp:
|
|
|
|
target = inp
|
|
|
|
else:
|
|
|
|
target = chan
|
2013-09-05 06:22:14 +02:00
|
|
|
notice("Attempting to cycle {}...".format(target))
|
2012-04-02 22:14:38 +02:00
|
|
|
conn.part(target)
|
|
|
|
conn.join(target)
|
2011-11-20 10:23:31 +01:00
|
|
|
|
2012-02-29 06:15:35 +01:00
|
|
|
|
2013-08-01 09:03:40 +02:00
|
|
|
@hook.command(permissions=["botcontrol"])
|
2013-09-04 12:30:48 +02:00
|
|
|
def nick(inp, notice=None, conn=None):
|
|
|
|
"""nick <nick> -- Changes the bots nickname to <nick>."""
|
2012-03-12 22:18:51 +01:00
|
|
|
if not re.match("^[A-Za-z0-9_|.-\]\[]*$", inp.lower()):
|
|
|
|
notice("Invalid username!")
|
|
|
|
return
|
2013-09-05 03:46:49 +02:00
|
|
|
notice("Attempting to change nick to \"{}\"...".format(inp))
|
2012-03-27 23:27:18 +02:00
|
|
|
conn.set_nick(inp)
|
2011-11-20 10:23:31 +01:00
|
|
|
|
2012-02-29 06:15:35 +01:00
|
|
|
|
2013-08-01 09:03:40 +02:00
|
|
|
@hook.command(permissions=["botcontrol"])
|
2012-03-23 06:08:58 +01:00
|
|
|
def raw(inp, conn=None, notice=None):
|
2013-09-04 12:30:48 +02:00
|
|
|
"""raw <command> -- Sends a RAW IRC command."""
|
2011-11-20 10:23:31 +01:00
|
|
|
notice("Raw command sent.")
|
2012-03-23 06:08:58 +01:00
|
|
|
conn.send(inp)
|
2011-11-20 10:23:31 +01:00
|
|
|
|
2012-02-29 06:15:35 +01:00
|
|
|
|
2013-08-01 09:03:40 +02:00
|
|
|
@hook.command(permissions=["botcontrol"])
|
2013-09-04 12:30:48 +02:00
|
|
|
def say(inp, conn=None, chan=None):
|
|
|
|
"""say [channel] <message> -- Makes the bot say <message> in [channel].
|
|
|
|
If [channel] is blank the bot will say the <message> in the channel
|
|
|
|
the command was used in."""
|
2012-04-02 06:30:04 +02:00
|
|
|
inp = inp.split(" ")
|
|
|
|
if inp[0][0] == "#":
|
2013-09-04 13:05:39 +02:00
|
|
|
message = " ".join(inp[1:])
|
2013-09-05 03:46:49 +02:00
|
|
|
out = "PRIVMSG {} :{}".format(inp[0], message)
|
2011-11-20 10:23:31 +01:00
|
|
|
else:
|
2013-09-04 13:05:39 +02:00
|
|
|
message = " ".join(inp[0:])
|
2013-09-05 03:46:49 +02:00
|
|
|
out = "PRIVMSG {} :{}".format(chan, message)
|
2012-03-25 04:15:11 +02:00
|
|
|
conn.send(out)
|
2011-11-20 10:23:31 +01:00
|
|
|
|
2012-02-29 06:15:35 +01:00
|
|
|
|
2013-08-01 09:03:40 +02:00
|
|
|
@hook.command("act", permissions=["botcontrol"])
|
|
|
|
@hook.command(permissions=["botcontrol"])
|
2013-09-04 12:30:48 +02:00
|
|
|
def me(inp, conn=None, chan=None):
|
|
|
|
"""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
|
|
|
|
command was used in."""
|
2012-04-02 06:30:04 +02:00
|
|
|
inp = inp.split(" ")
|
|
|
|
if inp[0][0] == "#":
|
2012-02-19 03:20:25 +01:00
|
|
|
message = ""
|
2012-04-02 06:30:04 +02:00
|
|
|
for x in inp[1:]:
|
2012-02-19 03:20:25 +01:00
|
|
|
message = message + x + " "
|
|
|
|
message = message[:-1]
|
2013-09-05 03:46:49 +02:00
|
|
|
out = "PRIVMSG {} :\x01ACTION {}\x01".format(inp[0], message)
|
2012-02-19 03:20:25 +01:00
|
|
|
else:
|
|
|
|
message = ""
|
2012-04-02 06:30:04 +02:00
|
|
|
for x in inp[0:]:
|
2012-02-19 03:20:25 +01:00
|
|
|
message = message + x + " "
|
|
|
|
message = message[:-1]
|
2013-09-05 03:46:49 +02:00
|
|
|
out = "PRIVMSG {} :\x01ACTION {}\x01".format(chan, message)
|
2012-03-25 04:15:11 +02:00
|
|
|
conn.send(out)
|