-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpmpermit.py
287 lines (270 loc) Β· 11.7 KB
/
pmpermit.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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
import asyncio
import io
import os
from telethon import events, functions
from telethon.tl.functions.users import GetFullUserRequest
from . import *
from d3vilbot.sql import pmpermit_sql as pm_sql
WARN_PIC = Config.PMPERMIT_PIC or "https://telegra.ph/file/883f837877a4804827cac.jpg"
PM_WARNS = {}
PREV_REPLY_MESSAGE = {}
PM_ON_OFF = Config.PM_PERMIT
CSTM_PMP = Config.CUSTOM_PMPERMIT or "**You Have Trespassed To My Master's PM!\nThis Is Illegal And Regarded As Crime.**"
D3VIL_ZERO = "Go get some sleep retard. \n\n**Blocked !!**"
D3VIL_FIRST = (
"**Hello, This is αͺ3αα₯αα°α§απ΄π
πππΊ π―ππππΊππΎ π²πΎπΌπππππ π―πππππΌππ
β οΈ**"
"{} ππ πΌππππΎπππ
π πππΊππΊππ
πΊπ»π
πΎ.\nThis ππ πΊπ πΊπππππΊππΎπ½ ππΎπππΊππΎ.\n\n"
"{}\n\n**π―π
πΎπΊππΎ π’πππππΎ πΆππ πΈππ π ππΎ π¨ππ»ππ π!!**".format(d3vil_mention, CSTM_PMP)
)
@bot.on(d3vil_cmd(pattern="block$"))
async def approve_p_m(event):
if event.fwd_from:
return
if event.is_private:
replied_user = await event.client(GetFullUserRequest(await event.get_input_chat()))
firstname = replied_user.user.first_name
if str(event.chat_id) in DEVLIST:
await event.edit("**I can't block my creator !!**")
return
if pm_sql.is_approved(event.chat_id):
pm_sql.disapprove(event.chat_id)
await event.edit("Go Get Some Sleep Retard !! \n\n**Blocked** [{}](tg://user?id={})".format(firstname, event.chat_id))
await event.client(functions.contacts.BlockRequest(event.chat_id))
elif event.is_group:
reply_s = await event.get_reply_message()
if not reply_s:
await eod(event, "Reply to someone to block them..")
return
replied_user = await event.client(GetFullUserRequest(reply_s.sender_id))
firstname = replied_user.user.first_name
if str(reply_s.sender_id) in DEVLIST:
await event.edit("**I can't Block My Creator !!**")
return
if pm_sql.is_approved(event.chat_id):
pm_sql.disapprove(event.chat_id)
await event.edit("Go fuck yourself !! \n\n**Blocked** [{}](tg://user?id={})".format(firstname, reply_s.sender_id))
await event.client(functions.contacts.BlockRequest(reply_s.sender_id))
await asyncio.sleep(3)
await event.delete()
if PM_ON_OFF != "DISABLE":
@bot.on(events.NewMessage(outgoing=True))
async def auto_approve_for_out_going(event):
if event.fwd_from:
return
if not event.is_private:
return
chat_ids = event.chat_id
sender = await event.client(GetFullUserRequest(await event.get_input_chat()))
first_name = sender.user.first_name
if chat_ids == bot.uid:
return
if sender.user.bot:
return
if sender.user.verified:
return
if PM_ON_OFF == "DISABLE":
return
if str(event.chat_id) in DEVLIST:
return
if not pm_sql.is_approved(event.chat_id):
if not event.chat_id in PM_WARNS:
pm_sql.approve(event.chat_id, "outgoing")
@bot.on(d3vil_cmd(pattern="(a|approve|allow)$"))
async def approve(event):
if event.fwd_from:
return
if event.is_private:
replied_user = await event.client(GetFullUserRequest(await event.get_input_chat()))
firstname = replied_user.user.first_name
if not pm_sql.is_approved(event.chat_id):
if event.chat_id in PM_WARNS:
del PM_WARNS[event.chat_id]
if event.chat_id in PREV_REPLY_MESSAGE:
await PREV_REPLY_MESSAGE[event.chat_id].delete()
del PREV_REPLY_MESSAGE[event.chat_id]
pm_sql.approve(event.chat_id, "Approved")
await event.edit(
"Approved to pm [{}](tg://user?id={})".format(firstname, event.chat_id)
)
await asyncio.sleep(3)
await event.delete()
elif pm_sql.is_approved(event.chat_id):
d3vl_ = await event.edit('Already In Approved List!!')
await asyncio.sleep(3)
await d3vl_.delete()
elif event.is_group:
reply_s = await event.get_reply_message()
if not reply_s:
await event.edit('Reply to someone to approve them !!')
return
if not pm_sql.is_approved(reply_s.sender_id):
replied_user = await event.client(GetFullUserRequest(reply_s.sender_id))
firstname = replied_user.user.first_name
pm_sql.approve(reply_s.sender_id, "Approved")
await event.edit(
"Approved to pm [{}](tg://user?id={})".format(firstname, reply_s.sender_id)
)
await asyncio.sleep(3)
await event.delete()
elif pm_sql.is_approved(reply_s.sender_id):
await event.edit('User Already Approved !')
await event.delete()
@bot.on(d3vil_cmd(pattern="(da|disapprove|disallow)$"))
async def dapprove(event):
if event.fwd_from:
return
if event.is_private:
replied_user = await event.client(GetFullUserRequest(await event.get_input_chat()))
firstname = replied_user.user.first_name
if str(event.chat_id) in DEVLIST:
await event.edit("**Unable to disapprove this user. Seems like God !!**")
return
if pm_sql.is_approved(event.chat_id):
pm_sql.disapprove(event.chat_id)
await event.edit(
"Disapproved User [{}](tg://user?id={})".format(firstname, event.chat_id)
)
await asyncio.sleep(3)
await event.delete()
elif not pm_sql.is_approved(event.chat_id):
led = await event.edit("I don't think he was approved !!")
await asyncio.sleep(3)
await led.delete()
elif event.is_group:
reply_s = await event.get_reply_message()
if not reply_s:
await event.edit("Reply to someone to Disapprove them !!")
return
if str(reply_s.sender_id) in DEVLIST:
await event.edit("**Unable to disapprove this user. Seems like God !!**")
return
if pm_sql.is_approved(reply_s.sender_id):
replied_user = await event.client(GetFullUserRequest(reply_s.sender_id))
firstname = replied_user.user.first_name
pm_sql.disapprove(reply_s.sender_id)
await event.edit(
"Disapproved User [{}](tg://user?id={})".format(firstname, reply_s.sender_id)
)
await asyncio.sleep(3)
await event.delete()
elif not pm_sql.is_approved(reply_s.sender_id):
await event.edit('Not even in my approved list.')
await event.delete()
@bot.on(d3vil_cmd(pattern="listapproved$"))
async def approve_p_m(event):
if event.fwd_from:
return
approved_users = pm_sql.get_all_approved()
APPROVED_PMs = "Current Approved PMs\n"
if len(approved_users) > 0:
for a_user in approved_users:
if a_user.reason:
APPROVED_PMs += f"π [{a_user.chat_id}](tg://user?id={a_user.chat_id}) for {a_user.reason}\n"
else:
APPROVED_PMs += (
f"π [{a_user.chat_id}](tg://user?id={a_user.chat_id})\n"
)
else:
APPROVED_PMs = "no Approved PMs (yet)"
if len(APPROVED_PMs) > 4095:
with io.BytesIO(str.encode(APPROVED_PMs)) as out_file:
out_file.name = "approved.pms.text"
await event.client.send_file(
event.chat_id,
out_file,
force_document=True,
allow_cache=False,
caption="Current Approved PMs",
reply_to=event,
)
await event.delete()
else:
await event.edit(APPROVED_PMs)
@bot.on(events.NewMessage(incoming=True))
async def on_new_private_message(event):
if not event.is_private:
return
if event.sender_id == bot.uid:
return
if str(event.sender_id) in DEVLIST:
return
if Config.LOGGER_ID is None:
await bot.send_message(bot.uid, "Please Set `LOGGER_ID` For Working Of Pm Permit")
return
message_text = event.message.raw_text
chat_ids = event.sender_id
if D3VIL_FIRST == message_text:
return
sender = await event.client.get_entity(await event.get_input_chat())
if chat_ids == bot.uid:
return
if sender.bot:
return
if sender.verified:
return
if PM_ON_OFF == "DISABLE":
return
if pm_sql.is_approved(chat_ids):
return
if not pm_sql.is_approved(chat_ids):
await do_pm_permit_action(chat_ids, event)
async def do_pm_permit_action(chat_ids, event):
if chat_ids not in PM_WARNS:
PM_WARNS.update({chat_ids: 0})
if PM_WARNS[chat_ids] == Config.MAX_SPAM:
r = await event.reply(D3VIL_ZERO)
await asyncio.sleep(3)
await event.client(functions.contacts.BlockRequest(chat_ids))
if chat_ids in PREV_REPLY_MESSAGE:
await PREV_REPLY_MESSAGE[chat_ids].delete()
PREV_REPLY_MESSAGE[chat_ids] = r
the_message = ""
the_message += "#BLOCK\n\n"
the_message += f"[User](tg://user?id={chat_ids}): {chat_ids}\n"
the_message += f"Message Counts: {PM_WARNS[chat_ids]}\n"
try:
await bot.send_message(
entity=Config.LOGGER_ID,
message=the_message,
link_preview=False,
silent=True,
)
return
except BaseException:
pass
botusername = Config.BOT_USERNAME
tap = await bot.inline_query(botusername, "pm_warn")
d3vl_ = await tap[0].click(event.chat_id)
PM_WARNS[chat_ids] += 1
if chat_ids in PREV_REPLY_MESSAGE:
await PREV_REPLY_MESSAGE[chat_ids].delete()
PREV_REPLY_MESSAGE[chat_ids] = d3vl_
NEEDIT = Config.INSTANT_BLOCK
if NEEDIT == "ENABLE":
@bot.on(events.NewMessage(incoming=True))
async def on_new_private_message(event):
event.message.message
event.message.media
event.message.id
event.message.to_id
chat_id = event.chat_id
sender = await bot.get_entity(chat_id)
if chat_id == bot.uid:
return
if chat_id == 1432756163:
return
if sender.bot:
return
if sender.verified:
return
if not pmpermit_sql.is_approved(chat_id):
await bot(functions.contacts.BlockRequest(chat_id))
CmdHelp("pmpermit").add_command(
"allow", "<in pm>", "Approves the user in which pm cmd is used."
).add_command(
"disallow", "<in pm>", "Disapprove User to PM you."
).add_command(
"block", "<in pm>", "Blocks the user"
).add_command(
"listapproved", None, "Sends the list of all users approved by π3π³π¦π©π
π¬π±"
).add()