Example #1
0
File: cards.py Project: Kile/Killua
    async def exec(self) -> None:
        author = User(self.ctx.author.id)
        try:
            self._has_effect_check(author, str(self.id))
        except CheckFailure:
            if not author.count_card(self.id) > 1:
                raise CheckFailure("You don't have another copy of this card to renew the effect")
            view = ConfirmButton(user_id=self.ctx.author.id)
            msg = await self.ctx.send(f"You still have {author.has_effect(str(self.id))[1]} protections left. Do you really want to use this card now and overwrite the current protection?", view=view)
            await view.wait()
            await view.disable(msg)

            if view.timed_out:
                raise CheckFailure("Timed out!")
            elif view.value is False:
                raise CheckFailure("Successfully canceled!")

        if author.has_effect(str(self.id)):
            author.remove_effect(str(self.id))

        # if (amount:=author.count_card(self.id)) > 1:
        #     for i in range(amount):
        #         author.remove_card(self.id)

        author.add_effect(str(self.id), 10)

        await self.ctx.send('Done, you will be automatically protected from the next 10 attacks! You need to keep the card in your inventory until all 10 defenses are used up')
Example #2
0
    async def sell(self, ctx, item:int, amount=1):
        """Sell any amount of cards you own"""
        
        user = User(ctx.author.id)
        if amount < 1:
            amount = 1
        if len(user.all_cards) == 0:
            return await ctx.send('You don\'t have any cards yet!')
        try:
            card = Card(item)
        except CardNotFound:
            return await ctx.send(f'A card with the id `{item}` does not exist', allowed_mentions=discord.AllowedMentions.none())

        in_possesion = user.count_card(card.id, including_fakes=False)

        if in_possesion < amount:
            return await ctx.send(f'Seems you don\'t own enough copies of this card. You own {in_possesion} cop{"y" if in_possesion == 1 else "ies"} of this card')
        
        if item == 0:
            return await ctx.send("You cannot sell this card!")

        jenny = int((PRICES[card.rank]*amount)/10)
        if user.is_entitled_to_double_jenny:
            jenny *= 2
        view = ConfirmButton(ctx.author.id, timeout=80)
        msg = await ctx.send(f"You will receive {jenny} Jenny for selling {'this card' if amount == 1 else 'those cards'}, do you want to proceed?", view=view)
        await view.wait()
        await view.disable(msg)

        if not view.value:
            if view.timed_out:
                return await ctx.send(f'Timed out!')
            else:
                return await ctx.send(f"Successfully canceled!")
            
        card_amount = user.count_card(item, False)

        if not card_amount >= amount:
            return await ctx.send('Seems like you don\'t own enough non-fake copies of this card you try to sell')
        else:
            for i in range(amount):
                user.remove_card(item, False)
            user.add_jenny(jenny)
            await ctx.send(f'Successfully sold {amount} cop{"y" if amount == 1 else "ies"} of card number {item} for {jenny} Jenny!')