From af14e3989f71e8dc6c0d78fbcd4c4b8c83e2848c Mon Sep 17 00:00:00 2001 From: Cal Corum Date: Wed, 29 Nov 2023 09:56:53 -0600 Subject: [PATCH] Update weekly posts Add bot ready check to weekly post Add season post to weekly message --- cogs/transactions.py | 51 ++++++++++++++++++++++++++++++++++++-------- helpers.py | 2 +- 2 files changed, 43 insertions(+), 10 deletions(-) diff --git a/cogs/transactions.py b/cogs/transactions.py index ac36ef2..ab91bda 100644 --- a/cogs/transactions.py +++ b/cogs/transactions.py @@ -332,15 +332,6 @@ class Transactions(commands.Cog): @tasks.loop(minutes=1) async def weekly_loop(self): - try: - guild = self.bot.get_guild(int(os.environ.get('GUILD_ID'))) - if not guild: - logging.error(f'Could not pull guild; exiting loop') - return - except Exception as e: - logging.error(f'Could not run weekly_loop: {e}') - return - current = await db_get('current') now = datetime.datetime.now() logging.info(f'Datetime: {now} / weekday: {now.weekday()}') @@ -375,6 +366,8 @@ class Transactions(commands.Cog): f'{stars}\n```' logging.info(f'Freeze string:\n\n{freeze_message}') await send_to_channel(self.bot, 'transaction-log', freeze_message) + if current['week'] > 0 and current['week'] <= 18: + await self.post_weekly_info(current) # End Freeze # elif now.weekday() == 5 and now.hour == 5 and current['freeze']: # Spring/Summer @@ -391,6 +384,12 @@ class Transactions(commands.Cog): await self.process_freeze_moves(current) await send_to_channel(self.bot, 'transaction-log', freeze_message) self.trade_season = False + if current['week'] > 0 and current['week'] <= 18: + await self.post_weekly_info(current) + + @weekly_loop.before_loop + async def before_notif_check(self): + await self.bot.wait_until_ready() async def run_transactions(self, current): m_query = await db_get('transactions', params=[ @@ -604,6 +603,35 @@ class Transactions(commands.Cog): await send_to_channel(self.bot, 'transaction-log', embed=embed) + async def post_weekly_info(self, current): + guild = self.bot.get_guild(int(os.environ.get('GUILD_ID'))) + info_channel = discord.utils.get(guild.text_channels, name='weekly-info') + async for message in info_channel.history(limit=25): + await message.delete() + + night_str = '\U0001F319 Night' + day_str = '\U0001F31E Day' + + season_str = f'\U0001F3D6 **Summer**' + if current['week'] <= 5: + season_str = f'\U0001F33C **Spring**' + elif current['week'] > 14: + season_str = f'\U0001F342 **Fall**' + + is_div_week = False + if current['week'] in [1, 3, 6, 14, 16, 18]: + is_div_week = True + + weekly_str = f'**Season**: {season_str}\n' \ + f'**Time of Day**: {night_str} / {night_str if is_div_week else day_str} / ' \ + f'{night_str} / {night_str if is_div_week else day_str}' + + await info_channel.send( + content=f'Each team has manage permissions in their home ballpark. They may pin messages and rename the ' + f'channel.\n\n**Make sure your ballpark starts with your team abbreviation.**' + ) + await info_channel.send(weekly_str) + # async def send_stats_to_sheets(self, channel='commissioners-office', which='all'): # current = await db_get('current') # b_stats = None @@ -721,6 +749,11 @@ class Transactions(commands.Cog): await self.process_freeze_moves(current) await ctx.send(random_conf_gif()) + @commands.command(name='post-weekly') + @commands.is_owner() + async def post_weekly_info_command(self, ctx): + await self.post_weekly_info(await db_get('current')) + @commands.command(name='trade', help='Trade players') @commands.has_any_role(SBA_PLAYERS_ROLE_NAME) async def trade_command(self, ctx): diff --git a/helpers.py b/helpers.py index 13f1e87..667c4f9 100644 --- a/helpers.py +++ b/helpers.py @@ -937,7 +937,7 @@ async def get_player_embed(player, current, ctx=None, season=None): whip = f'{(p["bb"] + p["hit"]) / p["ip"]:.2f}' pitching_string = f'```\n' \ f' W L SV ERA IP SO WHIP\n' \ - f'{win: >2} {loss: >2} {save: >2} {era: >5} {ip: >5}\n``````\n' \ + f'{win: >2} {loss: >2} {save: >2} {era: >5} {ip: >5} ' \ f'{so: >3} {whip: >4}\n```' if batting_string and batter_priority: