1
Fork 0
mirror of https://github.com/wlinator/luminara.git synced 2024-10-02 18:03:12 +00:00

feat: Add daily command

This commit is contained in:
wlinator 2024-09-01 09:40:09 -04:00
parent 8229082099
commit 2adf5185c5
3 changed files with 85 additions and 0 deletions

View file

@ -1,11 +1,14 @@
TOKEN= TOKEN=
INSTANCE= INSTANCE=
OWNER_IDS= OWNER_IDS=
XP_GAIN_PER_MESSAGE= XP_GAIN_PER_MESSAGE=
XP_GAIN_COOLDOWN= XP_GAIN_COOLDOWN=
DBX_OAUTH2_REFRESH_TOKEN= DBX_OAUTH2_REFRESH_TOKEN=
DBX_APP_KEY= DBX_APP_KEY=
DBX_APP_SECRET= DBX_APP_SECRET=
MARIADB_USER= MARIADB_USER=
MARIADB_PASSWORD= MARIADB_PASSWORD=
MARIADB_ROOT_PASSWORD= MARIADB_ROOT_PASSWORD=

View file

82
modules/economy/daily.py Normal file
View file

@ -0,0 +1,82 @@
from datetime import datetime, timedelta
import pytz
from discord import Embed
from discord.ext import commands
from lib.const import CONST
from services.currency_service import Currency
from services.daily_service import Dailies
from ui.embeds import Builder
tz = pytz.timezone("US/Eastern")
def seconds_until(hours: int, minutes: int) -> int:
now = datetime.now(tz)
given_time = now.replace(hour=hours, minute=minutes, second=0, microsecond=0)
if given_time < now:
given_time += timedelta(days=1)
return int((given_time - now).total_seconds())
class Daily(commands.Cog):
def __init__(self, bot: commands.Bot) -> None:
self.bot: commands.Bot = bot
@commands.hybrid_command(
name="daily",
aliases=["timely"],
)
async def daily(
self,
ctx: commands.Context[commands.Bot],
) -> None:
"""
Claim your daily reward.
Parameters
----------
ctx : commands.Context[commands.Bot]
The context of the command.
"""
ctx_daily: Dailies = Dailies(ctx.author.id)
if not ctx_daily.can_be_claimed():
wait_time: datetime = datetime.now(tz) + timedelta(seconds=seconds_until(7, 0))
unix_time: int = int(round(wait_time.timestamp()))
error_embed: Embed = Builder.create_embed(
theme="error",
user_name=ctx.author.name,
author_text=CONST.STRINGS["daily_already_claimed_author"],
description=CONST.STRINGS["daily_already_claimed_description"].format(
unix_time,
),
footer_text=CONST.STRINGS["daily_already_claimed_footer"],
)
await ctx.send(embed=error_embed)
return
ctx_daily.streak = ctx_daily.streak + 1 if ctx_daily.streak_check() else 1
ctx_daily.claimed_at = datetime.now(tz=ctx_daily.tz)
ctx_daily.amount = 100 * 12 * (ctx_daily.streak - 1)
ctx_daily.refresh()
embed: Embed = Builder.create_embed(
theme="success",
user_name=ctx.author.name,
author_text=CONST.STRINGS["daily_success_claim_author"],
description=CONST.STRINGS["daily_success_claim_description"].format(
Currency.format(ctx_daily.amount),
),
footer_text=CONST.STRINGS["daily_streak_footer"].format(ctx_daily.streak) if ctx_daily.streak > 1 else None,
)
await ctx.send(embed=embed)
async def setup(bot: commands.Bot) -> None:
await bot.add_cog(Daily(bot))