mirror of
https://gitlab.com/ddorn/tfjm-discord-bot.git
synced 2024-12-27 11:42:22 +00:00
🐛 fix special characters in fractal seed + add FRACTAL_COOLDOWN
This commit is contained in:
parent
5a402eaf09
commit
860cbb563e
@ -2,6 +2,7 @@ import datetime
|
|||||||
import io
|
import io
|
||||||
import itertools
|
import itertools
|
||||||
import random
|
import random
|
||||||
|
import urllib
|
||||||
from dataclasses import dataclass, field
|
from dataclasses import dataclass, field
|
||||||
from operator import attrgetter
|
from operator import attrgetter
|
||||||
from time import time
|
from time import time
|
||||||
@ -50,6 +51,7 @@ class MiscCog(Cog, name="Divers"):
|
|||||||
self.bot = bot
|
self.bot = bot
|
||||||
self.show_hidden = False
|
self.show_hidden = False
|
||||||
self.verify_checks = True
|
self.verify_checks = True
|
||||||
|
self.last_fractal_time = 0.0
|
||||||
|
|
||||||
@command(
|
@command(
|
||||||
name="choose",
|
name="choose",
|
||||||
@ -100,19 +102,37 @@ class MiscCog(Cog, name="Divers"):
|
|||||||
|
|
||||||
@command(hidden=True)
|
@command(hidden=True)
|
||||||
async def fractal(self, ctx: Context):
|
async def fractal(self, ctx: Context):
|
||||||
|
|
||||||
|
if time() > self.last_fractal_time + FRACTAL_COOLDOWN or has_role(
|
||||||
|
ctx.author, Role.DEV
|
||||||
|
):
|
||||||
|
self.last_fractal_time = time()
|
||||||
|
else:
|
||||||
|
return await ctx.send(
|
||||||
|
f"Merci de ne pas générer plus d'une fractale "
|
||||||
|
f"toutes les {FRACTAL_COOLDOWN} secondes :wink: "
|
||||||
|
f"Il reste {round(FRACTAL_COOLDOWN - (time() - self.last_fractal_time), 1)}s."
|
||||||
|
)
|
||||||
|
|
||||||
await ctx.message.add_reaction(Emoji.CHECK)
|
await ctx.message.add_reaction(Emoji.CHECK)
|
||||||
msg: discord.Message = ctx.message
|
msg: discord.Message = ctx.message
|
||||||
seed = msg.content[len("!fractal ") :]
|
seed = msg.content[len("!fractal ") :]
|
||||||
seed = seed or random.randint(0, 1_000_000_000)
|
seed = seed or str(random.randint(0, 1_000_000_000))
|
||||||
async with aiohttp.ClientSession() as session:
|
async with aiohttp.ClientSession() as session:
|
||||||
async with session.get(FRACTAL_URL.format(seed=seed)) as resp:
|
async with session.get(
|
||||||
|
FRACTAL_URL.format(seed=urllib.parse.quote(seed))
|
||||||
|
) as resp:
|
||||||
if resp.status != 200:
|
if resp.status != 200:
|
||||||
return await ctx.send("Could not download file...")
|
return await ctx.send(
|
||||||
|
"Il y a un problème pour calculer/télécharger l'image..."
|
||||||
|
)
|
||||||
data = io.BytesIO(await resp.read())
|
data = io.BytesIO(await resp.read())
|
||||||
await ctx.send(
|
await ctx.send(
|
||||||
f"Seed: {seed}", file=discord.File(data, "cool_image.png")
|
f"Seed: {seed}", file=discord.File(data, "cool_image.png")
|
||||||
)
|
)
|
||||||
|
|
||||||
|
self.last_fractal_time = time()
|
||||||
|
|
||||||
@command(hidden=True, aliases=["bang", "pan"])
|
@command(hidden=True, aliases=["bang", "pan"])
|
||||||
async def pew(self, ctx):
|
async def pew(self, ctx):
|
||||||
await ctx.send("Tu t'es raté ! Kwaaack :duck:")
|
await ctx.send("Tu t'es raté ! Kwaaack :duck:")
|
||||||
|
@ -14,6 +14,7 @@ __all__ = [
|
|||||||
"TOURNOIS",
|
"TOURNOIS",
|
||||||
"EMBED_COLOR",
|
"EMBED_COLOR",
|
||||||
"FRACTAL_URL",
|
"FRACTAL_URL",
|
||||||
|
"FRACTAL_COOLDOWN",
|
||||||
"File",
|
"File",
|
||||||
"Emoji",
|
"Emoji",
|
||||||
]
|
]
|
||||||
@ -36,6 +37,7 @@ BOT = 703305132300959754
|
|||||||
TEAMS_CHANNEL_CATEGORY = "Channels d'équipes"
|
TEAMS_CHANNEL_CATEGORY = "Channels d'équipes"
|
||||||
EMBED_COLOR = 0xFFA500
|
EMBED_COLOR = 0xFFA500
|
||||||
FRACTAL_URL = "https://thefractal.space/img/{seed}.png?size=1500"
|
FRACTAL_URL = "https://thefractal.space/img/{seed}.png?size=1500"
|
||||||
|
FRACTAL_COOLDOWN = 30 # seconds
|
||||||
|
|
||||||
ROUND_NAMES = ["premier tour", "deuxième tour"]
|
ROUND_NAMES = ["premier tour", "deuxième tour"]
|
||||||
TOURNOIS = [
|
TOURNOIS = [
|
||||||
|
Loading…
Reference in New Issue
Block a user