import random from commands.common import CommandHelpers as CH from commands.common import GameHelpers 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) if not command: # Do nothing if there is no command. return if command == "cmd" or command == "commands": if cmdtype == "cmd": connection.privmsg(replyto, grey + "Games: " + CH.ccc(self, "8ball") + CH.ccc(self, "dice")[:-2] + ".") elif command.split()[0] == "8ball": if cmdtype == "help": #Display help text. connection.privmsg(replyto, "Ask a question of the mighty and illusive 8-Ball.") connection.privmsg(replyto, grey + "Usage: " + blue + "!8ball " + reset + italic + "question") elif cmdtype == "cmd": if len(command.split()) < 2: # Command contains only !8ball. messages = [ "Don't forget to ask a question...", "Hey, that's not a question!", "What would you like to know?", "You want me to predict nothing?", "Are you intentionally not asking a question?", "Ask a question you tease!", "You do not seem to grasp this, for help type: " + blue + self.helpchar + "8ball", "You will die alone.", ] connection.privmsg(replyto, random.choice(messages)) else: messages = [ "Yes.", "No.", "Affirmative.", "No way!", "Negative.", "Positive.", "Correct.", "Incorrect.", "Likely", "Unlikely", "Maybe.", "Definately!", "Perhaps?", "Most indubitably.", "Does the pope shit in the woods?", "When hell freezes over.", "Only between 9 and 5.", "Only just before you die.", red + bold + "ERROR: " + bold + "probability failure.", "Ask again later.", "I don't know.", "Unpredictable.", ] connection.privmsg(replyto, random.choice(messages)) elif command.split()[0] == "dice": if cmdtype == "help": #Display help text. if len(command.split()) is not 1: return connection.privmsg(replyto, "Rolls multiple dices of chosen type. Specifying type or amount is optional.") connection.privmsg(replyto, grey + "Usage: " + blue + "!dice " + reset + italic + "amount type") connection.privmsg(replyto, grey + "Example: " + blue + "!dice " + reset + italic + "2 d10") connection.privmsg(replyto, grey + "Note: " + reset + "The dice type is specified as a " + italic + "d " + reset + "followed by the amount of sides.") elif cmdtype == "cmd": arguments = len(command.split()) - 1 if arguments == 0: connection.privmsg(replyto, str(random.randint(1, 6)) + " & " + str(random.randint(1, 6)) + ".") elif arguments == 1: try: diceamount = int(command.split()[1]) except ValueError: # Argument is not an integer. if command.split()[1].startswith("d"): # Specific dice type. try: dicetype = int(command.split()[1][1:]) except ValueError: # "d" not followd by interger. connection.privmsg(replyto, "Invalid number or type of dice. For help type: " + blue + self.helpchar + "dice" + reset + ".") return if dicetype == 0 : connection.action(replyto, "can not create objects with less then one side.") else: connection.privmsg(replyto, str(GameHelpers.roll_dice(1, dicetype)[0])) else: # Argument does not start with "d" and is not an integer. connection.privmsg(replyto, "Invalid number or type of dice. For help type: " + blue + self.helpchar + "dice" + reset + ".") return if diceamount == 0: connection.privmsg(replyto, "Rolling " + bold + "no " + reset + "dice.") else: connection.privmsg(replyto, ", ".join(str(rolls) for rolls in GameHelpers.roll_dice(diceamount, 6)) + ".") # Roll x amount of dice. elif arguments == 2: try: diceamount = int(command.split()[1]) except ValueError: # First argument not an integer. connection.privmsg(replyto, "Invalid number of dice. For help type: " + blue + self.helpchar + "dice" + reset + ".") return try: dicetype = int(command.split()[2][1:]) except ValueError: # Second argument not a dice type. connection.privmsg(replyto, "Invalid type of dice. For help type: " + blue + self.helpchar + "dice" + reset + ".") return if diceamount == 0: connection.privmsg(replyto, "Rolling " + bold + "no " + reset + "dice.") elif dicetype == 0 : connection.action(replyto, "can not create objects with less then one side.") else: connection.privmsg(replyto, ", ".join(str(rolls) for rolls in GameHelpers.roll_dice(diceamount, dicetype)) + ".") # Roll x amount of x type dice. else: # Invalid amount of arguments. connection.privmsg(replyto, "Too many arguments. For help type: " + blue + self.helpchar + "dice" + reset + ".")