Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 0 additions & 16 deletions src/discord-cluster-manager/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,16 +119,13 @@ async def _setup_leaderboards(self): # noqa: C901
forum_channel = None
submission_channel = None
general_channel = None
leaderboard_channel = None
for channel in category.channels:
if channel.name == "central" and isinstance(channel, discord.ForumChannel):
forum_channel = channel
elif channel.name == "submissions" and isinstance(channel, discord.TextChannel):
submission_channel = channel
elif channel.name == "general" and isinstance(channel, discord.TextChannel):
general_channel = channel
elif channel.name == "active-leaderboards" and isinstance(channel, discord.TextChannel):
leaderboard_channel = channel

if not forum_channel:
forum_channel = await category.create_forum(
Expand All @@ -140,19 +137,6 @@ async def _setup_leaderboards(self): # noqa: C901
name="general", reason="Created for leaderboard general"
)

if not leaderboard_channel:
overwrites = {
guild.default_role: discord.PermissionOverwrite(
read_messages=True, send_messages=False
),
guild.me: discord.PermissionOverwrite(read_messages=True, send_messages=True),
}
leaderboard_channel = await category.create_text_channel(
name="active-leaderboards",
reason="Created for viewing leaderboards",
overwrites=overwrites,
)

if not submission_channel:
submission_channel = await category.create_text_channel(
name="submissions", reason="Created for leaderboard submissions"
Expand Down
41 changes: 1 addition & 40 deletions src/discord-cluster-manager/cogs/leaderboard_cog.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
get_gpu_by_name,
)
from discord import app_commands
from discord.ext import commands, tasks
from discord.ext import commands
from leaderboard_db import leaderboard_name_autocomplete
from report import MultiProgressReporter
from submission import SubmissionRequest, prepare_submission
Expand Down Expand Up @@ -377,48 +377,9 @@ def __init__(self, bot: "ClusterBot"):
name="get-submission", description="Retrieve one of your past submissions"
)(self.get_submission_by_id)

# Start updating leaderboard
self.leaderboard_update.start()

# --------------------------------------------------------------------------
# | LOOPING FUNCTIONS |
# --------------------------------------------------------------------------
@tasks.loop(minutes=1)
async def leaderboard_update(self):
"""Task that updates the leaderboard every minute."""
for guild in self.bot.guilds:
channel = await self.ensure_channel_exists(guild, "active-leaderboards")

# Get the pinned message or create a new one
pinned_messages = await channel.pins()
if pinned_messages:
message = pinned_messages[0]
else:
message = await channel.send("Loading leaderboard...")
await message.pin()

# Update the leaderboard message
embed, view = await self._get_leaderboard_helper()

if embed:
await message.edit(content="", embed=embed, view=view)
else:
await message.edit(content="There are currently no active leaderboards.")

@leaderboard_update.before_loop
async def before_leaderboard_update(self):
"""Wait for the bot to be ready before starting the task."""
await self.bot.wait_until_ready()

# --------------------------------------------------------------------------
# | HELPER FUNCTIONS |
# --------------------------------------------------------------------------
async def ensure_channel_exists(self, guild, channel_name):
"""Ensure the leaderboard channel exists, and create it if not."""
channel = discord.utils.get(guild.text_channels, name=channel_name)
if not channel:
channel = await guild.create_text_channel(channel_name)
return channel

async def _display_lb_submissions_helper(
self,
Expand Down
2 changes: 2 additions & 0 deletions src/discord-cluster-manager/report.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ class Text:
"""
Text represents markdown-formatted text to be added to the report.
"""

text: str


Expand All @@ -64,6 +65,7 @@ class Log:
message, it can be broken up automatically (and reasonably) into multiple
smaller messages.
"""

header: str
content: str

Expand Down
Loading