-
Notifications
You must be signed in to change notification settings - Fork 1
/
stickers.py
590 lines (539 loc) · 23.7 KB
/
stickers.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
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
import asyncio
import io
import math
import os
import random
import textwrap
import urllib.request
from os import remove
from PIL import Image, ImageDraw, ImageFont
from telethon import events
from telethon.errors.rpcerrorlist import YouBlockedUserError
from telethon.tl.functions.messages import GetStickerSetRequest
from telethon.tl.types import DocumentAttributeFilename, DocumentAttributeSticker, InputStickerSetID, MessageMediaPhoto, InputMessagesFilterDocument
from . import *
KANGING_STR = [
"Using Witchery to kang this sticker...",
"Plagiarising hehe...",
"Inviting this sticker over to my pack...",
"Kanging this sticker...",
"Hey that's a nice sticker!\nMind if I kang?!..",
"hehe me stel ur stikér\nhehe.",
"Ay look over there (☉。☉)!→\nWhile I kang this...",
"Roses are red violets are blue, kanging this sticker so my pacc looks cool",
"Imprisoning this sticker...",
"Mr.Steal Your Sticker is stealing this sticker... ",
"Hey! That's my sticker. Lemme get it back...",
"Turn around, Go straight and f*ck off...",
]
d3vilbot = Config.STICKER_PACKNAME
@bot.on(d3vil_cmd(outgoing=True, pattern="kang"))
@bot.on(sudo_cmd(pattern="kang", allow_sudo=True))
async def kang(args):
user = await bot.get_me()
if not user.username:
user.username = user.first_name
message = await args.get_reply_message()
photo = None
emojibypass = False
is_anim = False
emoji = None
if message and message.media:
if isinstance(message.media, MessageMediaPhoto):
d3vil = await eor(args, f"`{random.choice(KANGING_STR)}`")
photo = io.BytesIO()
photo = await bot.download_media(message.photo, photo)
elif "image" in message.media.document.mime_type.split("/"):
d3vil = await eor(args, f"`{random.choice(KANGING_STR)}`")
photo = io.BytesIO()
await bot.download_file(message.media.document, photo)
if (
DocumentAttributeFilename(file_name="sticker.webp")
in message.media.document.attributes
):
emoji = message.media.document.attributes[1].alt
emojibypass = True
elif "tgsticker" in message.media.document.mime_type:
d3vil = await eor(args, f"`{random.choice(KANGING_STR)}`")
await bot.download_file(message.media.document, "AnimatedSticker.tgs")
attributes = message.media.document.attributes
for attribute in attributes:
if isinstance(attribute, DocumentAttributeSticker):
emoji = attribute.alt
emojibypass = True
is_anim = True
photo = 1
else:
await eod(args, "`Unsupported File!`")
return
else:
await eod(args, "`I can't kang that...`")
return
if photo:
splat = args.text.split()
if not emojibypass:
emoji = "🤣"
pack = 1
if len(splat) == 3:
pack = splat[2] # User sent both
emoji = splat[1]
elif len(splat) == 2:
if splat[1].isnumeric():
# User wants to push into different pack, but is okay with
# thonk as emote.
pack = int(splat[1])
else:
# User sent just custom emote, wants to push to default
# pack
emoji = splat[1]
packname = f"{user.username}_D3vilbot_{pack}"
packnick = (
f"{d3vilbot} Vol.{pack}"
if d3vilbot
else f"@{user.username}'s D3vilBot Vol.{pack}"
)
cmd = "/newpack"
file = io.BytesIO()
if not is_anim:
image = await resize_photo(photo)
file.name = "sticker.png"
image.save(file, "PNG")
else:
packname += "_anim"
packnick += " (Animated)"
cmd = "/newanimated"
response = urllib.request.urlopen(
urllib.request.Request(f"http://t.me/addstickers/{packname}")
)
htmlstr = response.read().decode("utf8").split("\n")
if (
" A <strong>Telegram</strong> user has created the <strong>Sticker Set</strong>."
not in htmlstr
):
async with bot.conversation("Stickers") as conv:
await conv.send_message("/addsticker")
await conv.get_response()
# Ensure user doesn't get spamming notifications
await bot.send_read_acknowledge(conv.chat_id)
await conv.send_message(packname)
x = await conv.get_response()
while "120" in x.text:
pack += 1
packname = f"{user.username}_by_{user.username}_{pack}"
packnick = (
f"{d3vilbot} Vol.{pack}"
if d3vilbot
else f"@{user.username}'s D3vilBot Vol.{pack}"
)
await d3vil.edit(
"`Switching to Pack "
+ str(pack)
+ " due to insufficient space`"
)
await conv.send_message(packname)
x = await conv.get_response()
if x.text == "Invalid pack selected.":
await conv.send_message(cmd)
await conv.get_response()
# Ensure user doesn't get spamming notifications
await bot.send_read_acknowledge(conv.chat_id)
await conv.send_message(packnick)
await conv.get_response()
# Ensure user doesn't get spamming notifications
await bot.send_read_acknowledge(conv.chat_id)
if is_anim:
await conv.send_file("AnimatedSticker.tgs")
remove("AnimatedSticker.tgs")
else:
file.seek(0)
await conv.send_file(file, force_document=True)
await conv.get_response()
await conv.send_message(emoji)
# Ensure user doesn't get spamming notifications
await bot.send_read_acknowledge(conv.chat_id)
await conv.get_response()
await conv.send_message("/publish")
if is_anim:
await conv.get_response()
await conv.send_message(f"<{packnick}>")
# Ensure user doesn't get spamming notifications
await conv.get_response()
await bot.send_read_acknowledge(conv.chat_id)
await conv.send_message("/skip")
# Ensure user doesn't get spamming notifications
await bot.send_read_acknowledge(conv.chat_id)
await conv.get_response()
await conv.send_message(packname)
# Ensure user doesn't get spamming notifications
await bot.send_read_acknowledge(conv.chat_id)
await conv.get_response()
# Ensure user doesn't get spamming notifications
await bot.send_read_acknowledge(conv.chat_id)
await d3vil.edit(
f"`Sticker added in a Different Pack !\
\nThis Pack is Newly created!\
\nYour pack can be found [here](t.me/addstickers/{packname})",
parse_mode="md",
)
return
if is_anim:
await conv.send_file("AnimatedSticker.tgs")
remove("AnimatedSticker.tgs")
else:
file.seek(0)
await conv.send_file(file, force_document=True)
rsp = await conv.get_response()
if "Sorry, the file type is invalid." in rsp.text:
await d3vil.edit(
"`Failed to add sticker, use` @Stickers `bot to add the sticker manually.`"
)
return
await conv.send_message(emoji)
# Ensure user doesn't get spamming notifications
await bot.send_read_acknowledge(conv.chat_id)
await conv.get_response()
await conv.send_message("/done")
await conv.get_response()
# Ensure user doesn't get spamming notifications
await bot.send_read_acknowledge(conv.chat_id)
else:
await d3vil.edit("`Preparing a new pack....`")
async with bot.conversation("Stickers") as conv:
await conv.send_message(cmd)
await conv.get_response()
# Ensure user doesn't get spamming notifications
await bot.send_read_acknowledge(conv.chat_id)
await conv.send_message(packnick)
await conv.get_response()
# Ensure user doesn't get spamming notifications
await bot.send_read_acknowledge(conv.chat_id)
if is_anim:
await conv.send_file("AnimatedSticker.tgs")
remove("AnimatedSticker.tgs")
else:
file.seek(0)
await conv.send_file(file, force_document=True)
rsp = await conv.get_response()
if "Sorry, the file type is invalid." in rsp.text:
await d3vil.edit(
"`Failed to add sticker, use` @Stickers `bot to add the sticker manually.`"
)
return
await conv.send_message(emoji)
# Ensure user doesn't get spamming notifications
await bot.send_read_acknowledge(conv.chat_id)
await conv.get_response()
await conv.send_message("/publish")
if is_anim:
await conv.get_response()
await conv.send_message(f"<{packnick}>")
# Ensure user doesn't get spamming notifications
await conv.get_response()
await bot.send_read_acknowledge(conv.chat_id)
await conv.send_message("/skip")
# Ensure user doesn't get spamming notifications
await bot.send_read_acknowledge(conv.chat_id)
await conv.get_response()
await conv.send_message(packname)
# Ensure user doesn't get spamming notifications
await bot.send_read_acknowledge(conv.chat_id)
await conv.get_response()
# Ensure user doesn't get spamming notifications
await bot.send_read_acknowledge(conv.chat_id)
await d3vil.edit(
f"✔︎** 𝚃𝙷𝙸𝚂 𝚂𝚃𝙸𝙲𝙺𝙴𝚁 𝙸𝚂 ➪[𝖪𝖺𝗇𝗀𝖾𝖽](t.me/addstickers/{packname}) 𝚂𝚄𝙲𝙴𝚂𝚂𝙵𝚄𝙻𝙻𝚈 𝚃𝙾 𝚈𝙾𝚄𝚁 𝙿𝙰𝙲𝙺 **✔︎",
parse_mode="md",
)
async def resize_photo(photo):
""" Resize the given photo to 512x512 """
image = Image.open(photo)
maxsize = (512, 512)
if (image.width and image.height) < 512:
size1 = image.width
size2 = image.height
if image.width > image.height:
scale = 512 / size1
size1new = 512
size2new = size2 * scale
else:
scale = 512 / size2
size1new = size1 * scale
size2new = 512
size1new = math.floor(size1new)
size2new = math.floor(size2new)
sizenew = (size1new, size2new)
image = image.resize(sizenew)
else:
image.thumbnail(maxsize)
return image
@bot.on(admin_cmd(outgoing=True, pattern="stkrinfo"))
@bot.on(sudo_cmd(pattern="stkrinfo", allow_sudo=True))
async def get_pack_info(event):
if not event.is_reply:
await edit_or_reply(event, "`I can't fetch info from black hole!!!`")
return
rep_msg = await event.get_reply_message()
if not rep_msg.document:
await edit_or_reply(event, "`Reply to a sticker to get the pack details`")
return
try:
stickerset_attr = rep_msg.document.attributes[1]
await edit_or_reply(event, "`Fetching details of the sticker pack, please wait..`")
except BaseException:
await edit_or_reply(event, "`This is not a sticker. Reply to a sticker.`")
return
if not isinstance(stickerset_attr, DocumentAttributeSticker):
await edit_or_reply(event, "`This is not a sticker. Reply to a sticker.`")
return
get_stickerset = await bot(
GetStickerSetRequest(
InputStickerSetID(
id=stickerset_attr.stickerset.id,
access_hash=stickerset_attr.stickerset.access_hash,
)
)
)
pack_emojis = []
for document_sticker in get_stickerset.packs:
if document_sticker.emoticon not in pack_emojis:
pack_emojis.append(document_sticker.emoticon)
OUTPUT = (
f"𖣔 **𝐒𝐭𝐢𝐜𝐤𝐞𝐫 𝐓𝐢𝐭𝐥𝐞➪** `{get_stickerset.set.title}\n`"
f"𖣔 **𝐒𝐭𝐢𝐜𝐤𝐞𝐫 𝐒𝐡𝐨𝐫𝐭 𝐍𝐚𝐦𝐞➪** `{get_stickerset.set.short_name}`\n"
f"𖣔 **𝐎𝐟𝐟𝐢𝐜𝐢𝐚𝐥➪** `{get_stickerset.set.official}`\n"
f"𖣔 **𝐀𝐫𝐜𝐡𝐢𝐯𝐞𝐝➪** `{get_stickerset.set.archived}`\n"
f"𖣔 **𝐒𝐭𝐢𝐜𝐤𝐞𝐫𝐬 𝐈𝐧 𝐏𝐚𝐜𝐤➪** `{len(get_stickerset.packs)}`\n"
f"𖣔 **𝐄𝐦𝐨𝐣𝐢𝐬 𝐈𝐧 𝐏𝐚𝐜𝐤➪**\n{' '.join(pack_emojis)}"
)
await edit_or_reply(event, OUTPUT)
@bot.on(d3vil_cmd(pattern=r"delst ?(.*)", outgoing=True))
@bot.on(sudo_cmd(pattern=r"delst ?(.*)", allow_sudo=True))
async def _(event):
if event.fwd_from:
return
if not event.reply_to_msg_id:
await event.edit("`Reply to any user's message.`")
return
reply_message = await event.get_reply_message()
chat = "@Stickers"
reply_message.sender
if reply_message.sender.bot:
await edit_or_reply(event, "`Reply to actual user's message.`")
return
await event.edit("🥴 `Deleting sticker...`")
async with bot.conversation(chat) as conv:
try:
response = conv.wait_event(
events.NewMessage(incoming=True, from_users=429000)
)
await conv.send_message("/delsticker")
await conv.get_response()
await asyncio.sleep(2)
await bot.forward_messages(chat, reply_message)
response = await response
except YouBlockedUserError:
await event.reply("Please unblock @Stickers and try again")
return
if response.text.startswith("Sorry, I can't do this, it seems that you are not the owner of the relevant pack."):
await event.edit("**🥴 Nashe me hai kya lawde!!**"
)
elif response.text.startswith("You don't have any sticker packs yet. You can create one using the /newpack command."):
await event.edit("**😪 You don't have any sticker pack to delete stickers.** \n\n@Stickers :- 'Pehle Pack Bna Lamde 🤧'")
elif response.text.startswith("Please send me the sticker."):
await event.edit("**😪 Nashe me hai kya lawde**")
elif response.text.startswith("Invalid pack selected."):
await event.edit("**😪 Nashe me hai kya lawde**")
else:
await event.edit("**😐 Deleted that replied sticker, it will stop being available to Telegram users within about an hour.**")
@bot.on(d3vil_cmd(pattern=r"editst ?(.*)", outgoing=True))
@bot.on(sudo_cmd(pattern=r"editst ?(.*)", allow_sudo=True))
async def _(event):
if event.fwd_from:
return
if not event.reply_to_msg_id:
await event.edit("`Reply to any user's message.`")
return
reply_message = await event.get_reply_message()
d3vil = event.pattern_match.group(1)
chat = "@Stickers"
reply_message.sender
if reply_message.sender.bot:
await edit_or_reply(event, "`Reply to actual user's message.`")
return
await event.edit("📝 `Editing sticker emoji...`")
if d3vil == "":
await event.edit("**🤧 Nashe me hai kya lawde**")
else:
async with bot.conversation(chat) as conv:
try:
response = conv.wait_event(
events.NewMessage(incoming=True, from_users=429000)
)
await conv.send_message(f"/editsticker")
await conv.get_response()
await asyncio.sleep(2)
await bot.forward_messages(chat, reply_message)
await conv.get_response()
await asyncio.sleep(2)
await conv.send_message(f"{d3vil}")
response = await response
except YouBlockedUserError:
await event.reply("Please unblock @Stickers and try again")
return
if response.text.startswith("Invalid pack selected."):
await event.edit("**🥴 Nashe me h kya lawde**"
)
elif response.text.startswith("Please send us an emoji that best describes your sticker."):
await event.edit("**🤧 Nashe me hai kya lawde**")
else:
await event.edit(f"**😉 Done!! Edited sticker emoji**\n\nNew Emoji(s) :- {d3vil}")
@bot.on(d3vil_cmd(pattern="pkang ?(.*)"))
@bot.on(sudo_cmd(pattern="pkang ?(.*)", allow_sudo=True))
async def _(event):
d3vl_ = await eor(event, "`Preparing pack kang...`")
rply = await event.get_reply_message()
d3vil = event.text[7:]
bot_ = Config.BOT_USERNAME
bot_un = bot_.replace("@", "")
user = await bot.get_me()
un = f"@{user.username}" if user.username else user.first_name
un_ = user.username if user.username else d3vilkrish
if not rply:
return await eod(d3vl_, "`Reply to a stciker to kang that pack.`")
if d3vil == "":
pname = f"{un}'s ᴅ3ᴠɪʟʙᴏᴛ ᴘᴀᴄᴋ"
else:
pname = d3vil
if rply and rply.media and rply.media.document.mime_type == "image/webp":
d3vil_id = rply.media.document.attributes[1].stickerset.id
d3vil_hash = rply.media.document.attributes[1].stickerset.access_hash
got_stcr = await bot(
functions.messages.GetStickerSetRequest(
stickerset=types.InputStickerSetID(id=d3vil_id, access_hash=d3vil_hash)
)
)
stcrs = []
for sti in got_stcr.documents:
inp = get_input_document(sti)
stcrs.append(
types.InputStickerSetItem(
document=inp,
emoji=(sti.attributes[1]).alt,
)
)
try:
gvarstat("PKANG")
except BaseException:
addgvar("PKANG", "0")
x = gvarstat("PKANG")
try:
pack = int(x) + 1
except BaseException:
pack = 1
await d3vl_.edit("`Starting kang process...`")
try:
create_st = await tbot(
functions.stickers.CreateStickerSetRequest(
user_id=d3vilkrish,
title=pname,
short_name=f"d3vil_{un_}_pack{pack}_by_{bot_un}",
stickers=stcrs,
)
)
addgvar("PKANG", str(pack))
except PackShortNameOccupiedError:
await asyncio.sleep(1)
await d3vl_.edit("`Pack name already occupied... making new pack`")
pack += 1
create_st = await tbot(
functions.stickers.CreateStickerSetRequest(
user_id=d3vilkrish,
title=pname,
short_name=f"d3vil_{un_}_pack{pack}_by_{bot_un}",
stickers=stcrs,
)
)
addgvar("PKANG", str(pack))
await d3vl_.edit(f"✔︎** This Sticker Pack iz [kanged](t.me/addstickers/{create_st.set.short_name}) successfully **")
else:
await d3vl_.edit("Unsupported File. Please Reply to a sticker only.")
@bot.on(d3vil_cmd(pattern="text (.*)"))
@bot.on(sudo_cmd(pattern="text (.*)", allow_sudo=True))
async def sticklet(event):
R = random.randint(0, 256)
G = random.randint(0, 256)
B = random.randint(0, 256)
sticktext = event.pattern_match.group(1)
await event.delete()
sticktext = textwrap.wrap(sticktext, width=10)
sticktext = "\n".join(sticktext)
image = Image.new("RGBA", (512, 512), (255, 255, 255, 0))
draw = ImageDraw.Draw(image)
fontsize = 230
FONT_FILE = await get_font_file(event.client, "@HellFonts")
font = ImageFont.truetype(FONT_FILE, size=fontsize)
while draw.multiline_textsize(sticktext, font=font) > (512, 512):
fontsize -= 3
font = ImageFont.truetype(FONT_FILE, size=fontsize)
width, height = draw.multiline_textsize(sticktext, font=font)
draw.multiline_text(
((512 - width) / 2, (512 - height) / 2), sticktext, font=font, fill=(R, G, B)
)
image_stream = io.BytesIO()
image_stream.name = "D3vilbot.webp"
image.save(image_stream, "WebP")
image_stream.seek(0)
await event.client.send_message(
event.chat_id,
"{}".format(sticktext),
file=image_stream,
reply_to=event.message.reply_to_msg_id,
)
try:
os.remove(FONT_FILE)
except:
pass
async def get_font_file(client, channel_id):
font_file_message_s = await client.get_messages(
entity=channel_id,
filter=InputMessagesFilterDocument,
limit=None,
)
font_file_message = random.choice(font_file_message_s)
return await client.download_media(font_file_message)
@bot.on(d3vil_cmd(pattern="waifu(?: |$)(.*)", outgoing=True))
@bot.on(sudo_cmd(pattern="waifu(?: |$)(.*)", allow_sudo=True))
async def waifu(animu):
text = animu.pattern_match.group(1)
if not text:
if animu.is_reply:
text = (await animu.get_reply_message()).message
else:
await eod(animu, "Give some text... **PRO !!**")
return
animus = [1, 3, 7, 9, 13, 22, 34, 35, 36, 37, 43, 44, 45, 52, 53, 55]
sticcers = await bot.inline_query(
"stickerizerbot", f"#{random.choice(animus)}{(deEmojify(text))}"
)
await sticcers[0].click(
animu.chat_id,
reply_to=animu.reply_to_msg_id,
silent=True if animu.is_reply else False,
hide_via=True,
)
await animu.delete()
CmdHelp("stickers").add_command(
"kang", "<emoji> <number>", "Adds the sticker to desired pack with a custom emoji of your choice. If emoji is not mentioned then default is 😎. And if number is not mentioned then Pack will go on serial wise. \n ✓(1 pack = 120 non-animated stickers)\n ✓(1 pack = 50 animated stickers)"
).add_command(
"stkrinfo", "<reply to sticker>", "Gets all the infos of the sticker pack"
).add_command(
"delst", "<reply to sticker>", "Deletes The Replied Sticker from your pack."
).add_command(
"editst", "<reply to sticker> <new emoji>", "Edits the emoji of replied sticker of your pack."
).add_command(
"text", "<word>", "Sends the written text in sticker format."
).add_command(
"waifu", "<word>", "Waifu writes the word for you."
).add_command(
"pkang", "<reply to a sticker> <pack name>", "Kangs all the stickers in replied pack to your pack. Also supports custom pack name. Just give name after command.", "pkang My kang pack"
).add()