Skip to content

Commit

Permalink
add new functionalites
Browse files Browse the repository at this point in the history
  • Loading branch information
hiddify-com committed Jul 12, 2024
1 parent e726613 commit 46f6246
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 8 deletions.
4 changes: 2 additions & 2 deletions hiddifypanel_bot/hiddifyapi/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,15 +106,15 @@ async def reset_user_last_reset_time(self, uuid: str) -> User:

async def reset_package_days(self, uuid: str) -> User:
"""Update the package days for a user."""
user_data = await self.find_user(uuid)
user_data = await self.get_user(uuid)
if not user_data:
raise HiddifyApiError("User not found.")
user_data |= {"last_reset_time": datetime.now().strftime("%Y-%m-%d"), "start_date": None}
return await self.update_user(uuid, user_data)

async def reset_traffic(self, uuid: str) -> User:
"""Reset the traffic limit for a user to 0."""
user_data = await self.find_user(uuid)
user_data = await self.get_user(uuid)
if not user_data:
raise HiddifyApiError("User not found.")
user_data["current_usage_GB"] = 0
Expand Down
31 changes: 28 additions & 3 deletions hiddifypanel_bot/modules/admin/edit_user.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,35 @@ async def enable_user_handler(call: HCallbackQuery):
await bot.answer_callback_query(call.id)


@bot.callback_query_handler(call_action=C.USER_ENABLE, role=Role.AGENT)
async def enable_user_handler(call: HCallbackQuery):
@bot.callback_query_handler(call_action=C.USER_DISABLE, role=Role.AGENT)
async def disable_user_handler(call: HCallbackQuery):
uuid = call.data.split(":")[-1]
user = await call.message.hapi.update_user(uuid, {"enable": True})
user = await call.message.hapi.update_user(uuid, {"enable": False})
await send_user_info(call.message, user)
await bot.delete_message(call.message.chat_id, call.message.id)
await bot.answer_callback_query(call.id)


@bot.callback_query_handler(call_action=C.USER_RESET_DAYS, role=Role.AGENT)
async def disable_user_handler(call: HCallbackQuery):
uuid = call.data.split(":")[-1]
user = await call.message.hapi.reset_package_days(uuid)
await send_user_info(call.message, user)
await bot.delete_message(call.message.chat_id, call.message.id)
await bot.answer_callback_query(call.id)

@bot.callback_query_handler(call_action=C.USER_RESET_USAGE, role=Role.AGENT)
async def disable_user_handler(call: HCallbackQuery):
uuid = call.data.split(":")[-1]
user = await call.message.hapi.reset_traffic(uuid)
await send_user_info(call.message, user)
await bot.delete_message(call.message.chat_id, call.message.id)
await bot.answer_callback_query(call.id)

@bot.callback_query_handler(call_action=C.USER_DELETE, role=Role.AGENT)
async def disable_user_handler(call: HCallbackQuery):
uuid = call.data.split(":")[-1]
user = await call.message.hapi.delete_user(uuid)
await bot.delete_message(call.message.chat_id, call.message.id)
await bot.answer_callback_query(call.id,_("admin.user.removed"),show_alert=True)

4 changes: 2 additions & 2 deletions hiddifypanel_bot/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
"add_user":"Add User",
"server_info":"Server Info",
"admin_users":"Admins",
"userinfo_started":"Name: ${name}\nUsage Limit: ${usage_limit_GB} GB\nCurrent Usage: ${current_usage_GB} GB\nLast Online: ${online_icon} ${last_online_relative}\nPackage Days: ${package_days}\nStart Date: ${start_date_relative}",
"userinfo_notstarted":"Name: ${name}\nUsage Limit: ${usage_limit} GB\nCurrent Usage: ${current_usage} GB\nLast Online: ${online_icon} ${last_online}\nPackage Days: ${package_days}\nStart Date: ${start_date}"
"userinfo_started":"Name: ${name}\nUsage: ${current_usage_GB} GB / ${usage_limit_GB} GB\nLast Online: ${online_icon} ${last_online_relative}\nPackage Days: ${package_days}\nStart Date: ${start_date_relative}",
"userinfo_not_started":"Name: ${name}\nCurrent Usage: ${current_usage_GB} GB / ${usage_limit_GB} GB\nLast Online: ${online_icon} ${last_online}\nPackage Days: ${package_days}\nStart Date: ${start_date}"
},
"unauthorized": "You do not have permission to use this bot.",
"authorized": "Unauthorized",
Expand Down
2 changes: 1 addition & 1 deletion hiddifypanel_bot/utils/tghelper.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def format_user_message_from_admin(lang, user_data):
user_data["online_icon"] = "❌"

user_data["current_usage_GB"] = "{:.3f}".format(user_data.get("current_usage_GB", 0))
user_data["usage_limit_GB"] = "{:.3f}".format(user_data.get("profile_usage_total", 0))
user_data["usage_limit_GB"] = "{:.3f}".format(user_data.get("usage_limit_GB", 0))

if start_date:
user_data["start_date_relative"] = format_timedelta(time_diff, lang, granularity="days")
Expand Down

0 comments on commit 46f6246

Please sign in to comment.