1
0

games.py 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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 amount and amount < 1:
  18. await ctx.send("You want me to roll less as one die? How!?")
  19. elif amount and amount > 25:
  20. await ctx.send("I can not hold so many dice at one time.")
  21. elif sides and sides < 2:
  22. await ctx.send("A die has physical minimum of 2 sides. Don't ask for impossible objects.")
  23. else:
  24. if sides:
  25. sides = sides
  26. else:
  27. sides = 6
  28. if not amount:
  29. amount = 2
  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. else:
  53. messages = [
  54. "Yes.",
  55. "No.",
  56. "Affirmative.",
  57. "No way!",
  58. "Negative.",
  59. "Positive.",
  60. "Correct.",
  61. "Incorrect.",
  62. "Likely",
  63. "Unlikely",
  64. "Maybe.",
  65. "Definately!",
  66. "Perhaps?",
  67. "Most indubitably.",
  68. "Does the pope shit in the woods?",
  69. "When hell freezes over.",
  70. "Only between 9 and 5.",
  71. "Only just before you die.",
  72. "ERROR: Probability failure.",
  73. "Ask again later.",
  74. "I don't know.",
  75. "Unpredictable.",
  76. ]
  77. await ctx.send(random.choice(messages))