From 601db8da656f781680a4a449a46fde2ba2499df5 Mon Sep 17 00:00:00 2001 From: Yuuki Date: Wed, 25 Dec 2024 20:20:13 +0900 Subject: [PATCH] Add commands.py - added /8ball --- cogs/commands.py | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 cogs/commands.py diff --git a/cogs/commands.py b/cogs/commands.py new file mode 100644 index 0000000..d38bee8 --- /dev/null +++ b/cogs/commands.py @@ -0,0 +1,38 @@ +# -*- coding: utf-8 -*- + +import random + +import disnake +from disnake.ext import commands +from disnake.ext.commands import slash_command, Param + +from logger import Logger + +logger = Logger('Liza Modules') + + +class SlashCommands(commands.Cog): + GUILD = 1321397320620965909 + + def __init__(self, bot): + self.bot = bot + logger.info('/8ball.py loaded.') + + @slash_command(name='8ball', description='Ask a question.', guild_ids=[GUILD]) + async def eightball(self, + ctx: disnake.AppCommandInter, + question: str = Param(name='question', description='Question.')): + answers = ['Outlook good.', 'It is certain.', 'You may rely on it.', 'Ask again later.', + 'Concentrate and ask again.', 'Reply hazy, try again.', 'My reply is no.', 'My sources say no.'] + + if question.endswith('?'): + if len(question) >= 1: + await ctx.response.send_message(f'Q: {question}\nA: {random.choice(answers)}') + else: + await ctx.response.send_message(':x: Please ask me a question first.', ephemeral=True) + else: + await ctx.response.send_message(':x: Your question must end with a question mark.', ephemeral=True) + + +def setup(bot): + bot.add_cog(SlashCommands(bot))