jokes with images

This commit is contained in:
ddorn 2020-05-10 12:43:21 +02:00
parent ab5c95771f
commit 4336fe7d3c
3 changed files with 21 additions and 16 deletions

View File

@ -1,12 +1,3 @@
```
- 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 !
```
---
Why did the chicken cross the mobius strip? Why did the chicken cross the mobius strip?
|| To get to the same side. || || To get to the same side. ||
--- ---

View File

@ -37,6 +37,7 @@ class Joke(yaml.YAMLObject):
joker: int joker: int
likes: Set[int] = field(default_factory=set) likes: Set[int] = field(default_factory=set)
dislikes: Set[int] = field(default_factory=set) dislikes: Set[int] = field(default_factory=set)
file: str = None
class MiscCog(Cog, name="Divers"): class MiscCog(Cog, name="Divers"):
@ -154,14 +155,21 @@ class MiscCog(Cog, name="Divers"):
yaml.safe_dump_all(jokes, f) yaml.safe_dump_all(jokes, f)
@group(name="joke", invoke_without_command=True) @group(name="joke", invoke_without_command=True)
async def joke(self, ctx): async def joke(self, ctx: Context):
await ctx.message.delete()
m: discord.Message = ctx.message
await m.delete()
jokes = self.load_jokes() jokes = self.load_jokes()
joke_id = random.randrange(len(jokes)) joke_id = random.randrange(len(jokes))
joke = jokes[joke_id] joke = jokes[joke_id]
message: discord.Message = await ctx.send(joke.joke) if joke.file:
file = discord.File(joke.file)
else:
file = None
message: discord.Message = await ctx.send(joke.joke, file=file)
await message.add_reaction(Emoji.PLUS_1) await message.add_reaction(Emoji.PLUS_1)
await message.add_reaction(Emoji.MINUS_1) await message.add_reaction(Emoji.MINUS_1)
@ -171,18 +179,23 @@ class MiscCog(Cog, name="Divers"):
@send_and_bin @send_and_bin
async def new_joke(self, ctx: Context): async def new_joke(self, ctx: Context):
"""Ajoute une blague pour le concours de blague.""" """Ajoute une blague pour le concours de blague."""
jokes = self.load_jokes()
joke_id = len(jokes)
author: discord.Member = ctx.author author: discord.Member = ctx.author
message: discord.Message = ctx.message message: discord.Message = ctx.message
start = "!joke new " msg = message.content[len("!joke new ") :]
msg = message.content[len(start) :]
joke = Joke(msg, ctx.author.id, set()) joke = Joke(msg, ctx.author.id, set())
jokes = self.load_jokes() if message.attachments:
file: discord.Attachment = message.attachments[0]
joke.file = str(File.MEMES / f"{joke_id}-{file.filename}")
await file.save(joke.file)
jokes.append(joke) jokes.append(joke)
self.save_jokes(jokes) self.save_jokes(jokes)
joke_id = len(jokes) - 1
await message.add_reaction(Emoji.PLUS_1) await message.add_reaction(Emoji.PLUS_1)
await message.add_reaction(Emoji.MINUS_1) await message.add_reaction(Emoji.MINUS_1)

View File

@ -76,6 +76,7 @@ class File:
TEAMS = TOP_LEVEL / "data" / "teams" TEAMS = TOP_LEVEL / "data" / "teams"
JOKES = TOP_LEVEL / "data" / "jokes" JOKES = TOP_LEVEL / "data" / "jokes"
JOKES_V2 = TOP_LEVEL / "data" / "jokesv2" JOKES_V2 = TOP_LEVEL / "data" / "jokesv2"
MEMES = TOP_LEVEL / "data" / "memes"
with open(File.TOP_LEVEL / "data" / "problems") as f: with open(File.TOP_LEVEL / "data" / "problems") as f: