- Validate and enforce positive price for SPECIFIC_PRICE alerts
- improve error handling and alert squelching logic.
This commit is contained in:
2026-01-28 17:49:28 -08:00
parent 62b20cf4ab
commit 35ad75cd7c
4 changed files with 48 additions and 39 deletions

View File

@@ -226,7 +226,7 @@ class Tracker(Extension):
case AlertCategory.CUSTOM:
alert_type = AlertType.SPECIFIC_PRICE
except TimeoutError:
except (TimeoutError, ValueError):
return
else:
@@ -531,14 +531,16 @@ class Tracker(Extension):
price_str = modal_ctx.responses["price_input"]
try:
price_gold = int(price_str.replace(",", "").replace(" ", "").replace("g", ""))
if price_gold <= 0:
await modal_ctx.send("Price must be greater than 0", ephemeral=True)
# Convert gold to copper (1 gold = 10000 copper)
price_copper = price_gold
await modal_ctx.send(f"Custom price alert set for {format(price_gold, ',')}g", ephemeral=True)
return price_copper
except ValueError:
await modal_ctx.send("Invalid price. Please enter a valid number.", ephemeral=True)
raise
if price_gold <= 0:
await modal_ctx.send("Price must be greater than 0", ephemeral=True)
raise ValueError("Price must be greater than 0")
await modal_ctx.send(f"Custom price alert set for {format(price_gold, ',')}g", ephemeral=True)
return price_gold
async def _user_is_registered(self, ctx: SlashContext) -> bool:
if not await self._users.exists(ctx.user.id):