diff --git a/src/bot.py b/src/bot.py index 6a32248..393f5ee 100644 --- a/src/bot.py +++ b/src/bot.py @@ -127,6 +127,7 @@ async def on_ready(self): if not self.change_status.is_running(): self.change_status.start() await self.fetch_vars() + await self.reports_cog.update_report_channel.run_immediately() async def close(self): await self.session.close() diff --git a/src/reports.py b/src/reports.py index b3ad22b..c132ba7 100644 --- a/src/reports.py +++ b/src/reports.py @@ -154,17 +154,31 @@ async def on_submit(self, interaction: discord.Interaction) -> None: ) -class ReportsView(MILBotView): +class SubmitButton(discord.ui.Button): def __init__(self, bot: MILBot): self.bot = bot - super().__init__(timeout=None) + if not is_active(): + super().__init__( + label="Reports are not currently active.", + style=discord.ButtonStyle.grey, + disabled=True, + custom_id="reports_view:submit", + ) + elif datetime.datetime.today().weekday() in [0, 1]: + super().__init__( + label="Reports can only be submitted between Wednesday and Sunday.", + style=discord.ButtonStyle.red, + disabled=True, + custom_id="reports_view:submit", + ) + else: + super().__init__( + label="Submit your report!", + style=discord.ButtonStyle.green, + custom_id="reports_view:submit", + ) - @discord.ui.button( - label="Submit your report!", - style=discord.ButtonStyle.green, - custom_id="reports_view:submit", - ) - async def submit(self, interaction: discord.Interaction, _: discord.ui.Button): + async def callback(self, interaction: discord.Interaction): # If button is triggered on Sunday or Monday, send error message if datetime.datetime.today().weekday() in [0, 1]: return await interaction.response.send_message( @@ -182,6 +196,13 @@ async def submit(self, interaction: discord.Interaction, _: discord.ui.Button): await interaction.response.send_modal(ReportsModal(self.bot)) +class ReportsView(MILBotView): + def __init__(self, bot: MILBot): + self.bot = bot + super().__init__(timeout=None) + self.add_item(SubmitButton(bot)) + + @dataclass class Student: name: str @@ -217,6 +238,7 @@ def __init__(self, bot: MILBot): self.post_reminder.start(self) self.last_week_summary.start(self) self.individual_reminder.start(self) + self.update_report_channel.start(self) def date_to_column(self, date: datetime.date) -> int: """ @@ -332,6 +354,16 @@ async def last_week_summary(self): team_leads_ch = self.bot.team_leads_ch(team) await team_leads_ch.send(embed=embed) + @run_on_weekday([calendar.MONDAY, calendar.WEDNESDAY], 0, 0) + async def update_report_channel(self): + channel_history = [m async for m in self.bot.reports_channel.history(limit=1)] + if not channel_history: + return + + last_message = channel_history[0] + if last_message.author == self.bot.user: + await last_message.edit(view=ReportsView(self.bot)) + @commands.is_owner() @commands.command() async def reportview(self, ctx):