Beispiel #1
0
    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')
Beispiel #2
0
    def _use_check(self, ctx, item:int, args:Optional[Union[discord.Member, int, str]], add_args: Optional[int]) -> None:
        """Makes sure the inputs are valid if they exist"""
        if item in [*DEF_SPELLS, *VIEW_DEF_SPELLS]:
            raise CheckFailure('You can only use this card in response to an attack!')

        try:
            if Card(item).type != "spell":
                raise CheckFailure("You can only use spell cards!")
        except CardNotFound:
            raise CheckFailure("Invalid card id")

        if not item in [x[0] for x in User(ctx.author.id).fs_cards] and not item in [1036]:
            raise CheckFailure('You are not in possesion of this card!')

        if args:
            if isinstance(args, discord.Member):
                if args.id == ctx.author.id:
                    raise CheckFailure('You can\'t use spell cards on yourself')
                elif args.bot:
                    raise CheckFailure("You can't use spell cards on bots")

            if isinstance(args, int):
                if args < 1:
                    raise CheckFailure('You can\'t use an integer less than 1')

        if add_args:
            if add_args < 1:
                raise CheckFailure('You can\'t use an integer less than 1')
Beispiel #3
0
    async def exec(self, page:int) -> None:
        author = User(self.ctx.author.id)

        if page > 6 or page < 1:
            raise CheckFailure('You need to choose a page between 1 and 6')
        self._has_effect_check(author, f"page_protection_{page}")
        author.remove_card(self.id)
        author.add_effect(f'page_protection_{page}', datetime.utcnow()) # The value doesn't matter here
        await self.ctx.send(f'Success! Page {page} is now permanently protected')
Beispiel #4
0
    async def exec(self, effect:str, card_id:int) -> None:
        author = User(self.ctx.author.id)

        if not str(self.id) in author.effects and not author.has_fs_card(self.id):
            raise CheckFailure(f'You need to have used the card {self.id} once to use this command')

        if author.has_fs_card(self.id) and not str(self.id) in author.effects:
            author.remove_card(self.id)
        author.add_effect(str(self.id), datetime.utcnow())

        if not effect.lower() in ["list", "analysis", "1031", "1038"]:
            raise CheckFailure(f'Invalid effect to use! You can use either `analysis` or `list` with this card. Usage: `{self.client.command_prefix(self.client, self.ctx.message)[2]}use {self.id} <list/analysis> <card_id>`')

        if effect.lower() in ["list", "1038"]:
            embed = self._get_list_embed(card_id)
        if effect.lower() in ["analysis", "1031"]:
            embed = self._get_analysis_embed(card_id)
        await self.ctx.send(embed=embed)
Beispiel #5
0
    async def exec(self, card_id:int) -> None:
        self._is_valid_card_check(card_id)

        if card_id == 0:
            raise CheckFailure("Redacted card!")

        User(self.ctx.author.id).remove_card(self.id)

        embed = self._get_list_embed(card_id)
        await self.ctx.send(embed=embed)
Beispiel #6
0
    async def exec(self, card_id:int) -> None:
        user = User(self.ctx.author.id)

        if not user.has_any_card(card_id, False):
            raise CheckFailure('Seems like you don\'t own this card You already need to own a (non-fake) copy of the card you want to duplicate')

        self._is_maxed_check(card_id)
        user.remove_card(self.id)
        user.add_card(card_id, clone=True)

        await self.ctx.send(f'Successfully added another copy of {card_id} to your book!') 
Beispiel #7
0
    async def exec(self, card_id:int) -> None:
        self._is_valid_card_check(card_id)

        if card_id > 99 or card_id < 1:
            raise CheckFailure(f"You can only use \"{self.name}\" on a card with id between 1 and 99!")

        author = User(self.ctx.author.id)

        author.remove_card(self.id)
        author.add_card(card_id, True)
        await self.ctx.send(f'Created a fake of card No. {card_id}! Make sure to remember that it\'s a fake, fakes don\'t count towards completion of the album')
