Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -939,20 +939,6 @@ async def process_broadcast(client, message):
|
|
| 939 |
await message.reply(f"β
Broadcast Complete!\nSuccess: {success}\nFailed: {failed}")
|
| 940 |
except Exception as e: print(e)
|
| 941 |
|
| 942 |
-
@bot.on_message(filters.command(["png", "addvideo"]) & filters.private & filters.user(ADMIN_IDS))
|
| 943 |
-
async def add_png(client, message):
|
| 944 |
-
try:
|
| 945 |
-
parts = message.command
|
| 946 |
-
needed_ref, duration = 3, "random"
|
| 947 |
-
if len(parts) == 4 and parts[1].isdigit(): needed_ref, duration, thumbnail_url = int(parts[1]), parts[2], parts[3]
|
| 948 |
-
elif len(parts) == 3 and parts[1].isdigit(): needed_ref, thumbnail_url = int(parts[1]), parts[2]
|
| 949 |
-
elif len(parts) == 2: thumbnail_url = parts[1]
|
| 950 |
-
else: return await message.reply("β Invalid format.")
|
| 951 |
-
|
| 952 |
-
admin_states[message.chat.id] = {"step": 1, "thumbnail_url": f"{thumbnail_url}||{duration}", "needed_ref": needed_ref}
|
| 953 |
-
await message.reply("β
Now send the Video/Embed Link.")
|
| 954 |
-
except Exception as e: print(e)
|
| 955 |
-
|
| 956 |
@bot.on_message(filters.command("clean") & filters.private & filters.user(ADMIN_IDS))
|
| 957 |
async def manual_clean_channel(client, message):
|
| 958 |
await message.reply("β³ <b>Starting channel cleanup...</b>\nChecking database users to verify active sessions. This might take a while.")
|
|
@@ -978,7 +964,7 @@ async def manual_clean_channel(client, message):
|
|
| 978 |
is_valid = False
|
| 979 |
if res_session.data:
|
| 980 |
session_string = res_session.data[0]['session_string']
|
| 981 |
-
temp_client = Client(f"
|
| 982 |
try:
|
| 983 |
await temp_client.connect()
|
| 984 |
await temp_client.get_me()
|
|
@@ -992,13 +978,64 @@ async def manual_clean_channel(client, message):
|
|
| 992 |
try: await temp_client.disconnect()
|
| 993 |
except: pass
|
| 994 |
is_valid = True
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 995 |
|
| 996 |
if not is_valid:
|
| 997 |
try:
|
| 998 |
await bot.ban_chat_member(PREMIUM_CHANNEL_ID, user_id)
|
| 999 |
await bot.unban_chat_member(PREMIUM_CHANNEL_ID, user_id)
|
| 1000 |
-
except Exception:
|
|
|
|
|
|
|
| 1001 |
await asyncio.sleep(2)
|
|
|
|
| 1002 |
except FloodWait as e:
|
| 1003 |
await asyncio.sleep(e.value + 1)
|
| 1004 |
except Exception:
|
|
|
|
| 939 |
await message.reply(f"β
Broadcast Complete!\nSuccess: {success}\nFailed: {failed}")
|
| 940 |
except Exception as e: print(e)
|
| 941 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 942 |
@bot.on_message(filters.command("clean") & filters.private & filters.user(ADMIN_IDS))
|
| 943 |
async def manual_clean_channel(client, message):
|
| 944 |
await message.reply("β³ <b>Starting channel cleanup...</b>\nChecking database users to verify active sessions. This might take a while.")
|
|
|
|
| 964 |
is_valid = False
|
| 965 |
if res_session.data:
|
| 966 |
session_string = res_session.data[0]['session_string']
|
| 967 |
+
temp_client = Client(f"manual_chk_{user_id}", session_string=session_string, api_id=API_ID, api_hash=API_HASH, in_memory=True)
|
| 968 |
try:
|
| 969 |
await temp_client.connect()
|
| 970 |
await temp_client.get_me()
|
|
|
|
| 978 |
try: await temp_client.disconnect()
|
| 979 |
except: pass
|
| 980 |
is_valid = True
|
| 981 |
+
|
| 982 |
+
if not is_valid:
|
| 983 |
+
try:
|
| 984 |
+
await client.ban_chat_member(PREMIUM_CHANNEL_ID, user_id)
|
| 985 |
+
await client.unban_chat_member(PREMIUM_CHANNEL_ID, user_id)
|
| 986 |
+
kicked += 1
|
| 987 |
+
except Exception: pass
|
| 988 |
+
|
| 989 |
+
await asyncio.sleep(1.5)
|
| 990 |
+
except FloodWait as e:
|
| 991 |
+
await asyncio.sleep(e.value + 1)
|
| 992 |
+
except Exception:
|
| 993 |
+
pass
|
| 994 |
+
|
| 995 |
+
await message.reply(f"β
<b>Cleanup Complete!</b>\n\nπ₯ Members checked: {checked}\nπ’ Users Kicked: {kicked}")
|
| 996 |
+
except Exception as e:
|
| 997 |
+
await message.reply(f"β Error: {e}")
|
| 998 |
+
|
| 999 |
+
async def auto_clean_channel_loop():
|
| 1000 |
+
await asyncio.sleep(60)
|
| 1001 |
+
while True:
|
| 1002 |
+
try:
|
| 1003 |
+
res_users = await db_query(lambda: supabase.table('referrals').select('user_id').execute())
|
| 1004 |
+
if res_users.data:
|
| 1005 |
+
user_ids = [u['user_id'] for u in res_users.data]
|
| 1006 |
+
for user_id in set(user_ids):
|
| 1007 |
+
try:
|
| 1008 |
+
chat_member = await bot.get_chat_member(PREMIUM_CHANNEL_ID, user_id)
|
| 1009 |
+
if chat_member.status in [enums.ChatMemberStatus.MEMBER, enums.ChatMemberStatus.RESTRICTED]:
|
| 1010 |
+
res_session = await db_query(lambda: supabase.table('user_sessions').select('session_string').eq('user_id', user_id).execute())
|
| 1011 |
+
|
| 1012 |
+
is_valid = False
|
| 1013 |
+
if res_session.data:
|
| 1014 |
+
session_string = res_session.data[0]['session_string']
|
| 1015 |
+
temp_client = Client(f"bg_chk_{user_id}", session_string=session_string, api_id=API_ID, api_hash=API_HASH, in_memory=True)
|
| 1016 |
+
try:
|
| 1017 |
+
await temp_client.connect()
|
| 1018 |
+
await temp_client.get_me()
|
| 1019 |
+
await temp_client.disconnect()
|
| 1020 |
+
is_valid = True
|
| 1021 |
+
except (SessionRevoked, AuthKeyUnregistered, UserDeactivated):
|
| 1022 |
+
try: await temp_client.disconnect()
|
| 1023 |
+
except: pass
|
| 1024 |
+
await db_query(lambda: supabase.table('user_sessions').delete().eq('user_id', user_id).execute())
|
| 1025 |
+
except Exception:
|
| 1026 |
+
try: await temp_client.disconnect()
|
| 1027 |
+
except: pass
|
| 1028 |
+
is_valid = True
|
| 1029 |
|
| 1030 |
if not is_valid:
|
| 1031 |
try:
|
| 1032 |
await bot.ban_chat_member(PREMIUM_CHANNEL_ID, user_id)
|
| 1033 |
await bot.unban_chat_member(PREMIUM_CHANNEL_ID, user_id)
|
| 1034 |
+
except Exception:
|
| 1035 |
+
pass
|
| 1036 |
+
|
| 1037 |
await asyncio.sleep(2)
|
| 1038 |
+
|
| 1039 |
except FloodWait as e:
|
| 1040 |
await asyncio.sleep(e.value + 1)
|
| 1041 |
except Exception:
|