From e59ece4666afa4df94d38e92bc3bfedd82705fa8 Mon Sep 17 00:00:00 2001 From: snipe <72265661+notsniped@users.noreply.github.com> Date: Sat, 18 Mar 2023 13:14:09 +0000 Subject: [PATCH 1/7] Add user data storage database --- database/user_data.json | 1 + 1 file changed, 1 insertion(+) create mode 100644 database/user_data.json diff --git a/database/user_data.json b/database/user_data.json new file mode 100644 index 00000000..0967ef42 --- /dev/null +++ b/database/user_data.json @@ -0,0 +1 @@ +{} From 2a3f8266a362240d10685036d17e6f393b50ca11 Mon Sep 17 00:00:00 2001 From: snipe <72265661+notsniped@users.noreply.github.com> Date: Sat, 18 Mar 2023 13:22:00 +0000 Subject: [PATCH 2/7] Add database management for userdat db --- cogs/economy.py | 11 ++++++++++- main.py | 3 ++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/cogs/economy.py b/cogs/economy.py index 7de3a44c..a1d5168e 100644 --- a/cogs/economy.py +++ b/cogs/economy.py @@ -37,10 +37,12 @@ def get_item_names(self) -> list: with open(f"{wdir}/database/currency.json", 'r') as f: currency = json.load(f) with open(f"{wdir}/database/items.json", 'r') as f: items = json.load(f) with open(f"{wdir}/config/shop.json", 'r') as f: shopitem = json.load(f) +with open(f"{wdir}/database/user_data.json", 'r') as f: userdat = json.load(f) def save(): with open(f"{wdir}/database/currency.json", 'w+') as f: json.dump(currency, f, indent=4) with open(f"{wdir}/database/items.json", 'w+') as f: json.dump(items, f, indent=4) + with open(f"{wdir}/database/user_data.json", 'w+') as f: json.dump(userdat, f, indent=4) # Functions def get_user_networth(user_id:int): @@ -72,7 +74,14 @@ def get_user_count(): for x in currency["wallet"].keys(): users += 1 return users - + +def new_userdat(id: int): + if str(id) not in userdat.keys(): + userdat[str(id)] = {"work_job": None} + save() + return 0 + else: return 1 + # Commands class Economy(commands.Cog): def __init__(self, bot): diff --git a/main.py b/main.py index 3c6d2ca9..8443926b 100644 --- a/main.py +++ b/main.py @@ -21,7 +21,7 @@ from discord import ApplicationContext, option from discord.ext import commands from discord.ext.commands import * -from cogs.economy import new_bank, new_wallet +from cogs.economy import new_bank, new_wallet, new_userdat from cogs.isocoin import create_isocoin_key from cogs.moderation import new_warnings_guild, new_warnings_user @@ -110,6 +110,7 @@ async def on_message(ctx): new_warnings_guild(ctx.guild.id) new_warnings_user(ctx.guild.id, ctx.author.id) create_isocoin_key(ctx.author.id) + new_userdat(ctx.author.id) if str(ctx.author.id) not in items: items[str(ctx.author.id)] = {} if str(ctx.author.id) not in levels: levels[str(ctx.author.id)] = {"xp": 0, "level": 0} if str(ctx.guild.id) not in automod_config: From fc47cfe8ef8e1c710158fcd14592cf40d199a4b1 Mon Sep 17 00:00:00 2001 From: snipe <72265661+notsniped@users.noreply.github.com> Date: Sat, 18 Mar 2023 13:34:11 +0000 Subject: [PATCH 3/7] Add a jobs list, and add `/work_select` command for selecting a job --- cogs/economy.py | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/cogs/economy.py b/cogs/economy.py index a1d5168e..8d070020 100644 --- a/cogs/economy.py +++ b/cogs/economy.py @@ -33,6 +33,15 @@ def get_item_names(self) -> list: color = discord.Color.random() shop_data = ShopData(f"{wdir}/config/shop.json") all_item_ids = shop_data.get_item_ids() +jobs = [ + "Discord mod", + "YouTuber", + "Streamer", + "Developer", + "Scientist", + "Engineer", + "Doctor" +] with open(f"{wdir}/database/currency.json", 'r') as f: currency = json.load(f) with open(f"{wdir}/database/items.json", 'r') as f: items = json.load(f) @@ -469,7 +478,20 @@ async def work(self, ctx: ApplicationContext): currency['wallet'][str(ctx.author.id)] += i save() await ctx.respond(f'{ctx.author.mention} worked for a 30-minute shift and earned {i} coins.') - + + @commands.slash_command( + name="work_select", + description="Choose the job you want to work." + ) + @option(name="job", description="What job do you want to work?", options=jobs, type=str) + @commands.cooldown(1, 1800, commands.BucketType.user) + async def work_select(self, ctx: ApplicationContext, job: str): + if job not in jobs: return await ctx.respond(f"This job does not exist. What kind of a job is even {job}??", ephemeral=True) + userdat[str(ctx.author.id)]["work_job"] = job + save() + localembed = discord.Embed(title="New job!", description=f"You are now working as a {job}!") + await ctx.reply(embed=localembed) + @commands.slash_command( name='donate', description="Donate money to whoever you want" From 086a576454a5423e731f4a63bfa8c0d56a2e3b8a Mon Sep 17 00:00:00 2001 From: snipe <72265661+notsniped@users.noreply.github.com> Date: Sat, 18 Mar 2023 13:51:06 +0000 Subject: [PATCH 4/7] Add `/work_list` to show the list of available jobs --- cogs/economy.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/cogs/economy.py b/cogs/economy.py index 8d070020..3e0d92dc 100644 --- a/cogs/economy.py +++ b/cogs/economy.py @@ -479,6 +479,18 @@ async def work(self, ctx: ApplicationContext): save() await ctx.respond(f'{ctx.author.mention} worked for a 30-minute shift and earned {i} coins.') + @commands.slash_command( + name="work_list", + description="Shows a list of all the jobs currently available." + ) + async def work_list(self, ctx: ApplicationContext): + localembed = discord.Embed( + title="All jobs currently available", + description="To join a job, make sure you meet the required level first.\n\n**Discord mod**: Moderate community servers and earn money from the owner\n Salary: `5000 - 10000 coins` per shift\n Level experience: None required\n\n**YouTuber**: Make YouTube videos and earn money from monetization\n Salary: `10000-15000 coins` per shift\n Level experience: Level 3\n\n**Streamer**: Stream on Twitch and earn money from viewer donations\n Salary: `12000-18000 coins` per shift\n Level experience: Level 5\n\n**Developer**: Write code for *stuff* and make money\n Salary: `20000-40000 coins` per shift\n Level experience: Level 10\n\n**Scientist**: Make large amounts of money by working as a scientist at a undisclosed lab\n Salary: `50000-100000 coins` per shift\n Level experience: Level 20\n\n**Engineer**: Work as a highly-skilled engineer in a big company and make tons of money\n Salary: `100000-175000 coins` per shift\n Level experience: Level 25\n\n**Doctor**: Perform a job as a surgeon in a big hospital and earn money\n Salary: `200000-300000 coins` per shift\n Level experience: Level 40" + ) + localembed.footer(text="More jobs are coming soon!") + await ctx.respond(embed=localembed) + @commands.slash_command( name="work_select", description="Choose the job you want to work." From 8a90079b0bccf63cd6cedd653809a542e3cd1803 Mon Sep 17 00:00:00 2001 From: snipe <72265661+notsniped@users.noreply.github.com> Date: Sat, 18 Mar 2023 13:55:14 +0000 Subject: [PATCH 5/7] Add `/work_resign` to allow users to quit their job --- cogs/economy.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/cogs/economy.py b/cogs/economy.py index 3e0d92dc..ebf21018 100644 --- a/cogs/economy.py +++ b/cogs/economy.py @@ -504,6 +504,17 @@ async def work_select(self, ctx: ApplicationContext, job: str): localembed = discord.Embed(title="New job!", description=f"You are now working as a {job}!") await ctx.reply(embed=localembed) + @commands.slash_command( + name="work_resign", + description="Quit your job." + ) + async def work_resign(self, ctx: ApplicationContext): + if userdat[str(ctx.author.id)]["work_job"] is not None: return await ctx.respond("You can't quit your job if you don't already have one!", ephemeral=True) + userdat[str(ctx.author.id)]["work_job"] = None + save() + localembed = discord.Embed(title="Resignation", description="You have successfully rrsigned from your job.") + await ctx.respond(embed=localembed) + @commands.slash_command( name='donate', description="Donate money to whoever you want" From bc9db71c859cc23580e241a6e214bb3603960994 Mon Sep 17 00:00:00 2001 From: snipe <72265661+notsniped@users.noreply.github.com> Date: Sat, 18 Mar 2023 14:01:35 +0000 Subject: [PATCH 6/7] Add level checking for jobs in `/work_select` --- cogs/economy.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/cogs/economy.py b/cogs/economy.py index ebf21018..704fe4ae 100644 --- a/cogs/economy.py +++ b/cogs/economy.py @@ -11,6 +11,7 @@ from random import randint from discord import option, ApplicationContext from discord.ext import commands +from cogs.levelling import get_level # Classes class ShopData: @@ -499,6 +500,12 @@ async def work_list(self, ctx: ApplicationContext): @commands.cooldown(1, 1800, commands.BucketType.user) async def work_select(self, ctx: ApplicationContext, job: str): if job not in jobs: return await ctx.respond(f"This job does not exist. What kind of a job is even {job}??", ephemeral=True) + if job == "YouTuber" and get_level(ctx.author.id) < 3: return await ctx.respond("You currently do not have the required level to perform this job!", ephemeral=True) + elif job == "Streamer" and get_level(ctx.author.id) < 5: return await ctx.respond("You currently do not have the required level to perform this job!", ephemeral=True) + elif job == "Developer" and get_level(ctx.author.id) < 10: return await ctx.respond("You currently do not have the required level to perform this job!", ephemeral=True) + elif job == "Scientist" and get_level(ctx.author.id) < 20: return await ctx.respond("You currently do not have the required level to perform this job!", ephemeral=True) + elif job == "Engineer" and get_level(ctx.author.id) < 25: return await ctx.respond("You currently do not have the required level to perform this job!", ephemeral=True) + elif job == "Doctor" and get_level(ctx.author.id) < 40: return await ctx.respond("You currently do not have the required level to perform this job!", ephemeral=True) userdat[str(ctx.author.id)]["work_job"] = job save() localembed = discord.Embed(title="New job!", description=f"You are now working as a {job}!") From 296865b951e4931aa1f0a174a216abd1dcea470d Mon Sep 17 00:00:00 2001 From: snipe <72265661+notsniped@users.noreply.github.com> Date: Sat, 18 Mar 2023 14:15:19 +0000 Subject: [PATCH 7/7] Add different salaries for different jobs in `/work` command --- cogs/economy.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/cogs/economy.py b/cogs/economy.py index 704fe4ae..403e6ac9 100644 --- a/cogs/economy.py +++ b/cogs/economy.py @@ -475,10 +475,18 @@ async def give(self, ctx: ApplicationContext, user:discord.User, amount:int): ) @commands.cooldown(1, 1800, commands.BucketType.user) async def work(self, ctx: ApplicationContext): - i = randint(10000, 20000) + if userdat[str(ctx.author.id)]["work_job"] == None: return await ctx.respond("You don't currently have a job! Join one by using the `/work_select` command.", ephemeral=True) + # TODO: make salaries for different jobs + if userdat[str(ctx.author.id)]["work_job"] == "Discord mod": i = randint(5000, 10000) + elif userdat[str(ctx.author.id)]["work_job"] == "YouTuber": i = randint(10000, 15000) + elif userdat[str(ctx.author.id)]["work_job"] == "Streamer": i = randint(12000, 18000) + elif userdat[str(ctx.author.id)]["work_job"] == "Developer": i = randint(20000, 40000) + elif userdat[str(ctx.author.id)]["work_job"] == "Scientist": i = randint(50000, 100000) + elif userdat[str(ctx.author.id)]["work_job"] == "Engineer": i = randint(100000, 175000) + elif userdat[str(ctx.author.id)]["work_job"] == "Doctor": i = randint(200000, 300000) currency['wallet'][str(ctx.author.id)] += i save() - await ctx.respond(f'{ctx.author.mention} worked for a 30-minute shift and earned {i} coins.') + await ctx.respond(f'{ctx.author.mention} worked for a 30-minute shift as a {userdat[str(ctx.author.id)]["work_job"]} and earned {i} coins.') @commands.slash_command( name="work_list",