Update chatbot/__main__.py
Browse files- chatbot/__main__.py +28 -0
chatbot/__main__.py
CHANGED
@@ -39,6 +39,33 @@ logging.getLogger("pyrogram.syncer").setLevel(logging.WARNING)
|
|
39 |
logging.getLogger("pyrogram.client").setLevel(logging.WARNING)
|
40 |
loop = asyncio.get_event_loop()
|
41 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
42 |
async def process_unfreezes(client):
|
43 |
while True:
|
44 |
try:
|
@@ -83,6 +110,7 @@ async def main():
|
|
83 |
randydev = Randydev(loop=loop)
|
84 |
|
85 |
await randydev.start()
|
|
|
86 |
asyncio.create_task(process_unfreezes(randydev))
|
87 |
LOGS.info("Application startup complete")
|
88 |
|
|
|
39 |
logging.getLogger("pyrogram.client").setLevel(logging.WARNING)
|
40 |
loop = asyncio.get_event_loop()
|
41 |
|
42 |
+
async def premium_expiry_monitor(client):
|
43 |
+
while True:
|
44 |
+
try:
|
45 |
+
now = dt.now()
|
46 |
+
expired = db.user_premium.find({
|
47 |
+
"is_premium": True,
|
48 |
+
"premium_expiry": {"$lt": now}
|
49 |
+
})
|
50 |
+
|
51 |
+
async for user in expired:
|
52 |
+
await db.user_premium.update_one(
|
53 |
+
{"user_id": user["user_id"]},
|
54 |
+
{"$set": {"is_premium": False}}
|
55 |
+
)
|
56 |
+
with suppress(Exception):
|
57 |
+
await client.send_message(
|
58 |
+
user["user_id"],
|
59 |
+
"⚠️ Your premium subscription has expired\n"
|
60 |
+
"You've been downgraded to free tier (5 images/day)\n\n"
|
61 |
+
)
|
62 |
+
|
63 |
+
await asyncio.sleep(3600)
|
64 |
+
|
65 |
+
except Exception as e:
|
66 |
+
LOGS.error(f"Premium monitor error: {e}")
|
67 |
+
await asyncio.sleep(600)
|
68 |
+
|
69 |
async def process_unfreezes(client):
|
70 |
while True:
|
71 |
try:
|
|
|
110 |
randydev = Randydev(loop=loop)
|
111 |
|
112 |
await randydev.start()
|
113 |
+
asyncio.create_task(premium_expiry_monitor(randydev))
|
114 |
asyncio.create_task(process_unfreezes(randydev))
|
115 |
LOGS.info("Application startup complete")
|
116 |
|