Merge pull request #8 from prosolis/claude/fix-cheapshark-rating-bug-pxVJv
More bugfixes
This commit is contained in:
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
__pycache__/
|
||||||
|
*.pyc
|
||||||
@@ -63,6 +63,7 @@ All configuration is via environment variables (see `.env.example`):
|
|||||||
| `MIN_DEAL_RATING` | No | 8.0 | Minimum CheapShark deal rating (0-10) |
|
| `MIN_DEAL_RATING` | No | 8.0 | Minimum CheapShark deal rating (0-10) |
|
||||||
| `MIN_DISCOUNT_PERCENT` | No | 50 | Minimum discount percentage |
|
| `MIN_DISCOUNT_PERCENT` | No | 50 | Minimum discount percentage |
|
||||||
| `MAX_PRICE_USD` | No | 20 | Maximum sale price in USD |
|
| `MAX_PRICE_USD` | No | 20 | Maximum sale price in USD |
|
||||||
|
| `SEND_INTRO_MESSAGE` | No | false | Send "The deals must flow." to the room on startup |
|
||||||
| `DATABASE_PATH` | No | deals.db | Path to SQLite database file |
|
| `DATABASE_PATH` | No | deals.db | Path to SQLite database file |
|
||||||
|
|
||||||
## Preflight Check
|
## Preflight Check
|
||||||
|
|||||||
@@ -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()
|
||||||
|
|||||||
@@ -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:
|
||||||
|
|||||||
@@ -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")
|
||||||
|
|
||||||
|
|||||||
@@ -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()
|
||||||
|
|||||||
Reference in New Issue
Block a user