Skip to content

Commit

Permalink
Fix unable to upload telegram stickers
Browse files Browse the repository at this point in the history
  • Loading branch information
laggykiller committed Dec 3, 2024
1 parent 0dcd9c1 commit ef7fd78
Showing 1 changed file with 20 additions and 26 deletions.
46 changes: 20 additions & 26 deletions src/sticker_convert/uploaders/upload_telegram.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,7 @@ async def upload_pack(

init_input_stickers: List[InputSticker] = []
sticker_format = None
sticker_format_prev = None
for count, src in enumerate(stickers):
for src in stickers:
self.cb.put(f"Verifying {src} for uploading to telegram")

emoji = extract_emojis(emoji_dict.get(Path(src).stem, ""))
Expand Down Expand Up @@ -206,29 +205,7 @@ async def upload_pack(
)

if sticker_set is None:
if count < 50 and (
sticker_format_prev is None
or sticker_format_prev == sticker_format
):
init_input_stickers.append(input_sticker)
else:
start_msg = f"Creating pack and bulk uploading {count} stickers with same format of {pack_short_name}"
finish_msg = f"Created pack and bulk uploaded {count} stickers with same format of {pack_short_name}"
error_msg = f"Cannot create pack and bulk upload {count} stickers with same format of {pack_short_name} due to"
self.cb.put(start_msg)
try:
await bot.create_new_sticker_set(
user_id=self.telegram_userid,
name=pack_short_name,
title=pack_title,
stickers=init_input_stickers,
sticker_type=sticker_type,
)
sticker_set = True
self.cb.put(finish_msg)
except TelegramError as e:
self.cb.put(f"{error_msg} {e}")
return None
init_input_stickers.append(input_sticker)
else:
try:
# We could use tg.start_soon() here
Expand All @@ -252,7 +229,24 @@ async def upload_pack(
f"Cannot upload sticker {src} of {pack_short_name} due to {e}"
)

sticker_format_prev = sticker_format
if sticker_set is None and len(init_input_stickers) > 0:
start_msg = f"Creating pack and bulk uploading {len(init_input_stickers)} stickers with same format of {pack_short_name}"
finish_msg = f"Created pack and bulk uploaded {len(init_input_stickers)} stickers with same format of {pack_short_name}"
error_msg = f"Cannot create pack and bulk upload {len(init_input_stickers)} stickers with same format of {pack_short_name} due to"
self.cb.put(start_msg)
try:
await bot.create_new_sticker_set(
user_id=self.telegram_userid,
name=pack_short_name,
title=pack_title,
stickers=init_input_stickers,
sticker_type=sticker_type,
)
sticker_set = True
self.cb.put(finish_msg)
except TelegramError as e:
self.cb.put(f"{error_msg} {e}")
return None

cover_path = MetadataHandler.get_cover(self.opt_output.dir)
if cover_path:
Expand Down

0 comments on commit ef7fd78

Please sign in to comment.