-
Notifications
You must be signed in to change notification settings - Fork 24
Expand file tree
/
Copy pathdemot.py
More file actions
608 lines (541 loc) · 22.7 KB
/
demot.py
File metadata and controls
608 lines (541 loc) · 22.7 KB
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
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
# -*- coding: utf-8 -*-
# Module author: @GovnoCodules, @ftgmodulesbyfl1yd, @D4n13l3k00
# requires: Pillow
import io
import textwrap
from asyncio.exceptions import CancelledError, TimeoutError
from textwrap import wrap
import requests
from PIL import Image, ImageDraw, ImageFont, ImageOps
from telethon import events, functions
from telethon.errors.rpcerrorlist import YouBlockedUserError
from telethon.events import NewMessage
from .. import loader, utils
CHAT = "@demotilifebot"
@loader.tds
class DemotivatorMod(loader.Module):
"""Deotivators"""
strings = {"name": "Demotivator"}
async def client_ready(self, client, db):
self.client = client
@loader.owner
async def demoticmd(self, message):
"""Demotiving photo without compression"""
await cmds(message, 0)
async def demotcmd(self, message):
"""Demotiving photo"""
await cmds(message, 1)
async def bottomcmd(self, message):
"""Imposes text in the photo from below"""
return await procces_img(message, 1)
async def topcmd(self, message):
"""Imposes text on the photo at the top"""
return await procces_img(message, 2)
async def centercmd(self, message):
"""Imposes text on the photo at the center"""
return await procces_img(message, 3)
async def demotirandcmd(self, message):
"""Random demotiving photo without compression"""
await cmdrands(message, 0)
async def demotrandcmd(self, message):
"""Random demotiving photo"""
await cmdrands(message, 1)
async def nqcmd(self, message):
"""Quotes from the message"""
chat = "@ShittyQuoteBot"
text = utils.get_args_raw(message)
reply = await message.get_reply_message()
if not text and not reply:
await message.edit("<b>No reply</b>")
return
await message.edit("<b>Demotivating...</b>")
async with message.client.conversation(chat) as conv:
if text:
try:
response = conv.wait_event(
events.NewMessage(incoming=True, from_users=1389323591)
)
await message.client.send_message(chat, text)
response = await response
except YouBlockedUserError:
return await message.edit("<b>Unblock @ShittyQuoteBot</b>")
else:
try:
user = await utils.get_user(reply)
response = conv.wait_event(
events.NewMessage(incoming=True, from_users=1389323591)
)
await message.client.send_message(
chat, f"{reply.raw_text} (с) {user.first_name}"
)
response = await response
except YouBlockedUserError:
return await message.edit("<b>Unblock @ShittyQuoteBot</b>")
if response.text:
await message.client.send_message(message.to_id, f"<b> {response.text}</b>")
await message.delete()
if response.media:
await message.client.send_file(
message.to_id, response.media, reply_to=reply.id if reply else None
)
await message.delete()
await message.client(
functions.messages.DeleteHistoryRequest(
peer="ShittyQuoteBot", max_id=0, just_clear=False, revoke=True
)
)
async def mqcmd(self, message):
"""Quotes from the message 2"""
bw = not utils.get_args(message)
reply = await message.get_reply_message()
if not reply or not reply.raw_text:
return await message.edit("<b>Reply to message!</b>")
sender = reply.sender_id
if not sender:
sender = message.chat.id
if sender == 1087968824:
sender = message.chat.id
pfp = await message.client.download_profile_photo(sender, bytes)
await message.edit("<b>Demotivating...</b>")
if not pfp:
pfp = b"BM:\x00\x00\x00\x00\x00\x00\x006\x00\x00\x00(\x00\x00\x00\x01\x00\x00\x00\x01\x00\x00\x00\x01\x00\x18\x00\x00\x00\x00\x00\x04\x00\x00\x00\xc4\x0e\x00\x00\xc4\x0e\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xff\xff\xff\x00"
text = "\n".join(wrap(reply.raw_text, 30))
text = "“" + text + "„"
bf = requests.get(
"https://raw.githubusercontent.com/KeyZenD/l/master/times.ttf"
).content
font = ImageFont.truetype(io.BytesIO(bf), 50)
im = Image.open(io.BytesIO(pfp))
if bw:
im = im.convert("L")
im = im.convert("RGBA").resize((1024, 1024))
w, h = im.size
w_, h_ = 20 * (w // 100), 20 * (h // 100)
im_ = Image.new("RGBA", (w - w_, h - h_), (0, 0, 0))
im_.putalpha(150)
im.paste(im_, (w_ // 2, h_ // 2), im_)
draw = ImageDraw.Draw(im)
_w, _h = draw.textsize(text=text, font=font)
x, y = (w - _w) // 2, (h - _h) // 2
draw.text((x, y), text=text, font=font, fill="#fff", align="center")
output = io.BytesIO()
im.save(output, "PNG")
output.seek(0)
await reply.reply(file=output)
await message.delete()
async def cmds(message, type_):
event, is_reply = await check_media(message)
if not event:
if message.client._conversations.get(1376531590) is not None:
return await message.edit("<b>Please wait.</b>")
reply = await message.get_reply_message()
if (
not reply
or not reply.media
or not any(
True
for _ in ("sticker", "photo", "video", "video_note", "animation")
if getattr(reply, _, None) is not None
)
):
return await message.edit("<b>Reply to photo/video/sticker/gif</b>")
if reply.file.size > 4194304:
return await message.edit("<b>Video only up to 4mb</b>")
args = utils.get_args_raw(message) or reply.message
if not args:
return await message.edit("<b>No text</b>")
if len(args) > 500:
return await message.edit("<b>Text only up to 500 symbols</b>")
await message.edit("<b>Demotivating...</b>")
async with message.client.conversation(CHAT, timeout=160) as conv:
try:
response = conv.wait_event(NewMessage(incoming=True, from_users=CHAT))
msg = await reply.forward_to(CHAT)
await msg.reply(f"/demoti {args}")
response = await response
if not response.media:
if response.raw_text.startswith("[400]"):
return await message.edit("<b>Please wait 10 sec</b>")
response = await conv.wait_event(
NewMessage(incoming=True, from_users=CHAT)
)
except YouBlockedUserError:
return await message.edit(f"<b>Unblock {CHAT}</b>")
except (TimeoutError, CancelledError):
return await message.edit("<b>Bot isn`t responding</b>")
if response.media is None:
return await message.edit("<b>Error</b>")
await message.client.send_file(
message.to_id, response.media, reply_to=reply
)
await message.delete()
await message.client(
functions.messages.DeleteHistoryRequest(
peer=CHAT, max_id=0, just_clear=False, revoke=True
)
)
return
text = utils.get_args_raw(message)
if not text:
await message.edit("<b>Reply to photo with text</b>")
return
await message.edit("Demotivating...")
bytes_image = await event.download_media(bytes)
demotivator = await demotion(font_bytes, bytes_image, text, type_)
await message.edit("Sending...")
if is_reply:
await message.delete()
return await event.reply(file=demotivator)
return await event.edit(file=demotivator, text="")
async def cmdrands(message, type_):
event, is_reply = await check_media(message)
if not event:
args = utils.get_args_raw(message)
reply = await message.get_reply_message()
if not reply:
await message.edit("<b>Reply to media</b>")
return
try:
media = reply.media
except Exception:
return await message.edit("<b>Only media</b>")
chat = "@super_rjaka_demotivator_bot"
await message.edit("<b>Demotivating...</b>")
async with message.client.conversation(chat) as conv:
try:
response = conv.wait_event(
events.NewMessage(incoming=True, from_users=1016409811)
)
mm = await message.client.send_file(chat, media, caption=args)
response = await response
await mm.delete()
except YouBlockedUserError:
await message.reply("<b>Разблокируй @super_rjaka_demotivator_bot</b>")
return
await message.edit("<b>Sending...</b>")
await message.delete()
await response.delete()
await message.client.send_file(
message.to_id,
response.media,
reply_to=await message.get_reply_message(),
)
await message.client(
functions.messages.DeleteHistoryRequest(
peer="super_rjaka_demotivator_bot",
max_id=0,
just_clear=False,
revoke=True,
)
)
text = utils.get_args_raw(message)
if not text:
await message.edit("<b>Reply to photo with text</b>")
return
await message.edit("<b>Demotivating...</b>")
bytes_image = await event.download_media(bytes)
demotivator = await demotion(font_bytes, bytes_image, text, type_)
await message.edit("<b>Sending...</b>")
if is_reply:
await message.delete()
return await event.reply(file=demotivator)
return await event.edit(file=demotivator, text="")
async def check_media(message):
reply = await message.get_reply_message()
is_reply = True
if not reply:
reply = message
is_reply = False
if not reply.file:
return False, ...
mime = reply.file.mime_type.split("/")[0].lower()
if mime != "image":
return False, ...
return reply, is_reply
async def textwrap(text, length=50, splitter="&&"):
out = []
lines = text.rsplit(splitter, 1)
for text in lines:
txt = []
parts = text.split("&&")
for part in parts:
part = "\n".join(wrap(part, length))
txt.append(part)
text = "\n".join(txt)
out.append(text)
return out
async def draw_main(
bytes_image,
type_,
frame_width_1=5,
frame_fill_1=(0, 0, 0),
frame_width_2=3,
frame_fill_2=(255, 255, 255),
expand_proc=10,
main_fill=(0, 0, 0),
):
main_ = Image.open(io.BytesIO(bytes_image))
main = Image.new("RGB", main_.size, "black")
main.paste(main_, (0, 0))
if type_ == 1:
main = main.resize((700, 550))
main = ImageOps.expand(main, frame_width_1, frame_fill_1)
main = ImageOps.expand(main, frame_width_2, frame_fill_2)
w, h = main.size
h_up = expand_proc * (h // 100)
im = Image.new("RGB", (w + (h_up * 2), h + h_up), main_fill)
im.paste(main, (h_up, h_up))
return im
async def _draw_text(
text,
font_bytes,
font_size,
font_add=30,
main_fill=(0, 0, 0),
text_fill=(255, 255, 255),
text_align="center",
):
font = ImageFont.truetype(io.BytesIO(font_bytes), font_size)
w_txt, h_txt = ImageDraw.Draw(Image.new("RGB", (1, 1))).multiline_textsize(
text=text, font=font
)
txt = Image.new("RGB", (w_txt, h_txt + font_add), main_fill)
ImageDraw.Draw(txt).text(
(0, 0), text=text, font=font, fill=text_fill, align=text_align
)
return txt
async def text_joiner(text_img_1, text_img_2, main_fill=(0, 0, 0)):
w_txt_1, h_txt_1 = text_img_1.size
w_txt_2, h_txt_2 = text_img_2.size
w = max(w_txt_1, w_txt_2)
h = h_txt_1 + h_txt_2
text = Image.new("RGB", (w, h), main_fill)
text.paste(text_img_1, ((w - w_txt_1) // 2, 0))
text.paste(text_img_2, ((w - w_txt_2) // 2, h_txt_1))
return text
async def draw_text(text, font_bytes, font_size):
text = await textwrap(text)
if len(text) == 1:
text = await _draw_text(text[0], font_bytes, font_size[0])
else:
text_img_1 = await _draw_text(text[0], font_bytes, font_size[0])
text_img_2 = await _draw_text(text[-1], font_bytes, font_size[1])
text = await text_joiner(text_img_1, text_img_2)
return text
async def text_finaller(text, main, expand_width_proc=25, main_fill=(0, 0, 0)):
x = min(main.size)
w_txt, h_txt = text.size
w_proc = expand_width_proc * (w_txt // 100)
h_proc = expand_width_proc * (h_txt // 100)
back = Image.new("RGB", (w_txt + (w_proc * 2), h_txt + (h_proc * 2)), main_fill)
back.paste(text, (w_proc, h_proc))
back.thumbnail((x, x))
return back
async def joiner(text_img, main_img, format_save="JPEG"):
w_im, h_im = main_img.size
w_txt, h_txt = text_img.size
text_img.thumbnail((min(w_im, h_im), min(w_im, h_im)))
w_txt, h_txt = text_img.size
main_img = main_img.crop((0, 0, w_im, h_im + h_txt))
main_img.paste(text_img, ((w_im - w_txt) // 2, h_im))
output = io.BytesIO()
main_img.save(output, format_save)
output.seek(0)
return output.getvalue()
async def demotion(font_bytes, bytes_image, text, type):
main = await draw_main(bytes_image, type)
font_size = [20 * (min(main.size) // 100), 15 * (min(main.size) // 100)]
text = await draw_text(text, font_bytes, font_size)
text = await text_finaller(text, main)
output = await joiner(text, main)
return output
async def demotionrand(font_bytes, bytes_image, text, type):
main = await draw_main(bytes_image, type)
font_size = [20 * (min(main.size) // 100), 15 * (min(main.size) // 100)]
text = await draw_text(text, font_bytes, font_size)
text = await text_finaller(text, main)
output = await joiner(text, main)
return output
tttxxx = [
"А че",
"заставляет задуматься",
"Жалко пацана",
"ты че сука??",
"ААХАХАХАХХАХА\n\nААХАХААХАХА",
"ГИГАНТ МЫСЛИ\n\nотец русской демократии",
"Он",
"ЧТО БЛЯТЬ?",
"охуенная тема",
"ВОТ ОНИ\n\nтипичные комедиклабовские шутки",
"НУ НЕ БЛЯДИНА?",
"Узнали?",
"Согласны?",
"Вот это мужик",
"ЕГО ИДЕИ\n\nбудут актуальны всегда",
"\n\nПРИ СТАЛИНЕ ОН БЫ СИДЕЛ",
"о вадим",
"2 месяца на дваче\n\nи это, блядь, нихуя не смешно",
"Что дальше?\n\nЧайник с функцией жопа?",
"\n\nИ нахуя мне эта информация?",
"Верхний текст",
"нижний текст",
"Показалось",
"Суды при анкапе",
"Хуйло с района\n\n\n\nтакая шелупонь с одной тычки ляжет",
"Брух",
"Расскажи им\n\nкак ты устал в офисе",
"Окурок блять\n\nесть 2 рубля?",
"Аниме ставшее легендой",
"СМИРИСЬ\n\n\n\nты никогда не станешь настолько же крутым",
"а ведь это идея",
"\n\nЕсли не лайкнешь у тебя нет сердца",
"Вместо тысячи слов",
"ШАХ И МАТ!!!",
"Самый большой член в мире\n\nУ этой девушки",
"Немного\n\nперфекционизма",
"кто",
"\n\nэта сука уводит чужих мужей",
"Кто он???",
"\n\nВы тоже хотели насрать туда в детстве?",
"\n\nВся суть современного общества\n\nв одном фото",
"Он обязательно выживет!",
"\n\nВы тоже хотите подрочить ему?",
"\n\nИ вот этой хуйне поклоняются русские?",
"Вот она суть\n\n\n\nчеловеческого общества в одной картинке",
"Вы думали это рофл?\n\nНет это жопа",
"\n\nПри сталине такой хуйни не было\n\nА у вас было?",
"Он грыз провода",
"Назло старухам\n\nна радость онанистам",
"Где-то в Челябинске",
"Агитация за Порошенко",
"ИДЕАЛЬНО",
"Грыз?",
"Ну давай расскажи им\n\nкакая у тебя тяжелая работа",
"\n\nЖелаю в каждом доме такого гостя",
"Шкура на вырост",
"НИКОГДА\n\nне сдавайся",
"Оппа гангнам стайл\n\nуууу сэкси лейди оп оп",
"Они сделали это\n\nсукины дети, они справились",
"Эта сука\n\nхочет денег",
"Это говно, а ты?",
"\n\nВот она нынешняя молодежь",
"Погладь кота\n\nпогладь кота сука",
"Я обязательно выживу",
"\n\nВот она, настоящая мужская дружба\n\nбез политики и лицимерия",
"\n\nОБИДНО ЧТО Я ЖИВУ В СТРАНЕ\n\nгде гантели стоят в 20 раз "
"дороже чем бутылка водки",
"Царь, просто царь",
"\n\nНахуй вы это в учебники вставили?\n\nИ ещё ебаную контрольную " "устроили",
"\n\nЭТО НАСТОЯЩАЯ КРАСОТА\n\nа не ваши голые бляди",
"\n\nТема раскрыта ПОЛНОСТЬЮ",
"\n\nРОССИЯ, КОТОРУЮ МЫ ПОТЕРЯЛИ",
"ЭТО - Я\n\nПОДУМАЙ МОЖЕТ ЭТО ТЫ",
"почему\n\nчто почему",
"КУПИТЬ БЫ ДЖЫП\n\nБЛЯТЬ ДА НАХУЙ НАДО",
"\n\n\n\nмы не продаём бомбастер лицам старше 12 лет",
"МРАЗЬ",
"Правильная аэрография",
"Вот она русская\n\nСМЕКАЛОЧКА",
"Он взял рехстаг!\n\nА чего добился ты?",
"На аватарку",
"Фотошоп по-деревенски",
"Инструкция в самолете",
"Цирк дю Солей",
"Вкус детства\n\nшколоте не понять",
"Вот оно - СЧАСТЬЕ",
"Он за тебя воевал\n\nа ты даже не знаешь его имени",
"Зато не за компьютером",
"\n\nНе трогай это на новый год",
"Мой первый рисунок\n\nмочой на снегу",
"\n\nМайские праздники на даче",
"Ваш пиздюк?",
"Тест драйв подгузников",
"Не понимаю\n\nкак это вообще выросло?",
"Супермен в СССР",
"Единственный\n\nкто тебе рад",
"Макдональдс отдыхает",
"Ну че\n\n как дела на работе пацаны?",
"Вся суть отношений",
"Беларусы, спасибо!",
"\n\nУ дверей узбекского военкомата",
"Вместо 1000 слов",
"Один вопрос\n\nнахуя?",
"Ответ на санкции\n\nЕВРОПЫ",
"ЦЫГАНСКИЕ ФОКУСЫ",
"Блять!\n\nда он гений!",
"\n\nУкраина ищет новые источники газа",
"ВОТ ЭТО\n\nНАСТОЯЩИЕ КАЗАКИ а не ряженные",
"Нового года не будет\n\nСанта принял Ислам",
"\n\nОн был против наркотиков\n\nа ты и дальше убивай себя",
"Всем похуй!\n\nВсем похуй!",
"БРАТЬЯ СЛАВЯНЕ\n\nпомните друг о друге",
"\n\nОН ПРИДУМАЛ ГОВНО\n\nа ты даже не знаешь его имени",
"\n\nкраткий курс истории нацболов",
"Эпоха ренессанса",
]
async def procces_img(message, way):
cols = {
"white": 1,
"whit": 1,
"whi": 1,
"wh": 1,
"w": 1,
"black": 2,
"blac": 2,
"bla": 2,
"bl": 2,
"b": 2,
}
col = 1
reply = await message.get_reply_message()
txt = utils.get_args_raw(message)
await message.edit("Waiting...")
if txt in cols:
col = cols[txt]
txt = None
if not txt:
txt = "я лошара."
if not reply:
await message.edit("Reply to photo/sticker")
return
if txt.split(" ")[0] in cols:
col = cols[txt.split(" ")[0]]
txt = " ".join(txt.split(" ")[1:])
bytes_font = requests.get(
"https://github.com/Fl1yd/FTG-modules/blob/master/stuff/font3.ttf?raw=true"
).content
bytes_back = await reply.download_media(bytes)
font = io.BytesIO(bytes_font)
font = ImageFont.truetype(font, 72)
img = Image.open(io.BytesIO(bytes_back))
W, H = img.size
txt = txt.replace("\n", "𓃐")
text = "\n".join(wrap(txt, 30))
t = text
t = t.replace("𓃐", "\n")
draw = ImageDraw.Draw(img)
w, h = draw.multiline_textsize(t, font=font)
imtext = Image.new("RGBA", (w + 20, h + 20), (0, 0, 0, 0))
draw = ImageDraw.Draw(imtext)
if col == 2:
draw.multiline_text((10, 10), t, (0, 0, 0), font=font, align="center")
else:
draw.multiline_text((10, 10), t, (255, 255, 255), font=font, align="center")
imtext.thumbnail((W, H))
w, h = imtext.size
if way == 1:
img.paste(imtext, ((W - w) // 2, (H - h) // 1), imtext)
if way == 2:
img.paste(imtext, ((W - w) // 2, (H - h) // 15), imtext)
if way == 3:
img.paste(imtext, ((W - w) // 2, (H - h) // 2), imtext)
output = io.BytesIO()
output.name = "клоун.png"
img.save(output, "png")
output.seek(0)
await message.client.send_file(message.to_id, output, reply_to=reply)
await message.delete()
font_bytes = requests.get(
"https://raw.githubusercontent.com/KeyZenD/l/master/times.ttf"
).content
#######################