✨ jokes leaderboard
This commit is contained in:
parent
6815c33ea1
commit
5c522f07e3
|
@ -24,10 +24,12 @@ from discord.ext.commands import (
|
||||||
BadArgument,
|
BadArgument,
|
||||||
RoleConverter,
|
RoleConverter,
|
||||||
)
|
)
|
||||||
|
from discord.utils import get
|
||||||
|
|
||||||
from src.constants import *
|
from src.constants import *
|
||||||
from src.constants import Emoji
|
from src.constants import Emoji
|
||||||
from src.core import CustomBot
|
from src.core import CustomBot
|
||||||
|
from src.errors import TfjmError
|
||||||
from src.utils import has_role, start_time, send_and_bin
|
from src.utils import has_role, start_time, send_and_bin
|
||||||
|
|
||||||
|
|
||||||
|
@ -179,14 +181,24 @@ 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: Context):
|
async def joke(self, ctx: Context, id: int = None):
|
||||||
|
|
||||||
m: discord.Message = ctx.message
|
m: discord.Message = ctx.message
|
||||||
await m.delete()
|
await m.delete()
|
||||||
|
|
||||||
jokes = self.load_jokes()
|
jokes = self.load_jokes()
|
||||||
joke_id = random.randrange(len(jokes))
|
if id is not None:
|
||||||
joke = jokes[joke_id]
|
joke_id = id
|
||||||
|
jokes = sorted(
|
||||||
|
jokes, key=lambda j: len(j.likes) - len(j.dislikes), reverse=True
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
joke_id = random.randrange(len(jokes))
|
||||||
|
|
||||||
|
try:
|
||||||
|
joke = jokes[joke_id]
|
||||||
|
except IndexError:
|
||||||
|
raise TfjmError("Il n'y a pas de blague avec cet ID.")
|
||||||
|
|
||||||
if joke.file:
|
if joke.file:
|
||||||
file = discord.File(joke.file)
|
file = discord.File(joke.file)
|
||||||
|
@ -254,6 +266,28 @@ class MiscCog(Cog, name="Divers"):
|
||||||
|
|
||||||
self.save_jokes(jokes)
|
self.save_jokes(jokes)
|
||||||
|
|
||||||
|
@joke.command(name="top", hidden=True)
|
||||||
|
async def best_jokes(self, ctx: Context):
|
||||||
|
"""Affiche le palmares des blagues."""
|
||||||
|
|
||||||
|
jokes = self.load_jokes()
|
||||||
|
|
||||||
|
s = sorted(jokes, key=lambda j: len(j.likes) - len(j.dislikes), reverse=True)
|
||||||
|
|
||||||
|
embed = discord.Embed(title="Palmares des blagues.")
|
||||||
|
for i, joke in enumerate(s[:10]):
|
||||||
|
who = get(ctx.guild.members, id=joke.joker)
|
||||||
|
|
||||||
|
text = joke.joke
|
||||||
|
if joke.file:
|
||||||
|
text += " - image non inclue - "
|
||||||
|
|
||||||
|
embed.add_field(
|
||||||
|
name=f"{i} - {who.display_name} - {len(joke.likes)}", value=text
|
||||||
|
)
|
||||||
|
|
||||||
|
await ctx.send(embed=embed)
|
||||||
|
|
||||||
# ----------------- Help ---------------- #
|
# ----------------- Help ---------------- #
|
||||||
|
|
||||||
@command(name="help", aliases=["h"])
|
@command(name="help", aliases=["h"])
|
||||||
|
|
Loading…
Reference in New Issue