Skip to content

Commit d21cc07

Browse files
committed
feat(add sticker): added sticker overflow handling
TODO: make quick stickerpack creation if queue of stickers is overflowing to create new stickerpack on-run
1 parent 8b0e028 commit d21cc07

1 file changed

Lines changed: 38 additions & 5 deletions

File tree

cogs/add_sticker.py

Lines changed: 38 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from struct import pack
2+
13
import cog
24
from utils.integrations.video_convert import convert_to_webm
35

@@ -79,6 +81,18 @@ async def receive_sticker_sticker_emojisa(
7981
current_format = data.get("current_format", "static")
8082
current_filename = data.get("current_filename", "sticker.png")
8183

84+
stickerset = await self.bot.get_sticker_set(packToAdd)
85+
if not stickerset:
86+
return await message.reply(
87+
"Oops! I can't found this stickerpack on telegram right now..."
88+
)
89+
90+
if (120 - len(stickerset.stickers) - len(stickers)) <= 0:
91+
return await message.reply("""Yo yo yo, you've hit the limit!
92+
You can't add more than in your queue in this pack now!
93+
Commit these stickers to your pack via /done or clear the queue via /cancel
94+
<i>jeez...</i>""")
95+
8296
if not current_sticker:
8397
await message.answer(
8498
"Error: sticker for this emojis was not found, send the sticker again."
@@ -99,7 +113,6 @@ async def receive_sticker_sticker_emojisa(
99113
current_format=None,
100114
current_filename=None,
101115
)
102-
stickerset = await self.bot.get_sticker_set(packToAdd)
103116

104117
await message.answer(
105118
f"""Sticker added to the queue!
@@ -137,6 +150,22 @@ async def receive_stickera(self, message: cog.Message, state: cog.FSMContext):
137150

138151
data = await state.get_data()
139152
copy_emoji = data.get("copy_emoji", False)
153+
packToAdd = data["packToAdd"]
154+
stickers = data.get("stickers", [])
155+
156+
stickerset = await self.bot.get_sticker_set(
157+
packToAdd + "_by_" + (await self.bot.get_me()).username
158+
)
159+
if not stickerset:
160+
return await message.reply(
161+
"Oops! I can't found this stickerpack on telegram right now..."
162+
)
163+
164+
if (120 - len(stickerset.stickers) - len(stickers)) <= 0:
165+
return await message.reply("""Yo yo yo, you've hit the limit!
166+
You can't add more than in your queue in this pack now!
167+
Commit these stickers to your pack via /done or clear the queue via /cancel
168+
<i>jeez...</i>""")
140169

141170
sticker_data = None
142171
sticker_format = "static"
@@ -224,8 +253,6 @@ async def receive_stickera(self, message: cog.Message, state: cog.FSMContext):
224253
)
225254
emojis = list(message.caption)
226255
self.bot.log("reading caption", caption=emojis, type="debug")
227-
data = await state.get_data()
228-
stickers = data.get("stickers", [])
229256
stickers.append(
230257
{
231258
"emojis": emojis,
@@ -236,7 +263,10 @@ async def receive_stickera(self, message: cog.Message, state: cog.FSMContext):
236263
)
237264
await state.update_data(stickers=stickers)
238265
await message.answer(
239-
"Sticker added to the pack!\nYou can send me more stickers to add to the pack, or send /done when you are finished."
266+
f"""Sticker added to the pack!
267+
You can send me more stickers to add to the pack, or send /done when you are finished.
268+
269+
<i>*you can add up to {120 - len(stickerset.stickers) - len(stickers)} stickers to this pack now</i>"""
240270
)
241271
elif copy_emoji and message.sticker and message.sticker.emoji:
242272
emojis = message.sticker.emoji
@@ -252,7 +282,10 @@ async def receive_stickera(self, message: cog.Message, state: cog.FSMContext):
252282
)
253283
await state.update_data(stickers=stickers)
254284
await message.answer(
255-
f"Sticker added to the pack with emojis: {' '.join(emojis)}!\nYou can send me more stickers to add to the pack, or send /done when you are finished."
285+
f"""Sticker added to the pack with emojis: {" ".join(emojis)}!
286+
You can send me more stickers to add to the pack, or send /done when you are finished.
287+
288+
<i>*you can add up to {120 - len(stickerset.stickers) - len(stickers)} stickers to this pack now</i>"""
256289
)
257290
else:
258291
await state.update_data(

0 commit comments

Comments
 (0)