Пример #1
0
    async def exec(self, card_id:int) -> None:
        self._is_valid_card_check(card_id)

        author = User(self.ctx.author.id)
        author.remove_card(self.id)
        embed = self._get_analysis_embed(card_id)
        await self.ctx.send(embed=embed)
Пример #2
0
    async def _wait_for_defense(self, ctx:commands.Context, other:User, effects:list) -> None:

        if len(effects) == 0:
            return

        effects = [Card(c) for c in effects]
        view = View(other.id, timeout=20)
        view.add_item(Select(options=[discord.SelectOption(label=c.name, emoji=c.emoji, value=str(c.id)) for c in effects]))
        view.add_item(Button(label="Ignore", style=discord.ButtonStyle.red))

        msg = await ctx.send(f"<@{other.id}> {ctx.author} has used the spell `{self.id}` on you! You have {len(effects)} spells to defend yourself. You can either choose one of them to defend yourself with or let the attack go through", view=view)
        await view.wait()
        await view.disable(msg)

        if not view.value:
            if view.timed_out:
                await ctx.send(f"No response from the attacked user, the attack goes through!", reference=msg)
            else:
                await ctx.send("You decided not to use a defense spell, the attack goes through!", reference=msg)
            return

        if isinstance(view.value, int): 
            other.remove_card(view.value)
            raise SuccessfullDefense(f"<@{other.id}> successfully defended against your attack")
        else:
            await ctx.send("You decided not to use a defense spell, the attack goes through!", reference=msg)
Пример #3
0
    async def discard(self, ctx, card:int):
        """Discard a card you want to get rid of with this command. If you want to throw a fake away, make sure it's in the free slots"""
        
        user = User(ctx.author.id)
        try:
            card = Card(card)
        except CardNotFound:
            return await ctx.send('This card does not exist!')

        if not user.has_any_card(card.id):
            return await ctx.send('You are not in possesion of this card!')

        if card.id == 0:
            return await ctx.send("You cannot discard this card!")

        view = ConfirmButton(ctx.author.id, timeout=20)
        msg = await ctx.send(f"Do you really want to throw this card away? (if you want to throw a fake aware, make sure it's in the free slots (unless it's the only copy you own. You can switch cards between free and restricted slots with `{self.client.command_prefix(self.client, ctx.message)[2]}swap <card_id>`)", view=view, allowed_mentions=discord.AllowedMentions.none())
        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!")

        try:
            user.remove_card(card.id, remove_fake=True, restricted_slot=False)
            # essentially here it first looks for fakes in your free slots and tried to remove them. If it doesn't find any fakes in the free slots, it will remove the first match of the card it finds in free or restricted slots
        except NoMatches:
            user.remove_card(card.id)
        await ctx.send(f'Successfully thrown away card No. `{card.id}`')
Пример #4
0
    async def exec(self) -> None:
        author = User(self.ctx.author.id)
        author.remove_card(self.id)

        users = []
        stolen_cards = []

        async for message in self.ctx.channel.history(limit=20):
            if message.author not in users and message.author.bot is False and message.author != self.ctx.author:
                users.append(message.author)

        for user in users:
            try:
                self._permission_check(self.ctx, user)
                u = User(user.id)
                self._has_cards_check(u.all_cards)
                target = random.choice([x for x in u.all_cards if x[0] != 0])
                await self._attack_defense_check(self.ctx, u, target)
                r = u.remove_card(target[0], target[1]["fake"])
                stolen_cards.append(r)
            except Exception as e:
                continue

        if len(stolen_cards) > 0:
            author.add_multi(stolen_cards)
            await self.ctx.send(f'Success! Stole the card{"s" if len(stolen_cards) > 1 else ""} {", ".join([str(x[0]) for x in stolen_cards])} from {len(stolen_cards)} user{"s" if len(users) > 1 else ""}!')
        else:
            await self.ctx.send('All targetted users were able to defend themselves!')
Пример #5
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')
Пример #6
0
    async def exec(self) -> None:
        author = User(self.ctx.author.id)
        self._is_full_check(author)

        target = random.choice([x['_id'] for x in items.find({'type': 'normal', "available": True}) if x['rank'] != 'SS' and x["_id"] != 0]) # random card for lottery
        author.remove_card(self.id)
        self._is_maxed_check(target)
        author.add_card(target)

        await self.ctx.send(f'Successfully added card No. {target} to your inventory')
Пример #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')
Пример #8
0
    async def exec(self, member:discord.Member) -> None:
        author = User(self.ctx.author.id)
        other = User(member.id)
        author.remove_card(self.id)

        self._has_cards_check(other.rs_cards, f" in their restricted slots!", uses_up=True)
        card = random.choice([x for x in other.rs_cards if x[0] != 0])
        self._is_maxed_check(card[0])

        author.add_card(card[0], card[1]["fake"], True)
        await self.ctx.send(f'Successfully added another copy of card No. {card[0]} to your book! This card is {"not" if card[1]["fake"] is False else ""} a fake!')
