games.py 2.8 KB

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