Skip to content

Commit

Permalink
daily rewards
Browse files Browse the repository at this point in the history
  • Loading branch information
ohld committed Jun 7, 2024
1 parent f8bde4c commit 8d94f52
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 2 deletions.
35 changes: 35 additions & 0 deletions src/flows/rewards/daily.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
from datetime import datetime

from prefect import flow
from telegram.constants import ParseMode

from src import localizer
from src.tgbot.bot import bot
from src.tgbot.handlers.treasury.constants import PAYOUTS, TrxType
from src.tgbot.handlers.treasury.payments import pay_if_not_paid
from src.tgbot.logs import log
from src.tgbot.user_info import get_user_info


@flow
async def reward_user_for_daily_activity(user_id: int):
user_info = await get_user_info(user_id)
if user_info["memes_watched_today"] == 10:
res = await pay_if_not_paid(
user_id,
TrxType.DAILY_REWARD,
external_id=datetime.today().strftime("%Y-%m-%d"),
)
if res:
msg = (
localizer.t(
"rewards.daily_reward",
user_info["interface_lang"],
).format(amount=PAYOUTS[TrxType.DAILY_REWARD]),
)
await bot.send_message(
user_id,
msg,
parse_mode=ParseMode.HTML,
)
await log(msg)
4 changes: 2 additions & 2 deletions src/flows/rewards/uploaded_memes.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,8 @@ async def reward_ru_users_for_weekly_top_uploaded_memes():
enternal_id=today,
)

await log_meme_sent(top_meme["id"], channel=Channel.TG_CHANNEL_RU)
await update_meme(top_meme["id"], status=MemeStatus.PUBLISHED)
await log_meme_sent(top_meme["meme_id"], channel=Channel.TG_CHANNEL_RU)
await update_meme(top_meme["meme_id"], status=MemeStatus.PUBLISHED)

# send message to tgchannelru

Expand Down
2 changes: 2 additions & 0 deletions src/tgbot/handlers/reaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
ContextTypes,
)

from src.flows.rewards.daily import reward_user_for_daily_activity
from src.recommendations.service import (
update_user_last_active_at,
update_user_meme_reaction,
Expand All @@ -28,6 +29,7 @@ async def handle_reaction(update: Update, context: ContextTypes.DEFAULT_TYPE) ->
# do that in sync since we'll use counters in next_message
await update_user_info_counters(user_id)
asyncio.create_task(update_user_last_active_at(user_id))
asyncio.create_task(reward_user_for_daily_activity(user_id))

reaction_is_new = await update_user_meme_reaction(
user_id=user_id,
Expand Down
4 changes: 4 additions & 0 deletions src/tgbot/handlers/treasury/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ class TrxType(str, Enum):
UPLOADER_TOP_WEEKLY_4 = "uploader_top_weekly_4"
UPLOADER_TOP_WEEKLY_5 = "uploader_top_weekly_5"

DAILY_REWARD = "daily_reward"


PAYOUTS = {
TrxType.MEME_UPLOADER: 5,
Expand All @@ -24,6 +26,7 @@ class TrxType(str, Enum):
TrxType.UPLOADER_TOP_WEEKLY_3: 200,
TrxType.UPLOADER_TOP_WEEKLY_4: 100,
TrxType.UPLOADER_TOP_WEEKLY_5: 50,
TrxType.DAILY_REWARD: 1,
}

# TODO: localize
Expand All @@ -37,4 +40,5 @@ class TrxType(str, Enum):
TrxType.UPLOADER_TOP_WEEKLY_3: "weekly top 3 meme",
TrxType.UPLOADER_TOP_WEEKLY_4: "weekly top 4 meme",
TrxType.UPLOADER_TOP_WEEKLY_5: "weekly top 5 meme",
TrxType.DAILY_REWARD: "daily activity",
}
42 changes: 42 additions & 0 deletions static/localization/rewards.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
rewards.daily_reward:
en: |-
💳 /b: +<b>{amount} 🍔</b>. It's your daily reward for watching memes ❤️
ru: |-
💳 /b: +<b>{amount} 🍔</b> за то, что посмотрели мемы сегодня ❤️
uk: |-
💳 /b: +<b>{amount} 🍔</b> за те, що переглянули меми сьогодні ❤️
kz: |-
💳 /b: +<b>{amount} 🍔</b> бұл сіздің мемелерді көру үшін күндізгі мүшелеріңіз ❤️
be: |-
💳 /b: +<b>{amount} 🍔</b> за тое, што паглядзелі мемы сёння ❤️
kk: |-
💳 /b: +<b>{amount} 🍔</b> сіздің мемелерді көру үшін күндізгі мүшелеріңіз ❤️
uz: |-
💳 /b: +<b>{amount} 🍔</b>. Siz bugungi kunda memlarni ko'rganingiz uchun ❤️
tr: |-
💳 /b: +<b>{amount} 🍔</b>. Bugün memelere baktığınız için ❤️
es: |-
💳 /b: +<b>{amount} 🍔</b>. Es tu recompensa diaria por ver memes ❤️
pt-br: |-
💳 /b: +<b>{amount} 🍔</b>. É a sua recompensa diária por ver memes ❤️
pl: |-
💳 /b: +<b>{amount} 🍔</b>. To twoja codzienna nagroda za oglądanie memów ❤️
de: |-
💳 /b: +<b>{amount} 🍔</b>. Es ist deine tägliche Belohnung für das Ansehen von Memes ❤️
fr: |-
💳 /b: +<b>{amount} 🍔</b>. C'est votre récompense quotidienne pour avoir regardé des mèmes ❤️
id: |-
💳 /b: +<b>{amount} 🍔</b>. Ini adalah hadiah harian Anda untuk menonton meme ❤️
ar: |-
💳 /b: +<b>{amount} 🍔</b>. إنها مكافأتك اليومية لمشاهدة الصور الساخرة ❤️
fa: |-
💳 /b: +<b>{amount} 🍔</b>. این پاداش روزانه شما برای تماشای میم‌هاست ❤️
ja: |-
💳 /b: +<b>{amount} 🍔</b>。これはミームを見るための毎日の報酬です ❤️
zh: |-
💳 /b: +<b>{amount} 🍔</b>。这是您每天观看表情包的奖励 ❤️
ko: |-
💳 /b: +<b>{amount} 🍔</b>. 미미를 보는 것에 대한 매일 보상입니다 ❤️
vi: |-
💳 /b: +<b>{amount} 🍔</b>. Đây là phần thưởng hàng ngày của bạn vì đã xem meme ❤️

0 comments on commit 8d94f52

Please sign in to comment.