games.py 6.1 KB

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