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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# <============================================== IMPORTS =========================================================>
|
2 |
+
import html
|
3 |
+
|
4 |
+
from telegram import ChatPermissions, Update
|
5 |
+
from telegram.constants import ParseMode
|
6 |
+
from telegram.error import BadRequest
|
7 |
+
from telegram.ext import CommandHandler, ContextTypes, MessageHandler, filters
|
8 |
+
from telegram.helpers import mention_html, mention_markdown
|
9 |
+
|
10 |
+
import Database.sql.blsticker_sql as sql
|
11 |
+
from Mikobot import LOGGER, dispatcher
|
12 |
+
from Mikobot.plugins.connection import connected
|
13 |
+
from Mikobot.plugins.disable import DisableAbleCommandHandler
|
14 |
+
from Mikobot.plugins.helper_funcs.alternate import send_message
|
15 |
+
from Mikobot.plugins.helper_funcs.chat_status import check_admin, user_not_admin
|
16 |
+
from Mikobot.plugins.helper_funcs.misc import split_message
|
17 |
+
from Mikobot.plugins.helper_funcs.string_handling import extract_time
|
18 |
+
from Mikobot.plugins.log_channel import loggable
|
19 |
+
from Mikobot.plugins.warns import warn
|
20 |
+
|
21 |
+
# <=======================================================================================================>
|
22 |
+
|
23 |
+
|
24 |
+
# <================================================ FUNCTION =======================================================>
|
25 |
+
async def blackliststicker(update: Update, context: ContextTypes.DEFAULT_TYPE):
|
26 |
+
msg = update.effective_message # type: Optional[Message]
|
27 |
+
chat = update.effective_chat # type: Optional[Chat]
|
28 |
+
user = update.effective_user # type: Optional[User]
|
29 |
+
bot, args = context.bot, context.args
|
30 |
+
conn = await connected(bot, update, chat, user.id, need_admin=False)
|
31 |
+
if conn:
|
32 |
+
chat_id = conn
|
33 |
+
chat_obj = await dispatcher.bot.getChat(conn)
|
34 |
+
chat_name = chat_obj.title
|
35 |
+
else:
|
36 |
+
if chat.type == "private":
|
37 |
+
return
|
38 |
+
chat_id = update.effective_chat.id
|
39 |
+
chat_name = chat.title
|
40 |
+
|
41 |
+
sticker_list = "<b>List blacklisted stickers currently in {}:</b>\n".format(
|
42 |
+
chat_name,
|
43 |
+
)
|
44 |
+
|
45 |
+
all_stickerlist = sql.get_chat_stickers(chat_id)
|
46 |
+
|
47 |
+
if len(args) > 0 and args[0].lower() == "copy":
|
48 |
+
for trigger in all_stickerlist:
|
49 |
+
sticker_list += "<code>{}</code>\n".format(html.escape(trigger))
|
50 |
+
elif len(args) == 0:
|
51 |
+
for trigger in all_stickerlist:
|
52 |
+
sticker_list += " - <code>{}</code>\n".format(html.escape(trigger))
|
53 |
+
|
54 |
+
split_text = split_message(sticker_list)
|
55 |
+
for text in split_text:
|
56 |
+
if sticker_list == "<b>List blacklisted stickers currently in {}:</b>\n".format(
|
57 |
+
chat_name,
|
58 |
+
).format(html.escape(chat_name)):
|
59 |
+
await send_message(
|
60 |
+
update.effective_message,
|
61 |
+
"There are no blacklist stickers in <b>{}</b>!".format(
|
62 |
+
html.escape(chat_name),
|
63 |
+
),
|
64 |
+
parse_mode=ParseMode.HTML,
|
65 |
+
)
|
66 |
+
return
|
67 |
+
await send_message(
|
68 |
+
update.effective_message,
|
69 |
+
text,
|
70 |
+
parse_mode=ParseMode.HTML,
|
71 |
+
)
|
72 |
+
|
73 |
+
|
74 |
+
@check_admin(is_user=True)
|
75 |
+
async def add_blackliststicker(update: Update, context: ContextTypes.DEFAULT_TYPE):
|
76 |
+
bot = context.bot
|
77 |
+
msg = update.effective_message # type: Optional[Message]
|
78 |
+
chat = update.effective_chat # type: Optional[Chat]
|
79 |
+
user = update.effective_user # type: Optional[User]
|
80 |
+
words = msg.text.split(None, 1)
|
81 |
+
bot = context.bot
|
82 |
+
conn = await connected(bot, update, chat, user.id)
|
83 |
+
if conn:
|
84 |
+
chat_id = conn
|
85 |
+
chat_obj = await dispatcher.bot.getChat(conn)
|
86 |
+
chat_name = chat_obj.title
|
87 |
+
else:
|
88 |
+
chat_id = update.effective_chat.id
|
89 |
+
if chat.type == "private":
|
90 |
+
return
|
91 |
+
else:
|
92 |
+
chat_name = chat.title
|
93 |
+
|
94 |
+
if len(words) > 1:
|
95 |
+
text = words[1].replace("https://t.me/addstickers/", "")
|
96 |
+
to_blacklist = list(
|
97 |
+
{trigger.strip() for trigger in text.split("\n") if trigger.strip()},
|
98 |
+
)
|
99 |
+
|
100 |
+
added = 0
|
101 |
+
for trigger in to_blacklist:
|
102 |
+
try:
|
103 |
+
get = await bot.getStickerSet(trigger)
|
104 |
+
sql.add_to_stickers(chat_id, trigger.lower())
|
105 |
+
added += 1
|
106 |
+
except BadRequest:
|
107 |
+
await send_message(
|
108 |
+
update.effective_message,
|
109 |
+
"Sticker `{}` can not be found!".format(trigger),
|
110 |
+
parse_mode="markdown",
|
111 |
+
)
|
112 |
+
|
113 |
+
if added == 0:
|
114 |
+
return
|
115 |
+
|
116 |
+
if len(to_blacklist) == 1:
|
117 |
+
await send_message(
|
118 |
+
update.effective_message,
|
119 |
+
"Sticker <code>{}</code> added to blacklist stickers in <b>{}</b>!".format(
|
120 |
+
html.escape(to_blacklist[0]),
|
121 |
+
html.escape(chat_name),
|
122 |
+
),
|
123 |
+
parse_mode=ParseMode.HTML,
|
124 |
+
)
|
125 |
+
else:
|
126 |
+
await send_message(
|
127 |
+
update.effective_message,
|
128 |
+
"<code>{}</code> stickers added to blacklist sticker in <b>{}</b>!".format(
|
129 |
+
added,
|
130 |
+
html.escape(chat_name),
|
131 |
+
),
|
132 |
+
parse_mode=ParseMode.HTML,
|
133 |
+
)
|
134 |
+
elif msg.reply_to_message:
|
135 |
+
added = 0
|
136 |
+
trigger = msg.reply_to_message.sticker.set_name
|
137 |
+
if trigger is None:
|
138 |
+
await send_message(
|
139 |
+
update.effective_message,
|
140 |
+
"Sticker is invalid!",
|
141 |
+
)
|
142 |
+
return
|
143 |
+
try:
|
144 |
+
get = await bot.getStickerSet(trigger)
|
145 |
+
sql.add_to_stickers(chat_id, trigger.lower())
|
146 |
+
added += 1
|
147 |
+
except BadRequest:
|
148 |
+
await send_message(
|
149 |
+
update.effective_message,
|
150 |
+
"Sticker `{}` can not be found!".format(trigger),
|
151 |
+
parse_mode="markdown",
|
152 |
+
)
|
153 |
+
|
154 |
+
if added == 0:
|
155 |
+
return
|
156 |
+
|
157 |
+
await send_message(
|
158 |
+
update.effective_message,
|
159 |
+
"Sticker <code>{}</code> added to blacklist stickers in <b>{}</b>!".format(
|
160 |
+
trigger,
|
161 |
+
html.escape(chat_name),
|
162 |
+
),
|
163 |
+
parse_mode=ParseMode.HTML,
|
164 |
+
)
|
165 |
+
else:
|
166 |
+
await send_message(
|
167 |
+
update.effective_message,
|
168 |
+
"Tell me what stickers you want to add to the blacklist.",
|
169 |
+
)
|
170 |
+
|
171 |
+
|
172 |
+
@check_admin(is_user=True)
|
173 |
+
async def unblackliststicker(update: Update, context: ContextTypes.DEFAULT_TYPE):
|
174 |
+
bot = context.bot
|
175 |
+
msg = update.effective_message # type: Optional[Message]
|
176 |
+
chat = update.effective_chat # type: Optional[Chat]
|
177 |
+
user = update.effective_user # type: Optional[User]
|
178 |
+
words = msg.text.split(None, 1)
|
179 |
+
bot = context.bot
|
180 |
+
conn = await connected(bot, update, chat, user.id)
|
181 |
+
if conn:
|
182 |
+
chat_id = conn
|
183 |
+
chat_obj = await dispatcher.bot.getChat(conn)
|
184 |
+
chat_name = chat_obj.title
|
185 |
+
else:
|
186 |
+
chat_id = update.effective_chat.id
|
187 |
+
if chat.type == "private":
|
188 |
+
return
|
189 |
+
else:
|
190 |
+
chat_name = chat.title
|
191 |
+
|
192 |
+
if len(words) > 1:
|
193 |
+
text = words[1].replace("https://t.me/addstickers/", "")
|
194 |
+
to_unblacklist = list(
|
195 |
+
{trigger.strip() for trigger in text.split("\n") if trigger.strip()},
|
196 |
+
)
|
197 |
+
|
198 |
+
successful = 0
|
199 |
+
for trigger in to_unblacklist:
|
200 |
+
success = sql.rm_from_stickers(chat_id, trigger.lower())
|
201 |
+
if success:
|
202 |
+
successful += 1
|
203 |
+
|
204 |
+
if len(to_unblacklist) == 1:
|
205 |
+
if successful:
|
206 |
+
await send_message(
|
207 |
+
update.effective_message,
|
208 |
+
"Sticker <code>{}</code> deleted from blacklist in <b>{}</b>!".format(
|
209 |
+
html.escape(to_unblacklist[0]),
|
210 |
+
html.escape(chat_name),
|
211 |
+
),
|
212 |
+
parse_mode=ParseMode.HTML,
|
213 |
+
)
|
214 |
+
else:
|
215 |
+
await send_message(
|
216 |
+
update.effective_message,
|
217 |
+
"This sticker is not on the blacklist...!",
|
218 |
+
)
|
219 |
+
|
220 |
+
elif successful == len(to_unblacklist):
|
221 |
+
await send_message(
|
222 |
+
update.effective_message,
|
223 |
+
"Sticker <code>{}</code> deleted from blacklist in <b>{}</b>!".format(
|
224 |
+
successful,
|
225 |
+
html.escape(chat_name),
|
226 |
+
),
|
227 |
+
parse_mode=ParseMode.HTML,
|
228 |
+
)
|
229 |
+
|
230 |
+
elif not successful:
|
231 |
+
await send_message(
|
232 |
+
update.effective_message,
|
233 |
+
"None of these stickers exist, so they cannot be removed.",
|
234 |
+
parse_mode=ParseMode.HTML,
|
235 |
+
)
|
236 |
+
|
237 |
+
else:
|
238 |
+
await send_message(
|
239 |
+
update.effective_message,
|
240 |
+
"Sticker <code>{}</code> deleted from blacklist. {} did not exist, so it's not deleted.".format(
|
241 |
+
successful,
|
242 |
+
len(to_unblacklist) - successful,
|
243 |
+
),
|
244 |
+
parse_mode=ParseMode.HTML,
|
245 |
+
)
|
246 |
+
elif msg.reply_to_message:
|
247 |
+
trigger = msg.reply_to_message.sticker.set_name
|
248 |
+
if trigger is None:
|
249 |
+
await send_message(
|
250 |
+
update.effective_message,
|
251 |
+
"Sticker is invalid!",
|
252 |
+
)
|
253 |
+
return
|
254 |
+
success = sql.rm_from_stickers(chat_id, trigger.lower())
|
255 |
+
|
256 |
+
if success:
|
257 |
+
await send_message(
|
258 |
+
update.effective_message,
|
259 |
+
"Sticker <code>{}</code> deleted from blacklist in <b>{}</b>!".format(
|
260 |
+
trigger,
|
261 |
+
chat_name,
|
262 |
+
),
|
263 |
+
parse_mode=ParseMode.HTML,
|
264 |
+
)
|
265 |
+
else:
|
266 |
+
await send_message(
|
267 |
+
update.effective_message,
|
268 |
+
"{} not found on blacklisted stickers...!".format(trigger),
|
269 |
+
)
|
270 |
+
else:
|
271 |
+
await send_message(
|
272 |
+
update.effective_message,
|
273 |
+
"Tell me what stickers you want to add to the blacklist.",
|
274 |
+
)
|
275 |
+
|
276 |
+
|
277 |
+
@loggable
|
278 |
+
@check_admin(is_user=True)
|
279 |
+
async def blacklist_mode(update: Update, context: ContextTypes.DEFAULT_TYPE):
|
280 |
+
chat = update.effective_chat # type: Optional[Chat]
|
281 |
+
user = update.effective_user # type: Optional[User]
|
282 |
+
msg = update.effective_message # type: Optional[Message]
|
283 |
+
bot, args = context.bot, context.args
|
284 |
+
conn = await connected(bot, update, chat, user.id, need_admin=True)
|
285 |
+
if conn:
|
286 |
+
chat = await dispatcher.bot.getChat(conn)
|
287 |
+
chat_id = conn
|
288 |
+
chat_obj = await dispatcher.bot.getChat(conn)
|
289 |
+
chat_name = chat_obj.title
|
290 |
+
else:
|
291 |
+
if update.effective_message.chat.type == "private":
|
292 |
+
await send_message(
|
293 |
+
update.effective_message,
|
294 |
+
"You can do this command in groups, not PM",
|
295 |
+
)
|
296 |
+
return ""
|
297 |
+
chat = update.effective_chat
|
298 |
+
chat_id = update.effective_chat.id
|
299 |
+
chat_name = update.effective_message.chat.title
|
300 |
+
|
301 |
+
if args:
|
302 |
+
if args[0].lower() in ["off", "nothing", "no"]:
|
303 |
+
settypeblacklist = "turn off"
|
304 |
+
sql.set_blacklist_strength(chat_id, 0, "0")
|
305 |
+
elif args[0].lower() in ["del", "delete"]:
|
306 |
+
settypeblacklist = "left, the message will be deleted"
|
307 |
+
sql.set_blacklist_strength(chat_id, 1, "0")
|
308 |
+
elif args[0].lower() == "warn":
|
309 |
+
settypeblacklist = "warned"
|
310 |
+
sql.set_blacklist_strength(chat_id, 2, "0")
|
311 |
+
elif args[0].lower() == "mute":
|
312 |
+
settypeblacklist = "muted"
|
313 |
+
sql.set_blacklist_strength(chat_id, 3, "0")
|
314 |
+
elif args[0].lower() == "kick":
|
315 |
+
settypeblacklist = "kicked"
|
316 |
+
sql.set_blacklist_strength(chat_id, 4, "0")
|
317 |
+
elif args[0].lower() == "ban":
|
318 |
+
settypeblacklist = "banned"
|
319 |
+
sql.set_blacklist_strength(chat_id, 5, "0")
|
320 |
+
elif args[0].lower() == "tban":
|
321 |
+
if len(args) == 1:
|
322 |
+
teks = """It looks like you are trying to set a temporary value to blacklist, but has not determined the time; use `/blstickermode tban <timevalue>`.
|
323 |
+
Examples of time values: 4m = 4 minute, 3h = 3 hours, 6d = 6 days, 5w = 5 weeks."""
|
324 |
+
await send_message(
|
325 |
+
update.effective_message,
|
326 |
+
teks,
|
327 |
+
parse_mode="markdown",
|
328 |
+
)
|
329 |
+
return
|
330 |
+
settypeblacklist = "temporary banned for {}".format(args[1])
|
331 |
+
sql.set_blacklist_strength(chat_id, 6, str(args[1]))
|
332 |
+
elif args[0].lower() == "tmute":
|
333 |
+
if len(args) == 1:
|
334 |
+
teks = """It looks like you are trying to set a temporary value to blacklist, but has not determined the time; use `/blstickermode tmute <timevalue>`.
|
335 |
+
Examples of time values: 4m = 4 minute, 3h = 3 hours, 6d = 6 days, 5w = 5 weeks."""
|
336 |
+
await send_message(
|
337 |
+
update.effective_message,
|
338 |
+
teks,
|
339 |
+
parse_mode="markdown",
|
340 |
+
)
|
341 |
+
return
|
342 |
+
settypeblacklist = "temporary muted for {}".format(args[1])
|
343 |
+
sql.set_blacklist_strength(chat_id, 7, str(args[1]))
|
344 |
+
else:
|
345 |
+
await send_message(
|
346 |
+
update.effective_message,
|
347 |
+
"I only understand off/del/warn/ban/kick/mute/tban/tmute!",
|
348 |
+
)
|
349 |
+
return
|
350 |
+
if conn:
|
351 |
+
text = "Blacklist sticker mode changed, users will be `{}` at *{}*!".format(
|
352 |
+
settypeblacklist,
|
353 |
+
chat_name,
|
354 |
+
)
|
355 |
+
else:
|
356 |
+
text = "Blacklist sticker mode changed, users will be `{}`!".format(
|
357 |
+
settypeblacklist,
|
358 |
+
)
|
359 |
+
await send_message(
|
360 |
+
update.effective_message,
|
361 |
+
text,
|
362 |
+
parse_mode="markdown",
|
363 |
+
)
|
364 |
+
return (
|
365 |
+
"<b>{}:</b>\n"
|
366 |
+
"<b>Admin:</b> {}\n"
|
367 |
+
"Changed sticker blacklist mode. users will be {}.".format(
|
368 |
+
html.escape(chat.title),
|
369 |
+
mention_html(user.id, html.escape(user.first_name)),
|
370 |
+
settypeblacklist,
|
371 |
+
)
|
372 |
+
)
|
373 |
+
else:
|
374 |
+
getmode, getvalue = sql.get_blacklist_setting(chat.id)
|
375 |
+
if getmode == 0:
|
376 |
+
settypeblacklist = "not active"
|
377 |
+
elif getmode == 1:
|
378 |
+
settypeblacklist = "delete"
|
379 |
+
elif getmode == 2:
|
380 |
+
settypeblacklist = "warn"
|
381 |
+
elif getmode == 3:
|
382 |
+
settypeblacklist = "mute"
|
383 |
+
elif getmode == 4:
|
384 |
+
settypeblacklist = "kick"
|
385 |
+
elif getmode == 5:
|
386 |
+
settypeblacklist = "ban"
|
387 |
+
elif getmode == 6:
|
388 |
+
settypeblacklist = "temporarily banned for {}".format(getvalue)
|
389 |
+
elif getmode == 7:
|
390 |
+
settypeblacklist = "temporarily muted for {}".format(getvalue)
|
391 |
+
if conn:
|
392 |
+
text = "Blacklist sticker mode is currently set to *{}* in *{}*.".format(
|
393 |
+
settypeblacklist,
|
394 |
+
chat_name,
|
395 |
+
)
|
396 |
+
else:
|
397 |
+
text = "Blacklist sticker mode is currently set to *{}*.".format(
|
398 |
+
settypeblacklist,
|
399 |
+
)
|
400 |
+
await send_message(
|
401 |
+
update.effective_message,
|
402 |
+
text,
|
403 |
+
parse_mode=ParseMode.MARKDOWN,
|
404 |
+
)
|
405 |
+
return ""
|
406 |
+
|
407 |
+
|
408 |
+
@user_not_admin
|
409 |
+
async def del_blackliststicker(update: Update, context: ContextTypes.DEFAULT_TYPE):
|
410 |
+
bot = context.bot
|
411 |
+
chat = update.effective_chat # type: Optional[Chat]
|
412 |
+
message = update.effective_message # type: Optional[Message]
|
413 |
+
user = update.effective_user
|
414 |
+
to_match = message.sticker
|
415 |
+
if not to_match or not to_match.set_name:
|
416 |
+
return
|
417 |
+
bot = context.bot
|
418 |
+
getmode, value = sql.get_blacklist_setting(chat.id)
|
419 |
+
|
420 |
+
chat_filters = sql.get_chat_stickers(chat.id)
|
421 |
+
for trigger in chat_filters:
|
422 |
+
if to_match.set_name.lower() == trigger.lower():
|
423 |
+
try:
|
424 |
+
if getmode == 0:
|
425 |
+
return
|
426 |
+
elif getmode == 1:
|
427 |
+
await message.delete()
|
428 |
+
elif getmode == 2:
|
429 |
+
await message.delete()
|
430 |
+
warn(
|
431 |
+
update.effective_user,
|
432 |
+
chat,
|
433 |
+
"Using sticker '{}' which in blacklist stickers".format(
|
434 |
+
trigger,
|
435 |
+
),
|
436 |
+
message,
|
437 |
+
update.effective_user,
|
438 |
+
# conn=False,
|
439 |
+
)
|
440 |
+
return
|
441 |
+
elif getmode == 3:
|
442 |
+
await message.delete()
|
443 |
+
await bot.restrict_chat_member(
|
444 |
+
chat.id,
|
445 |
+
update.effective_user.id,
|
446 |
+
permissions=ChatPermissions(can_send_messages=False),
|
447 |
+
)
|
448 |
+
await bot.sendMessage(
|
449 |
+
chat.id,
|
450 |
+
"{} muted because using '{}' which in blacklist stickers".format(
|
451 |
+
mention_markdown(user.id, user.first_name),
|
452 |
+
trigger,
|
453 |
+
),
|
454 |
+
parse_mode="markdown",
|
455 |
+
message_thread_id=message.message_thread_id
|
456 |
+
if chat.is_forum
|
457 |
+
else None,
|
458 |
+
)
|
459 |
+
return
|
460 |
+
elif getmode == 4:
|
461 |
+
await message.delete()
|
462 |
+
res = chat.unban_member(update.effective_user.id)
|
463 |
+
if res:
|
464 |
+
await bot.sendMessage(
|
465 |
+
chat.id,
|
466 |
+
"{} kicked because using '{}' which in blacklist stickers".format(
|
467 |
+
mention_markdown(user.id, user.first_name),
|
468 |
+
trigger,
|
469 |
+
),
|
470 |
+
parse_mode="markdown",
|
471 |
+
message_thread_id=message.message_thread_id
|
472 |
+
if chat.is_forum
|
473 |
+
else None,
|
474 |
+
)
|
475 |
+
return
|
476 |
+
elif getmode == 5:
|
477 |
+
await message.delete()
|
478 |
+
await chat.ban_member(user.id)
|
479 |
+
await bot.sendMessage(
|
480 |
+
chat.id,
|
481 |
+
"{} banned because using '{}' which in blacklist stickers".format(
|
482 |
+
mention_markdown(user.id, user.first_name),
|
483 |
+
trigger,
|
484 |
+
),
|
485 |
+
parse_mode="markdown",
|
486 |
+
message_thread_id=message.message_thread_id
|
487 |
+
if chat.is_forum
|
488 |
+
else None,
|
489 |
+
)
|
490 |
+
return
|
491 |
+
elif getmode == 6:
|
492 |
+
await message.delete()
|
493 |
+
bantime = await extract_time(message, value)
|
494 |
+
await chat.ban_member(user.id, until_date=bantime)
|
495 |
+
await bot.sendMessage(
|
496 |
+
chat.id,
|
497 |
+
"{} banned for {} because using '{}' which in blacklist stickers".format(
|
498 |
+
mention_markdown(user.id, user.first_name),
|
499 |
+
value,
|
500 |
+
trigger,
|
501 |
+
),
|
502 |
+
parse_mode="markdown",
|
503 |
+
message_thread_id=message.message_thread_id
|
504 |
+
if chat.is_forum
|
505 |
+
else None,
|
506 |
+
)
|
507 |
+
return
|
508 |
+
elif getmode == 7:
|
509 |
+
await message.delete()
|
510 |
+
mutetime = await extract_time(message, value)
|
511 |
+
await bot.restrict_chat_member(
|
512 |
+
chat.id,
|
513 |
+
user.id,
|
514 |
+
permissions=ChatPermissions(can_send_messages=False),
|
515 |
+
until_date=mutetime,
|
516 |
+
)
|
517 |
+
await bot.sendMessage(
|
518 |
+
chat.id,
|
519 |
+
"{} muted for {} because using '{}' which in blacklist stickers".format(
|
520 |
+
mention_markdown(user.id, user.first_name),
|
521 |
+
value,
|
522 |
+
trigger,
|
523 |
+
),
|
524 |
+
parse_mode="markdown",
|
525 |
+
message_thread_id=message.message_thread_id
|
526 |
+
if chat.is_forum
|
527 |
+
else None,
|
528 |
+
)
|
529 |
+
return
|
530 |
+
except BadRequest as excp:
|
531 |
+
if excp.message != "Message to delete not found":
|
532 |
+
LOGGER.exception("Error while deleting blacklist message.")
|
533 |
+
break
|
534 |
+
|
535 |
+
|
536 |
+
async def __import_data__(chat_id, data, message):
|
537 |
+
# set chat blacklist
|
538 |
+
blacklist = data.get("sticker_blacklist", {})
|
539 |
+
for trigger in blacklist:
|
540 |
+
sql.add_to_stickers(chat_id, trigger)
|
541 |
+
|
542 |
+
|
543 |
+
def __migrate__(old_chat_id, new_chat_id):
|
544 |
+
sql.migrate_chat(old_chat_id, new_chat_id)
|
545 |
+
|
546 |
+
|
547 |
+
def __chat_settings__(chat_id, user_id):
|
548 |
+
blacklisted = sql.num_stickers_chat_filters(chat_id)
|
549 |
+
return "There are `{} `blacklisted stickers.".format(blacklisted)
|
550 |
+
|
551 |
+
|
552 |
+
def __stats__():
|
553 |
+
return "• {} blacklist stickers, across {} chats.".format(
|
554 |
+
sql.num_stickers_filters(),
|
555 |
+
sql.num_stickers_filter_chats(),
|
556 |
+
)
|
557 |
+
|
558 |
+
|
559 |
+
__mod_name__ = "Stickers Blacklist"
|
560 |
+
|
561 |
+
# <================================================ HANDLER =======================================================>
|
562 |
+
BLACKLIST_STICKER_HANDLER = DisableAbleCommandHandler(
|
563 |
+
"blsticker", blackliststicker, admin_ok=True, block=False
|
564 |
+
)
|
565 |
+
ADDBLACKLIST_STICKER_HANDLER = DisableAbleCommandHandler(
|
566 |
+
"addblsticker", add_blackliststicker, block=False
|
567 |
+
)
|
568 |
+
UNBLACKLIST_STICKER_HANDLER = CommandHandler(
|
569 |
+
["unblsticker", "rmblsticker"], unblackliststicker, block=False
|
570 |
+
)
|
571 |
+
BLACKLISTMODE_HANDLER = CommandHandler("blstickermode", blacklist_mode, block=False)
|
572 |
+
BLACKLIST_STICKER_DEL_HANDLER = MessageHandler(
|
573 |
+
filters.Sticker.ALL & filters.ChatType.GROUPS, del_blackliststicker, block=False
|
574 |
+
)
|
575 |
+
|
576 |
+
dispatcher.add_handler(BLACKLIST_STICKER_HANDLER)
|
577 |
+
dispatcher.add_handler(ADDBLACKLIST_STICKER_HANDLER)
|
578 |
+
dispatcher.add_handler(UNBLACKLIST_STICKER_HANDLER)
|
579 |
+
dispatcher.add_handler(BLACKLISTMODE_HANDLER)
|
580 |
+
dispatcher.add_handler(BLACKLIST_STICKER_DEL_HANDLER)
|
581 |
+
# <================================================ END =======================================================>
|