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