Add dedicated channel for startup announcements
Add STARTUP_ANNOUNCEMENT_CHANNEL_ID to control where startup announcements are sent. Changes: - New config: STARTUP_ANNOUNCEMENT_CHANNEL_ID - Announcements sent only to specified channel - Falls back to first CHANNEL_ID if not set - Prevents announcement spam in all stock update channels 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -2,6 +2,7 @@
|
|||||||
DISCORD_TOKEN=your_discord_bot_token_here
|
DISCORD_TOKEN=your_discord_bot_token_here
|
||||||
CHANNEL_ID=your_channel_id_here,optional_second_channel_id
|
CHANNEL_ID=your_channel_id_here,optional_second_channel_id
|
||||||
STARTUP_ANNOUNCEMENT=
|
STARTUP_ANNOUNCEMENT=
|
||||||
|
STARTUP_ANNOUNCEMENT_CHANNEL_ID=
|
||||||
|
|
||||||
# Bot Configuration
|
# Bot Configuration
|
||||||
COMMAND_PREFIX=!
|
COMMAND_PREFIX=!
|
||||||
|
|||||||
@@ -161,6 +161,7 @@ Environment variables in `.env`:
|
|||||||
| `DISCORD_TOKEN` | Your Discord bot token | Required |
|
| `DISCORD_TOKEN` | Your Discord bot token | Required |
|
||||||
| `CHANNEL_ID` | Discord channel ID(s) for updates (comma-separated for multiple) | Required |
|
| `CHANNEL_ID` | Discord channel ID(s) for updates (comma-separated for multiple) | Required |
|
||||||
| `STARTUP_ANNOUNCEMENT` | Optional message to send when bot starts (empty = no announcement) | `""` |
|
| `STARTUP_ANNOUNCEMENT` | Optional message to send when bot starts (empty = no announcement) | `""` |
|
||||||
|
| `STARTUP_ANNOUNCEMENT_CHANNEL_ID` | Channel ID for startup announcements (defaults to first CHANNEL_ID) | `""` |
|
||||||
| `COMMAND_PREFIX` | Command prefix for bot | `!` |
|
| `COMMAND_PREFIX` | Command prefix for bot | `!` |
|
||||||
| `PRIMARY_TICKER` | Stock ticker for hourly updates | `PYPL` |
|
| `PRIMARY_TICKER` | Stock ticker for hourly updates | `PYPL` |
|
||||||
| `UPDATE_INTERVAL_HOURS` | Hours between updates | `1` |
|
| `UPDATE_INTERVAL_HOURS` | Hours between updates | `1` |
|
||||||
@@ -173,7 +174,9 @@ CHANNEL_ID=1442203998932304035,9876543210123456789
|
|||||||
**Startup Announcements:** Send a one-time message when the bot starts (useful for announcing updates):
|
**Startup Announcements:** Send a one-time message when the bot starts (useful for announcing updates):
|
||||||
```
|
```
|
||||||
STARTUP_ANNOUNCEMENT=Bot updated with new features: colored price changes and FinViz charts!
|
STARTUP_ANNOUNCEMENT=Bot updated with new features: colored price changes and FinViz charts!
|
||||||
|
STARTUP_ANNOUNCEMENT_CHANNEL_ID=1234567890123456789
|
||||||
```
|
```
|
||||||
|
If `STARTUP_ANNOUNCEMENT_CHANNEL_ID` is not set, announcements are sent to the first channel in `CHANNEL_ID`.
|
||||||
|
|
||||||
## Switching Stock API Providers
|
## Switching Stock API Providers
|
||||||
|
|
||||||
|
|||||||
30
bot.py
30
bot.py
@@ -104,7 +104,7 @@ class StockBot(commands.Bot):
|
|||||||
await self.send_stock_update(self.primary_ticker, channel_id)
|
await self.send_stock_update(self.primary_ticker, channel_id)
|
||||||
|
|
||||||
async def send_startup_announcement(self):
|
async def send_startup_announcement(self):
|
||||||
"""Send startup announcement to configured channels."""
|
"""Send startup announcement to configured announcement channel."""
|
||||||
embed = discord.Embed(
|
embed = discord.Embed(
|
||||||
title="🤖 Bot Update",
|
title="🤖 Bot Update",
|
||||||
description=Config.STARTUP_ANNOUNCEMENT,
|
description=Config.STARTUP_ANNOUNCEMENT,
|
||||||
@@ -112,13 +112,27 @@ class StockBot(commands.Bot):
|
|||||||
timestamp=datetime.now(pytz.timezone('America/New_York'))
|
timestamp=datetime.now(pytz.timezone('America/New_York'))
|
||||||
)
|
)
|
||||||
|
|
||||||
for channel_id in self.target_channel_ids:
|
# Use dedicated announcement channel if configured, otherwise use first target channel
|
||||||
channel = self.get_channel(channel_id)
|
announcement_channel_id = Config.STARTUP_ANNOUNCEMENT_CHANNEL_ID
|
||||||
if channel:
|
if announcement_channel_id:
|
||||||
await channel.send(embed=embed)
|
try:
|
||||||
logger.info(f"Sent startup announcement to channel {channel_id}")
|
channel_id = int(announcement_channel_id)
|
||||||
else:
|
except ValueError:
|
||||||
logger.error(f"Could not send announcement to channel {channel_id}")
|
logger.error(f"Invalid STARTUP_ANNOUNCEMENT_CHANNEL_ID: {announcement_channel_id}")
|
||||||
|
return
|
||||||
|
else:
|
||||||
|
channel_id = self.target_channel_ids[0] if self.target_channel_ids else None
|
||||||
|
|
||||||
|
if not channel_id:
|
||||||
|
logger.error("No channel configured for startup announcement")
|
||||||
|
return
|
||||||
|
|
||||||
|
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 find announcement channel {channel_id}")
|
||||||
|
|
||||||
async def send_stock_update(self, ticker: str, channel_id: int):
|
async def send_stock_update(self, ticker: str, channel_id: int):
|
||||||
"""
|
"""
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ class Config:
|
|||||||
CHANNEL_IDS = [id.strip() for id in os.getenv('CHANNEL_ID', '').split(',') if id.strip()]
|
CHANNEL_IDS = [id.strip() for id in os.getenv('CHANNEL_ID', '').split(',') if id.strip()]
|
||||||
COMMAND_PREFIX = os.getenv('COMMAND_PREFIX', '!')
|
COMMAND_PREFIX = os.getenv('COMMAND_PREFIX', '!')
|
||||||
STARTUP_ANNOUNCEMENT = os.getenv('STARTUP_ANNOUNCEMENT', '')
|
STARTUP_ANNOUNCEMENT = os.getenv('STARTUP_ANNOUNCEMENT', '')
|
||||||
|
STARTUP_ANNOUNCEMENT_CHANNEL_ID = os.getenv('STARTUP_ANNOUNCEMENT_CHANNEL_ID', '')
|
||||||
|
|
||||||
# Stock configuration
|
# Stock configuration
|
||||||
PRIMARY_TICKER = os.getenv('PRIMARY_TICKER', 'PYPL')
|
PRIMARY_TICKER = os.getenv('PRIMARY_TICKER', 'PYPL')
|
||||||
|
|||||||
Reference in New Issue
Block a user