mirror of
				https://gitlab.com/ddorn/tfjm-discord-bot.git
				synced 2025-11-04 14:32:20 +01:00 
			
		
		
		
	✨ misc cog + joke command
This commit is contained in:
		
							
								
								
									
										8
									
								
								data/jokes
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										8
									
								
								data/jokes
									
									
									
									
									
										Normal file
									
								
							@@ -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 !
 | 
				
			||||||
 | 
					```
 | 
				
			||||||
@@ -60,7 +60,7 @@ class DevCog(Cog, name="Dev tools"):
 | 
				
			|||||||
        MAP = {"d": "dev", "ts": "teams", "t": "tirages"}
 | 
					        MAP = {"d": "dev", "ts": "teams", "t": "tirages"}
 | 
				
			||||||
        name = MAP.get(name, name)
 | 
					        name = MAP.get(name, name)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if name in ("dev", "teams", "tirages"):
 | 
					        if not "." in name:
 | 
				
			||||||
            name = f"src.cogs.{name}"
 | 
					            name = f"src.cogs.{name}"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        try:
 | 
					        try:
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										35
									
								
								src/cogs/misc.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										35
									
								
								src/cogs/misc.py
									
									
									
									
									
										Normal file
									
								
							@@ -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())
 | 
				
			||||||
@@ -657,10 +657,6 @@ class TirageCog(Cog, name="Tirages"):
 | 
				
			|||||||
    async def draw_group(self, ctx: Context) -> None:
 | 
					    async def draw_group(self, ctx: Context) -> None:
 | 
				
			||||||
        """Groupe de commandes pour les tirages. Détails: `!help draw`"""
 | 
					        """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(
 | 
					    @draw_group.command(
 | 
				
			||||||
        name="start", usage="équipe1 équipe2 équipe3 (équipe4)",
 | 
					        name="start", usage="équipe1 équipe2 équipe3 (équipe4)",
 | 
				
			||||||
    )
 | 
					    )
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -9,6 +9,7 @@ __all__ = [
 | 
				
			|||||||
    "ROUND_NAMES",
 | 
					    "ROUND_NAMES",
 | 
				
			||||||
    "TIRAGES_FILE",
 | 
					    "TIRAGES_FILE",
 | 
				
			||||||
    "TEAMS_FILE",
 | 
					    "TEAMS_FILE",
 | 
				
			||||||
 | 
					    "JOKES_FILE",
 | 
				
			||||||
    "TEAMS_CHANNEL_CATEGORY",
 | 
					    "TEAMS_CHANNEL_CATEGORY",
 | 
				
			||||||
    "DIEGO",
 | 
					    "DIEGO",
 | 
				
			||||||
    "TOURNOIS",
 | 
					    "TOURNOIS",
 | 
				
			||||||
@@ -58,6 +59,7 @@ ROUND_NAMES = ["premier tour", "deuxième tour"]
 | 
				
			|||||||
TOP_LEVEL_DIR = Path(__file__).parent.parent
 | 
					TOP_LEVEL_DIR = Path(__file__).parent.parent
 | 
				
			||||||
TIRAGES_FILE = TOP_LEVEL_DIR / "data" / "tirages.yaml"
 | 
					TIRAGES_FILE = TOP_LEVEL_DIR / "data" / "tirages.yaml"
 | 
				
			||||||
TEAMS_FILE = TOP_LEVEL_DIR / "data" / "teams"
 | 
					TEAMS_FILE = TOP_LEVEL_DIR / "data" / "teams"
 | 
				
			||||||
 | 
					JOKES_FILE = TOP_LEVEL_DIR / "data" / "jokes"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
with open(TOP_LEVEL_DIR / "data" / "problems") as f:
 | 
					with open(TOP_LEVEL_DIR / "data" / "problems") as f:
 | 
				
			||||||
    PROBLEMS = f.read().splitlines()
 | 
					    PROBLEMS = f.read().splitlines()
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -26,23 +26,6 @@ async def on_ready():
 | 
				
			|||||||
    print(f"{bot.user} has connected to Discord!")
 | 
					    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
 | 
					@bot.event
 | 
				
			||||||
async def on_command_error(ctx: Context, error, *args, **kwargs):
 | 
					async def on_command_error(ctx: Context, error, *args, **kwargs):
 | 
				
			||||||
    if isinstance(error, commands.CommandInvokeError):
 | 
					    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.tirages")
 | 
				
			||||||
bot.load_extension("src.cogs.teams")
 | 
					bot.load_extension("src.cogs.teams")
 | 
				
			||||||
bot.load_extension("src.cogs.dev")
 | 
					bot.load_extension("src.cogs.dev")
 | 
				
			||||||
 | 
					bot.load_extension("src.cogs.misc")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
if __name__ == "__main__":
 | 
					if __name__ == "__main__":
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user