summaryrefslogtreecommitdiff
path: root/commands/economy.py
diff options
context:
space:
mode:
authorJoe Robinson <joe@lc8n.com>2021-11-25 03:25:44 +0000
committerJoe Robinson <joe@lc8n.com>2021-11-25 03:25:44 +0000
commit439022f058cb2b9bbf6e2b46c067f4c828a1cab0 (patch)
treee1f40f477d3bb3597f52250541326885f9dbfdf8 /commands/economy.py
Initial commit
Diffstat (limited to 'commands/economy.py')
-rw-r--r--commands/economy.py42
1 files changed, 42 insertions, 0 deletions
diff --git a/commands/economy.py b/commands/economy.py
new file mode 100644
index 0000000..1960827
--- /dev/null
+++ b/commands/economy.py
@@ -0,0 +1,42 @@
+from discord.ext.commands import Bot, Cog
+from discord_slash import cog_ext, SlashContext
+from base import config
+from models.user import User
+import random
+import yaml
+
+
+class Economy(Cog):
+ def __init__(self, bot: Bot):
+ self.bot = bot
+ with open("config.yaml", "r") as yamlfile:
+ config = yaml.load(yamlfile, Loader=yaml.CLoader)
+ print("Read config successful")
+ self.config = config
+ print(config["discord_server_id"])
+
+ @cog_ext.cog_slash(
+ name="daily",
+ description="Get some coins.",
+ guild_ids=[config["discord_server_id"]],
+ )
+ 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")
+
+ @cog_ext.cog_slash(
+ name="coins",
+ description="Check your coins.",
+ guild_ids=[config["discord_server_id"]],
+ )
+ 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")
+
+
+def setup(bot):
+ bot.add_cog(Economy(bot))
+ print("Loaded Economy")