| 1 |
a47eb4c |
Dawsh |
2y ago |
from datetime import datetime |
| 2 |
a47eb4c |
Dawsh |
2y ago |
from app.db import GetDB, crud |
| 3 |
a47eb4c |
Dawsh |
2y ago |
from app.models.user import UserResponse |
| 4 |
a47eb4c |
Dawsh |
2y ago |
from app.telegram import bot |
| 5 |
a47eb4c |
Dawsh |
2y ago |
# from pytz import UTC |
| 6 |
a47eb4c |
Dawsh |
2y ago |
from telebot.custom_filters import ChatFilter |
| 7 |
a47eb4c |
Dawsh |
2y ago |
from telebot.util import extract_arguments |
| 8 |
a47eb4c |
Dawsh |
2y ago |
|
| 9 |
a47eb4c |
Dawsh |
2y ago |
from app.utils.system import readable_size |
| 10 |
a47eb4c |
Dawsh |
2y ago |
|
| 11 |
a47eb4c |
Dawsh |
2y ago |
bot.add_custom_filter(ChatFilter()) |
| 12 |
a47eb4c |
Dawsh |
2y ago |
|
| 13 |
a47eb4c |
Dawsh |
2y ago |
|
| 14 |
a47eb4c |
Dawsh |
2y ago |
@bot.message_handler(commands=['usage']) |
| 15 |
a47eb4c |
Dawsh |
2y ago |
def usage_command(message): |
| 16 |
a47eb4c |
Dawsh |
2y ago |
username = extract_arguments(message.text) |
| 17 |
a47eb4c |
Dawsh |
2y ago |
if not username: |
| 18 |
a47eb4c |
Dawsh |
2y ago |
return bot.reply_to(message, 'Usage: `/usage <username>`', parse_mode='MarkdownV2') |
| 19 |
a47eb4c |
Dawsh |
2y ago |
|
| 20 |
a47eb4c |
Dawsh |
2y ago |
with GetDB() as db: |
| 21 |
a47eb4c |
Dawsh |
2y ago |
dbuser = crud.get_user(db, username) |
| 22 |
a47eb4c |
Dawsh |
2y ago |
|
| 23 |
a47eb4c |
Dawsh |
2y ago |
if not dbuser: |
| 24 |
a47eb4c |
Dawsh |
2y ago |
return bot.reply_to(message, "No user found with this username") |
| 25 |
a47eb4c |
Dawsh |
2y ago |
user = UserResponse.model_validate(dbuser) |
| 26 |
a47eb4c |
Dawsh |
2y ago |
|
| 27 |
a47eb4c |
Dawsh |
2y ago |
statuses = { |
| 28 |
a47eb4c |
Dawsh |
2y ago |
'active': '✅', |
| 29 |
a47eb4c |
Dawsh |
2y ago |
'expired': '🕰', |
| 30 |
a47eb4c |
Dawsh |
2y ago |
'limited': '📵', |
| 31 |
a47eb4c |
Dawsh |
2y ago |
'disabled': '❌'} |
| 32 |
a47eb4c |
Dawsh |
2y ago |
|
| 33 |
a47eb4c |
Dawsh |
2y ago |
text = f'''\ |
| 34 |
a47eb4c |
Dawsh |
2y ago |
┌─{statuses[user.status]} <b>Status:</b> <code>{user.status.title()}</code> |
| 35 |
a47eb4c |
Dawsh |
2y ago |
│ └─<b>Username:</b> <code>{user.username}</code> |
| 36 |
a47eb4c |
Dawsh |
2y ago |
│ |
| 37 |
a47eb4c |
Dawsh |
2y ago |
├─🔋 <b>Data limit:</b> <code>{readable_size(user.data_limit) if user.data_limit else 'Unlimited'}</code> |
| 38 |
a47eb4c |
Dawsh |
2y ago |
│ └─<b>Data Used:</b> <code>{readable_size(user.used_traffic) if user.used_traffic else "-"}</code> |
| 39 |
a47eb4c |
Dawsh |
2y ago |
│ |
| 40 |
a47eb4c |
Dawsh |
2y ago |
└─📅 <b>Expiry Date:</b> <code>{datetime.fromtimestamp(user.expire).date() if user.expire else 'Never'}</code> |
| 41 |
a47eb4c |
Dawsh |
2y ago |
└─<b>Days left:</b> <code>{(datetime.fromtimestamp(user.expire or 0) - datetime.now()).days if user.expire else '-'}</code>''' |
| 42 |
a47eb4c |
Dawsh |
2y ago |
|
| 43 |
a47eb4c |
Dawsh |
2y ago |
return bot.reply_to(message, text, parse_mode='HTML') |