diff options
| author | 2019-03-26 14:53:13 -0400 | |
|---|---|---|
| committer | 2019-03-26 14:53:13 -0400 | |
| commit | 0bc509af4c7e5184a575763279756dac0a425dab (patch) | |
| tree | e444b611009bd084a7148a4724ed3f9a446e2b8a /bot/seasons/evergreen/magic_8ball.py | |
| parent | Respect docstring summary/description spacing. (diff) | |
| parent | Merge pull request #132 from python-discord/dpy-cog-changes (diff) | |
Merge branch 'master' into flake8-docstring
Resolve merge conflicts
Diffstat (limited to 'bot/seasons/evergreen/magic_8ball.py')
| -rw-r--r-- | bot/seasons/evergreen/magic_8ball.py | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/bot/seasons/evergreen/magic_8ball.py b/bot/seasons/evergreen/magic_8ball.py new file mode 100644 index 00000000..7b5f8e1a --- /dev/null +++ b/bot/seasons/evergreen/magic_8ball.py @@ -0,0 +1,33 @@ +import json +import logging +import random +from pathlib import Path + +from discord.ext import commands + +log = logging.getLogger(__name__) + + +class Magic8ball: + """A Magic 8ball command to respond to a users question.""" + + def __init__(self, bot): + self.bot = bot + with open(Path("bot", "resources", "evergreen", "magic8ball.json"), "r") as file: + self.answers = json.load(file) + + @commands.command(name="8ball") + async def output_answer(self, ctx, *, question): + """Return a magic 8 ball answer from answers list.""" + if len(question.split()) >= 3: + answer = random.choice(self.answers) + await ctx.send(answer) + else: + await ctx.send("Usage: .8ball <question> (minimum length of 3 eg: `will I win?`)") + + +def setup(bot): + """Magic 8ball cog load.""" + + bot.add_cog(Magic8ball(bot)) + log.info("Magic8ball cog loaded") |