Create myinfo.py
Browse files- chatbot/plugins/myinfo.py +62 -0
chatbot/plugins/myinfo.py
ADDED
@@ -0,0 +1,62 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import time
|
2 |
+
import os
|
3 |
+
from pyrogram import *
|
4 |
+
from pyrogram.types import *
|
5 |
+
|
6 |
+
from logger import LOGS
|
7 |
+
from database import db
|
8 |
+
from datetime import datetime as dt, timedelta
|
9 |
+
|
10 |
+
@Client.on_message(filters.command("mypremium"))
|
11 |
+
async def check_premium_status(client, message):
|
12 |
+
user_id = message.from_user.id
|
13 |
+
|
14 |
+
try:
|
15 |
+
user_data = await db.user_premium.find_one({"user_id": user_id}) or {
|
16 |
+
"is_premium": False,
|
17 |
+
"credits_used": 0,
|
18 |
+
"last_reset": datetime.now(),
|
19 |
+
"premium_expiry": None
|
20 |
+
}
|
21 |
+
|
22 |
+
credit_limit = 50 if user_data["is_premium"] else 5
|
23 |
+
remaining_credits = max(0, credit_limit - user_data.get("credits_used", 0))
|
24 |
+
|
25 |
+
is_active = user_data["is_premium"] and (
|
26 |
+
user_data.get("premium_expiry") is None or
|
27 |
+
user_data["premium_expiry"] > dt.now()
|
28 |
+
)
|
29 |
+
|
30 |
+
reset_time = user_data["last_reset"] + timedelta(days=1)
|
31 |
+
time_left = reset_time - datetime.now()
|
32 |
+
hours_left = int(time_left.total_seconds() // 3600)
|
33 |
+
|
34 |
+
status = "ACTIVE β
" if is_active else "INACTIVE β"
|
35 |
+
premium_expiry = (
|
36 |
+
f"\nβ Expires: {user_data['premium_expiry'].strftime('%Y-%m-%d %H:%M')}"
|
37 |
+
if user_data.get("premium_expiry")
|
38 |
+
else ""
|
39 |
+
)
|
40 |
+
|
41 |
+
text = (
|
42 |
+
f"π <b>Your Premium Status</b>\n\n"
|
43 |
+
f"β’ Status: {status}{premium_expiry}\n"
|
44 |
+
f"β’ Credits: {remaining_credits}/{credit_limit} images\n"
|
45 |
+
f"β’ Reset in: {hours_left} hours\n"
|
46 |
+
f"β’ Plan: {'Premium' if is_active else 'Free Tier'}\n\n"
|
47 |
+
)
|
48 |
+
|
49 |
+
markup = None
|
50 |
+
if not is_active:
|
51 |
+
markup = InlineKeyboardMarkup([[
|
52 |
+
InlineKeyboardButton("β¨ Upgrade Premium", callback_data="get_premium")
|
53 |
+
]])
|
54 |
+
|
55 |
+
await message.reply_text(
|
56 |
+
text,
|
57 |
+
reply_markup=markup,
|
58 |
+
disable_web_page_preview=True
|
59 |
+
)
|
60 |
+
except Exception as e:
|
61 |
+
LOGS.error(f"Premium check error: {str(e)}")
|
62 |
+
await message.reply_text("β Error checking your status. Please try again later.")
|