summaryrefslogtreecommitdiff
path: root/commands/economy.py
diff options
context:
space:
mode:
Diffstat (limited to 'commands/economy.py')
-rw-r--r--commands/economy.py57
1 files changed, 52 insertions, 5 deletions
diff --git a/commands/economy.py b/commands/economy.py
index 1960827..720a00d 100644
--- a/commands/economy.py
+++ b/commands/economy.py
@@ -1,7 +1,9 @@
from discord.ext.commands import Bot, Cog
from discord_slash import cog_ext, SlashContext
+from discord import Embed
from base import config
from models.user import User
+import datetime
import random
import yaml
@@ -22,10 +24,30 @@ 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 = 10 + user.level * 2
+ user.daily_gained_time = time_now
+ user.add_coins(num_coins)
+ user.save()
+ embed = Embed(
+ description=f"Here you go {ctx.author.mention}, have your daily coins",
+ colour=0x00FF00,
+ )
+ embed.add_field(name="Gained:", value=f"{num_coins} {config['currency']}")
+ else:
+ embed = Embed(
+ description=f"No {config['currency']} for you {user.display_name}, come back in {remaining.seconds // 3600} hours, {(remaining.seconds % 3600) // 60 } minutes.",
+ colour=0xFF8800,
+ )
+ await ctx.send(embed=embed)
@cog_ext.cog_slash(
name="coins",
@@ -34,7 +56,32 @@ 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")
+ embed = Embed(
+ description=f"{ctx.author.mention}, here is your current balance:",
+ colour=0x0000FF,
+ )
+ embed.add_field(name="Currency:", value=f"{user.currency} {config['currency']}")
+ await ctx.send(embed=embed)
+
+ @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)
+ embed = Embed(
+ title="Currency Leaderboard",
+ colour=0x0000FF,
+ )
+ i = 1
+ for user in users:
+ embed.add_field(
+ name=f"#{i} {user.display_name}", value=f"{user.currency} {config['currency']}"
+ )
+ i += 1
+
+ await ctx.send(embed=embed)
def setup(bot):