aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar S. Co1 <[email protected]>2019-03-25 10:12:10 -0400
committerGravatar GitHub <[email protected]>2019-03-25 10:12:10 -0400
commite2723b5e7d2923b94640ab86127790498186d569 (patch)
tree976cdcf1d32ebe9d0bc4e9ea01e7835f156cab7d
parentMerge pull request #153 from python-discord/easter (diff)
parentUse keyword-only arg, output usage if length requirement not met (diff)
Merge pull request #152 from bramz/feature/124/magic-8ball
Magic 8ball command
-rw-r--r--bot/resources/evergreen/magic8ball.json22
-rw-r--r--bot/seasons/evergreen/magic_8ball.py36
2 files changed, 58 insertions, 0 deletions
diff --git a/bot/resources/evergreen/magic8ball.json b/bot/resources/evergreen/magic8ball.json
new file mode 100644
index 00000000..6fe86950
--- /dev/null
+++ b/bot/resources/evergreen/magic8ball.json
@@ -0,0 +1,22 @@
+[
+ "It is certain",
+ "It is decidedly so",
+ "Without a doubt",
+ "Yes definitely",
+ "You may rely on it",
+ "As I see it, yes",
+ "Most likely",
+ "Outlook good",
+ "Yes",
+ "Signs point to yes",
+ "Reply hazy try again",
+ "Ask again later",
+ "Better not tell you now",
+ "Cannot predict now",
+ "Concentrate and ask again",
+ "Don't count on it",
+ "My reply is no",
+ "My sources say no",
+ "Outlook not so good",
+ "Very doubtful"
+] \ No newline at end of file
diff --git a/bot/seasons/evergreen/magic_8ball.py b/bot/seasons/evergreen/magic_8ball.py
new file mode 100644
index 00000000..88c9fd26
--- /dev/null
+++ b/bot/seasons/evergreen/magic_8ball.py
@@ -0,0 +1,36 @@
+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?`)")
+
+
+# Required in order to load the cog, use the class name in the add_cog function.
+def setup(bot):
+ bot.add_cog(Magic8ball(bot))
+ log.info("Magic 8ball cog loaded")