forked from sultansq/kiu
-
Notifications
You must be signed in to change notification settings - Fork 0
/
autoleave.py
79 lines (70 loc) · 2.79 KB
/
autoleave.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import asyncio
from datetime import datetime
import config
from AnonX import app
from AnonX.core.call import Anon, autoend
from AnonX.utils.database import (get_client, is_active_chat,
is_autoend)
from strings.filters import command
async def auto_leave():
if config.AUTO_LEAVING_ASSISTANT == str(True):
while not await asyncio.sleep(
config.AUTO_LEAVE_ASSISTANT_TIME
):
from AnonX.core.userbot import assistants
for num in assistants:
client = await get_client(num)
left = 0
try:
async for i in client.iter_dialogs():
chat_type = i.chat.type
if chat_type in [
"supergroup",
"group",
"channel",
]:
chat_id = i.chat.id
if (
chat_id != config.LOG_GROUP_ID
and chat_id != -1001686672798
and chat_id != -1001840101403
and chat_id != -1001549206010
):
if left == 20:
continue
if not await is_active_chat(chat_id):
try:
await client.leave_chat(
chat_id
)
left += 1
except:
continue
except:
pass
asyncio.create_task(auto_leave())
async def auto_end():
while not await asyncio.sleep(5):
if not await is_autoend():
continue
for chat_id in autoend:
timer = autoend.get(chat_id)
if not timer:
continue
if datetime.now() > timer:
if not await is_active_chat(chat_id):
autoend[chat_id] = {}
continue
autoend[chat_id] = {}
try:
await Anon.stop_stream(chat_id)
except:
continue
try:
await app.send_message(
chat_id,
"» ʙᴏᴛ ᴀᴜᴛᴏᴍᴀᴛɪᴄᴀʟʟʏ ʟᴇғᴛ ᴠɪᴅᴇᴏᴄʜᴀᴛ ʙᴇᴄᴀᴜsᴇ ɴᴏ ᴏɴᴇ ᴡᴀs ʟɪsᴛᴇɴɪɴɢ ᴏɴ ᴠɪᴅᴇᴏᴄʜᴀᴛ.",
)
except:
continue
asyncio.create_task(auto_end())