Skip to content

Commit e8f3c12

Browse files
authored
fix: active user charge bug (#177)
1 parent cb0acbe commit e8f3c12

File tree

3 files changed

+16
-9
lines changed

3 files changed

+16
-9
lines changed

app/api/types/marzneshin/user.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -103,12 +103,20 @@ def is_expired(self) -> bool:
103103
@property
104104
def time_to_second(self) -> int:
105105
if self.expire_strategy == UserExpireStrategy.NEVER:
106-
return None
106+
return 0
107107
elif self.expire_strategy == UserExpireStrategy.FIXED_DATE and self.expire_date:
108-
return self.expire_date.second
109-
elif self.expire_strategy == UserExpireStrategy.START_ON_FIRST_USE:
108+
return int(
109+
(
110+
self.expire_date.astimezone(timezone.utc)
111+
- datetime.now(timezone.utc)
112+
).total_seconds()
113+
)
114+
elif (
115+
self.expire_strategy == UserExpireStrategy.START_ON_FIRST_USE
116+
and self.usage_duration
117+
):
110118
return self.usage_duration
111-
return None
119+
return 0
112120

113121
@property
114122
def data_percent(self) -> int:

app/routers/users/data.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ async def data(callback: CallbackQuery, callback_data: PageCB):
2424
user = await ClinetManager.get_user(server, callback_data.dataid)
2525
if not user:
2626
return await callback.answer(text=MessageTexts.NOT_FOUND, show_alert=True)
27-
2827
return await callback.message.edit_text(
2928
text=user.format_data_str(),
3029
reply_markup=BotKeys.selector(

app/settings/utils/user.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -156,12 +156,12 @@ def advenced_charge_user_data(
156156
if user.data_limit
157157
else 0,
158158
expire_strategy=expire_strategy,
159-
expire_date=(user.expire_date or datetime.utcnow())
160-
+ timedelta(days=int(datelimit))
159+
expire_date=timedelta(
160+
seconds=user.time_to_second + int(datelimit * (24 * 60 * 60))
161+
)
161162
if expire_strategy == MarzneshinUserExpireStrategy.FIXED_DATE
162163
else None,
163-
usage_duration=(user.usage_duration or 0)
164-
+ (int(datelimit) * (24 * 60 * 60))
164+
usage_duration=user.time_to_second + (int(datelimit) * (24 * 60 * 60))
165165
if expire_strategy == MarzneshinUserExpireStrategy.START_ON_FIRST_USE
166166
else None,
167167
).dict()

0 commit comments

Comments
 (0)