Skip to content

Commit

Permalink
bureau does not participate
Browse files Browse the repository at this point in the history
  • Loading branch information
Lysquid committed Apr 22, 2024
1 parent 924623c commit a54f73e
Showing 1 changed file with 34 additions and 10 deletions.
44 changes: 34 additions & 10 deletions cogs/code_golf.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class CodeGolf(cmds.Cog, name="Code golf"):
"ml": "OCaml",
"zig": "Zig",
"nim": "Nim",
"ua": "Uiua",
}

def __init__(self, bot: CustomBot):
Expand Down Expand Up @@ -151,6 +152,7 @@ def check(reaction: discord.Reaction, user: discord.User):


@golf.command()
@cmds.guild_only()
async def scores(self, ctx: cmds.Context, challenge: challenge = None):
"""
Display the scoreboard of a code golf challenge
Expand All @@ -168,19 +170,30 @@ async def scores(self, ctx: cmds.Context, challenge: challenge = None):
text = []
for i, submission in enumerate(submissions):
size, _, file = submission
participant, extension = file.stem, file.suffix[1:]
name, extension = file.stem, file.suffix[1:]
language = CodeGolf.EXTENSIONS[extension] if extension in CodeGolf.EXTENSIONS else extension
if ctx.guild:
participant = discord.utils.get(ctx.guild.members, name=participant)
participant = participant.mention if participant else participant
text.append(f"{i}. {participant} : {size} bytes ({language})")

member = discord.utils.get(ctx.guild.members, name=name)
mention = member.mention if member else name
bureau = discord.utils.get(ctx.guild.roles, id=ids.BUREAU)

if member and bureau in member.roles:
mention = f"~~{mention}~~"

line = f"{i}. {mention} : {size} bytes ({language})"

if member and bureau in member.roles:
line = f"{line} {bureau.mention}"

text.append(line)

embed.add_field(name=f"Challenge {challenge}", value="\n".join(text), inline=False)

await ctx.send(embed=embed, silent=True)


@golf.command(aliases=["lead"])
@cmds.guild_only()
async def leaderboard(self, ctx: cmds.Context):
"""
Display the leaderboard of of the code golf contest
Expand Down Expand Up @@ -224,11 +237,22 @@ async def leaderboard(self, ctx: cmds.Context):

text = []
for i, item in enumerate(leaderboard):
size, count, participant = item
if ctx.guild:
participant = discord.utils.get(ctx.guild.members, name=participant)
participant = participant.mention if participant else participant
text.append(f"{i}. {participant} : {size} bytes ({count} challenge{'s' if count > 1 else ''})")
size, count, name = item
mention = name

participant = discord.utils.get(ctx.guild.members, name=name)
mention = participant.mention if participant else name
bureau = discord.utils.get(ctx.guild.roles, id=ids.BUREAU)

if participant and bureau in participant.roles:
mention = f"~~{mention}~~"

line = f"{i}. {mention} : {size} bytes ({count} challenge{'s' if count > 1 else ''})"

if participant and bureau in participant.roles:
mention = f"{line} {bureau.mention}"

text.append(line)

embed.add_field(name=f"Leaderboard", value="\n".join(text), inline=False)
await ctx.send(embed=embed, silent=True)
Expand Down

0 comments on commit a54f73e

Please sign in to comment.