Add optional intro message on bot startup

When SEND_INTRO_MESSAGE=true, the bot sends "The deals must flow." as
an m.notice to the Matrix room right after startup, before the first
scheduled deal checks. Defaults to off.

https://claude.ai/code/session_017eMsVwUopgmnEyd6JJedpV
This commit is contained in:
Claude
2026-02-28 03:01:20 +00:00
parent 3f7e8196e3
commit 0fd58c32b4
4 changed files with 34 additions and 0 deletions

View File

@@ -69,6 +69,8 @@ async def main():
scheduler.start() scheduler.start()
logger.info("Bot started — scheduler running") logger.info("Bot started — scheduler running")
await bot.send_intro()
# Run initial checks immediately (after first-run population is done) # Run initial checks immediately (after first-run population is done)
await bot.check_cheapshark() await bot.check_cheapshark()
await bot.check_epic_free_games() await bot.check_epic_free_games()

View File

@@ -72,6 +72,12 @@ class DealsBot:
total = len(deals) + len(current_free) + len(upcoming) total = len(deals) + len(current_free) + len(upcoming)
logger.info("First run: recorded %d existing deals/games", total) logger.info("First run: recorded %d existing deals/games", total)
async def send_intro(self):
"""Send an intro message to the Matrix room if configured."""
if not self.config.send_intro_message:
return
await self.matrix.send_notice("The deals must flow.")
async def check_cheapshark(self): async def check_cheapshark(self):
"""Poll CheapShark for deals and post new ones.""" """Poll CheapShark for deals and post new ones."""
if not self._first_run_done: if not self._first_run_done:

View File

@@ -19,6 +19,11 @@ class Config:
self.min_discount_percent = int(os.environ.get("MIN_DISCOUNT_PERCENT", "50")) self.min_discount_percent = int(os.environ.get("MIN_DISCOUNT_PERCENT", "50"))
self.max_price_usd = float(os.environ.get("MAX_PRICE_USD", "20")) self.max_price_usd = float(os.environ.get("MAX_PRICE_USD", "20"))
# Intro message on startup
self.send_intro_message = os.environ.get(
"SEND_INTRO_MESSAGE", "false"
).lower() in ("true", "1", "yes")
# Database # Database
self.database_path = os.environ.get("DATABASE_PATH", "deals.db") self.database_path = os.environ.get("DATABASE_PATH", "deals.db")

View File

@@ -47,5 +47,26 @@ class MatrixDealsClient:
logger.error("Matrix send error: %s", exc) logger.error("Matrix send error: %s", exc)
return False return False
async def send_notice(self, text: str) -> bool:
"""Send a plain m.notice (non-highlight) message to the configured room."""
content = {
"msgtype": "m.notice",
"body": text,
}
try:
resp = await self._client.room_send(
room_id=self.room_id,
message_type="m.room.message",
content=content,
)
if isinstance(resp, RoomSendError):
logger.error("Failed to send notice: %s", resp.message)
return False
return True
except Exception as exc:
logger.error("Matrix send error: %s", exc)
return False
async def close(self): async def close(self):
await self._client.close() await self._client.close()