Пример #9
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!') 
Пример #10
0
    async def exec(self, member:discord.Member) -> None:
        self._permission_check(self.ctx, member)

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

        self._has_cards_check(other.rs_cards, " in their restricted slots")

        target_card = random.choice([x for x in other.rs_cards if not x[0] in INDESTRUCTABLE and x[0] != 0])
        author.remove_card(self.id)
        await self._attack_defense_check(self.ctx, other, target_card)
        other.remove_card(target_card[0], remove_fake=target_card[1]["fake"], restricted_slot=True, clone=target_card[1]["clone"])
        await self.ctx.send(f'Success, you destroyed card No. {target_card[0]}!')
Пример #11
0
    async def exec(self, member:discord.Member) -> None:
        author = User(self.ctx.author.id)
        other = User(member.id)

        self._has_met_check(self.ctx.bot.command_prefix(self.ctx.bot, self.ctx.message)[2], author, member)

        author.remove_card(self.id)

        self._has_cards_check(other.all_cards)

        async def make_embed(page, embed, pages):
            return await Book(self.ctx.bot.session).create(member, page)

        return await Paginator(self.ctx, max_pages=6+math.ceil(len(other.fs_cards)/18), func=make_embed, has_file=True).start()
Пример #12
0
    async def exec(self, member:discord.Member) -> None:
        author = User(self.ctx.author.id)
        other = User(member.id)

        self._has_met_check(self.ctx.bot.command_prefix(self.ctx.bot, self.ctx.message)[2], author, member)
        
        self._permission_check(self.ctx, member)    
        author.remove_card(self.id)
        await self._view_defense_check(self.ctx, other)

        async def make_embed(page, embed, pages):
            return await Book(self.ctx.bot.session).create(member, page)

        await Paginator(self.ctx, max_pages=6, func=make_embed, has_file=True).start() 
Пример #13
0
    async def exec(self, member:discord.Member):
        self._permission_check(self.ctx, member)

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

        self._has_cards_check(other.rs_cards, " in their restricted slots")

        target_card = random.choice([x[0] for x in other.rs_cards if x[0] != 0])
        author.remove_card(self.id)
        await self._attack_defense_check(self.ctx, other, target_card)

        removed_card = other.remove_card(target_card, restricted_slot=True)
        author.add_card(target_card, removed_card[1]["fake"])
        await self.ctx.send(f'Successfully stole card number `{target_card}` from `{member}`!')
Пример #14
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!")
Пример #15
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)
Пример #16
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!')
Пример #17
0
    async def exec(self, member:discord.Member) -> None:
        self._permission_check(self.ctx, member)

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

        self._has_cards_check(other.all_cards)
        self._has_other_card_check(author.all_cards)

        target_card = random.choice([x[0] for x in other.all_cards if x[0] != 1008 and x[0] != 0])
        await self._attack_defense_check(self.ctx, other, target_card)

        author.remove_card(self.id)
        removed_card_other = other.remove_card(target_card)
        removed_card_author = author.remove_card(random.choice([x[0] for x in author.all_cards if x[0] != 0]))
        other.add_card(removed_card_author[0], removed_card_author[1]["fake"])
        author.add_card(removed_card_other[0], removed_card_other[1]["fake"])

        await self.ctx.send(f'Successfully swapped cards! Gave {member} the card `{removed_card_author[0]}` and took card number `{removed_card_other[0]}` from them!')
Пример #18
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)}')
Пример #19
0
    async def _attack_defense_check(self, ctx: commands.Context, other: User, target_card:int) -> None:
        if target_card in [x[0] for x in other.rs_cards]: # A list of cards that steal from restricted slots
            if f'page_protection_{int((target_card-10)/18+2)}' in other.effects and not target_card in [x[0] for x in other.fs_cards]:
                raise SuccessfullDefense('The user has protected the page this card is in against spells!')

        if other.has_effect('1026')[0]:
            if 1026 in [x[0] for x in other.all_cards]: # Card has to remain in posession
                if other.effects['1026']-1 == 0:
                    other.remove_effect('1026')
                    other.remove_card(1026) 
                else:
                    other.add_effect('1026', other.effects['1026']-1)
                raise SuccessfullDefense('The user had remaining protection from card 1026 thus your attack failed')

        effects = []
        for c in other.fs_cards:
            if c[0] in DEF_SPELLS and not c[0] in effects:
                if c[0] == 1019 and not self.range == 'SR':
                    continue
                if c[0] == 1004 and self.ctx.author.id not in other.met_user:
                    continue
                effects.append(c[0])

        await self._wait_for_defense(ctx, other, effects)