2012-03-12 12:26:01 +01:00
|
|
|
# Plugin made by iloveportalz0r, TheNoodle, Lukeroge and neersighted
|
2011-11-20 10:23:31 +01:00
|
|
|
from util import hook
|
2012-03-01 23:17:12 +01:00
|
|
|
import os
|
2012-04-02 07:37:32 +02:00
|
|
|
import re
|
2012-02-29 06:09:40 +01:00
|
|
|
import sys
|
2012-04-02 07:37:32 +02:00
|
|
|
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
|
|
|
|
2012-03-12 07:24:52 +01:00
|
|
|
|
2012-03-12 07:33:55 +01:00
|
|
|
@hook.command(autohelp=False)
|
2012-04-02 07:37:32 +02:00
|
|
|
def admins(inp, notice=None, bot=None):
|
|
|
|
".admins -- Lists bot's admins."
|
2012-04-03 02:40:52 +02:00
|
|
|
if bot.config["admins"]:
|
|
|
|
notice("Admins are: %s." % ", ".join(bot.config["admins"]))
|
2012-04-02 07:37:32 +02:00
|
|
|
else:
|
|
|
|
notice("No users are admins!")
|
|
|
|
return
|
|
|
|
|
2012-03-23 01:22:23 +01:00
|
|
|
|
2012-04-02 07:37:32 +02:00
|
|
|
@hook.command(adminonly=True)
|
2012-04-03 02:31:25 +02:00
|
|
|
def addadmin(inp, notice=None, bot=None, config=None):
|
2012-04-03 02:40:52 +02:00
|
|
|
".addadmin <nick|host> -- Make <nick|host> an admin. " \
|
|
|
|
"(you can add multiple admins at once)"
|
|
|
|
targets = inp.lower().split()
|
|
|
|
for target in targets:
|
|
|
|
if target in bot.config["admins"]:
|
|
|
|
notice("%s is already an admin." % target)
|
|
|
|
else:
|
|
|
|
notice("%s is now an admin." % target)
|
|
|
|
bot.config["admins"].append(target)
|
|
|
|
bot.config["admins"].sort()
|
|
|
|
json.dump(bot.config, open('config', 'w'), sort_keys=True, indent=2)
|
2012-04-02 07:37:32 +02:00
|
|
|
return
|
|
|
|
|
2012-04-02 18:17:55 +02:00
|
|
|
|
2012-04-02 07:37:32 +02:00
|
|
|
@hook.command(adminonly=True)
|
2012-04-03 02:31:25 +02:00
|
|
|
def deladmin(inp, notice=None, bot=None, config=None):
|
2012-04-03 02:40:52 +02:00
|
|
|
".deladmin <nick|host> -- Make <nick|host> a non-admin." \
|
|
|
|
"(you can delete multiple admins at once)"
|
|
|
|
targets = inp.lower().split()
|
|
|
|
for target in targets:
|
|
|
|
if target in bot.config["admins"]:
|
|
|
|
notice("%s is no longer an admin." % target)
|
|
|
|
bot.config["admins"].remove(target)
|
|
|
|
bot.config["admins"].sort()
|
|
|
|
json.dump(bot.config, open('config', 'w'), sort_keys=True, indent=2)
|
|
|
|
else:
|
|
|
|
notice("%s is not an admin." % target)
|
2012-04-02 07:37:32 +02:00
|
|
|
return
|
2012-03-19 12:14:20 +01:00
|
|
|
|
2012-04-02 18:17:55 +02:00
|
|
|
|
2012-03-19 12:14:20 +01:00
|
|
|
@hook.command(autohelp=False)
|
|
|
|
def channels(inp, conn=None):
|
|
|
|
".channels -- Lists the channels that the bot is in."
|
2012-03-29 00:07:41 +02:00
|
|
|
return "I am in these channels: %s" % ", ".join(conn.channels)
|
2012-03-12 07:24:52 +01:00
|
|
|
|
|
|
|
|
2012-04-02 07:37:32 +02:00
|
|
|
@hook.command("quit", autohelp=False, adminonly=True)
|
2012-03-12 22:43:28 +01:00
|
|
|
@hook.command(autohelp=False, adminonly=True)
|
2012-03-23 06:08:58 +01:00
|
|
|
def stop(inp, nick=None, conn=None):
|
2012-03-12 21:31:41 +01:00
|
|
|
".stop [reason] -- Kills the bot with [reason] as its quit message."
|
2012-02-26 07:47:13 +01:00
|
|
|
if inp:
|
2012-03-23 06:08:58 +01:00
|
|
|
conn.cmd("QUIT", ["Killed by %s (%s)" % (nick, inp)])
|
2012-02-26 07:47:13 +01:00
|
|
|
else:
|
2012-03-23 06:08:58 +01:00
|
|
|
conn.cmd("QUIT", ["Killed by %s." % 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
|
|
|
|
2012-03-12 21:31:41 +01:00
|
|
|
@hook.command(autohelp=False, adminonly=True)
|
2012-03-27 23:44:07 +02:00
|
|
|
def restart(inp, nick=None, conn=None):
|
2012-03-12 21:31:41 +01:00
|
|
|
".restart [reason] -- Restarts the bot with [reason] as its quit message."
|
2012-02-28 09:34:04 +01:00
|
|
|
if inp:
|
2012-03-27 23:44:07 +02:00
|
|
|
conn.cmd("QUIT", ["Restarted by %s (%s)" % (nick, inp)])
|
2012-02-28 09:34:04 +01:00
|
|
|
else:
|
2012-03-27 23:44:07 +02:00
|
|
|
conn.cmd("QUIT", ["Restarted by %s." % nick])
|
2012-03-01 22:52:09 +01:00
|
|
|
time.sleep(5)
|
2012-04-02 21:32:42 +02:00
|
|
|
os.execl("./cloudbot", "cloudbot", "restart")
|
2012-02-29 06:09:40 +01:00
|
|
|
|
2012-03-12 12:25:38 +01:00
|
|
|
|
2012-03-12 21:31:41 +01:00
|
|
|
@hook.command(autohelp=False, adminonly=True)
|
2012-03-23 06:08:58 +01:00
|
|
|
def clearlogs(inp, input=None):
|
|
|
|
".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
|
|
|
|
|
|
|
|
2012-03-12 21:31:41 +01:00
|
|
|
@hook.command(adminonly=True)
|
2012-03-25 04:15:11 +02:00
|
|
|
def join(inp, conn=None, notice=None):
|
|
|
|
".join <channel> -- Joins <channel>."
|
2012-03-27 23:27:18 +02:00
|
|
|
notice("Attempting to join %s..." % inp)
|
|
|
|
conn.join(inp)
|
2011-11-20 10:23:31 +01:00
|
|
|
|
2012-02-26 07:47:13 +01:00
|
|
|
|
2012-04-02 22:14:38 +02:00
|
|
|
@hook.command(autohelp=False, adminonly=True)
|
|
|
|
def part(inp, conn=None, chan=None, notice=None):
|
|
|
|
".part <channel> -- Leaves <channel>." \
|
|
|
|
"If [channel] is blank the bot will leave the " \
|
|
|
|
"channel the command was used in."
|
|
|
|
if inp:
|
|
|
|
target = inp
|
|
|
|
else:
|
|
|
|
target = chan
|
|
|
|
notice("Attempting to leave %s..." % target)
|
|
|
|
conn.part(target)
|
2011-11-20 10:23:31 +01:00
|
|
|
|
2012-02-29 06:15:35 +01:00
|
|
|
|
2012-04-02 22:14:38 +02:00
|
|
|
@hook.command(autohelp=False, adminonly=True)
|
|
|
|
def cycle(inp, conn=None, chan=None, notice=None):
|
|
|
|
".cycle <channel> -- Cycles <channel>." \
|
|
|
|
"If [channel] is blank the bot will cycle the " \
|
|
|
|
"channel the command was used in."
|
|
|
|
if inp:
|
|
|
|
target = inp
|
|
|
|
else:
|
|
|
|
target = chan
|
|
|
|
notice("Attempting to cycle %s..." % target)
|
|
|
|
conn.part(target)
|
|
|
|
conn.join(target)
|
2011-11-20 10:23:31 +01:00
|
|
|
|
2012-02-29 06:15:35 +01:00
|
|
|
|
2012-03-12 21:31:41 +01:00
|
|
|
@hook.command(adminonly=True)
|
2012-03-27 23:27:18 +02:00
|
|
|
def nick(inp, input=None, notice=None, conn=None):
|
2012-02-28 03:03:43 +01:00
|
|
|
".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
|
2012-03-27 23:27:18 +02:00
|
|
|
notice("Attempting to change nick to \"%s\"..." % inp)
|
|
|
|
conn.set_nick(inp)
|
2011-11-20 10:23:31 +01:00
|
|
|
|
2012-02-29 06:15:35 +01:00
|
|
|
|
2012-03-12 21:31:41 +01:00
|
|
|
@hook.command(adminonly=True)
|
2012-03-23 06:08:58 +01:00
|
|
|
def raw(inp, conn=None, notice=None):
|
2012-02-28 03:03:43 +01: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
|
|
|
|
2012-03-12 21:31:41 +01:00
|
|
|
@hook.command(adminonly=True)
|
2012-03-26 12:18:19 +02:00
|
|
|
def say(inp, conn=None, chan=None, notice=None):
|
2012-04-02 22:06:31 +02:00
|
|
|
".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] == "#":
|
2011-11-20 10:23:31 +01:00
|
|
|
message = ""
|
2012-04-02 06:30:04 +02:00
|
|
|
for x in inp[1:]:
|
2011-11-20 10:23:31 +01:00
|
|
|
message = message + x + " "
|
|
|
|
message = message[:-1]
|
2012-04-02 06:30:04 +02:00
|
|
|
out = "PRIVMSG %s :%s" % (inp[0], message)
|
2011-11-20 10:23:31 +01:00
|
|
|
else:
|
|
|
|
message = ""
|
2012-04-02 06:30:04 +02:00
|
|
|
for x in inp[0:]:
|
2011-11-20 10:23:31 +01:00
|
|
|
message = message + x + " "
|
|
|
|
message = message[:-1]
|
2012-03-26 12:18:19 +02:00
|
|
|
out = "PRIVMSG %s :%s" % (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
|
|
|
|
2012-03-31 02:07:29 +02:00
|
|
|
@hook.command("act", adminonly=True)
|
2012-03-12 21:31:41 +01:00
|
|
|
@hook.command(adminonly=True)
|
2012-03-31 02:07:29 +02:00
|
|
|
def me(inp, conn=None, chan=None, notice=None):
|
2012-04-02 22:06:31 +02:00
|
|
|
".me [channel] <action> -- Makes the bot act out <action> in [channel]. " \
|
2012-04-02 22:10:44 +02:00
|
|
|
"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]
|
2012-04-02 06:30:04 +02:00
|
|
|
out = "PRIVMSG %s :\x01ACTION %s\x01" % (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]
|
2012-03-31 02:19:47 +02:00
|
|
|
out = "PRIVMSG %s :\x01ACTION %s\x01" % (chan, message)
|
2012-03-25 04:15:11 +02:00
|
|
|
conn.send(out)
|