taslim19
commited on
Commit
·
fe3062a
1
Parent(s):
7710b6e
Fix kang.py: ensure valid Telegram sticker pack short names
Browse files
DragMusic/plugins/management/kang.py
CHANGED
@@ -1,4 +1,3 @@
|
|
1 |
-
|
2 |
import imghdr
|
3 |
import os
|
4 |
from asyncio import gather
|
@@ -33,9 +32,7 @@ from DragMusic.utils.stickerset import (
|
|
33 |
|
34 |
# -----------
|
35 |
|
36 |
-
MAX_STICKERS =
|
37 |
-
120 # would be better if we could fetch this limit directly from telegram
|
38 |
-
)
|
39 |
SUPPORTED_TYPES = ["jpeg", "png", "webp"]
|
40 |
# ------------------------------------------
|
41 |
@app.on_message(filters.command("get_sticker"))
|
@@ -131,15 +128,14 @@ async def kang(client, message: Message):
|
|
131 |
e = format_exc()
|
132 |
return print(e)
|
133 |
#-------
|
|
|
134 |
packnum = 0
|
135 |
-
packname = "f
|
136 |
limit = 0
|
137 |
try:
|
138 |
while True:
|
139 |
-
# Prevent infinite rules
|
140 |
if limit >= 50:
|
141 |
return await msg.delete()
|
142 |
-
|
143 |
stickerset = await get_sticker_set_by_name(client, packname)
|
144 |
if not stickerset:
|
145 |
stickerset = await create_sticker_set(
|
@@ -151,14 +147,7 @@ async def kang(client, message: Message):
|
|
151 |
)
|
152 |
elif stickerset.set.count >= MAX_STICKERS:
|
153 |
packnum += 1
|
154 |
-
packname =
|
155 |
-
"f"
|
156 |
-
+ str(packnum)
|
157 |
-
+ "_"
|
158 |
-
+ str(message.from_user.id)
|
159 |
-
+ "_by_"
|
160 |
-
+ BOT_USERNAME
|
161 |
-
)
|
162 |
limit += 1
|
163 |
continue
|
164 |
else:
|
@@ -168,15 +157,12 @@ async def kang(client, message: Message):
|
|
168 |
return await msg.edit("[ERROR]: INVALID_EMOJI_IN_ARGUMENT")
|
169 |
limit += 1
|
170 |
break
|
171 |
-
|
172 |
await msg.edit(
|
173 |
-
"Sticker Kanged To [Pack](t.me/addstickers/{})\nEmoji: {}"
|
174 |
-
packname, sticker_emoji
|
175 |
-
)
|
176 |
)
|
177 |
except (PeerIdInvalid, UserIsBlocked):
|
178 |
keyboard = InlineKeyboardMarkup(
|
179 |
-
[[InlineKeyboardButton(text="Start", url=f"t.me/{
|
180 |
)
|
181 |
await msg.edit(
|
182 |
"You Need To Start A Private Chat With Me.",
|
|
|
|
|
1 |
import imghdr
|
2 |
import os
|
3 |
from asyncio import gather
|
|
|
32 |
|
33 |
# -----------
|
34 |
|
35 |
+
MAX_STICKERS = 120
|
|
|
|
|
36 |
SUPPORTED_TYPES = ["jpeg", "png", "webp"]
|
37 |
# ------------------------------------------
|
38 |
@app.on_message(filters.command("get_sticker"))
|
|
|
128 |
e = format_exc()
|
129 |
return print(e)
|
130 |
#-------
|
131 |
+
bot_username = BOT_USERNAME.lstrip("@")
|
132 |
packnum = 0
|
133 |
+
packname = f"f{message.from_user.id}_by_{bot_username}"
|
134 |
limit = 0
|
135 |
try:
|
136 |
while True:
|
|
|
137 |
if limit >= 50:
|
138 |
return await msg.delete()
|
|
|
139 |
stickerset = await get_sticker_set_by_name(client, packname)
|
140 |
if not stickerset:
|
141 |
stickerset = await create_sticker_set(
|
|
|
147 |
)
|
148 |
elif stickerset.set.count >= MAX_STICKERS:
|
149 |
packnum += 1
|
150 |
+
packname = f"f{packnum}_{message.from_user.id}_by_{bot_username}"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
151 |
limit += 1
|
152 |
continue
|
153 |
else:
|
|
|
157 |
return await msg.edit("[ERROR]: INVALID_EMOJI_IN_ARGUMENT")
|
158 |
limit += 1
|
159 |
break
|
|
|
160 |
await msg.edit(
|
161 |
+
f"Sticker Kanged To [Pack](t.me/addstickers/{packname})\nEmoji: {sticker_emoji}"
|
|
|
|
|
162 |
)
|
163 |
except (PeerIdInvalid, UserIsBlocked):
|
164 |
keyboard = InlineKeyboardMarkup(
|
165 |
+
[[InlineKeyboardButton(text="Start", url=f"t.me/{bot_username}")]]
|
166 |
)
|
167 |
await msg.edit(
|
168 |
"You Need To Start A Private Chat With Me.",
|