Add optional startup announcement feature

Bot can now send a one-time announcement to all configured channels when it starts.

Configuration:
- Set STARTUP_ANNOUNCEMENT in .env with your message
- Leave empty to disable announcements
- Prevents duplicate announcements on reconnects

Usage example:
STARTUP_ANNOUNCEMENT=Bot updated! New features: colored prices and charts

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Michael Simard
2025-12-03 22:32:32 -06:00
parent 76516a4e73
commit 388430780d
4 changed files with 31 additions and 0 deletions

23
bot.py
View File

@@ -38,6 +38,7 @@ class StockBot(commands.Bot):
self.scheduler = AsyncIOScheduler(timezone=pytz.timezone('America/New_York'))
self.target_channel_ids = [int(id) for id in Config.CHANNEL_IDS]
self.primary_ticker = Config.PRIMARY_TICKER
self.startup_announced = False
async def setup_hook(self):
"""Initialize the bot and set up scheduled tasks."""
@@ -77,6 +78,11 @@ class StockBot(commands.Bot):
else:
logger.error(f'Could not find channel with ID {channel_id}')
# Send startup announcement if configured and not already sent
if Config.STARTUP_ANNOUNCEMENT and not self.startup_announced:
await self.send_startup_announcement()
self.startup_announced = True
async def send_hourly_update(self):
"""Send hourly stock price update if market is open."""
if not MarketHours.is_market_open():
@@ -97,6 +103,23 @@ class StockBot(commands.Bot):
for channel_id in self.target_channel_ids:
await self.send_stock_update(self.primary_ticker, channel_id)
async def send_startup_announcement(self):
"""Send startup announcement to configured channels."""
embed = discord.Embed(
title="🤖 Bot Update",
description=Config.STARTUP_ANNOUNCEMENT,
color=discord.Color.blue(),
timestamp=datetime.now(pytz.timezone('America/New_York'))
)
for channel_id in self.target_channel_ids:
channel = self.get_channel(channel_id)
if channel:
await channel.send(embed=embed)
logger.info(f"Sent startup announcement to channel {channel_id}")
else:
logger.error(f"Could not send announcement to channel {channel_id}")
async def send_stock_update(self, ticker: str, channel_id: int):
"""
Fetch stock data and send formatted embed to specified channel.