games.py 3.2 KB

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