games.py 3.0 KB

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