| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117 |
- from discord.ext import commands
- import discord
- import random
- from typing import Optional
- from query.channel import get_games
- from query.user import is_ignored
- def setup(bot: commands.Bot):
- bot.add_cog(Games(bot))
- class Games(commands.Cog):
- """Gaming commands."""
- def __init__(self, bot: commands.Bot):
- self.bot = bot
- @commands.command(
- description="Simulate dice rolls.",
- brief="Roll dice",
- help="Roll two dice."
- )
- async def dice(self, ctx: commands.Context, amount: Optional[int], sides: Optional[int]):
- # Ignore user if on the ignore list.
- if await is_ignored(self.bot.pg, ctx.author.id):
- return
- if not await get_games(self.bot.pg, ctx.channel.id):
- ctx.author.send(f"Games are disabled in {ctx.channel}, ask an admin to enable them.")
- return
- if not amount:
- amount = 2
- if not sides:
- sides = 6
- if amount < 1:
- await ctx.send("You want me to roll less than one die? How!?")
- elif amount > 25:
- await ctx.send("I can not hold so many dice at one time.")
- elif sides < 2:
- await ctx.send("A die has physical minimum of 2 sides. Don't ask for impossible objects.")
- elif sides > 256:
- await ctx.send("My tiny hands can not handle such large dice. Even if both are virtual.")
- else:
- embed = discord.Embed(title = "Dice roll", description=f"Rolling {amount} dice, with {sides} sides.")
- while amount > 0:
- embed.insert_field_at(0, name=f"Die {amount}", value=random.randint(1, sides), inline=True)
- amount -= 1
- await ctx.send(embed=embed)
- @commands.command(
- description="Ask the magic 8-ball.",
- brief="Pose question",
- help="Simulate the iconic 8-ball gimmic.",
- name="8ball"
- )
- async def eightball(self, ctx: commands.Context, *, question: str = None):
- # Ignore user if on the ignore list.
- if await is_ignored(self.bot.pg, ctx.author.id):
- return
- if not await get_games(self.bot.pg, ctx.channel.id):
- ctx.author.send(f"Games are disabled in {ctx.channel}, ask an admin to enable them.")
- return
- if not question:
- messages = [
- "Don't forget to ask a question...",
- "Hey, that's not a question!",
- "What would you like to know?",
- "You want me to predict nothing?",
- "Are you intentionally not asking a question?",
- "Ask a question you tease!",
- "You will die alone.",
- ]
- elif question.strip().count(" ") == 0:
- messages = [
- "What?",
- "That is not a question",
- "Can you use more than one word?",
- "What is the question?",
- "Sorry?"
- ]
- elif question.strip()[-1] != "?":
- messages = [
- "Did you forget to end with a question mark?",
- "Is that a statement or question?",
- "Don't questions usually end with a question mark?",
- "Don't forget to use punctuation."
- ]
- else:
- messages = [
- "Yes.",
- "No.",
- "Affirmative.",
- "No way!",
- "Negative.",
- "Positive.",
- "Correct.",
- "Incorrect.",
- "Likely",
- "Unlikely",
- "Maybe.",
- "Definately!",
- "Perhaps?",
- "Most indubitably.",
- "Does the pope shit in the woods?",
- "When hell freezes over.",
- "Only between 9 and 5.",
- "Only just before you die.",
- "ERROR: Probability failure.",
- "Ask again later.",
- "I don't know.",
- "Unpredictable.",
- "Unknown",
- ]
- await ctx.send(random.choice(messages))
|