from common import userstatus, queries, font from commands.common import CommandHelpers as CH def do_command(self, connection, event, user, channel): cmdtype, trigger, command, replyto = CH.disect_command(self, event) # Do nothing if it's not a type of command. if not cmdtype: return # Do nothing if there is no command. if not command: return # The first word of the command sting with arguments, is just the command without arguments. try: one = command.split()[0] except: return # The actual commands: # if command == "test": # if cmdtype == "help": #Display help text. # if len(command.split()) != 1: # return # connection.privmsg(replyto, "Strictly for testing purposes only!") # elif cmdtype == "cmd": # connection.privmsg(replyto, str(self.channels[self.homechannel].owners())) # connection.privmsg(event.source.nick, self.channels[event.target].users()) if command == 'cmd' or command == 'cmds' or command == 'commands': if len(command.split()) == 1: # No arguments. if cmdtype == 'help': #Display help text. connection.privmsg(replyto, 'Displays a list of commands, usage: %s%s%s' % (font.blue, self.network.command_character, command)) return elif cmdtype == 'cmd': connection.privmsg(replyto, '%sPublic: %s %s' % (font.grey, CH.ccc(self, "cmd"), CH.ccc(self, "help")[:-2]))# + CH.ccc(self, "away") + CH.ccc(self, "stopgreet")[:-2] + ".") if command == 'help': if cmdtype == 'help': #Display help text. if len(command.split()) != 1: return connection.privmsg(replyto, 'Explains how to get help on any specific command and hints the user to the commandlist. Example: %s%s%s' % (font.blue, self.network.command_character, command)) elif cmdtype == 'cmd': connection.privmsg(replyto, "Replace the " + font.italic + self.network.command_character + " " + font.reset + "prefix of any comand with " + font.italic + self.network.help_character + " " + font.reset + "for help with a specific command. Request the command list with: " + font.blue + self.network.command_character + "cmd") connection.privmsg(replyto, font.grey + "Example: " + font.reset + font.blue + self.network.help_character + "help") # elif one == "stopgreet": # if cmdtype == "help": #Display help text. # if len(command.split()) != 1: # return # connection.privmsg(replyto, "Stops the bot from greeting you or a specific user. Channel, user and option to resume optional.") # connection.privmsg(replyto, font.grey + "Usage: " + font.blue + "!stopgreet " + font.reset + font.italic + "resume " + font.red + "channel user") # elif cmdtype == "cmd": # # # Check for resume variation of command. # resume = False # try: # if command.split()[1] == "resume": # resume = True # command = command.split(' ', 1)[1] # Remove the resume argument. Which makes the following logic easier. # except: # pass # # if len(command.split()) == 1: # No arguments. # if event.target == connection.get_nickname(): # PM. # connection.privmsg(replyto, "Specify at least a channel. For help type " + font.blue + self.network.help_character + "stopgreet" + font.reset + ".") # return # user = event.source.nick # channel = event.target # # if len(command.split()) == 2: # One argument. # if command.split()[1] not in self.channels: # Argument is not a channel the bot inhabits. # if event.target == connection.get_nickname(): # PM. # connection.action(replyto, "does not inhabit " + font.red + command.split()[1] + font.reset + ".") # return # # Channel message # if not userstatus.atleast_halfop(self, event.source.nick, self.homechannel) and not userstatus.atleast_halfop(self, event.source.nick, event.target): # Insufficient rights. # connection.privmsg(replyto, "Denied. You need to have at least halfop status in " + font.red + self.homechannel + font.reset + " or " + font.red + event.target + font.reset + ".") # return # # Stopgreet for x user in current channel # user = command.split()[1] # channel = event.target # else: # Bot inhabit channel. # user = event.source.nick # channel = command.split()[1] # if len(command.split()) == 3: # Two arguments. # if command.split()[1] not in self.channels: # Bot does not inhabit channel. # connection.action(replyto, "does not inhabit " + font.red + command.split()[1] + font.reset + ".") # return # if not userstatus.atleast_halfop(self, event.source.nick, self.homechannel) and not userstatus.atleast_halfop(self, event.source.nick, command.split()[1]): # Insufficient rights. # connection.privmsg(replyto, "Denied. You need to have at least halfop status in " + font.red + self.homechannel + font.reset + " or " + font.red + command.split()[1] + font.reset + ".") # return # user = command.split()[2] # channel = command.split()[1] # if len(command.split()) > 3: # Too many arguments. # connection.privmsg(replyto, "Too many arguments. For help type " + font.blue + self.network.help_character + "stopgreet" + font.reset + ".") # return # # # Check for database record. # result = self.db.one("SELECT id, stopgreet FROM joins WHERE LOWER(\"user\")=LOWER('" + user + "') AND user_network='" + self.network + "' AND LOWER(channel)=LOWER('" + channel + "') AND channel_network='" + self.network + "'") # if not result: # No record in database. # connection.action(replyto, "has not yet had the pleasure of greeting " + font.red + user + font.reset + " in " + font.red + channel + font.reset + ".") # return # # if resume: # stopgreet = False # message = "has already every intention to greet " # else: # stopgreet = True # message = "has already stopped greeting " # if result[1] == stopgreet: # connection.action(replyto, message + font.red + user + font.reset + " in " + font.red + channel + font.reset + ".") # return # print(str(stopgreet) + str(user) + str(channel)) # try: # self.db.run("UPDATE joins SET stopgreet='" + str(stopgreet) + "' WHERE LOWER(\"user\")=LOWER('" + user + "') AND user_network='" + self.network + "' AND lower(channel)=LOWER('" + channel + "') AND channel_network='" + self.network + "'") # except: # connection.privmsg(replyto, "Failed to update database.") # # elif one == "away": # if cmdtype == "help": #Display help text. # if len(command.split()) != 1: # return # connection.privmsg(replyto, "Sets you away, optionally with reason. This affects the !seen command and the game.") # connection.privmsg(replyto, font.grey + "Usage: " + font.blue + "!away " + font.reset + font.italic + "reason") # # elif cmdtype == "cmd": # queries.create_ifnot_onrecord(self, "users", event.source.nick) # if len(trigger.split()) == 1: # self.db.run("UPDATE users SET away=TRUE, away_reason=NULL WHERE name='" + event.source.nick + "' AND network='" + self.network + "'") # else: # self.db.run("UPDATE users SET away=TRUE, away_reason=%s WHERE name='" + event.source.nick + "' AND network='" + self.network + "'", (trigger.split(maxsplit=1)[1], ))