diff options
author | 2021-09-05 19:46:37 +0100 | |
---|---|---|
committer | 2021-09-05 19:46:37 +0100 | |
commit | 8a410f3abd39a1b48c514d32651a50d4bdced492 (patch) | |
tree | 17fbb917adec0a1283d3d2456d8b09eee0334371 /bot/exts/fun/magic_8ball.py | |
parent | Merge pull request #845 from python-discord/Pin-platform-in-Dockerfile (diff) | |
parent | Merge branch 'main' into lance-restructure (diff) |
Merge pull request #851 from python-discord/lance-restructure
Restructure Sir Lancebot
Diffstat (limited to 'bot/exts/fun/magic_8ball.py')
-rw-r--r-- | bot/exts/fun/magic_8ball.py | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/bot/exts/fun/magic_8ball.py b/bot/exts/fun/magic_8ball.py new file mode 100644 index 00000000..a7b682ca --- /dev/null +++ b/bot/exts/fun/magic_8ball.py @@ -0,0 +1,30 @@ +import json +import logging +import random +from pathlib import Path + +from discord.ext import commands + +from bot.bot import Bot + +log = logging.getLogger(__name__) + +ANSWERS = json.loads(Path("bot/resources/fun/magic8ball.json").read_text("utf8")) + + +class Magic8ball(commands.Cog): + """A Magic 8ball command to respond to a user's question.""" + + @commands.command(name="8ball") + async def output_answer(self, ctx: commands.Context, *, question: str) -> None: + """Return a Magic 8ball answer from answers list.""" + if len(question.split()) >= 3: + answer = random.choice(ANSWERS) + await ctx.send(answer) + else: + await ctx.send("Usage: .8ball <question> (minimum length of 3 eg: `will I win?`)") + + +def setup(bot: Bot) -> None: + """Load the Magic8Ball Cog.""" + bot.add_cog(Magic8ball()) |