blob: 7bb3d8860a4c167ff05c69c4283f8ae61dfd8b9a (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
|
import json
import random
from pathlib import Path
from discord.ext import commands
from pydis_core.utils.logging import get_logger
from bot.bot import Bot
log = get_logger(__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?`)")
async def setup(bot: Bot) -> None:
"""Load the Magic8Ball Cog."""
await bot.add_cog(Magic8ball())
|