games.py 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. from discord.ext import commands
  2. import discord
  3. import random
  4. from typing import Optional
  5. def setup(bot: commands.Bot):
  6. bot.add_cog(Games(bot))
  7. class Games(commands.Cog):
  8. """Gaming commands."""
  9. def __init__(self, bot: commands.Bot):
  10. self.bot = bot
  11. @commands.command(
  12. description="Simulate dice rolls.",
  13. brief="Roll dice",
  14. help="Roll two dice."
  15. )
  16. async def dice(self, ctx: commands.Context, amount: Optional[int], sides: Optional[int]):
  17. if not amount:
  18. amount = 2
  19. if not sides:
  20. sides = 6
  21. if amount < 1:
  22. await ctx.send("You want me to roll less than one die? How!?")
  23. elif amount > 25:
  24. await ctx.send("I can not hold so many dice at one time.")
  25. elif sides < 2:
  26. await ctx.send("A die has physical minimum of 2 sides. Don't ask for impossible objects.")
  27. elif sides > 256:
  28. await ctx.send("My tiny hands can not handle such large dice. Even if both are virtual.")
  29. else:
  30. embed = discord.Embed(title = "Dice roll", description=f"Rolling {amount} dice, with {sides} sides.")
  31. while amount > 0:
  32. embed.insert_field_at(0, name=f"Die {amount}", value=random.randint(1, sides), inline=True)
  33. amount -= 1
  34. await ctx.send(embed=embed)
  35. @commands.command(
  36. description="Ask the magic 8-ball.",
  37. brief="Pose question",
  38. help="Simulate the iconic 8-ball gimmic.",
  39. name="8ball"
  40. )
  41. async def eightball(self, ctx: commands.Context, *, question: str = None):
  42. if not question:
  43. messages = [
  44. "Don't forget to ask a question...",
  45. "Hey, that's not a question!",
  46. "What would you like to know?",
  47. "You want me to predict nothing?",
  48. "Are you intentionally not asking a question?",
  49. "Ask a question you tease!",
  50. "You will die alone.",
  51. ]
  52. elif question.strip().count(" ") == 0:
  53. messages = [
  54. "What?",
  55. "That is not a question",
  56. "Can you use more than one word?",
  57. "What is the question?",
  58. "Sorry?"
  59. ]
  60. elif question.strip()[-1] != "?":
  61. messages = [
  62. "Did you forget to end with a question mark?",
  63. "Is that a statement or question?",
  64. "Don't questions usually end with a question mark?",
  65. "Don't forget to use punctuation."
  66. ]
  67. else:
  68. messages = [
  69. "Yes.",
  70. "No.",
  71. "Affirmative.",
  72. "No way!",
  73. "Negative.",
  74. "Positive.",
  75. "Correct.",
  76. "Incorrect.",
  77. "Likely",
  78. "Unlikely",
  79. "Maybe.",
  80. "Definately!",
  81. "Perhaps?",
  82. "Most indubitably.",
  83. "Does the pope shit in the woods?",
  84. "When hell freezes over.",
  85. "Only between 9 and 5.",
  86. "Only just before you die.",
  87. "ERROR: Probability failure.",
  88. "Ask again later.",
  89. "I don't know.",
  90. "Unpredictable.",
  91. "Unknown",
  92. ]
  93. await ctx.send(random.choice(messages))