From 63deb177236f3e4e67283d5906e5c457a010afac Mon Sep 17 00:00:00 2001 From: ddorn Date: Tue, 28 Apr 2020 20:25:27 +0200 Subject: [PATCH] :sparkles: misc cog + joke command --- data/jokes | 8 ++++++++ src/cogs/dev.py | 2 +- src/cogs/misc.py | 35 +++++++++++++++++++++++++++++++++++ src/cogs/tirages.py | 4 ---- src/constants.py | 2 ++ src/tfjm_discord_bot.py | 18 +----------------- 6 files changed, 47 insertions(+), 22 deletions(-) create mode 100644 data/jokes create mode 100644 src/cogs/misc.py diff --git a/data/jokes b/data/jokes new file mode 100644 index 0000000..252e4a2 --- /dev/null +++ b/data/jokes @@ -0,0 +1,8 @@ +``` +- Quelle est votre principale qualité ? +- Je suis très rapide en calcul mental. +- 23 x 547 ? +- 56 +- Mais c'est faux ! +- Oui mais c'est rapide ! +``` \ No newline at end of file diff --git a/src/cogs/dev.py b/src/cogs/dev.py index 19710c3..901c222 100644 --- a/src/cogs/dev.py +++ b/src/cogs/dev.py @@ -60,7 +60,7 @@ class DevCog(Cog, name="Dev tools"): MAP = {"d": "dev", "ts": "teams", "t": "tirages"} name = MAP.get(name, name) - if name in ("dev", "teams", "tirages"): + if not "." in name: name = f"src.cogs.{name}" try: diff --git a/src/cogs/misc.py b/src/cogs/misc.py new file mode 100644 index 0000000..be2ab98 --- /dev/null +++ b/src/cogs/misc.py @@ -0,0 +1,35 @@ +import random + +from discord.ext.commands import Cog, command, Context, Bot + +from src.constants import * + + +class MiscCog(Cog, name="Divers"): + @command( + name="choose", + usage='choix1 choix2 "choix 3"...', + aliases=["choice", "choix", "ch"], + ) + async def choose(self, ctx: Context, *args): + """ + Choisit une option parmi tous les arguments. + + Pour les options qui contiennent une espace, + il suffit de mettre des guillemets (`"`) autour. + """ + + choice = random.choice(args) + await ctx.send(f"J'ai choisi... **{choice}**") + + @command(name="joke", aliases=["blague"], hidden=True) + async def joke_cmd(self, ctx): + with open(JOKES_FILE) as f: + jokes = f.read().split("\n\n\n") + + msg = random.choice(jokes) + await ctx.send(msg) + + +def setup(bot: Bot): + bot.add_cog(MiscCog()) diff --git a/src/cogs/tirages.py b/src/cogs/tirages.py index e71d02c..9cf9051 100644 --- a/src/cogs/tirages.py +++ b/src/cogs/tirages.py @@ -657,10 +657,6 @@ class TirageCog(Cog, name="Tirages"): async def draw_group(self, ctx: Context) -> None: """Groupe de commandes pour les tirages. Détails: `!help draw`""" - help = self.bot.get_command("help") - await help.callback(ctx, "draw") - await ctx.send("wtf man") - @draw_group.command( name="start", usage="équipe1 équipe2 équipe3 (équipe4)", ) diff --git a/src/constants.py b/src/constants.py index 7c2e873..128c5aa 100644 --- a/src/constants.py +++ b/src/constants.py @@ -9,6 +9,7 @@ __all__ = [ "ROUND_NAMES", "TIRAGES_FILE", "TEAMS_FILE", + "JOKES_FILE", "TEAMS_CHANNEL_CATEGORY", "DIEGO", "TOURNOIS", @@ -58,6 +59,7 @@ ROUND_NAMES = ["premier tour", "deuxième tour"] TOP_LEVEL_DIR = Path(__file__).parent.parent TIRAGES_FILE = TOP_LEVEL_DIR / "data" / "tirages.yaml" TEAMS_FILE = TOP_LEVEL_DIR / "data" / "teams" +JOKES_FILE = TOP_LEVEL_DIR / "data" / "jokes" with open(TOP_LEVEL_DIR / "data" / "problems") as f: PROBLEMS = f.read().splitlines() diff --git a/src/tfjm_discord_bot.py b/src/tfjm_discord_bot.py index 1ac2e36..40b00b6 100644 --- a/src/tfjm_discord_bot.py +++ b/src/tfjm_discord_bot.py @@ -26,23 +26,6 @@ async def on_ready(): print(f"{bot.user} has connected to Discord!") -@bot.command( - name="choose", - usage='choix1 choix2 "choix 3"...', - aliases=["choice", "choix", "ch"], -) -async def choose(ctx: Context, *args): - """ - Choisit une option parmi tous les arguments. - - Pour les options qui contiennent une espace, - il suffit de mettre des guillemets (`"`) autour. - """ - - choice = random.choice(args) - await ctx.send(f"J'ai choisi... **{choice}**") - - @bot.event async def on_command_error(ctx: Context, error, *args, **kwargs): if isinstance(error, commands.CommandInvokeError): @@ -81,6 +64,7 @@ async def on_command_error(ctx: Context, error, *args, **kwargs): bot.load_extension("src.cogs.tirages") bot.load_extension("src.cogs.teams") bot.load_extension("src.cogs.dev") +bot.load_extension("src.cogs.misc") if __name__ == "__main__":