randydev commited on
Commit
d3029ef
·
verified ·
1 Parent(s): 1ec243b

Create sticker.py

Browse files
Files changed (1) hide show
  1. akn/Akeno/sticker.py +285 -0
akn/Akeno/sticker.py ADDED
@@ -0,0 +1,285 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import asyncio
2
+ import math
3
+ import os
4
+ import shlex
5
+ import textwrap
6
+ from io import BytesIO
7
+ from random import choice
8
+ from typing import Tuple
9
+
10
+ import cv2
11
+ import requests
12
+ from bs4 import BeautifulSoup as bs
13
+ from PIL import Image, ImageDraw, ImageFont
14
+ from pymediainfo import MediaInfo
15
+ from pyrogram import Client as ren
16
+ from pyrogram import *
17
+ from pyrogram.enums import ParseMode
18
+ from pyrogram.errors import *
19
+ from pyrogram.raw.functions.messages import GetStickerSet
20
+ from pyrogram.raw.types import InputStickerSetShortName
21
+ from pyrogram.types import *
22
+
23
+ from akn.utils.handler import *
24
+ from akn.utils.tools import *
25
+ from akn.utils.prefixprem import command
26
+ from config import *
27
+
28
+
29
+ @Akeno(
30
+ ~filters.scheduled
31
+ & command(["kang", "tikel"])
32
+ & filters.me
33
+ & ~filters.forwarded
34
+ )
35
+ async def kang(client, message):
36
+ user = client.me
37
+ replied = message.reply_to_message
38
+ um = await message.edit_text("`Trying to kang...`")
39
+ media_ = None
40
+ emoji_ = None
41
+ is_anim = False
42
+ is_video = False
43
+ resize = False
44
+ ff_vid = False
45
+ if replied and replied.media:
46
+ if replied.photo:
47
+ resize = True
48
+ elif replied.document and "image" in replied.document.mime_type:
49
+ resize = True
50
+ replied.document.file_name
51
+ elif replied.document and "tgsticker" in replied.document.mime_type:
52
+ is_anim = True
53
+ replied.document.file_name
54
+ elif replied.document and "video" in replied.document.mime_type:
55
+ resize = True
56
+ is_video = True
57
+ ff_vid = True
58
+ elif replied.animation:
59
+ resize = True
60
+ is_video = True
61
+ ff_vid = True
62
+ elif replied.video:
63
+ resize = True
64
+ is_video = True
65
+ ff_vid = True
66
+ elif replied.sticker:
67
+ if not replied.sticker.file_name:
68
+ await um.edit_text("**The sticker has no Name!**")
69
+ return
70
+ emoji_ = replied.sticker.emoji
71
+ is_anim = replied.sticker.is_animated
72
+ is_video = replied.sticker.is_video
73
+ if not (
74
+ replied.sticker.file_name.endswith(".tgs")
75
+ or replied.sticker.file_name.endswith(".webm")
76
+ ):
77
+ resize = True
78
+ ff_vid = True
79
+ else:
80
+ await um.edit_text("**Unsupported Files**")
81
+ return
82
+ media_ = await client.download_media(replied, file_name="resources/")
83
+ else:
84
+ await um.edit_text("**Please Reply to Photo/GIF/Sticker Media!**")
85
+ return
86
+ if media_:
87
+ args = get_arg(message)
88
+ pack = 1
89
+ if len(args) == 2:
90
+ emoji_, pack = args
91
+ elif len(args) == 1:
92
+ if args[0].isnumeric():
93
+ pack = int(args[0])
94
+ else:
95
+ emoji_ = args[0]
96
+
97
+ if emoji_ and emoji_ not in (
98
+ getattr(emoji, _) for _ in dir(emoji) if not _.startswith("_")
99
+ ):
100
+ emoji_ = None
101
+ if not emoji_:
102
+ emoji_ = "🗿"
103
+
104
+ u_name = user.username
105
+ u_name = "@" + u_name if u_name else user.first_name or user.id
106
+ packname = f"Sticker_u{user.id}_v{pack}"
107
+ custom_packnick = f"{client.me.first_name} by {u_name}"
108
+ packnick = f"{custom_packnick} Vol.{pack}"
109
+ cmd = "/newpack"
110
+ if resize:
111
+ media_ = await resize_media(media_, is_video, ff_vid)
112
+ if is_anim:
113
+ packname += "_animated"
114
+ packnick += " (Animated)"
115
+ cmd = "/newanimated"
116
+ if is_video:
117
+ packname += "_video"
118
+ packnick += " (Video)"
119
+ cmd = "/newvideo"
120
+ exist = False
121
+ while True:
122
+ try:
123
+ exist = await client.invoke(
124
+ GetStickerSet(
125
+ stickerset=InputStickerSetShortName(short_name=packname), hash=0
126
+ )
127
+ )
128
+ except StickersetInvalid:
129
+ exist = False
130
+ break
131
+ limit = 50 if (is_video or is_anim) else 120
132
+ if exist.set.count >= limit:
133
+ pack += 1
134
+ packname = f"a{user.id}_by_akeno_{pack}"
135
+ packnick = f"{custom_packnick} Vol.{pack}"
136
+ if is_anim:
137
+ packname += f"_anim{pack}"
138
+ packnick += f" (Animated){pack}"
139
+ if is_video:
140
+ packname += f"_video{pack}"
141
+ packnick += f" (Video){pack}"
142
+ await um.edit_text(
143
+ f"`Create a New Sticker Pack {pack} Because the Sticker Pack Is Full`"
144
+ )
145
+ continue
146
+ break
147
+ if exist is not False:
148
+ try:
149
+ await client.send_message("stickers", "/addsticker")
150
+ except YouBlockedUser:
151
+ await client.unblock_user("stickers")
152
+ await client.send_message("stickers", "/addsticker")
153
+ except Exception as e:
154
+ return await um.edit(f"**ERROR:** `{e}`")
155
+ await asyncio.sleep(2)
156
+ await client.send_message("stickers", packname)
157
+ await asyncio.sleep(2)
158
+ limit = "50" if is_anim else "120"
159
+ while limit in await get_response(message, client):
160
+ pack += 1
161
+ packname = f"a{user.id}_by_{user.username}_{pack}"
162
+ packnick = f"{custom_packnick} vol.{pack}"
163
+ if is_anim:
164
+ packname += "_anim"
165
+ packnick += " (Animated)"
166
+ if is_video:
167
+ packname += "_video"
168
+ packnick += " (Video)"
169
+ await um.edit(
170
+ "`Create a New Sticker Pack "
171
+ + str(pack)
172
+ + " Because the sticker pack is full`"
173
+ )
174
+ await client.send_message("stickers", packname)
175
+ await asyncio.sleep(2)
176
+ if await get_response(message, client) == "Invalid pack selected.":
177
+ await client.send_message("stickers", cmd)
178
+ await asyncio.sleep(2)
179
+ await client.send_message("stickers", packnick)
180
+ await asyncio.sleep(2)
181
+ await client.send_document("stickers", media_)
182
+ await asyncio.sleep(2)
183
+ await client.send_message("Stickers", emoji_)
184
+ await asyncio.sleep(2)
185
+ await client.send_message("Stickers", "/publish")
186
+ await asyncio.sleep(2)
187
+ if is_anim:
188
+ await client.send_message(
189
+ "Stickers", f"<{packnick}>", parse_mode=ParseMode.MARKDOWN
190
+ )
191
+ await asyncio.sleep(2)
192
+ await client.send_message("Stickers", "/skip")
193
+ await asyncio.sleep(2)
194
+ await client.send_message("Stickers", packname)
195
+ await asyncio.sleep(2)
196
+ await um.edit(
197
+ f"**Sticker Added Successfully!**\n **[CLICK HERE](https://t.me/addstickers/{packname})**\n**To Use Stickers**"
198
+ )
199
+ return
200
+ await client.send_document("stickers", media_)
201
+ await asyncio.sleep(2)
202
+ if (
203
+ await get_response(message, client)
204
+ == "Sorry, the file type is invalid."
205
+ ):
206
+ await um.edit_text(
207
+ "**Failed to Add Sticker, Use @Stickers Bot To Add Your Sticker.**"
208
+ )
209
+ return
210
+ await client.send_message("Stickers", emoji_)
211
+ await asyncio.sleep(2)
212
+ await client.send_message("Stickers", "/done")
213
+ else:
214
+ await um.edit_text("`Create a New Sticker Pack`")
215
+ try:
216
+ await client.send_message("Stickers", cmd)
217
+ except YouBlockedUser:
218
+ await client.unblock_user("stickers")
219
+ await client.send_message("stickers", "/addsticker")
220
+ await asyncio.sleep(2)
221
+ await client.send_message("Stickers", packnick)
222
+ await asyncio.sleep(2)
223
+ await client.send_document("stickers", media_)
224
+ await asyncio.sleep(2)
225
+ if (
226
+ await get_response(message, client)
227
+ == "Sorry, the file type is invalid."
228
+ ):
229
+ await um.edit_text(
230
+ "**Failed to Add Sticker, Use @Stickers Bot To Add Your Sticker.**"
231
+ )
232
+ return
233
+ await client.send_message("Stickers", emoji_)
234
+ await asyncio.sleep(2)
235
+ await client.send_message("Stickers", "/publish")
236
+ await asyncio.sleep(2)
237
+ if is_anim:
238
+ await client.send_message("Stickers", f"<{packnick}>")
239
+ await asyncio.sleep(2)
240
+ await client.send_message("Stickers", "/skip")
241
+ await asyncio.sleep(2)
242
+ await client.send_message("Stickers", packname)
243
+ await asyncio.sleep(2)
244
+ await um.edit_text(
245
+ f"**Sticker Added Successfully!**\n **[CLICK HERE](https://t.me/addstickers/{packname})**"
246
+ )
247
+ if os.path.exists(str(media_)):
248
+ os.remove(media_)
249
+
250
+ async def get_response(message, client):
251
+ return [x async for x in client.get_chat_history("Stickers", limit=1)][0].text
252
+
253
+ @Akeno(
254
+ ~filters.scheduled
255
+ & command(["mmf"])
256
+ & filters.me
257
+ & ~filters.forwarded
258
+ )
259
+ async def memify(client, message):
260
+ if not message.reply_to_message_id:
261
+ await message.edit_text("**Plz reply to an sticker!**")
262
+ return
263
+ reply_message = message.reply_to_message
264
+ if not reply_message.media:
265
+ await message.text("**Please Reply to photo or sticker!**")
266
+ return
267
+ file = await client.download_media(reply_message)
268
+ mm = await message.edit_text("`Processing . . .`")
269
+ text = get_arg(message)
270
+ if len(text) < 1:
271
+ return await mm.edit("`Please Type `.mmf text")
272
+ meme = await add_text_img(file, text)
273
+ await asyncio.gather(
274
+ mm.delete(),
275
+ client.send_sticker(
276
+ message.chat.id,
277
+ sticker=meme,
278
+ reply_to_message_id=message.id,
279
+ ),
280
+ )
281
+ os.remove(meme)
282
+
283
+ module = modules_help.add_module("sticker", __file__)
284
+ module.add_command("kang", "Kang To Sticker Or Image To Add To Sticker Pack.")
285
+ module.add_command("mmf", "Reply to Message Sticker or Photo will be changed into a specified meme text sticker")