mirror of
https://github.com/wlinator/luminara.git
synced 2024-10-02 16:03:12 +00:00
feat: Add daily command
This commit is contained in:
parent
8229082099
commit
2adf5185c5
3 changed files with 85 additions and 0 deletions
|
@ -1,11 +1,14 @@
|
|||
TOKEN=
|
||||
INSTANCE=
|
||||
OWNER_IDS=
|
||||
|
||||
XP_GAIN_PER_MESSAGE=
|
||||
XP_GAIN_COOLDOWN=
|
||||
|
||||
DBX_OAUTH2_REFRESH_TOKEN=
|
||||
DBX_APP_KEY=
|
||||
DBX_APP_SECRET=
|
||||
|
||||
MARIADB_USER=
|
||||
MARIADB_PASSWORD=
|
||||
MARIADB_ROOT_PASSWORD=
|
||||
|
|
0
modules/economy/__init__.py
Normal file
0
modules/economy/__init__.py
Normal file
82
modules/economy/daily.py
Normal file
82
modules/economy/daily.py
Normal 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))
|
Loading…
Reference in a new issue