Skip to content

Commit

Permalink
Small style changes for black
Browse files Browse the repository at this point in the history
  • Loading branch information
49Indium committed Nov 26, 2023
1 parent 9e02f86 commit 5e2cd08
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 19 deletions.
38 changes: 23 additions & 15 deletions uqcsbot/advent.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import io
import logging
import os
from datetime import datetime
from datetime import datetime
from random import choices
from typing import Callable, Dict, Iterable, List, Optional, Literal
import requests
Expand All @@ -15,7 +15,16 @@
from uqcsbot.bot import UQCSBot
from uqcsbot.models import AOCRegistrations, AOCWinners
from uqcsbot.utils.err_log_utils import FatalErrorWithLog
from uqcsbot.utils.advent_utils import Member, Day, Json, InvalidHTTPSCode, ADVENT_DAYS, CACHE_TIME, parse_leaderboard_column_string, print_leaderboard
from uqcsbot.utils.advent_utils import (
Member,
Day,
Json,
InvalidHTTPSCode,
ADVENT_DAYS,
CACHE_TIME,
parse_leaderboard_column_string,
print_leaderboard,
)

# Leaderboard API URL with placeholders for year and code.
LEADERBOARD_URL = "https://adventofcode.com/{year}/leaderboard/private/view/{code}.json"
Expand Down Expand Up @@ -267,12 +276,16 @@ async def reminder_fifteen_minutes(self):
return
role = discord.utils.get(self.bot.uqcs_server.roles, name=self.bot.AOC_ROLE)
if role is None:
logging.warning(f"The role @{self.bot.AOC_ROLE} could not be found for an Advent of Code puzzle pre-release ping.")
logging.warning(
f"The role @{self.bot.AOC_ROLE} could not be found for an Advent of Code puzzle pre-release ping."
)
# Still return a message, as it is better to message and not ping than to not message at all.
ping = ""
else:
ping = f"{role.mention} "
await channel.send(f"{ping}Today's Advent of Code puzzle is released in 15 minutes.")
await channel.send(
f"{ping}Today's Advent of Code puzzle is released in 15 minutes."
)

async def reminder_released(self):
"""
Expand All @@ -291,7 +304,9 @@ async def reminder_released(self):
return
role = discord.utils.get(self.bot.uqcs_server.roles, name=self.bot.AOC_ROLE)
if role is None:
logging.warning(f"The role @{self.bot.AOC_ROLE} could not be found for an Advent of Code puzzle release ping.")
logging.warning(
f"The role @{self.bot.AOC_ROLE} could not be found for an Advent of Code puzzle release ping."
)
# Still return a message, as it is better to message and not ping than to not message at all.
ping = ""
else:
Expand All @@ -317,9 +332,7 @@ def _add_winners(self, winners: List[Member], year: int, prize: str):
"""
for winner in winners:
db_session = self.bot.create_db_session()
db_session.add(
AOCWinners(aoc_userid=winner.id, year=year, prize=prize)
)
db_session.add(AOCWinners(aoc_userid=winner.id, year=year, prize=prize))
db_session.commit()
db_session.close()

Expand All @@ -342,7 +355,6 @@ def _random_choices_without_repition(

return result


@advent_command_group.command(name="help")
@app_commands.describe(command="The command you want to view help about.")
async def help_command(
Expand Down Expand Up @@ -615,9 +627,7 @@ async def register_command(self, interaction: discord.Interaction, aoc_name: str
return

db_session.add(
AOCRegistrations(
aoc_userid=AOC_id, year=year, discord_userid=discord_id
)
AOCRegistrations(aoc_userid=AOC_id, year=year, discord_userid=discord_id)
)
db_session.commit()
db_session.close()
Expand Down Expand Up @@ -693,9 +703,7 @@ async def register_admin_command(
return

db_session.add(
AOCRegistrations(
aoc_userid=aoc_id, year=year, discord_userid=discord_id
)
AOCRegistrations(aoc_userid=aoc_id, year=year, discord_userid=discord_id)
)
db_session.commit()
db_session.close()
Expand Down
8 changes: 6 additions & 2 deletions uqcsbot/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ class Base(DeclarativeBase):
class AOCWinners(Base):
__tablename__ = "aoc_winners"

id: Mapped[int] = mapped_column("id", BigInteger, primary_key=True, nullable=False, autoincrement=True)
id: Mapped[int] = mapped_column(
"id", BigInteger, primary_key=True, nullable=False, autoincrement=True
)
aoc_userid: Mapped[int] = mapped_column("aoc_userid", Integer, nullable=False)
year: Mapped[int] = mapped_column("year", Integer, nullable=False)
prize: Mapped[str] = mapped_column("prize", String, nullable=True)
Expand All @@ -28,7 +30,9 @@ class AOCWinners(Base):
class AOCRegistrations(Base):
__tablename__ = "aoc_registrations"

id: Mapped[int] = mapped_column("id", BigInteger, primary_key=True, nullable=False, autoincrement=True)
id: Mapped[int] = mapped_column(
"id", BigInteger, primary_key=True, nullable=False, autoincrement=True
)
aoc_userid: Mapped[int] = mapped_column("aoc_userid", Integer, nullable=False)
year: Mapped[int] = mapped_column("year", Integer, nullable=False)
discord_userid: Mapped[int] = mapped_column(
Expand Down
6 changes: 4 additions & 2 deletions uqcsbot/utils/advent_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@
# The time to cache results to limit requests to adventofcode.com. Note that 15 minutes is the recomended minimum time.
CACHE_TIME = timedelta(minutes=15)


class InvalidHTTPSCode(Exception):
def __init__(self, message, request_code):
def __init__(self, message: str, request_code: int):
super().__init__(message)
self.request_code = request_code

Expand Down Expand Up @@ -166,6 +167,7 @@ def _format_seconds_long(seconds: Optional[int]):
def _get_member_star_progress_bar(member: Member):
return "".join(_star_char(len(member.times[day])) for day in ADVENT_DAYS)


class LeaderboardColumn:
"""
A column in a leaderboard. The title is the name of the column as 2 lines and the calculation is a function that determines what is printed for a given member, index and day. The title and calculation should have the same constant width.
Expand Down Expand Up @@ -363,6 +365,7 @@ def parse_leaderboard_column_string(s: str, bot: UQCSBot) -> List[LeaderboardCol
columns.append(LeaderboardColumn.name_column(bot))
return columns


def print_leaderboard(
columns: List[LeaderboardColumn], members: List[Member], day: Optional[Day]
):
Expand All @@ -381,4 +384,3 @@ def print_leaderboard(
)

return leaderboard

0 comments on commit 5e2cd08

Please sign in to comment.