♻️ File and Emoji enum
This commit is contained in:
parent
3623f6a66d
commit
34fc5e3c60
|
@ -1,12 +1,11 @@
|
|||
import datetime
|
||||
import itertools
|
||||
import random
|
||||
import datetime
|
||||
from operator import attrgetter
|
||||
from pprint import pprint
|
||||
from time import time
|
||||
|
||||
import discord
|
||||
from discord import Guild, Emoji
|
||||
from discord import Guild
|
||||
from discord.ext import commands
|
||||
from discord.ext.commands import (
|
||||
Cog,
|
||||
|
@ -19,6 +18,7 @@ from discord.ext.commands import (
|
|||
)
|
||||
|
||||
from src.constants import *
|
||||
from src.constants import Emoji
|
||||
from src.utils import has_role
|
||||
|
||||
|
||||
|
@ -47,14 +47,14 @@ class MiscCog(Cog, name="Divers"):
|
|||
@command(name="joke", aliases=["blague"], hidden=True)
|
||||
async def joke_cmd(self, ctx):
|
||||
await ctx.message.delete()
|
||||
with open(JOKES_FILE) as f:
|
||||
with open(File.JOKES) as f:
|
||||
jokes = f.read().split("\n\n\n")
|
||||
|
||||
msg = random.choice(jokes)
|
||||
message: discord.Message = await ctx.send(msg)
|
||||
|
||||
await message.add_reaction("😂")
|
||||
await message.add_reaction("😭")
|
||||
await message.add_reaction(Emoji.JOY)
|
||||
await message.add_reaction(Emoji.SOB)
|
||||
|
||||
@command(name="status")
|
||||
@commands.has_role(Role.CNO)
|
||||
|
|
|
@ -18,7 +18,7 @@ class TeamsCog(Cog, name="Teams"):
|
|||
self.teams = self.load_teams()
|
||||
|
||||
def load_teams(self):
|
||||
with open(TEAMS_FILE) as f:
|
||||
with open(File.TEAMS) as f:
|
||||
# first line is header
|
||||
lines = f.read().splitlines()[1:]
|
||||
teams = [
|
||||
|
|
|
@ -140,15 +140,15 @@ class Tirage(yaml.YAMLObject):
|
|||
await ctx.channel.edit(overwrites={ctx.guild.default_role: send})
|
||||
|
||||
tl = {}
|
||||
if TIRAGES_FILE.exists():
|
||||
with open(TIRAGES_FILE) as f:
|
||||
if File.TIRAGES.exists():
|
||||
with open(File.TIRAGES) as f:
|
||||
tl = yaml.load(f)
|
||||
else:
|
||||
TIRAGES_FILE.touch()
|
||||
File.TIRAGES.touch()
|
||||
|
||||
key = max(0, *tl.keys()) + 1
|
||||
tl[key] = self
|
||||
with open(TIRAGES_FILE, "w") as f:
|
||||
with open(File.TIRAGES, "w") as f:
|
||||
yaml.dump(tl, f)
|
||||
|
||||
await ctx.send(
|
||||
|
@ -785,10 +785,10 @@ class TirageCog(Cog, name="Tirages"):
|
|||
await tirage.update_phase(ctx)
|
||||
|
||||
def get_tirages(self) -> Dict[int, Tirage]:
|
||||
if not TIRAGES_FILE.exists():
|
||||
if not File.TIRAGES.exists():
|
||||
return {}
|
||||
|
||||
with open(TIRAGES_FILE) as f:
|
||||
with open(File.TIRAGES) as f:
|
||||
tirages = yaml.load(f)
|
||||
|
||||
return tirages
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
import os
|
||||
from pathlib import Path
|
||||
from time import time
|
||||
|
||||
__all__ = [
|
||||
"TOKEN",
|
||||
|
@ -7,17 +8,15 @@ __all__ = [
|
|||
"PROBLEMS",
|
||||
"MAX_REFUSE",
|
||||
"ROUND_NAMES",
|
||||
"TIRAGES_FILE",
|
||||
"TEAMS_FILE",
|
||||
"JOKES_FILE",
|
||||
"TEAMS_CHANNEL_CATEGORY",
|
||||
"DIEGO",
|
||||
"TOURNOIS",
|
||||
"EMBED_COLOR",
|
||||
"START_TIME",
|
||||
"File",
|
||||
"Emoji",
|
||||
]
|
||||
|
||||
from time import time
|
||||
|
||||
TOKEN = os.environ.get("TFJM_DISCORD_TOKEN")
|
||||
|
||||
|
@ -30,9 +29,12 @@ if TOKEN is None:
|
|||
print()
|
||||
quit(1)
|
||||
|
||||
START_TIME = time()
|
||||
GUILD = "690934836696973404"
|
||||
DIEGO = "Diego" # Mon display name
|
||||
|
||||
TEAMS_CHANNEL_CATEGORY = "Channels d'équipes"
|
||||
EMBED_COLOR = 0xFFA500
|
||||
ROUND_NAMES = ["premier tour", "deuxième tour"]
|
||||
TOURNOIS = [
|
||||
"Lille",
|
||||
"Lyon",
|
||||
|
@ -56,18 +58,18 @@ class Role:
|
|||
PARTICIPANT = "Participant"
|
||||
|
||||
|
||||
TEAMS_CHANNEL_CATEGORY = "Channels d'équipes"
|
||||
class Emoji:
|
||||
JOY = "😂"
|
||||
SOB = "😭"
|
||||
|
||||
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"
|
||||
class File:
|
||||
TOP_LEVEL = Path(__file__).parent.parent
|
||||
TIRAGES = TOP_LEVEL / "data" / "tirages.yaml"
|
||||
TEAMS = TOP_LEVEL / "data" / "teams"
|
||||
JOKES = TOP_LEVEL / "data" / "jokes"
|
||||
|
||||
with open(TOP_LEVEL_DIR / "data" / "problems") as f:
|
||||
|
||||
with open(File.TOP_LEVEL / "data" / "problems") as f:
|
||||
PROBLEMS = f.read().splitlines()
|
||||
MAX_REFUSE = len(PROBLEMS) - 4 # -5 usually but not in 2020 because of covid-19
|
||||
|
||||
EMBED_COLOR = 0xFFA500
|
||||
START_TIME = time()
|
||||
|
|
Loading…
Reference in New Issue