1
0
mirror of https://gitlab.com/ddorn/tfjm-discord-bot.git synced 2024-12-25 06:22:21 +00:00

misc cog + joke command

This commit is contained in:
ddorn 2020-04-28 20:25:27 +02:00
parent 3b55bd0399
commit 63deb17723
6 changed files with 47 additions and 22 deletions

8
data/jokes Normal file
View 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 !
```

View File

@ -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:

35
src/cogs/misc.py Normal file
View 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())

View File

@ -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)",
)

View File

@ -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()

View File

@ -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__":