diff options
Diffstat (limited to 'commands/economy.py')
-rw-r--r-- | commands/economy.py | 42 |
1 files changed, 37 insertions, 5 deletions
diff --git a/commands/economy.py b/commands/economy.py index 1960827..a2178c4 100644 --- a/commands/economy.py +++ b/commands/economy.py @@ -2,6 +2,7 @@ from discord.ext.commands import Bot, Cog from discord_slash import cog_ext, SlashContext from base import config from models.user import User +import datetime import random import yaml @@ -22,10 +23,26 @@ class Economy(Cog): ) async def daily(self, ctx: SlashContext): user = User.get(User.discord_id == ctx.author_id) - num_coins = random.randrange(50, 100) - user.add_coins(num_coins) - user.save() - await ctx.send(content="Here have some coins") + time_now = datetime.datetime.utcnow() + day_ago = time_now - datetime.timedelta(hours=24) + if user.daily_gained_time is None: + user.daily_gained_time = day_ago + remaining = user.daily_gained_time - day_ago + print( + f"now: {time_now}, day: {day_ago}, user: {user.exp_gained_time}, remaining: {remaining}" + ) + if user.daily_gained_time is None or user.daily_gained_time <= day_ago: + num_coins = random.randrange(50, 100) + user.daily_gained_time = time_now + user.add_coins(num_coins) + user.save() + await ctx.send( + content=f"Here you go {user.display_name}, have {num_coins} {config['currency']}" + ) + else: + await ctx.send( + content=f"No {config['currency']} for you {user.display_name}, come back in {remaining.seconds // 3600} hours, {(remaining.seconds % 3600) // 60 } minutes." + ) @cog_ext.cog_slash( name="coins", @@ -34,7 +51,22 @@ class Economy(Cog): ) async def coins(self, ctx: SlashContext): user = User.get(User.discord_id == ctx.author_id) - await ctx.send(content=f"{user.display_name}, you have {user.currency} coins") + await ctx.send( + content=f"{user.display_name}, you have {user.currency} {config['currency']}" + ) + + @cog_ext.cog_slash( + name="leaderboard", + description="Show the currency leaderboard", + guild_ids=[config["discord_server_id"]], + ) + async def leaderboard(self, ctx: SlashContext): + users = User.select().order_by(User.currency.desc()).limit(10) + rank_text = "" + for user in users: + rank_text += f"{user.display_name}: {user.currency} {config['currency']} \n" + + await ctx.send(content=rank_text) def setup(bot): |