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
2 changes: 1 addition & 1 deletion commands/cogs/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ async def dump_log(self, ctx):
return

current_path = pathlib.Path(__file__).parent.resolve()
log_file = pathlib.Path(f"{current_path}/../../logs/bot.log")
log_file = current_path / ".." / ".." / "logs" / "bot.log"
if not log_file.exists():
await ctx.respond("Log file does not exist.")
return
Expand Down
38 changes: 31 additions & 7 deletions commands/cogs/rngdle.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,17 @@
from config import MAGIC_COLOR
from utils import get_or_fetch_user
from utils.database.dao.rngdle import RNGdleDao, RNGdleGuildConfigDao
from utils.database.schema import RNGdle as RNGdleEntry
from utils.image_generator import LeaderboardGenerator, RNGdleLeaderboardUser
from utils.number_utils import format_number
from utils.tasks.rngdle_sync import sync_guild_users
from utils.rngdle import (
format_percent,
format_tier,
get_score_percent,
get_score_tier,
get_tier_color,
)
from utils.tasks.rngdle_sync import rngdle_fetch_with_cooldown, sync_guild_users


class RNGdle(commands.Cog):
Expand Down Expand Up @@ -65,7 +73,9 @@ async def show(self, ctx: discord.ApplicationContext) -> None:
)
await ctx.respond(embed=message)

@rngdle_admin.command(description="Set the channel for daily RNGDLE leaderboard")
@rngdle_admin.command(
description="Set the channel for daily RNGDLE leaderboard"
)
@discord.default_permissions(administrator=True)
async def setleaderboard(
self,
Expand All @@ -78,7 +88,9 @@ async def setleaderboard(
await ctx.respond("This command can only be used in a server!")
return

await RNGdleGuildConfigDao.set_leaderboard_channel(ctx.guild.id, channel.id)
await RNGdleGuildConfigDao.set_leaderboard_channel(
ctx.guild.id, channel.id
)
message = discord.Embed(
title="RNGdle Leaderboard Channel",
color=discord.Colour(MAGIC_COLOR),
Expand Down Expand Up @@ -127,21 +139,33 @@ async def leaderboard(self, ctx: discord.ApplicationContext) -> None:
await ctx.respond("This command can only be used in a server!")
return

# Fetch rolls before accessing them
await rngdle_fetch_with_cooldown()

scores = await RNGdleDao.get_today_scores(ctx.guild.id)
if not scores:
await ctx.respond("No today scores found.")
return

users: list[RNGdleLeaderboardUser] = []
for score in scores:
user = await get_or_fetch_user(self.bot, score.user_id)
for score_col in scores:
user = await get_or_fetch_user(self.bot, score_col.user_id)
if user is None:
continue

score = int(score_col.score)
number = score_col.number

u = RNGdleLeaderboardUser()
u.user = user
u.score = format_number(score.score)
u.tirage = f"{score.number:,}".replace(",", " ")
u.score = format_number(score)
u.tirage = f"{number:,}".replace(",", " ")
u.rank = len(users) + 1
u.tier = get_score_tier(score)
u.tier_text = format_tier(u.tier)
u.percent = get_score_percent(score)
u.percent_text = format_percent(int(u.percent))
u.tier_color = get_tier_color(u.tier)
users.append(u)

generated = await self.leaderboard_generator.generate_leaderboard(users)
Expand Down
6 changes: 3 additions & 3 deletions config.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@

DATABASE_PATH = os.getenv("DATABASE_PATH", "dj4h.db")
MAGIC_COLOR = 5220337
# RNGdle sync interval in seconds (default 3600 = 1 hour)
RNGDLE_SYNC_INTERVAL = int(os.getenv("RNGDLE_SYNC_INTERVAL", "3600"))
# RNGdle sync interval in seconds (default 12 * 60 * 60s = 12 hours)
RNGDLE_SYNC_INTERVAL = int(os.getenv("RNGDLE_SYNC_INTERVAL", str(12 * 60 * 60)))


def setup_logging():

current_path = pathlib.Path(__file__).parent.resolve()
config_file = pathlib.Path(f"{current_path}/log_config.json")
config_file = current_path / "log_config.json"
os.makedirs("logs", exist_ok=True)
with open(config_file) as f_in:
config = json.load(f_in)
Expand Down
7 changes: 3 additions & 4 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
from config import BOT_TOKEN, DEBUG_GUILD_ID, LOGGER, setup_logging
from utils.database import init_db
from utils.tasks.rngdle_daily_leaderboard import rngdle_daily_leaderboard_task
from utils.tasks.rngdle_sync import rngdle_sync_task

from utils.tasks.rngdle_sync import rngdle_autosync_task

setup_logging()

Expand All @@ -23,8 +22,8 @@ async def on_ready():
LOGGER.info("Database initialized successfully.")
LOGGER.info("------")

if not rngdle_sync_task.is_running():
rngdle_sync_task.start()
if not rngdle_autosync_task.is_running():
rngdle_autosync_task.start()
LOGGER.info("RNGdle sync task started")
else:
LOGGER.info("RNGdle sync task already running")
Expand Down
Binary file added ressources/font/spacemono_bold.ttf
Binary file not shown.
Binary file added ressources/font/spacemono_regular.ttf
Binary file not shown.
Binary file added ressources/rngdle/arrow_up.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
102 changes: 102 additions & 0 deletions ressources/rngdle/compressed_score_to_percent.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
{
"1759": 0,
"2050": 1,
"2139": 2,
"2213": 3,
"2291": 4,
"2353": 5,
"2451": 6,
"2528": 7,
"2666": 8,
"2782": 9,
"2847": 10,
"2925": 11,
"2985": 12,
"3035": 13,
"3095": 14,
"3148": 15,
"3192": 16,
"3248": 17,
"3311": 18,
"3363": 19,
"3425": 20,
"3500": 21,
"3573": 22,
"3648": 23,
"3715": 24,
"3770": 25,
"3840": 26,
"3898": 27,
"3957": 28,
"4013": 29,
"4067": 30,
"4121": 31,
"4179": 32,
"4235": 33,
"4293": 34,
"4353": 35,
"4411": 36,
"4472": 37,
"4535": 38,
"4610": 39,
"4675": 40,
"4740": 41,
"4811": 42,
"4875": 43,
"4936": 44,
"5001": 45,
"5063": 46,
"5131": 47,
"5199": 48,
"5272": 49,
"5349": 50,
"5423": 51,
"5510": 52,
"5597": 53,
"5687": 54,
"5773": 55,
"5861": 56,
"5948": 57,
"6037": 58,
"6123": 59,
"6222": 60,
"6331": 61,
"6443": 62,
"6566": 63,
"6690": 64,
"6811": 65,
"6940": 66,
"7082": 67,
"7231": 68,
"7404": 69,
"7580": 70,
"7760": 71,
"7942": 72,
"8142": 73,
"8384": 74,
"8642": 75,
"8918": 76,
"9229": 77,
"9595": 78,
"9994": 79,
"10481": 80,
"11047": 81,
"11782": 82,
"12594": 83,
"13328": 84,
"14146": 85,
"15034": 86,
"16029": 87,
"17174": 88,
"18541": 89,
"20245": 90,
"23231": 91,
"27657": 92,
"29245": 93,
"31052": 94,
"33971": 95,
"39122": 96,
"47252": 97,
"76616": 98,
"150679": 99
}
Binary file added ressources/rngdle/trash.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading