games.py 6.9 KB

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