Skip to content

Commit

Permalink
now for real
Browse files Browse the repository at this point in the history
  • Loading branch information
ishefi committed Jul 29, 2024
1 parent dc6cd81 commit b66a74a
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
6 changes: 6 additions & 0 deletions common/tables.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@ class User(SQLModel, table=True):
first_login: datetime.datetime = Field(default_factory=datetime.datetime.utcnow)
subscription_expiry: datetime.datetime | None = None

def has_active_subscription(self) -> bool:
if self.subscription_expiry is None:
return False
else:
return self.subscription_expiry > datetime.datetime.utcnow()


class UserHistory(SQLModel, table=True):
__table_args__ = (
Expand Down
9 changes: 6 additions & 3 deletions logic/user_logic.py
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,10 @@ def clues_used(self) -> int:

async def get_clue(self) -> str | None:
if self.clues_used < len(self.clues):
if not self.user.active and await self._used_max_clues_for_inactive():
if (
not self.user.has_active_subscription()
and await self._used_max_clues_for_inactive()
):
raise ValueError() # TODO: custom exception
clue = await self.clues[self.clues_used]()
await self._update_clue_usage()
Expand All @@ -313,8 +316,8 @@ async def _used_max_clues_for_inactive(self) -> bool:
tables.UserClueCount.game_date
> self.date - self.CLUE_COOLDOWN_FOR_UNSUBSCRIBED
)
used_clues = session.exec(query).one()
return used_clues > self.MAX_CLUES_DURING_COOLDOWN
used_clues = session.exec(query).one() or 0
return used_clues >= self.MAX_CLUES_DURING_COOLDOWN

async def _update_clue_usage(self) -> None:
with hs_transaction(self.session) as session:
Expand Down
3 changes: 2 additions & 1 deletion static/semantle.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ function snackbarAlert(alertText, alertColor) {
x.innerText = alertText;
x.style.backgroundColor = alertColor;
x.className = "show";
setTimeout(function(){ x.className = x.className.replace("show", ""); }, 4000);
let duration = 60 * alertText.length;
setTimeout(function(){ x.className = x.className.replace("show", ""); }, duration);
}


Expand Down

0 comments on commit b66a74a

Please sign in to comment.