from commands.common import CommandHelpers as CH bold = "\x02" italic = "\x1D" underline = "\x1F" reverse = "\x16" # swap background and foreground colors ("reverse video") reset = "\x0F" blue = "\x0302" green = "\x0303" red = "\x0304" grey = "\x0314" def do_command(self, connection, event): cmdtype, trigger, command, replyto = CH.disect_command(self, event) # The actual commands: if command == "test": if cmdtype == "help": #Display help text. connection.privmsg(replyto, "Strictly for testing purposes only!") elif cmdtype == "cmd": connection.privmsg(replyto, event) elif command == "cmd" or command == "commands": if cmdtype == "help": #Display help text. connection.privmsg(replyto, "Displays a list of commands.") elif cmdtype == "cmd": connection.privmsg(replyto, grey + "Commands: " + CH.ccc(self, "cmd") + CH.ccc(self, "help") + CH.ccc(self, "joins")[:-2] + ".") elif command == "help": if cmdtype == "help": #Display help text. connection.privmsg(replyto, "Explains how to get help on any specific command and hints the user to the commandlist.") elif cmdtype == "cmd": connection.privmsg(replyto, "Replace the " + italic + "! " + reset + "prefix of any comand with " + italic + self.helpchar + " " + reset + "for help with a specific command. Request the command list with: " + blue + "!cmd") connection.privmsg(replyto, grey + "Example: " + reset + blue + self.helpchar + "help") elif command.split()[0] == "joins": if cmdtype == "help": #Display help text. connection.privmsg(replyto, "Display amount of joins of user and or channel. Channel and user optional.") connection.privmsg(replyto, grey + "Usage: " + blue + "!joins " + reset + italic + "channel user") elif cmdtype == "cmd": # Parse user input if len(command.split()) < 2: # Command contains only !joins. user = event.source.nick if connection.get_nickname() is not event.target: channel = event.target elif len(command.split()) < 3: # Command has one argument. if command.split()[1] in self.channels: channel = command.split()[1] else: user = command.split()[1] elif len(command.split()) < 4: # Command has two arguments. if not command.split()[1] in self.channels: # Bot does not inhabit requested channel. if not command.split()[2] in self.channels: # User did not revert channel and user in command syntax. connection.action(replyto, "does not inhabit " + red + command.split()[1] + reset + ".") return else: # User reverted user and channel in command syntax. user = command.split()[1] channel = command.split()[2] else: # Bot does inhabit requested channel. user = command.split()[2] channel = command.split()[1] elif len(command.split()) < 5: # To many arguments connection.privmsg(replyto, "To many arguments. For help type " + blue + self.helpchar + "joins" + reset + ".") return try: if user and channel: userjoins = str(self.db.one("SELECT joins FROM joins WHERE channel_network='" + self.network + "' AND \"user\"='" + user + "' AND user_network='" + self.network + "'")) userchanneljoins = str(self.db.one("SELECT joins FROM joins WHERE channel='" + channel + "' AND channel_network='" + self.network + "' AND \"user\"='" + user + "' AND user_network='" + self.network + "'")) channeljoins = str(sum(self.db.all("SELECT joins FROM joins WHERE channel='" + channel + "' AND channel_network='" + self.network + "' AND user_network='" + self.network + "'"))) connection.privmsg(replyto, red + user + reset + " has " + green + userjoins + reset + " joins. Of which " + green + userchanneljoins + reset + " have been in " + red + channel + reset + ", that has " + green + channeljoins + reset + " joins" + reset + " in total.") return except: pass try: if user: userjoins = str(self.db.one("SELECT joins FROM joins WHERE channel='" + event.target + "' AND channel_network='" + self.network + "' AND \"user\"='" + event.source.nick + "' AND user_network='" + self.network + "'")) connection.privmsg(replyto, red + user + reset + " has " + green + userjoins + reset + " joins in channels I monitor.") return except: pass try: if channel: channeljoins = str(sum(self.db.all("SELECT joins FROM joins WHERE channel='" + channel + "' AND channel_network='" + self.network + "' AND user_network='" + self.network + "'"))) connection.privmsg(replyto, red + channel + reset + " has been joined " + green + channeljoins + reset + " times.") return except: pass connection.privmsg(replyto, "tBKwtWS Was wondering if this programming was sloppy. When you see this message, it was.")