Skip to content

Commit

Permalink
Update AtCoder URL and add csacademy platform to kontests command
Browse files Browse the repository at this point in the history
  • Loading branch information
rtk-rnjn committed Mar 29, 2024
1 parent 5f4b23d commit ad73114
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
3 changes: 2 additions & 1 deletion cogs/rtfm/_kontests/atcoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from bs4 import BeautifulSoup

API = "https://atcoder.jp/contests"
BASE_URL = "https://atcoder.jp"
TIME_FORMAT = "%Y-%m-%d %H:%M:%S%z"


Expand All @@ -31,7 +32,7 @@ def rated_range(self) -> str:

@property
def url(self) -> str:
return API + self.__data["url"]
return BASE_URL + self.__data["url"]


class AtCoder:
Expand Down
15 changes: 12 additions & 3 deletions cogs/rtfm/rtfm.py
Original file line number Diff line number Diff line change
Expand Up @@ -1400,15 +1400,22 @@ async def bin(self, ctx: Context, *, code: str) -> None:

kontests_cache = {}

@commands.command(name="kontest-reload", hidden=True)
@commands.is_owner()
async def kontest_reload(self, ctx: Context) -> None:
self.kontests_cache.clear()
await ctx.tick()

@commands.command(name="kontests")
@commands.cooldown(1, 15, commands.BucketType.user)
@Context.with_type
async def kontests(self, ctx: Context, platform: str | None = None) -> None:
"""Get the upcoming contests on various competitive programming platforms."""

if random() < 0.1:
await ctx.send("From Owner: This command is still in development. Please be patient.")

available_platforms = {"hackerearth", "hackerrank", "codeforces", "atcoder"}
available_platforms = {"hackerearth", "hackerrank", "codeforces", "atcoder", "csacademy"}
if platform is None:
msg = "Please provide a platform to get the upcoming contests for."
msg += f"\n\nAvailable platforms: {', '.join(available_platforms)}"
Expand All @@ -1425,11 +1432,12 @@ async def kontests(self, ctx: Context, platform: str | None = None) -> None:
"hackerrank": self.kontest_hackerrank,
"codeforces": self.kontest_codeforces,
"atcoder": self.kontest_atcoder,
"csacademy": self.kontest_csacademy,
}

kontests = await mapping[platform]()
if not kontests:
await ctx.send(f"No upcoming contests found for {platform.capitalize()}.")
await ctx.send(f"No upcoming contests found for `{platform.capitalize()}`.")

await ctx.paginate(kontests, per_page=6)

Expand Down Expand Up @@ -1475,6 +1483,7 @@ async def kontest_codeforces(self) -> list:
self.kontests_cache["codeforces"] = codeforces.contests

contests = self.kontests_cache["codeforces"]
contests = [c for c in contests if c.phase != "FINISHED"]

return [
f"""ID: *{contest.id}* | **[{contest.name}]({contest.website_url})** | {contest.phase}
Expand All @@ -1496,8 +1505,8 @@ async def kontest_atcoder(self) -> list:

return [
f"""ID: NA | **[{contest.name}]({contest.url})**
*Description not available*
`Start:` {discord.utils.format_dt(contest.start_time, "R")}
`Time :` {contest.duration_minutes}
"""
for contest in contests
]
Expand Down

0 comments on commit ad73114

Please sign in to comment.