Skip to content

Commit

Permalink
Placate flake8
Browse files Browse the repository at this point in the history
  • Loading branch information
camcaswell committed Jul 8, 2022
1 parent f40ae59 commit 56d2f8e
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 16 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -135,4 +135,4 @@ dmypy.json
# vscode
.vscode/
*.code-workspace
.devcontainer
.devcontainer
29 changes: 14 additions & 15 deletions bot/exts/summer_aoc.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
import asyncio
import logging
from typing import Literal, Optional

import arrow
import asyncio
import discord
from async_rediscache import RedisCache
from discord.ext import commands, tasks
from discord.utils import MISSING

from bot.constants import Channels, Client, Roles
from bot.bot import SirRobin
from bot.constants import Channels, Client, Roles
from bot.utils.time import next_time_occurence, time_until


log = logging.getLogger(__name__)

AOC_URL = "https://adventofcode.com/{year}/day/{day}"
Expand Down Expand Up @@ -114,20 +113,20 @@ async def start(self, ctx: commands.Context, year: int, day_interval: int, post_
"""
Start the Summer AoC event.
To specify a starting day other than `1`, use the `force` command.
"""
""" # noqa: D205
if not FIRST_YEAR <= year <= LAST_YEAR:
raise commands.BadArgument(f"Year must be between {FIRST_YEAR} and {LAST_YEAR}, inclusive")

if day_interval < 1:
raise commands.BadArgument(f"Day interval must be at least 1")
raise commands.BadArgument("Day interval must be at least 1")

if not 0 <= post_time <= 23:
raise commands.BadArgument(f"Post time must be between 0 and 23")
raise commands.BadArgument("Post time must be between 0 and 23")

if self.is_running:
await ctx.send("A Summer AoC event is already running!")
return

self.is_running = True
self.year = year
self.current_day = 1
Expand All @@ -147,7 +146,7 @@ async def force_day(self, ctx: commands.Context, day: int, now: Optional[Literal
"""
Force-set the current day of the event. Use `now` to post the puzzle immediately.
Can be used without starting the event first as long as the necessary settings are already stored.
"""
""" # noqa: D205
if now is not None and now.lower() != "now":
raise commands.BadArgument(f"Unrecognized option: {now}")

Expand Down Expand Up @@ -201,10 +200,10 @@ async def load_event_state(self) -> None:
if self.is_configured():
await self.start_event()
else:
log.error(f"Summer AoC state incomplete, failed to start event")
log.error("Summer AoC state incomplete, failed to start event")
self.is_running = False
self.save_event_state()

async def save_event_state(self) -> None:
"""Save the current state in redis."""
await self.cache.update({
Expand All @@ -214,7 +213,7 @@ async def save_event_state(self) -> None:
"day_interval": self.day_interval,
"post_time": self.post_time,
})

async def start_event(self) -> None:
"""Start event by recording state and creating async tasks to post puzzles."""
log.info(f"Starting Summer AoC event with {self.year=} {self.current_day=} {self.day_interval=}")
Expand All @@ -239,15 +238,15 @@ async def stop_event(self) -> bool:
was_waiting = self.wait_task and not self.wait_task.done()
was_looping = self.loop_task and self.loop_task.is_running()
if was_waiting and was_looping:
log.error(f"Both wait and loop tasks were active. Both should now be cancelled.")
log.error("Both wait and loop tasks were active. Both should now be cancelled.")

if was_waiting:
self.wait_task.cancel()
log.debug(f"Summer AoC stopped during wait task")
log.debug("Summer AoC stopped during wait task")

if was_looping:
self.loop_task.cancel() # .cancel() doesn't allow the current iteration to finish
log.debug(f"Summer AoC stopped during loop task")
log.debug("Summer AoC stopped during loop task")

self.is_running = False
await self.save_event_state()
Expand All @@ -257,7 +256,7 @@ async def stop_event(self) -> bool:
async def post_puzzle(self) -> None:
"""Create a thread for the current day's puzzle."""
if self.current_day > LAST_DAY:
log.error(f"Attempted to post puzzle after last day, stopping event")
log.error("Attempted to post puzzle after last day, stopping event")
await self.stop_event()
return

Expand Down
1 change: 1 addition & 0 deletions bot/utils/time.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ def next_time_occurence(hour: int, minute: int = 0, second: int = 0) -> arrow.Ar
delta = time_until(hour, minute, second)
return arrow.get() + delta


def time_until(hour: int, minute: int = 0, second: int = 0) -> timedelta:
"""Return the difference between now and the next occurence of the given time of day in UTC."""
now = arrow.get()
Expand Down

0 comments on commit 56d2f8e

Please sign in to comment.