Beispiel #8
0
    async def exec(self, member:discord.Member, card_id:int) -> None:
        self._permission_check(self.ctx, member)

        if card_id == 0:
            raise CheckFailure("You cannot steal card 0")

        author = User(self.ctx.author.id)
        other = User(member.id)

        self._has_any_card(card_id, other)
        author.remove_card(self.id)
        await self._attack_defense_check(self.ctx, other, card_id)

        stolen = other.remove_card(card_id)
        author.add_card(stolen[0], stolen[1]["fake"])
        await self.ctx.send(f"Stole card number {card_id} successfully!")
Beispiel #9
0
    async def exec(self, member:discord.Member) -> None:
        other = User(member.id)
        author = User(self.ctx.author.id)

        tbr = [x for x in other.all_cards if x[1]["fake"] or x[1]["clone"]]

        if len(tbr) == 0:
            raise CheckFailure("This user does not have any cards you could target with this spell!")

        author.remove_card(self.id)

        rs_tbr = [x for x in other.rs_cards if x[1]["fake"] is True or x[1]["clone"] is True]
        fs_tbr = [x for x in other.fs_cards if x[1]["fake"] is True or x[1]["clone"] is True]

        for c in rs_tbr:
            other.rs_cards.remove(c)
        for c in fs_tbr:
            other.fs_cards.remove(c)

        other._update_val('cards', {'rs': other.rs_cards, 'fs': other.fs_cards, 'effects': other.effects}) 
        await self.ctx.send(f'Successfully removed all cloned and fake cards from `{member}`. Cards removed in total: {len(tbr)}')
Beispiel #10
0
 def _permission_check(self, ctx:commands.Context, member:discord.Member) -> None:
     perms = ctx.channel.permissions_for(member)
     if not perms.send_messages or not perms.read_messages:
         raise CheckFailure(f'You can only attack a user in a channel they have read and write permissions to which isn\'t the case with {self.Member.display_name}') 
Beispiel #11
0
 def _has_any_card(self, card_id:int, user:User) -> None:
     if not user.has_any_card(card_id):
         raise CheckFailure("The specified user doesn't have this card")
Beispiel #12
0
 def _has_met_check(self, prefix:str, author:User, other:discord.Member) -> None:
     if not author.has_met(other.id):
         raise CheckFailure(f"You haven\'t met this user yet! Use `{prefix}meet <@someone>` if they send a message in a channel to be able to use this card on them")
Beispiel #13
0
 def _has_other_card_check(self, cards:List[list]) -> None:
     if len(cards) < 2:
         raise CheckFailure(f"You don't have any cards other than card {self.name}!")
Beispiel #14
0
 def _is_maxed_check(self, card:int) -> None:
     c = Card(card)
     if len(c.owners) >= c.limit * ALLOWED_AMOUNT_MULTIPLE:
         raise CheckFailure(f'The maximum amount of existing cards with id {card} is reached!')
Beispiel #15
0
 def _has_cards_check(self, cards:List[list], card_type:str="", is_self:bool=False, uses_up:bool=False) -> None:
     if len(cards) == 0:
         raise CheckFailure((f"You do not have cards{card_type}!" if is_self else f"This user does not have any cards{card_type}!") + f" This information uses up card {self.name}." if uses_up else "")
Beispiel #16
0
 def _has_effect_check(self, user:User, effect:str) -> None:
     if user.has_effect(effect)[0]:
         raise CheckFailure("You already have this effect in place!")
Beispiel #17
0
 def _is_valid_card_check(self, card_id:int) -> None:
     try:
         Card(card_id)
     except CardNotFound:
         raise CheckFailure("Specified card is invalid!")
Beispiel #18
0
 def _is_full_check(self, user:User) -> None:
     if len(user.fs_cards) >= FREE_SLOTS:
         raise CheckFailure("You don't have any space in your free slots left!")