-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move out code about moving sticker into interactor
- Loading branch information
Showing
3 changed files
with
65 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
src/telegram_stickers_organizer/interactors/move_sticker_to_another_set.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
from ..utils.sticker_helpers import get_sticker_set, add_stickers_to_set | ||
from ..dispatcher import bot | ||
from ..constants import MAX_STICKERS_IN_STICKERSET | ||
import logging | ||
|
||
|
||
async def move_sticker_to_another_set( | ||
source_pack: str, destination_pack: str, file_id: str, user_id: int | ||
): | ||
try: | ||
# Get the source sticker set | ||
source_set = await get_sticker_set(source_pack) | ||
|
||
# Find the sticker with the given file_id in the source set | ||
sticker = next((s for s in source_set.stickers if s.file_id == file_id), None) | ||
|
||
if not sticker: | ||
return False, "Sticker not found in the source pack" | ||
|
||
# Get the destination sticker set | ||
destination_set = await get_sticker_set(destination_pack) | ||
|
||
# Check if the destination pack is full | ||
if len(destination_set.stickers) >= MAX_STICKERS_IN_STICKERSET: | ||
return False, "Destination pack is full (maximum 120 stickers)" | ||
|
||
# Add the sticker to the destination pack | ||
await add_stickers_to_set(user_id, destination_pack, [sticker]) | ||
|
||
# Remove the sticker from the source pack | ||
await bot.delete_sticker_from_set(file_id) | ||
|
||
return True, None | ||
except Exception as e: | ||
logging.error(f"Error moving sticker: {e}") | ||
return False, str(e) |