Skip to content

Commit

Permalink
[Hockey] I can't just add a delay to the AsyncIterator because that h…
Browse files Browse the repository at this point in the history
…as no context on whether I actually posted and need to wait.

- Catch the error if Message is missing in menus
  • Loading branch information
TrustyJAID committed Jan 21, 2024
1 parent 386c62a commit 249e2e6
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 12 deletions.
6 changes: 3 additions & 3 deletions hockey/game.py
Original file line number Diff line number Diff line change
Expand Up @@ -828,7 +828,7 @@ async def period_recap(self, bot: Red, period: Literal["1st", "2nd", "3rd"]) ->
post_state = ["all", self.home_team, self.away_team]
config = bot.get_cog("Hockey").config
all_channels = await bot.get_cog("Hockey").config.all_channels()
async for channel_id, data in AsyncIter(all_channels.items(), steps=5, delay=5):
async for channel_id, data in AsyncIter(all_channels.items(), steps=100):
await self.maybe_edit_gamedaythread_message(bot, channel_id, data)
channel = await get_channel_obj(bot, channel_id, data)
if not channel:
Expand Down Expand Up @@ -882,7 +882,7 @@ async def post_game_state(self, bot: Red) -> None:
state_text = await self.game_state_text()
tasks = []
all_channels = await bot.get_cog("Hockey").config.all_channels()
async for channel_id, data in AsyncIter(all_channels.items(), steps=5, delay=5):
async for channel_id, data in AsyncIter(all_channels.items(), steps=100):
await self.maybe_edit_gamedaythread_message(bot, channel_id, data)
channel = await get_channel_obj(bot, channel_id, data)
if not channel:
Expand Down Expand Up @@ -1117,7 +1117,7 @@ async def post_time_to_game_start(self, bot: Red, time_left: str) -> None:
)
tasks = []
all_channels = await bot.get_cog("Hockey").config.all_channels()
async for channel_id, data in AsyncIter(all_channels.items(), steps=5, delay=5):
async for channel_id, data in AsyncIter(all_channels.items(), steps=100):
channel = await get_channel_obj(bot, channel_id, data)
if not channel:
continue
Expand Down
4 changes: 2 additions & 2 deletions hockey/goal.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ async def post_team_goal(self, bot: Red, game_data: Game) -> List[Tuple[int, int
tasks = []
all_channels = await bot.get_cog("Hockey").config.all_channels()
post_data = []
async for channel_id, data in AsyncIter(all_channels.items(), steps=5, delay=5):
async for channel_id, data in AsyncIter(all_channels.items(), steps=100):
channel = await get_channel_obj(bot, channel_id, data)
if not channel:
continue
Expand Down Expand Up @@ -393,7 +393,7 @@ async def edit_team_goal(
em = await self.goal_post_embed(game_data)
if og_msg is None:
return
async for guild_id, channel_id, message_id in AsyncIter(og_msg, steps=5, delay=5):
async for guild_id, channel_id, message_id in AsyncIter(og_msg, steps=10):
guild = bot.get_guild(int(guild_id))
if not guild:
continue
Expand Down
6 changes: 3 additions & 3 deletions hockey/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -667,7 +667,7 @@ async def get_channel_obj(
if not channel:
# await bot.get_cog("Hockey").config.channel_from_id(channel_id).clear()
# log.info(f"{channel_id} channel was removed because it no longer exists")
log.info("%s Could not be found", channel_id)
log.info("channel ID %s Could not be found", channel_id)
return None
guild = channel.guild
await bot.get_cog("Hockey").config.channel(channel).guild_id.set(guild.id)
Expand All @@ -676,13 +676,13 @@ async def get_channel_obj(
if not guild:
# await bot.get_cog("Hockey").config.channel_from_id(channel_id).clear()
# log.info(f"{channel_id} channel was removed because it no longer exists")
log.info("%s Could not be found", channel_id)
log.info("guild ID %s Could not be found", channel_id)
return None
channel = guild.get_channel(channel_id)
thread = guild.get_thread(channel_id)
if channel is None and thread is None:
# await bot.get_cog("Hockey").config.channel_from_id(channel_id).clear()
# log.info(f"{channel_id} channel was removed because it no longer exists")
log.info("%s Could not be found", channel_id)
log.info("thread or channel ID %s Could not be found", channel_id)
return None
return channel or thread
2 changes: 1 addition & 1 deletion hockey/hockeypickems.py
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ async def get_pickem_object(
return self.all_pickems[str(guild.id)][str(game.game_id)]

async def fix_pickem_game_start(self, game: Game):
async for guild_id, data in AsyncIter(self.all_pickems.items(), steps=5, delay=10):
async for guild_id, data in AsyncIter(self.all_pickems.items(), steps=50, delay=10):
guild = self.bot.get_guild(int(guild_id))
if guild is None:
continue
Expand Down
10 changes: 8 additions & 2 deletions hockey/menu.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,10 @@ def __init__(
self.author = None

async def on_timeout(self):
await self.message.edit(view=None)
try:
await self.message.edit(view=None)
except Exception:
pass

async def start(self, ctx: commands.Context):
await self.source._prepare_once()
Expand Down Expand Up @@ -292,7 +295,10 @@ def source(self):
return self._source

async def on_timeout(self):
await self.message.edit(view=None)
try:
await self.message.edit(view=None)
except Exception:
pass

async def start(
self, ctx: commands.Context, content: Optional[str] = None, ephemeral: bool = False
Expand Down
2 changes: 1 addition & 1 deletion hockey/schedule.py
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ async def format_page(
if game_start < datetime.now(timezone.utc):
home_score = game.home_score
away_score = game.away_score
score_msg = f"{away_abr} **{away_score}** - " f"**{home_score}** {home_abr}"
score_msg = f"{away_abr} **{away_score}** - **{home_score}** {home_abr}"
if self.get_recap:
game_recap = await self.api.get_game_recap(game.id)
if game_recap is not None:
Expand Down

0 comments on commit 249e2e6

Please sign in to comment.