games.py 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. import random
  2. from commands.common import CommandHelpers as CH
  3. from commands.common import GameHelpers
  4. bold = "\x02"
  5. italic = "\x1D"
  6. underline = "\x1F"
  7. reverse = "\x16" # swap background and foreground colors ("reverse video")
  8. reset = "\x0F"
  9. blue = "\x0302"
  10. green = "\x0303"
  11. red = "\x0304"
  12. grey = "\x0314"
  13. def do_command(self, connection, event):
  14. cmdtype, trigger, command, replyto = CH.disect_command(self, event)
  15. if not command: # Do nothing if there is no command.
  16. return
  17. if command == "cmd" or command == "commands":
  18. if cmdtype == "cmd":
  19. connection.privmsg(replyto, grey + "Games: " + CH.ccc(self, "8ball") + CH.ccc(self, "dice")[:-2] + ".")
  20. elif command.split()[0] == "8ball":
  21. if cmdtype == "help": #Display help text.
  22. connection.privmsg(replyto, "Ask a question of the mighty and illusive 8-Ball.")
  23. connection.privmsg(replyto, grey + "Usage: " + blue + "!8ball " + reset + italic + "question")
  24. elif cmdtype == "cmd":
  25. if len(command.split()) < 2: # Command contains only !8ball.
  26. messages = [
  27. "Don't forget to ask a question...",
  28. "Hey, that's not a question!",
  29. "What would you like to know?",
  30. "You want me to predict nothing?",
  31. "Are you intentionally not asking a question?",
  32. "Ask a question you tease!",
  33. "You do not seem to grasp this, for help type: " + blue + self.helpchar + "8ball",
  34. "You will die alone.",
  35. ]
  36. connection.privmsg(replyto, random.choice(messages))
  37. else:
  38. messages = [
  39. "Yes.",
  40. "No.",
  41. "Affirmative.",
  42. "No way!",
  43. "Negative.",
  44. "Positive.",
  45. "Correct.",
  46. "Incorrect.",
  47. "Likely",
  48. "Unlikely",
  49. "Maybe.",
  50. "Definately!",
  51. "Perhaps?",
  52. "Most indubitably.",
  53. "Does the pope shit in the woods?",
  54. "When hell freezes over.",
  55. "Only between 9 and 5.",
  56. "Only just before you die.",
  57. red + bold + "ERROR: " + bold + "probability failure.",
  58. "Ask again later.",
  59. "I don't know.",
  60. "Unpredictable.",
  61. ]
  62. connection.privmsg(replyto, random.choice(messages))
  63. elif command.split()[0] == "dice":
  64. if cmdtype == "help": #Display help text.
  65. if len(command.split()) is not 1:
  66. return
  67. connection.privmsg(replyto, "Rolls multiple dices of chosen type. Specifying type or amount is optional.")
  68. connection.privmsg(replyto, grey + "Usage: " + blue + "!dice " + reset + italic + "amount type")
  69. connection.privmsg(replyto, grey + "Example: " + blue + "!dice " + reset + italic + "2 d10")
  70. connection.privmsg(replyto, grey + "Note: " + reset + "The dice type is specified as a " + italic + "d " + reset + "followed by the amount of sides.")
  71. elif cmdtype == "cmd":
  72. arguments = len(command.split()) - 1
  73. if arguments == 0:
  74. connection.privmsg(replyto, str(random.randint(1, 6)) + " & " + str(random.randint(1, 6)) + ".")
  75. elif arguments == 1:
  76. try:
  77. diceamount = int(command.split()[1])
  78. except ValueError: # Argument is not an integer.
  79. if command.split()[1].startswith("d"): # Specific dice type.
  80. try:
  81. dicetype = int(command.split()[1][1:])
  82. except ValueError: # "d" not followd by interger.
  83. connection.privmsg(replyto, "Invalid number or type of dice. For help type: " + blue + self.helpchar + "dice" + reset + ".")
  84. return
  85. if dicetype == 0 :
  86. connection.action(replyto, "can not create objects with less then one side.")
  87. else:
  88. connection.privmsg(replyto, str(GameHelpers.roll_dice(1, dicetype)[0]))
  89. else: # Argument does not start with "d" and is not an integer.
  90. connection.privmsg(replyto, "Invalid number or type of dice. For help type: " + blue + self.helpchar + "dice" + reset + ".")
  91. return
  92. if diceamount == 0:
  93. connection.privmsg(replyto, "Rolling " + bold + "no " + reset + "dice.")
  94. else:
  95. connection.privmsg(replyto, ", ".join(str(rolls) for rolls in GameHelpers.roll_dice(diceamount, 6)) + ".") # Roll x amount of dice.
  96. elif arguments == 2:
  97. try:
  98. diceamount = int(command.split()[1])
  99. except ValueError: # First argument not an integer.
  100. connection.privmsg(replyto, "Invalid number of dice. For help type: " + blue + self.helpchar + "dice" + reset + ".")
  101. return
  102. try:
  103. dicetype = int(command.split()[2][1:])
  104. except ValueError: # Second argument not a dice type.
  105. connection.privmsg(replyto, "Invalid type of dice. For help type: " + blue + self.helpchar + "dice" + reset + ".")
  106. return
  107. if diceamount == 0:
  108. connection.privmsg(replyto, "Rolling " + bold + "no " + reset + "dice.")
  109. elif dicetype == 0 :
  110. connection.action(replyto, "can not create objects with less then one side.")
  111. else:
  112. connection.privmsg(replyto, ", ".join(str(rolls) for rolls in GameHelpers.roll_dice(diceamount, dicetype)) + ".") # Roll x amount of x type dice.
  113. else: # Invalid amount of arguments.
  114. connection.privmsg(replyto, "Too many arguments. For help type: " + blue + self.helpchar + "dice" + reset + ".")