mirror of https://github.com/stijndcl/didier
Compare commits
No commits in common. "fff35c6c444b8ee8a3a9bab88dc691e597d2e3fd" and "5b510d1f45779f397af7dbad42b68d7f51940a57" have entirely different histories.
fff35c6c44
...
5b510d1f45
|
|
@ -154,6 +154,3 @@ cython_debug/
|
||||||
|
|
||||||
# PyCharm
|
# PyCharm
|
||||||
.idea/
|
.idea/
|
||||||
|
|
||||||
# Debugging files
|
|
||||||
debug.py
|
|
||||||
|
|
|
||||||
|
|
@ -1,28 +0,0 @@
|
||||||
"""Add missing defaults
|
|
||||||
|
|
||||||
Revision ID: 632b69cdadde
|
|
||||||
Revises: 8c4ad0a1d699
|
|
||||||
Create Date: 2022-07-03 16:29:07.387011
|
|
||||||
|
|
||||||
"""
|
|
||||||
from alembic import op
|
|
||||||
import sqlalchemy as sa
|
|
||||||
|
|
||||||
|
|
||||||
# revision identifiers, used by Alembic.
|
|
||||||
revision = '632b69cdadde'
|
|
||||||
down_revision = '8c4ad0a1d699'
|
|
||||||
branch_labels = None
|
|
||||||
depends_on = None
|
|
||||||
|
|
||||||
|
|
||||||
def upgrade() -> None:
|
|
||||||
# ### commands auto generated by Alembic - please adjust! ###
|
|
||||||
pass
|
|
||||||
# ### end Alembic commands ###
|
|
||||||
|
|
||||||
|
|
||||||
def downgrade() -> None:
|
|
||||||
# ### commands auto generated by Alembic - please adjust! ###
|
|
||||||
pass
|
|
||||||
# ### end Alembic commands ###
|
|
||||||
|
|
@ -1,32 +0,0 @@
|
||||||
"""Move dinks over to Bank & add invested amount
|
|
||||||
|
|
||||||
Revision ID: 8c4ad0a1d699
|
|
||||||
Revises: 0d03c226d881
|
|
||||||
Create Date: 2022-07-03 16:27:11.330746
|
|
||||||
|
|
||||||
"""
|
|
||||||
from alembic import op
|
|
||||||
import sqlalchemy as sa
|
|
||||||
|
|
||||||
|
|
||||||
# revision identifiers, used by Alembic.
|
|
||||||
revision = '8c4ad0a1d699'
|
|
||||||
down_revision = '0d03c226d881'
|
|
||||||
branch_labels = None
|
|
||||||
depends_on = None
|
|
||||||
|
|
||||||
|
|
||||||
def upgrade() -> None:
|
|
||||||
# ### commands auto generated by Alembic - please adjust! ###
|
|
||||||
with op.batch_alter_table('bank', schema=None) as batch_op:
|
|
||||||
batch_op.add_column(sa.Column('invested', sa.BigInteger(), server_default='0', nullable=False))
|
|
||||||
|
|
||||||
# ### end Alembic commands ###
|
|
||||||
|
|
||||||
|
|
||||||
def downgrade() -> None:
|
|
||||||
# ### commands auto generated by Alembic - please adjust! ###
|
|
||||||
with op.batch_alter_table('bank', schema=None) as batch_op:
|
|
||||||
batch_op.drop_column('invested')
|
|
||||||
|
|
||||||
# ### end Alembic commands ###
|
|
||||||
|
|
@ -5,7 +5,6 @@ from sqlalchemy.ext.asyncio import AsyncSession
|
||||||
from database.crud import users
|
from database.crud import users
|
||||||
from database.exceptions import currency as exceptions
|
from database.exceptions import currency as exceptions
|
||||||
from database.models import Bank
|
from database.models import Bank
|
||||||
from database.utils.math.currency import rob_upgrade_price, interest_upgrade_price, capacity_upgrade_price
|
|
||||||
|
|
||||||
|
|
||||||
NIGHTLY_AMOUNT = 420
|
NIGHTLY_AMOUNT = 420
|
||||||
|
|
@ -42,57 +41,3 @@ async def claim_nightly(session: AsyncSession, user_id: int):
|
||||||
session.add(bank)
|
session.add(bank)
|
||||||
session.add(nightly_data)
|
session.add(nightly_data)
|
||||||
await session.commit()
|
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
|
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,2 @@
|
||||||
class DoubleNightly(Exception):
|
class DoubleNightly(Exception):
|
||||||
"""Exception raised when claiming nightlies multiple times per day"""
|
"""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"""
|
|
||||||
|
|
|
||||||
|
|
@ -17,17 +17,16 @@ class Bank(Base):
|
||||||
bank_id: int = Column(Integer, primary_key=True)
|
bank_id: int = Column(Integer, primary_key=True)
|
||||||
user_id: int = Column(BigInteger, ForeignKey("users.user_id"))
|
user_id: int = Column(BigInteger, ForeignKey("users.user_id"))
|
||||||
|
|
||||||
dinks: int = Column(BigInteger, server_default="0", nullable=False)
|
dinks: int = Column(BigInteger, default=0, nullable=False)
|
||||||
invested: int = Column(BigInteger, server_default="0", nullable=False)
|
|
||||||
|
|
||||||
# Interest rate
|
# Interest rate
|
||||||
interest_level: int = Column(Integer, server_default="1", nullable=False)
|
interest_level: int = Column(Integer, default=1, nullable=False)
|
||||||
|
|
||||||
# Maximum amount that can be stored in the bank
|
# Maximum amount that can be stored in the bank
|
||||||
capacity_level: int = Column(Integer, server_default="1", nullable=False)
|
capacity_level: int = Column(Integer, default=1, nullable=False)
|
||||||
|
|
||||||
# Maximum amount that can be robbed
|
# Maximum amount that can be robbed
|
||||||
rob_level: int = Column(Integer, server_default="1", nullable=False)
|
rob_level: int = Column(Integer, default=1, nullable=False)
|
||||||
|
|
||||||
user: User = relationship("User", uselist=False, back_populates="bank", lazy="selectin")
|
user: User = relationship("User", uselist=False, back_populates="bank", lazy="selectin")
|
||||||
|
|
||||||
|
|
@ -68,7 +67,7 @@ class NightlyData(Base):
|
||||||
nightly_id: int = Column(Integer, primary_key=True)
|
nightly_id: int = Column(Integer, primary_key=True)
|
||||||
user_id: int = Column(BigInteger, ForeignKey("users.user_id"))
|
user_id: int = Column(BigInteger, ForeignKey("users.user_id"))
|
||||||
last_nightly: Optional[datetime] = Column(DateTime(timezone=True), nullable=True)
|
last_nightly: Optional[datetime] = Column(DateTime(timezone=True), nullable=True)
|
||||||
count: int = Column(Integer, server_default="0", nullable=False)
|
count: int = Column(Integer, default=0, nullable=False)
|
||||||
|
|
||||||
user: User = relationship("User", back_populates="nightly_data", uselist=False, lazy="selectin")
|
user: User = relationship("User", back_populates="nightly_data", uselist=False, lazy="selectin")
|
||||||
|
|
||||||
|
|
@ -82,7 +81,7 @@ class UforaCourse(Base):
|
||||||
name: str = Column(Text, nullable=False, unique=True)
|
name: str = Column(Text, nullable=False, unique=True)
|
||||||
code: str = Column(Text, nullable=False, unique=True)
|
code: str = Column(Text, nullable=False, unique=True)
|
||||||
year: int = Column(Integer, nullable=False)
|
year: int = Column(Integer, nullable=False)
|
||||||
log_announcements: bool = Column(Boolean, server_default="0", nullable=False)
|
log_announcements: bool = Column(Boolean, default=False, nullable=False)
|
||||||
|
|
||||||
announcements: list[UforaAnnouncement] = relationship(
|
announcements: list[UforaAnnouncement] = relationship(
|
||||||
"UforaAnnouncement", back_populates="course", cascade="all, delete-orphan", lazy="selectin"
|
"UforaAnnouncement", back_populates="course", cascade="all, delete-orphan", lazy="selectin"
|
||||||
|
|
|
||||||
|
|
@ -1,25 +0,0 @@
|
||||||
import math
|
|
||||||
|
|
||||||
|
|
||||||
def interest_upgrade_price(level: int) -> int:
|
|
||||||
"""Calculate the price to upgrade your interest level"""
|
|
||||||
base_cost = 600
|
|
||||||
growth_rate = 1.8
|
|
||||||
|
|
||||||
return math.floor(base_cost * (growth_rate**level))
|
|
||||||
|
|
||||||
|
|
||||||
def capacity_upgrade_price(level: int) -> int:
|
|
||||||
"""Calculate the price to upgrade your capacity level"""
|
|
||||||
base_cost = 800
|
|
||||||
growth_rate = 1.6
|
|
||||||
|
|
||||||
return math.floor(base_cost * (growth_rate**level))
|
|
||||||
|
|
||||||
|
|
||||||
def rob_upgrade_price(level: int) -> int:
|
|
||||||
"""Calculate the price to upgrade your rob level"""
|
|
||||||
base_cost = 950
|
|
||||||
growth_rate = 1.9
|
|
||||||
|
|
||||||
return math.floor(base_cost * (growth_rate**level))
|
|
||||||
|
|
@ -4,11 +4,10 @@ import discord
|
||||||
from discord.ext import commands
|
from discord.ext import commands
|
||||||
|
|
||||||
from database.crud import currency as crud
|
from database.crud import currency as crud
|
||||||
from database.exceptions.currency import DoubleNightly, NotEnoughDinks
|
from database.exceptions.currency import DoubleNightly
|
||||||
from didier import Didier
|
from didier import Didier
|
||||||
from didier.utils.discord.checks import is_owner
|
from didier.utils.discord.checks import is_owner
|
||||||
from didier.utils.discord.converters import abbreviated_number
|
from didier.utils.discord.converters import abbreviated_number
|
||||||
from database.utils.math.currency import capacity_upgrade_price, interest_upgrade_price, rob_upgrade_price
|
|
||||||
from didier.utils.types.string import pluralize
|
from didier.utils.types.string import pluralize
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -35,75 +34,11 @@ class Currency(commands.Cog):
|
||||||
mention_author=False,
|
mention_author=False,
|
||||||
)
|
)
|
||||||
|
|
||||||
@commands.group(name="bank", aliases=["B"], case_insensitive=True, invoke_without_command=True)
|
@commands.hybrid_group(name="bank", case_insensitive=True, invoke_without_command=True)
|
||||||
async def bank(self, ctx: commands.Context):
|
async def bank(self, ctx: commands.Context):
|
||||||
"""Show your Didier Bank information"""
|
"""Show your Didier Bank information"""
|
||||||
async with self.client.db_session as session:
|
async with self.client.db_session as session:
|
||||||
bank = await crud.get_bank(session, ctx.author.id)
|
await crud.get_bank(session, ctx.author.id)
|
||||||
|
|
||||||
embed = discord.Embed(colour=discord.Colour.blue())
|
|
||||||
embed.set_author(name=f"Bank van {ctx.author.display_name}")
|
|
||||||
embed.set_thumbnail(url=ctx.author.avatar.url)
|
|
||||||
|
|
||||||
embed.add_field(name="Interest level", value=bank.interest_level)
|
|
||||||
embed.add_field(name="Capaciteit level", value=bank.capacity_level)
|
|
||||||
embed.add_field(name="Momenteel geïnvesteerd", value=bank.invested, inline=False)
|
|
||||||
|
|
||||||
await ctx.reply(embed=embed, mention_author=False)
|
|
||||||
|
|
||||||
@bank.group(name="Upgrade", aliases=["U", "Upgrades"], case_insensitive=True, invoke_without_command=True)
|
|
||||||
async def bank_upgrades(self, ctx: commands.Context):
|
|
||||||
"""List the upgrades you can buy & their prices"""
|
|
||||||
async with self.client.db_session as session:
|
|
||||||
bank = await crud.get_bank(session, ctx.author.id)
|
|
||||||
|
|
||||||
embed = discord.Embed(colour=discord.Colour.blue())
|
|
||||||
embed.set_author(name="Bank upgrades")
|
|
||||||
|
|
||||||
embed.add_field(
|
|
||||||
name=f"Interest ({bank.interest_level})", value=str(interest_upgrade_price(bank.interest_level))
|
|
||||||
)
|
|
||||||
embed.add_field(
|
|
||||||
name=f"Capaciteit ({bank.capacity_level})", value=str(capacity_upgrade_price(bank.capacity_level))
|
|
||||||
)
|
|
||||||
embed.add_field(name=f"Rob ({bank.rob_level})", value=str(rob_upgrade_price(bank.rob_level)))
|
|
||||||
|
|
||||||
embed.set_footer(text="Didier Bank Upgrade [Categorie]")
|
|
||||||
|
|
||||||
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")
|
@commands.hybrid_command(name="dinks")
|
||||||
async def dinks(self, ctx: commands.Context):
|
async def dinks(self, ctx: commands.Context):
|
||||||
|
|
|
||||||
|
|
@ -29,9 +29,9 @@ class Tasks(commands.Cog):
|
||||||
if settings.UFORA_RSS_TOKEN is None or settings.UFORA_ANNOUNCEMENTS_CHANNEL is None:
|
if settings.UFORA_RSS_TOKEN is None or settings.UFORA_ANNOUNCEMENTS_CHANNEL is None:
|
||||||
return
|
return
|
||||||
|
|
||||||
async with self.client.db_session as db_session:
|
async with self.client.db_session as session:
|
||||||
announcements_channel = self.client.get_channel(settings.UFORA_ANNOUNCEMENTS_CHANNEL)
|
announcements_channel = self.client.get_channel(settings.UFORA_ANNOUNCEMENTS_CHANNEL)
|
||||||
announcements = await fetch_ufora_announcements(self.client.http_session, db_session)
|
announcements = await fetch_ufora_announcements(session)
|
||||||
|
|
||||||
for announcement in announcements:
|
for announcement in announcements:
|
||||||
await announcements_channel.send(embed=announcement.to_embed())
|
await announcements_channel.send(embed=announcement.to_embed())
|
||||||
|
|
|
||||||
|
|
@ -3,11 +3,9 @@ from dataclasses import dataclass, field
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from typing import Optional
|
from typing import Optional
|
||||||
|
|
||||||
import async_timeout
|
|
||||||
import discord
|
import discord
|
||||||
import feedparser
|
import feedparser
|
||||||
import pytz
|
import pytz
|
||||||
from aiohttp import ClientSession
|
|
||||||
from markdownify import markdownify as md
|
from markdownify import markdownify as md
|
||||||
from sqlalchemy.ext.asyncio import AsyncSession
|
from sqlalchemy.ext.asyncio import AsyncSession
|
||||||
|
|
||||||
|
|
@ -118,9 +116,7 @@ def parse_ids(url: str) -> Optional[tuple[int, int]]:
|
||||||
return int(spl[0]), int(spl[1])
|
return int(spl[0]), int(spl[1])
|
||||||
|
|
||||||
|
|
||||||
async def fetch_ufora_announcements(
|
async def fetch_ufora_announcements(session: AsyncSession) -> list[UforaNotification]:
|
||||||
http_session: ClientSession, database_session: AsyncSession
|
|
||||||
) -> list[UforaNotification]:
|
|
||||||
"""Fetch all new announcements"""
|
"""Fetch all new announcements"""
|
||||||
notifications: list[UforaNotification] = []
|
notifications: list[UforaNotification] = []
|
||||||
|
|
||||||
|
|
@ -128,7 +124,7 @@ async def fetch_ufora_announcements(
|
||||||
if settings.UFORA_RSS_TOKEN is None:
|
if settings.UFORA_RSS_TOKEN is None:
|
||||||
return notifications
|
return notifications
|
||||||
|
|
||||||
courses = await crud.get_courses_with_announcements(database_session)
|
courses = await crud.get_courses_with_announcements(session)
|
||||||
|
|
||||||
for course in courses:
|
for course in courses:
|
||||||
course_announcement_ids = list(map(lambda announcement: announcement.announcement_id, course.announcements))
|
course_announcement_ids = list(map(lambda announcement: announcement.announcement_id, course.announcements))
|
||||||
|
|
@ -138,9 +134,7 @@ async def fetch_ufora_announcements(
|
||||||
)
|
)
|
||||||
|
|
||||||
# Get the updated feed
|
# Get the updated feed
|
||||||
with async_timeout.timeout(10):
|
feed = feedparser.parse(course_url)
|
||||||
async with http_session.get(course_url) as response:
|
|
||||||
feed = feedparser.parse(await response.text())
|
|
||||||
|
|
||||||
# Remove old notifications
|
# Remove old notifications
|
||||||
fresh_feed: list[dict] = []
|
fresh_feed: list[dict] = []
|
||||||
|
|
@ -167,6 +161,6 @@ async def fetch_ufora_announcements(
|
||||||
notifications.append(notification)
|
notifications.append(notification)
|
||||||
|
|
||||||
# Create new db entry
|
# Create new db entry
|
||||||
await crud.create_new_announcement(database_session, notification_id, course, notification.published_dt)
|
await crud.create_new_announcement(session, notification_id, course, notification.published_dt)
|
||||||
|
|
||||||
return notifications
|
return notifications
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,6 @@
|
||||||
import os
|
import os
|
||||||
|
|
||||||
import discord
|
import discord
|
||||||
from aiohttp import ClientSession
|
|
||||||
from discord.ext import commands
|
from discord.ext import commands
|
||||||
from sqlalchemy.ext.asyncio import AsyncSession
|
from sqlalchemy.ext.asyncio import AsyncSession
|
||||||
|
|
||||||
|
|
@ -15,7 +14,6 @@ class Didier(commands.Bot):
|
||||||
"""DIDIER <3"""
|
"""DIDIER <3"""
|
||||||
|
|
||||||
initial_extensions: tuple[str, ...] = ()
|
initial_extensions: tuple[str, ...] = ()
|
||||||
http_session: ClientSession
|
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
activity = discord.Activity(type=discord.ActivityType.playing, name=settings.DISCORD_STATUS_MESSAGE)
|
activity = discord.Activity(type=discord.ActivityType.playing, name=settings.DISCORD_STATUS_MESSAGE)
|
||||||
|
|
@ -45,9 +43,6 @@ class Didier(commands.Bot):
|
||||||
await self._load_initial_extensions()
|
await self._load_initial_extensions()
|
||||||
await self._load_directory_extensions("didier/cogs")
|
await self._load_directory_extensions("didier/cogs")
|
||||||
|
|
||||||
# Create aiohttp session
|
|
||||||
self.http_session = ClientSession()
|
|
||||||
|
|
||||||
async def _load_initial_extensions(self):
|
async def _load_initial_extensions(self):
|
||||||
"""Load all extensions that should be loaded before the others"""
|
"""Load all extensions that should be loaded before the others"""
|
||||||
for extension in self.initial_extensions:
|
for extension in self.initial_extensions:
|
||||||
|
|
|
||||||
|
|
@ -30,8 +30,7 @@ disable = [
|
||||||
"missing-module-docstring",
|
"missing-module-docstring",
|
||||||
"too-few-public-methods",
|
"too-few-public-methods",
|
||||||
"too-many-arguments",
|
"too-many-arguments",
|
||||||
"too-many-instance-attributes",
|
"too-many-instance-attributes"
|
||||||
"too-many-locals"
|
|
||||||
]
|
]
|
||||||
|
|
||||||
[tool.pylint.format]
|
[tool.pylint.format]
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue