From fff35c6c444b8ee8a3a9bab88dc691e597d2e3fd Mon Sep 17 00:00:00 2001 From: stijndcl Date: Sun, 3 Jul 2022 17:44:16 +0200 Subject: [PATCH] Bank upgrades --- .gitignore | 3 + database/crud/currency.py | 55 +++++++++++++++++++ database/exceptions/currency.py | 4 ++ .../utils/math => database/utils}/__init__.py | 0 database/utils/math/__init__.py | 0 {didier => database}/utils/math/currency.py | 0 didier/cogs/currency.py | 37 ++++++++++++- pyproject.toml | 3 +- 8 files changed, 99 insertions(+), 3 deletions(-) rename {didier/utils/math => database/utils}/__init__.py (100%) create mode 100644 database/utils/math/__init__.py rename {didier => database}/utils/math/currency.py (100%) diff --git a/.gitignore b/.gitignore index a14d6d0..4a2e9dd 100644 --- a/.gitignore +++ b/.gitignore @@ -154,3 +154,6 @@ cython_debug/ # PyCharm .idea/ + +# Debugging files +debug.py diff --git a/database/crud/currency.py b/database/crud/currency.py index 9fe21e0..3ef4de0 100644 --- a/database/crud/currency.py +++ b/database/crud/currency.py @@ -5,6 +5,7 @@ from sqlalchemy.ext.asyncio import AsyncSession from database.crud import users from database.exceptions import currency as exceptions from database.models import Bank +from database.utils.math.currency import rob_upgrade_price, interest_upgrade_price, capacity_upgrade_price NIGHTLY_AMOUNT = 420 @@ -41,3 +42,57 @@ async def claim_nightly(session: AsyncSession, user_id: int): session.add(bank) session.add(nightly_data) await session.commit() + + +async def upgrade_capacity(database_session: AsyncSession, user_id: int) -> int: + """Upgrade capacity level""" + bank = await get_bank(database_session, user_id) + upgrade_price = capacity_upgrade_price(bank.capacity_level) + + # Can't afford this upgrade + if upgrade_price > bank.dinks: + raise exceptions.NotEnoughDinks + + bank.dinks -= upgrade_price + bank.capacity_level += 1 + + database_session.add(bank) + await database_session.commit() + + return bank.capacity_level + + +async def upgrade_interest(database_session: AsyncSession, user_id: int) -> int: + """Upgrade interest level""" + bank = await get_bank(database_session, user_id) + upgrade_price = interest_upgrade_price(bank.interest_level) + + # Can't afford this upgrade + if upgrade_price > bank.dinks: + raise exceptions.NotEnoughDinks + + bank.dinks -= upgrade_price + bank.interest_level += 1 + + database_session.add(bank) + await database_session.commit() + + return bank.interest_level + + +async def upgrade_rob(database_session: AsyncSession, user_id: int) -> int: + """Upgrade rob level""" + bank = await get_bank(database_session, user_id) + upgrade_price = rob_upgrade_price(bank.rob_level) + + # Can't afford this upgrade + if upgrade_price > bank.dinks: + raise exceptions.NotEnoughDinks + + bank.dinks -= upgrade_price + bank.rob_level += 1 + + database_session.add(bank) + await database_session.commit() + + return bank.rob_level diff --git a/database/exceptions/currency.py b/database/exceptions/currency.py index 6eab7a1..5710c62 100644 --- a/database/exceptions/currency.py +++ b/database/exceptions/currency.py @@ -1,2 +1,6 @@ class DoubleNightly(Exception): """Exception raised when claiming nightlies multiple times per day""" + + +class NotEnoughDinks(Exception): + """Exception raised when trying to do something you don't have the Dinks for""" diff --git a/didier/utils/math/__init__.py b/database/utils/__init__.py similarity index 100% rename from didier/utils/math/__init__.py rename to database/utils/__init__.py diff --git a/database/utils/math/__init__.py b/database/utils/math/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/didier/utils/math/currency.py b/database/utils/math/currency.py similarity index 100% rename from didier/utils/math/currency.py rename to database/utils/math/currency.py diff --git a/didier/cogs/currency.py b/didier/cogs/currency.py index 8cabb00..d4910ee 100644 --- a/didier/cogs/currency.py +++ b/didier/cogs/currency.py @@ -4,11 +4,11 @@ import discord from discord.ext import commands from database.crud import currency as crud -from database.exceptions.currency import DoubleNightly +from database.exceptions.currency import DoubleNightly, NotEnoughDinks from didier import Didier from didier.utils.discord.checks import is_owner from didier.utils.discord.converters import abbreviated_number -from didier.utils.math.currency import capacity_upgrade_price, interest_upgrade_price, rob_upgrade_price +from database.utils.math.currency import capacity_upgrade_price, interest_upgrade_price, rob_upgrade_price from didier.utils.types.string import pluralize @@ -72,6 +72,39 @@ class Currency(commands.Cog): await ctx.reply(embed=embed, mention_author=False) + @bank_upgrades.command(name="Capacity", aliases=["C"]) + async def bank_upgrade_capacity(self, ctx: commands.Context): + """Upgrade the capacity level of your bank""" + async with self.client.db_session as session: + try: + await crud.upgrade_capacity(session, ctx.author.id) + await ctx.message.add_reaction("⏫") + except NotEnoughDinks: + await ctx.reply("Je hebt niet genoeg Didier Dinks om dit te doen.", mention_author=False) + await self.client.reject_message(ctx.message) + + @bank_upgrades.command(name="Interest", aliases=["I"]) + async def bank_upgrade_interest(self, ctx: commands.Context): + """Upgrade the interest level of your bank""" + async with self.client.db_session as session: + try: + await crud.upgrade_interest(session, ctx.author.id) + await ctx.message.add_reaction("⏫") + except NotEnoughDinks: + await ctx.reply("Je hebt niet genoeg Didier Dinks om dit te doen.", mention_author=False) + await self.client.reject_message(ctx.message) + + @bank_upgrades.command(name="Rob", aliases=["R"]) + async def bank_upgrade_rob(self, ctx: commands.Context): + """Upgrade the rob level of your bank""" + async with self.client.db_session as session: + try: + await crud.upgrade_rob(session, ctx.author.id) + await ctx.message.add_reaction("⏫") + except NotEnoughDinks: + await ctx.reply("Je hebt niet genoeg Didier Dinks om dit te doen.", mention_author=False) + await self.client.reject_message(ctx.message) + @commands.hybrid_command(name="dinks") async def dinks(self, ctx: commands.Context): """Check your Didier Dinks""" diff --git a/pyproject.toml b/pyproject.toml index c97a7dd..a81c771 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -30,7 +30,8 @@ disable = [ "missing-module-docstring", "too-few-public-methods", "too-many-arguments", - "too-many-instance-attributes" + "too-many-instance-attributes", + "too-many-locals" ] [tool.pylint.format]