Bug fix
- Validate and enforce positive price for SPECIFIC_PRICE alerts - improve error handling and alert squelching logic.
This commit is contained in:
@@ -12,8 +12,13 @@ import token_bot.persistant_database as pdb
|
||||
|
||||
class Alert:
|
||||
def __init__(
|
||||
self, alert: pdb.AlertType, flavor: Flavor, region: Region, price: int = 0
|
||||
self, alert: pdb.AlertType, flavor: Flavor, region: Region, price: int = 0
|
||||
) -> None:
|
||||
# Validate price for SPECIFIC_PRICE alerts
|
||||
if alert == AlertType.SPECIFIC_PRICE:
|
||||
if price is None or price <= 0:
|
||||
raise ValueError("SPECIFIC_PRICE alerts require a positive price value")
|
||||
|
||||
# AlertType is the Primary Key
|
||||
self._alert_type: pdb.AlertType = alert
|
||||
# Flavor (Retail, Classic) is the Sort Key
|
||||
@@ -91,10 +96,10 @@ class Alert:
|
||||
|
||||
def __eq__(self, other):
|
||||
return (
|
||||
self.alert_type == other.alert_type
|
||||
and self.flavor == other.flavor
|
||||
and self.region == other.region
|
||||
and self.price == other.price
|
||||
self.alert_type == other.alert_type
|
||||
and self.flavor == other.flavor
|
||||
and self.region == other.region
|
||||
and self.price == other.price
|
||||
)
|
||||
|
||||
def to_human_string(self):
|
||||
@@ -142,7 +147,7 @@ class Alert:
|
||||
return self.users
|
||||
|
||||
async def add_user(
|
||||
self, table: Table, user: pdb.User, consistent: bool = False
|
||||
self, table: Table, user: pdb.User, consistent: bool = False
|
||||
) -> None:
|
||||
await self._lazy_load(table, consistent=consistent)
|
||||
|
||||
@@ -150,7 +155,7 @@ class Alert:
|
||||
await self._append_user(table=table, user=user)
|
||||
|
||||
async def remove_user(
|
||||
self, table: Table, user: pdb.User, consistent: bool = True
|
||||
self, table: Table, user: pdb.User, consistent: bool = True
|
||||
) -> None:
|
||||
await self._lazy_load(table, consistent=consistent)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user