Nightly, bank, award & dinks

This commit is contained in:
stijndcl 2022-06-30 21:17:48 +02:00
parent 4587a49311
commit 032b636b02
9 changed files with 157 additions and 5 deletions

54
didier/cogs/currency.py Normal file
View file

@ -0,0 +1,54 @@
import discord
from discord.ext import commands
from didier import Didier
from database.crud import currency as crud
from database.exceptions.currency import DoubleNightly
from didier.utils.discord.checks import is_owner
from didier.utils.types.string import pluralize
class Currency(commands.Cog):
"""Everything Dinks-related"""
client: Didier
def __init__(self, client: Didier):
super().__init__()
self.client = client
@commands.command(name="Award")
@commands.check(is_owner)
async def award(self, ctx: commands.Context, user: discord.User, amount: int):
async with self.client.db_session as session:
await crud.add_dinks(session, user.id, amount)
await self.client.confirm_message(ctx.message)
@commands.hybrid_command(name="bank")
async def bank(self, ctx: commands.Context):
"""Show your Didier Bank information"""
async with self.client.db_session as session:
await crud.get_bank(session, ctx.author.id)
@commands.hybrid_command(name="dinks")
async def dinks(self, ctx: commands.Context):
"""Check your Didier Dinks"""
async with self.client.db_session as session:
bank = await crud.get_bank(session, ctx.author.id)
plural = pluralize("Didier Dink", bank.dinks)
await ctx.reply(f"**{ctx.author.display_name}** heeft **{bank.dinks}** {plural}.", mention_author=False)
@commands.hybrid_command(name="nightly")
async def nightly(self, ctx: commands.Context):
"""Claim nightly Dinks"""
async with self.client.db_session as session:
try:
await crud.claim_nightly(session, ctx.author.id)
await ctx.reply(f"Je hebt je dagelijkse **{crud.NIGHTLY_AMOUNT}** Didier Dinks geclaimd.")
except DoubleNightly:
await ctx.reply("Je hebt je nightly al geclaimd vandaag.", mention_author=False, ephemeral=True)
async def setup(client: Didier):
await client.add_cog(Currency(client))

View file

@ -0,0 +1 @@
from .message_commands import is_owner

View file

@ -0,0 +1,6 @@
from discord.ext import commands
async def is_owner(ctx: commands.Context) -> bool:
"""Check that a command is being invoked by the owner of the bot"""
return await ctx.bot.is_owner(ctx.author)

View file

@ -20,3 +20,11 @@ def leading(character: str, string: str, target_length: Optional[int] = 2) -> st
frequency = math.ceil((target_length - len(string)) / len(character))
return (frequency * character) + string
def pluralize(word: str, amount: int, plural_form: Optional[str] = None) -> str:
"""Turn a word into plural"""
if amount == 1:
return word
return plural_form or (word + "s")