Skip to content

Commit

Permalink
show album of latest uploaded memes
Browse files Browse the repository at this point in the history
  • Loading branch information
ohld committed Jun 9, 2024
1 parent 708cc4e commit 94edf99
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
2 changes: 2 additions & 0 deletions src/tgbot/handlers/upload/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,8 @@ async def get_uploaded_memes_of_user_id(user_id: int) -> list[dict[str, Any]]:
SELECT
M.id meme_id,
M.status,
M.telegram_file_id,
M.type,
MS.nmemes_sent,
MS.nlikes,
MS.ndislikes
Expand Down
13 changes: 10 additions & 3 deletions src/tgbot/handlers/upload/stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@
"""


from telegram import Update
from telegram import (
InputMediaPhoto,
Update,
)
from telegram.constants import ParseMode
from telegram.ext import ContextTypes

Expand Down Expand Up @@ -50,17 +53,21 @@ async def handle_uploaded_memes_stats(
views - likes - like %"""

# show stats for last 5 uploads:
media = []
for uploaded_meme in uploaded_memes[-5:]:
views = uploaded_meme["nmemes_sent"]
likes = uploaded_meme["nlikes"]
dislikes = uploaded_meme["ndislikes"]
like_prc = round(likes * 100.0 / (likes + dislikes))

media.append(InputMediaPhoto(media=uploaded_meme["telegram_file_id"]))

STATS_TEXT += f"\n{views} - {likes} - {like_prc}%"

STATS_TEXT += "\n\nUpload more memes and win lots of 🍔 /kitchen"

await update.message.reply_text(
STATS_TEXT,
await update.message.reply_media_group(
media=media,
caption=STATS_TEXT,
parse_mode=ParseMode.HTML,
)

0 comments on commit 94edf99

Please sign in to comment.