|
|
@@ -12,14 +12,14 @@ grey = "\x0314"
|
|
|
|
|
|
def do_command(self, connection, event):
|
|
|
cmdtype, trigger, command, replyto = CH.disect_command(self, event)
|
|
|
- if not command: # Do nothing if there is no command.
|
|
|
- return
|
|
|
-
|
|
|
+ if not command:
|
|
|
+ return # Do nothing if there is no command.
|
|
|
+
|
|
|
# Ignore channel commands from users that do not have at least voice in homechannel or operator status in target channel.
|
|
|
if event.type == "pubmsg": # It's a channel message.
|
|
|
- if not self.channels[self.homechannel].is_owner(event.source.nick) and not self.channels[self.homechannel].is_admin(event.source.nick) and not self.channels[self.homechannel].is_oper(event.source.nick) and not self.channels[event.target].is_owner(event.source.nick) and not self.channels[event.target].is_admin(event.source.nick) and not self.channels[event.target].is_oper(event.source.nick): # Does not have at least voiced status in homechannel or operator status in target channel.
|
|
|
+ if not userstatus.atleast_oper(self, event.source.nick, self.homechannel) and not userstatus.atleast_oper(self, event.source.nick, event.target): # Does not have at least voiced status in homechannel or operator status in target channel.
|
|
|
return
|
|
|
-
|
|
|
+
|
|
|
if command == "cmd" or command == "commands":
|
|
|
if cmdtype == "cmd":
|
|
|
message = grey + "Admin: "
|
|
|
@@ -43,59 +43,50 @@ def do_command(self, connection, event):
|
|
|
return
|
|
|
connection.privmsg(replyto, message[:-2] + ".")
|
|
|
|
|
|
- elif command.split()[0] == "channelfunctions":
|
|
|
- if cmdtype == "help": #Display help text. # Help code block first, as it is impossible to predict for what channel a later command is going to be issued. Rights filtering after help test.
|
|
|
+ elif command.split()[0] == "die":
|
|
|
+ if not userstatus.atleast_admin(self, event.source.nick, self.homechannel):
|
|
|
+ connection.privmsg(replyto, "Denied, you need to have admin (super operator) status or higher in " + red + self.homechannel + reset + ".")
|
|
|
+ return
|
|
|
+ if cmdtype == "help": # Display help text.
|
|
|
if len(command.split()) is not 1:
|
|
|
return
|
|
|
- connection.privmsg(replyto, "Display or toggle the status channel functions. Channel, function and value optional.")
|
|
|
- connection.privmsg(replyto, grey + "Usage: " + blue + "!channelfunctions " + red + italic + "channel " + reset + italic + "function value")
|
|
|
+ connection.privmsg(replyto, "Kill " + connection.get_nickname() + ". Optionally with reason.")
|
|
|
+ connection.privmsg(replyto, grey + "Usage: " + blue + "!die " + reset + italic + "reason")
|
|
|
elif cmdtype == "cmd":
|
|
|
- if len(command.split()) == 1: # No arguments.
|
|
|
- if event.target == connection.get_nickname(): # Command issued via PM.
|
|
|
- connection.privmsg(replyto, "Nothing to display, Specify a channel.")
|
|
|
- else: # Command issued as channel message.
|
|
|
- message = CH.get_channelfunctions(self, event.target)
|
|
|
- connection.privmsg(replyto, message)
|
|
|
- elif len(command.split()) == 2: # One argument.
|
|
|
- if command.split()[1] in self.channels: # Info requested on specific channel.
|
|
|
- message = CH.get_channelfunctions(self, command.split()[1])
|
|
|
- connection.privmsg(replyto, message)
|
|
|
- else: # First argument is not a channel the bot inhabits.
|
|
|
- connection.privmsg(replyto, command.split()[1] + " is not a channel I inhabit. For help type " + blue + self.helpchar + "channelfunctions" + reset + ".")
|
|
|
- elif len(command.split()) == 3: # Two arguments.
|
|
|
- if event.target == connection.get_nickname(): # Command issued via PM.
|
|
|
- connection.privmsg(replyto, "One or three arguments required. For help type " + blue + self.helpchar + "channelfunctions" + reset + ".")
|
|
|
- else: # Command issued via channel.
|
|
|
- if not CH.is_channelfunction(self, command.split()[1]): # First argument is not a channelfunction.
|
|
|
- connection.privmsg(replyto, command.split()[1] + " is not a channel function. For help type " + blue + self.helpchar + "channelfunctions" + reset + ".")
|
|
|
- return
|
|
|
- if not command.split()[2].lower() in ["on", "off"]: # Second argument is not "on" or "off".
|
|
|
- connection.privmsg(replyto, "The value of this channel function can only be \"on\" or \"off\". For help type " + blue + self.helpchar + "channelfunctions" + reset + ".")
|
|
|
- return
|
|
|
- if not self.channels[self.homechannel].is_owner(event.source.nick) and not self.channels[self.homechannel].is_admin(event.source.nick) and not self.channels[self.homechannel].is_oper(event.source.nick) and not self.channels[event.target].is_owner(event.source.nick) and not self.channels[event.target].is_admin(event.source.nick) and not self.channels[event.target].is_oper(event.source.nick): # Does not have operator status or higher in target or home channel.
|
|
|
- connection.privmsg(replyto, "Denied. You need to have at least operator status in " + red + event.target + reset + " or " + red + self.homechannel + reset + ".")
|
|
|
- return
|
|
|
- self.db.run("UPDATE channels SET " + command.split()[1] + "='" + command.split()[2].lower() + "' WHERE name='" + event.target + "' AND network='" + self.network + "'")
|
|
|
- elif len(command.split()) == 4: # Three arguments.
|
|
|
- if not command.split()[1] in self.channels: # Bot does not inhabit channel to be altered.
|
|
|
- connection.privmsg(replyto, command.split()[1] + " is not a channel I inhabit. For help type " + blue + self.helpchar + "channelfunctions" + reset + ".")
|
|
|
- return
|
|
|
- if not CH.is_channelfunction(self, command.split()[2]): # Function does not exist.
|
|
|
- connection.privmsg(replyto, command.split()[2] + " is not a valid channel function. For a list help type: " + blue + self.cmdchar + "channelfunctions" + red + italic + "channel")
|
|
|
- return
|
|
|
- if not command.split()[3] in ["on", "off"]: # Third argument is not "on" or "off".
|
|
|
- connection.privmsg(replyto, "The value of this channel function can only be \"on\" or \"off\". For help type " + blue + self.helpchar + "channelfunctions" + reset + ".")
|
|
|
- return
|
|
|
- if not self.channels[self.homechannel].is_owner(event.source.nick) and not self.channels[self.homechannel].is_admin(event.source.nick) and not self.channels[self.homechannel].is_oper(event.source.nick) and not self.channels[command.split()[1]].is_owner(event.source.nick) and not self.channels[command.split()[1]].is_admin(event.source.nick) and not self.channels[command.split()[1]].is_oper(event.source.nick): # Does not have operator status or higher in target or home channel.
|
|
|
- connection.privmsg(replyto, "Denied. You need to have at least operator status in " + red + event.target + reset + " or " + red + self.homechannel + reset + ".")
|
|
|
- return
|
|
|
- try:
|
|
|
- self.db.run("UPDATE channels SET " + command.split()[2] + "='" + command.split()[3] + "' WHERE name='" + command.split()[1] + "' AND network='" + self.network + "'")
|
|
|
- except:
|
|
|
- connection.privmsg(replyto, "Error, database record not updated.")
|
|
|
- return
|
|
|
+ if len(command.split()) == 1:
|
|
|
+ self.die(msg = "Killed by " + event.source.nick)
|
|
|
else:
|
|
|
- connection.privmsg(replyto, "Too many arguments. For help type " + blue + self.helpchar + "channelfunctions" + reset + ".")
|
|
|
+ self.die(msg = "[" + event.source.nick + "] " + command.split(maxsplit=1)[1])
|
|
|
+
|
|
|
+ elif command.split()[0] == "reconnect":
|
|
|
+ if not self.channels[self.homechannel].is_owner(event.source.nick) and not self.channels[self.homechannel].is_admin(event.source.nick) and not self.channels[self.homechannel].is_oper(event.source.nick):
|
|
|
+ connection.privmsg(replyto, "Denied, you need to have operator status or higher in " + red + self.homechannel + reset + ".")
|
|
|
+ return
|
|
|
+ if cmdtype == "help": # Display help text.
|
|
|
+ if len(command.split()) is not 1:
|
|
|
+ return
|
|
|
+ connection.privmsg(replyto, "Reconnect " + connection.get_nickname() + ". Reason optional.")
|
|
|
+ connection.privmsg(replyto, grey + "Usage: " + blue + "!reconnect " + reset + italic + "reason")
|
|
|
+ elif cmdtype == "cmd":
|
|
|
+ if len(command.split()) == 1:
|
|
|
+ self.disconnect(msg = "Reconnect requested by " + event.source.nick)
|
|
|
+ else:
|
|
|
+ self.disconnect(msg = "[" + event.source.nick + "] " + command.split(maxsplit=1)[1])
|
|
|
+
|
|
|
+ elif command.split()[0] == "recovernick":
|
|
|
+ if not userstatus.atleast_voiced(self, event.source.nick, self.homechannel):
|
|
|
+ connection.privmsg(replyto, "Denied, you need to have voiced status or higher in " + red + self.homechannel + reset + ".")
|
|
|
+ return
|
|
|
+ if cmdtype == "help": # Display help text.
|
|
|
+ if len(command.split()) is not 1:
|
|
|
+ return
|
|
|
+ connection.privmsg(replyto, "Let " + connection.get_nickname() + " try to recover " + connection.nickname + " as nickname.")
|
|
|
+ elif cmdtype == "cmd":
|
|
|
+ if connection.get_nickname() == connection.nickname:
|
|
|
+ connection.action(replyto, "is already named " + red + connection.nickname + reset + ".")
|
|
|
+ return
|
|
|
+ from common.networkservices import NickServ
|
|
|
+ NickServ.recover_nick(connection, self.password)
|
|
|
|
|
|
elif command.split()[0] == "join":
|
|
|
if not userstatus.atleast_oper(self, event.source.nick, self.homechannel):
|
|
|
@@ -128,14 +119,11 @@ def do_command(self, connection, event):
|
|
|
connection.privmsg(replyto, grey + "Usage: " + blue + self.cmdchar + "join " + red + italic + "channel " + reset + italic + "password")
|
|
|
elif cmdtype == "cmd":
|
|
|
|
|
|
- if self.channels[self.homechannel].is_owner(event.source.nick) or self.channels[self.homechannel].is_admin(event.source.nick) or self.channels[self.homechannel].is_oper(event.source.nick): # Is at least operator in home channel.
|
|
|
+ if userstatus.atleast_oper(self, event.source.nick, self.homechannel): # Is at least operator in home channel.
|
|
|
homeadmin = True
|
|
|
|
|
|
- try:
|
|
|
- if self.channels[event.target].is_owner(event.source.nick) or self.channels[event.target].is_admin(event.source.nick) or self.channels[event.target].is_oper(event.source.nick):
|
|
|
- targetadmin = True
|
|
|
- except:
|
|
|
- pass
|
|
|
+ if userstatus.atleast_oper(self, event.source.nick, event.target):
|
|
|
+ targetadmin = True
|
|
|
|
|
|
if len(command.split()) == 1: # No arguments.
|
|
|
if event.target in self.channels: # It's a channel message.
|
|
|
@@ -152,7 +140,7 @@ def do_command(self, connection, event):
|
|
|
if command.split()[1] not in self.channels: # First argument is not a channel the bot inhabits.
|
|
|
connection.action(replyto, "does not inhabit " + red + command.split()[1] + reset + ". For help type " + blue + self.helpchar + "part" + reset + ".")
|
|
|
return
|
|
|
- if not homeadmin and not self.channels[command.split()[1]].is_owner(event.source.nick) and not self.channels[command.split()[1]].is_admin(event.source.nick) and not self.channels[command.split()[1]].is_oper(event.source.nick): # Insufficient rights.
|
|
|
+ if not homeadmin and not userstatus.atleast_oper(self, event.source.nick, command.split()[1]): # Insufficient rights.
|
|
|
connection.privmsg(replyto, "Denied. You need to have at least operator status in " + red + self.homechan + reset + " or " + red + command.split()[1] + reset + ".")
|
|
|
return
|
|
|
if command.split()[1] == self.homechannel:
|
|
|
@@ -163,51 +151,6 @@ def do_command(self, connection, event):
|
|
|
except:
|
|
|
connection.part(command.split()[1], event.source.nick)
|
|
|
|
|
|
- elif command.split()[0] == "die":
|
|
|
- if not self.channels[self.homechannel].is_owner(event.source.nick) and not self.channels[self.homechannel].is_admin(event.source.nick):
|
|
|
- connection.privmsg(replyto, "Denied, you need to have admin (super operator) status or higher in " + red + self.homechannel + reset + ".")
|
|
|
- return
|
|
|
- if cmdtype == "help": # Display help text.
|
|
|
- if len(command.split()) is not 1:
|
|
|
- return
|
|
|
- connection.privmsg(replyto, "Kill " + connection.get_nickname() + ". Optionally with reason.")
|
|
|
- connection.privmsg(replyto, grey + "Usage: " + blue + "!die " + reset + italic + "reason")
|
|
|
- elif cmdtype == "cmd":
|
|
|
- if len(command.split()) == 1:
|
|
|
- self.die(msg = "Killed by " + event.source.nick)
|
|
|
- else:
|
|
|
- self.die(msg = "[" + event.source.nick + "] " + command.split(maxsplit=1)[1])
|
|
|
-
|
|
|
- elif command.split()[0] == "reconnect":
|
|
|
- if not self.channels[self.homechannel].is_owner(event.source.nick) and not self.channels[self.homechannel].is_admin(event.source.nick) and not self.channels[self.homechannel].is_oper(event.source.nick):
|
|
|
- connection.privmsg(replyto, "Denied, you need to have operator status or higher in " + red + self.homechannel + reset + ".")
|
|
|
- return
|
|
|
- if cmdtype == "help": # Display help text.
|
|
|
- if len(command.split()) is not 1:
|
|
|
- return
|
|
|
- connection.privmsg(replyto, "Reconnect " + connection.get_nickname() + ". Reason optional.")
|
|
|
- connection.privmsg(replyto, grey + "Usage: " + blue + "!reconnect " + reset + italic + "reason")
|
|
|
- elif cmdtype == "cmd":
|
|
|
- if len(command.split()) == 1:
|
|
|
- self.disconnect(msg = "Reconnect requested by " + event.source.nick)
|
|
|
- else:
|
|
|
- self.disconnect(msg = "[" + event.source.nick + "] " + command.split(maxsplit=1)[1])
|
|
|
-
|
|
|
- elif command.split()[0] == "recovernick":
|
|
|
- if not self.channels[self.homechannel].is_owner(event.source.nick) and not self.channels[self.homechannel].is_admin(event.source.nick) and not self.channels[self.homechannel].is_oper(event.source.nick) and not self.channels[self.homechannel].is_halfop(event.source.nick) and not self.channels[self.homechannel].is_voiced(event.source.nick):
|
|
|
- connection.privmsg(replyto, "Denied, you need to have voiced status or higher in " + red + self.homechannel + reset + ".")
|
|
|
- return
|
|
|
- if cmdtype == "help": # Display help text.
|
|
|
- if len(command.split()) is not 1:
|
|
|
- return
|
|
|
- connection.privmsg(replyto, "Let " + connection.get_nickname() + " try to recover " + connection.nickname + " as nickname.")
|
|
|
- elif cmdtype == "cmd":
|
|
|
- if connection.get_nickname() == connection.nickname:
|
|
|
- connection.action(replyto, "is already named " + red + connection.nickname + reset + ".")
|
|
|
- return
|
|
|
- from common.networkservices import NickServ
|
|
|
- NickServ.recover_nick(connection, self.password)
|
|
|
-
|
|
|
elif command.split()[0] == "msg" or command.split(maxsplit=1)[0] == "act":
|
|
|
if cmdtype == "help": #Display help text.
|
|
|
if len(command.split()) is not 1:
|
|
|
@@ -249,7 +192,7 @@ def do_command(self, connection, event):
|
|
|
connection.action(replyto, "does not inhabit " + red + destination + reset + ".")
|
|
|
|
|
|
# Send message if user has at least operator status the home channel or the channel the message is intended for.
|
|
|
- elif self.channels[self.homechannel].is_owner(event.source.nick) or self.channels[self.homechannel].is_admin(event.source.nick) or self.channels[self.homechannel].is_oper(event.source.nick) or self.channels[destination].is_owner(event.source.nick) or self.channels[destination].is_admin(event.source.nick) or self.channels[destination].is_oper(event.source.nick):
|
|
|
+ elif userstatus.atleast_oper(self, event.source.nick, self.homechannel) or userstatus.atleast_oper(self, event.source.nick, destination):
|
|
|
if command.split(maxsplit=1)[0] == "act":
|
|
|
connection.action(destination, message)
|
|
|
else:
|
|
|
@@ -258,3 +201,57 @@ def do_command(self, connection, event):
|
|
|
# Reply error if user is not operator of destination channel.
|
|
|
else:
|
|
|
connection.privmsg(replyto, "Denied, you need to be an operator of " + red + destination + reset +".")
|
|
|
+
|
|
|
+ elif command.split()[0] == "channelfunctions":
|
|
|
+ if cmdtype == "help": #Display help text. # Help code block first, as it is impossible to predict for what channel a later command is going to be issued. Rights filtering after help test.
|
|
|
+ if len(command.split()) is not 1:
|
|
|
+ return
|
|
|
+ connection.privmsg(replyto, "Display or toggle the status channel functions. Channel, function and value optional.")
|
|
|
+ connection.privmsg(replyto, grey + "Usage: " + blue + "!channelfunctions " + red + italic + "channel " + reset + italic + "function value")
|
|
|
+ elif cmdtype == "cmd":
|
|
|
+ if len(command.split()) == 1: # No arguments.
|
|
|
+ if event.target == connection.get_nickname(): # Command issued via PM.
|
|
|
+ connection.privmsg(replyto, "Nothing to display, Specify a channel.")
|
|
|
+ else: # Command issued as channel message.
|
|
|
+ message = CH.get_channelfunctions(self, event.target)
|
|
|
+ connection.privmsg(replyto, message)
|
|
|
+ elif len(command.split()) == 2: # One argument.
|
|
|
+ if command.split()[1] in self.channels: # Info requested on specific channel.
|
|
|
+ message = CH.get_channelfunctions(self, command.split()[1])
|
|
|
+ connection.privmsg(replyto, message)
|
|
|
+ else: # First argument is not a channel the bot inhabits.
|
|
|
+ connection.privmsg(replyto, command.split()[1] + " is not a channel I inhabit. For help type " + blue + self.helpchar + "channelfunctions" + reset + ".")
|
|
|
+ elif len(command.split()) == 3: # Two arguments.
|
|
|
+ if event.target == connection.get_nickname(): # Command issued via PM.
|
|
|
+ connection.privmsg(replyto, "One or three arguments required. For help type " + blue + self.helpchar + "channelfunctions" + reset + ".")
|
|
|
+ else: # Command issued via channel.
|
|
|
+ if not CH.is_channelfunction(self, command.split()[1]): # First argument is not a channelfunction.
|
|
|
+ connection.privmsg(replyto, command.split()[1] + " is not a channel function. For help type " + blue + self.helpchar + "channelfunctions" + reset + ".")
|
|
|
+ return
|
|
|
+ if not command.split()[2].lower() in ["on", "off"] and not command.split()[1].lower() == "aggressiveness": # Second argument unsupported.
|
|
|
+ connection.privmsg(replyto, "The value of this channel function can only be \"on\" or \"off\". For help type " + blue + self.helpchar + "channelfunctions" + reset + ".")
|
|
|
+ return
|
|
|
+ if not userstatus.atleast_oper(self, event.source.nick, self.homechannel) and not userstatus.atleast_oper(self, event.source.nick, event.target): # Does not have operator status or higher in target or home channel.
|
|
|
+ connection.privmsg(replyto, "Denied. You need to have at least operator status in " + red + event.target + reset + " or " + red + self.homechannel + reset + ".")
|
|
|
+ return
|
|
|
+ self.db.run("UPDATE channels SET " + command.split()[1].lower() + "='" + command.split()[2].lower() + "' WHERE name='" + event.target + "' AND network='" + self.network + "'")
|
|
|
+ elif len(command.split()) == 4: # Three arguments.
|
|
|
+ if not command.split()[1] in self.channels: # Bot does not inhabit channel to be altered.
|
|
|
+ connection.privmsg(replyto, command.split()[1] + " is not a channel I inhabit. For help type " + blue + self.helpchar + "channelfunctions" + reset + ".")
|
|
|
+ return
|
|
|
+ if not CH.is_channelfunction(self, command.split()[2]): # Function does not exist.
|
|
|
+ connection.privmsg(replyto, command.split()[2] + " is not a valid channel function. For a list help type: " + blue + self.cmdchar + "channelfunctions" + red + italic + "channel")
|
|
|
+ return
|
|
|
+ if not command.split()[3].lower() in ["on", "off"] and not command.split()[2].lower() == "aggressiveness": # Third argument unsupported.
|
|
|
+ connection.privmsg(replyto, "The value of this channel function can only be \"on\" or \"off\". For help type " + blue + self.helpchar + "channelfunctions" + reset + ".")
|
|
|
+ return
|
|
|
+ if not userstatus.atleast_oper(self, event.source.nick, self.homechannel) and not userstatus.atleast_oper(self, event.source.nick, command.split()[1]): # Does not have operator status or higher in target or home channel.
|
|
|
+ connection.privmsg(replyto, "Denied. You need to have at least operator status in " + red + event.target + reset + " or " + red + self.homechannel + reset + ".")
|
|
|
+ return
|
|
|
+ try:
|
|
|
+ self.db.run("UPDATE channels SET " + command.split()[2].lower() + "='" + command.split()[3].lower() + "' WHERE LOWER(name)=LOWER('" + command.split()[1] + "') AND network='" + self.network + "'")
|
|
|
+ except:
|
|
|
+ connection.privmsg(replyto, "Error, database record not updated.")
|
|
|
+ return
|
|
|
+ else:
|
|
|
+ connection.privmsg(replyto, "Too many arguments. For help type " + blue + self.helpchar + "channelfunctions" + reset + ".")
|