Started tidying up admin.py

This commit is contained in:
Luke Rogers 2012-02-20 07:10:57 +13:00
parent 7c1fd68948
commit e357ae1c94

View file

@ -2,10 +2,15 @@
# Broken by The Noodle # Broken by The Noodle
from util import hook from util import hook
def isadmin(input):
if input.nick in input.bot.config["admins"]:
return True
else:
return False
@hook.command @hook.command
def join(inp, input=None, db=None, notice=None): def join(inp, input=None, db=None, notice=None):
".join <channel> -- joins a channel" ".join <channel> -- joins a channel"
if input.nick not in input.bot.config["admins"]: if not isadmin(input):
notice("Only bot admins can use this command!") notice("Only bot admins can use this command!")
return return
chan = inp.split(' ', 1) chan = inp.split(' ', 1)
@ -17,7 +22,7 @@ def join(inp, input=None, db=None, notice=None):
@hook.command @hook.command
def cycle(inp, input=None, db=None, notice=None): def cycle(inp, input=None, db=None, notice=None):
".cycle <channel> -- cycles a channel" ".cycle <channel> -- cycles a channel"
if input.nick not in input.bot.config["admins"]: if not isadmin(input):
notice("Only bot admins can use this command!") notice("Only bot admins can use this command!")
return return
notice("Attempting to cycle " + inp + "...") notice("Attempting to cycle " + inp + "...")
@ -27,7 +32,7 @@ def cycle(inp, input=None, db=None, notice=None):
@hook.command @hook.command
def part(inp, input=None, notice=None): def part(inp, input=None, notice=None):
".part <channel> -- leaves a channel" ".part <channel> -- leaves a channel"
if input.nick not in input.bot.config["admins"]: if not isadmin(input):
notice("Only bot admins can use this command!") notice("Only bot admins can use this command!")
return return
chan = inp.split(' ', 1) chan = inp.split(' ', 1)
@ -39,7 +44,7 @@ def part(inp, input=None, notice=None):
@hook.command @hook.command
def nick(inp, input=None, notice=None): def nick(inp, input=None, notice=None):
".nick <nick> -- change the bots nickname to <nick>" ".nick <nick> -- change the bots nickname to <nick>"
if input.nick not in input.bot.config["admins"]: if not isadmin(input):
notice("Only bot admins can use this command!") notice("Only bot admins can use this command!")
return return
chan = inp.split(' ', 1) chan = inp.split(' ', 1)
@ -51,7 +56,7 @@ def nick(inp, input=None, notice=None):
@hook.command @hook.command
def raw(inp, input=None, notice=None): def raw(inp, input=None, notice=None):
".raw <command> - Send a RAW IRC command!" ".raw <command> - Send a RAW IRC command!"
if input.nick not in input.bot.config["admins"]: if not isadmin(input):
notice("Only bot admins can use this command!") notice("Only bot admins can use this command!")
return return
chan = inp.split(' ', 1) chan = inp.split(' ', 1)
@ -61,80 +66,87 @@ def raw(inp, input=None, notice=None):
@hook.command @hook.command
def kick(inp, input=None, notice=None): def kick(inp, input=None, notice=None):
".kick [channel] <user> [reason] -- kick a user!" ".kick [channel] <user> [reason] -- kick a user!"
if input.nick not in input.bot.config["admins"]: if not isadmin(input):
notice("Only bot admins can use this command!") notice("Only bot admins can use this command!")
return return
stuff = inp.split(" ") split = inp.split(" ")
if stuff[0][0] == "#":
out = "KICK " + stuff[0] + " " + stuff[1] if split[0][0] == "#":
if len(stuff) > 2: chan = split[0]
user = split[1]
out = "KICK %s %s" % (chan, user)
if len(split) > 2:
reason = "" reason = ""
for x in stuff[2:]: for x in split[2:]:
reason = reason + x + " " reason = reason + x + " "
reason = reason[:-1] reason = reason[:-1]
out = out+" :"+reason out = out+" :"+reason
else: else:
out = "KICK " + input.chan + " " + stuff[0] chan = input.chan
if len(stuff) > 1: user = split[0]
out = "KICK %s %s" % (input.chan, split[0])
if len(split) > 1:
reason = "" reason = ""
for x in stuff[1:]: for x in split[1:]:
reason = reason + x + " " reason = reason + x + " "
reason = reason[:-1] reason = reason[:-1]
out = out + " :" + reason out = out + " :" + reason
notice("Attempting to kick " + inp + "...")
notice("Attempting to kick %s from %s..." % (user, chan))
input.conn.send(out) input.conn.send(out)
@hook.command @hook.command
def say(inp, input=None, notice=None): def say(inp, input=None, notice=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." ".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."
if input.nick not in input.bot.config["admins"]: if not isadmin(input):
notice("Only bot admins can use this command!") notice("Only bot admins can use this command!")
return return
stuff = inp.split(" ") split = inp.split(" ")
if stuff[0][0] == "#": if split[0][0] == "#":
message = "" message = ""
for x in stuff[1:]: for x in split[1:]:
message = message + x + " " message = message + x + " "
message = message[:-1] message = message[:-1]
out = "PRIVMSG " + stuff[0] + " :" + message out = "PRIVMSG %s :%s" % (split[0], message)
else: else:
message = "" message = ""
for x in stuff[0:]: for x in split[0:]:
message = message + x + " " message = message + x + " "
message = message[:-1] message = message[:-1]
out = "PRIVMSG " + input.chan + " :" + message out = "PRIVMSG %s :%s" % (input.chan, message)
input.conn.send(out) input.conn.send(out)
@hook.command @hook.command
def act(inp, input=None, notice=None): def act(inp, input=None, notice=None):
".act [channel] <action> -- makes the bot act <action> in [channel]. if [channel] is blank the bot will act the <action> in the channel the command was used in." ".act [channel] <action> -- makes the bot act <action> in [channel]. if [channel] is blank the bot will act the <action> in the channel the command was used in."
if input.nick not in input.bot.config["admins"]: if not isadmin(input):
notice("Only bot admins can use this command!") notice("Only bot admins can use this command!")
return return
stuff = inp.split(" ") split = inp.split(" ")
if stuff[0][0] == "#": if split[0][0] == "#":
message = "" message = ""
for x in stuff[1:]: for x in split[1:]:
message = message + x + " " message = message + x + " "
message = message[:-1] message = message[:-1]
out = "PRIVMSG " + stuff[0] + " :\x01ACTION " + message + "\x01" out = "PRIVMSG %s :\x01ACTION %s\x01" % (split[0], message)
else: else:
message = "" message = ""
for x in stuff[0:]: for x in split[0:]:
message = message + x + " " message = message + x + " "
message = message[:-1] message = message[:-1]
out = "PRIVMSG " + input.chan + " :\x01ACTION " + message + "\x01" out = "PRIVMSG %s :\x01ACTION %s\x01" % (input.chan, message)
input.conn.send(out) input.conn.send(out)
@hook.command @hook.command
def topic(inp, input=None, notice=None): def topic(inp, input=None, notice=None):
".topic [channel] <topic> -- change the topic of a channel" ".topic [channel] <topic> -- change the topic of a channel"
if input.nick not in input.bot.config["admins"]: if not isadmin(input):
notice("Only bot admins can use this command!") notice("Only bot admins can use this command!")
return return
stuff = inp.split(" ") split = inp.split(" ")
if stuff[0][0] == "#": if split[0][0] == "#":
out = "TOPIC " + stuff[0] + " :" + stuff[1] out = "PRIVMSG %s :%s" % (split[0], message)
else: else:
out = "TOPIC " + input.chan + " :" + stuff[0] out = "TOPIC %s :%s" % (input.chan, message)
input.conn.send(out) input.conn.send(out)