-
Notifications
You must be signed in to change notification settings - Fork 0
/
afk.py
157 lines (144 loc) · 4.98 KB
/
afk.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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
# Oreo
from . import get_help
__doc__ = get_help("help_afk")
import asyncio
from telegraph import upload_file as uf
from telethon import events
from pyOreo.dB.afk_db import add_afk, del_afk, is_afk
from pyOreo.dB.base import KeyManager
from . import (
LOG_CHANNEL,
NOSPAM_CHAT,
Redis,
asst,
get_string,
mediainfo,
udB,
oreo_bot,
oreo_cmd,
)
old_afk_msg = []
is_approved = KeyManager("PMPERMIT", cast=list).contains
@oreo_cmd(pattern="afk( (.*)|$)", owner_only=True)
async def set_afk(event):
if event.client._bot or is_afk():
return
text, media, media_type = None, None, None
if event.pattern_match.group(1).strip():
text = event.text.split(maxsplit=1)[1]
reply = await event.get_reply_message()
if reply:
if reply.text and not text:
text = reply.text
if reply.media:
media_type = mediainfo(reply.media)
if media_type.startswith(("pic", "gif")):
file = await event.client.download_media(reply.media)
iurl = uf(file)
media = f"https://graph.org{iurl[0]}"
else:
media = reply.file.id
await event.eor("`Done`", time=2)
add_afk(text, media_type, media)
oreo_bot.add_handler(remove_afk, events.NewMessage(outgoing=True))
oreo_bot.add_handler(
on_afk,
events.NewMessage(
incoming=True, func=lambda e: bool(e.mentioned or e.is_private)
),
)
msg1, msg2 = None, None
if text and media:
if "sticker" in media_type:
msg1 = await oreo_bot.send_file(event.chat_id, file=media)
msg2 = await oreo_bot.send_message(
event.chat_id, get_string("afk_5").format(text)
)
else:
msg1 = await oreo_bot.send_message(
event.chat_id, get_string("afk_5").format(text), file=media
)
elif media:
if "sticker" in media_type:
msg1 = await oreo_bot.send_file(event.chat_id, file=media)
msg2 = await oreo_bot.send_message(event.chat_id, get_string("afk_6"))
else:
msg1 = await oreo_bot.send_message(
event.chat_id, get_string("afk_6"), file=media
)
elif text:
msg1 = await event.respond(get_string("afk_5").format(text))
else:
msg1 = await event.respond(get_string("afk_6"))
old_afk_msg.append(msg1)
if msg2:
old_afk_msg.append(msg2)
return await asst.send_message(LOG_CHANNEL, msg2.text)
await asst.send_message(LOG_CHANNEL, msg1.text)
async def remove_afk(event):
if event.is_private and udB.get_key("PMSETTING") and not is_approved(event.chat_id):
return
elif "afk" in event.text.lower():
return
elif event.chat_id in NOSPAM_CHAT:
return
if is_afk():
_, _, _, afk_time = is_afk()
del_afk()
off = await event.reply(get_string("afk_1").format(afk_time))
await asst.send_message(LOG_CHANNEL, get_string("afk_2").format(afk_time))
for x in old_afk_msg:
try:
await x.delete()
except BaseException:
pass
await asyncio.sleep(10)
await off.delete()
async def on_afk(event):
if event.is_private and Redis("PMSETTING") and not is_approved(event.chat_id):
return
elif "afk" in event.text.lower():
return
elif not is_afk():
return
if event.chat_id in NOSPAM_CHAT:
return
sender = await event.get_sender()
if sender.bot or sender.verified:
return
text, media_type, media, afk_time = is_afk()
msg1, msg2 = None, None
if text and media:
if "sticker" in media_type:
msg1 = await event.reply(file=media)
msg2 = await event.reply(get_string("afk_3").format(afk_time, text))
else:
msg1 = await event.reply(
get_string("afk_3").format(afk_time, text), file=media
)
elif media:
if "sticker" in media_type:
msg1 = await event.reply(file=media)
msg2 = await event.reply(get_string("afk_4").format(afk_time))
else:
msg1 = await event.reply(get_string("afk_4").format(afk_time), file=media)
elif text:
msg1 = await event.reply(get_string("afk_3").format(afk_time, text))
else:
msg1 = await event.reply(get_string("afk_4").format(afk_time))
for x in old_afk_msg:
try:
await x.delete()
except BaseException:
pass
old_afk_msg.append(msg1)
if msg2:
old_afk_msg.append(msg2)
if udB.get_key("AFK_DB"):
oreo_bot.add_handler(remove_afk, events.NewMessage(outgoing=True))
oreo_bot.add_handler(
on_afk,
events.NewMessage(
incoming=True, func=lambda e: bool(e.mentioned or e.is_private)
),
)