Exemple #1
0
    async def card(self, ctx, item: int):
        """Buy a card from the shop with this command"""

        shop_data = shop.find_one({'_id': 'daily_offers'})
        shop_items = shop_data['offers']
        user = User(ctx.author.id)

        try:
            card = Card(item)
        except CardNotFound:
            return await ctx.send(
                f'This card is not for sale at the moment! Find what cards are in the shop with `{self.client.command_prefix(self.client, ctx.message)[2]}shop`',
                allowed_mentions=discord.AllowedMentions.none())

        if not item in shop_items:
            return await ctx.send(
                f'This card is not for sale at the moment! Find what cards are in the shop with `{self.client.command_prefix(self.client, ctx.message)[2]}shop`',
                allowed_mentions=discord.AllowedMentions.none())

        if not shop_data['reduced'] is None:
            if shop_items.index(
                    card.id) == shop_data['reduced']['reduced_item']:
                price = int(PRICES[card.rank] -
                            int(PRICES[card.rank] *
                                (shop_data['reduced']['reduced_by'] / 100)))
            else:
                price = PRICES[card.rank]
        else:
            price = PRICES[card.rank]

        if len(card.owners) >= (card.limit * ALLOWED_AMOUNT_MULTIPLE):
            return await ctx.send(
                'Unfortunately the global maximal limit of this card is reached! Someone needs to sell their card for you to buy one or trade/give it to you'
            )

        if len(user.fs_cards) >= FREE_SLOTS:
            return await ctx.send(
                f'Looks like your free slots are filled! Get rid of some with `{self.client.command_prefix(self.client, ctx.message)[2]}sell`',
                allowed_mentions=discord.AllowedMentions.none())

        if user.jenny < price:
            return await ctx.send(
                f'I\'m afraid you don\'t have enough Jenny to buy this card. Your balance is {user.jenny} while the card costs {price} Jenny'
            )
        try:
            user.add_card(item)
        except Exception as e:
            if isinstance(e, CardLimitReached):
                return await ctx.send(
                    f'Free slots card limit reached (`{FREE_SLOTS}`)! Get rid of one card in your free slots to add more cards with `{self.client.command_prefix(self.client, ctx.message)[2]}sell <card>`',
                    allowed_mentions=discord.AllowedMentions.none())
            else:
                print(e)

        user.remove_jenny(
            price
        )  #Always putting substracting points before giving the item so if the payment errors no item is given
        return await ctx.send(
            f'Successfully bought card number `{card.id}` {card.emoji} for {price} Jenny. Check it out in your inventory with `{self.client.command_prefix(self.client, ctx.message)[2]}book`!',
            allowed_mentions=discord.AllowedMentions.none())
Exemple #2
0
    async def buy_description(self, ctx):
        #Hi! You found a random comment! Now you have to vote for Killua :3 (Also thanks for checking out my code)
        """outsourcing todo buy in smaller functions"""
        list_id = editing[ctx.author.id]
        todo_list = TodoList(list_id)
        user = User(ctx.author.id)
        if user.jenny < 1000:
            return await ctx.send(
                'You don\'t have enough Jenny to buy a thumbnail for your todo list. You need 1000 Jenny'
            )

        step = await ctx.send(
            f'What should the description of your todo list be? (max 200 characters)'
        )

        def check(m):
            return m.author.id == ctx.author.id

        confirmmsg = await self._wait_for_response(step, check)
        if not confirmmsg:
            return

        if len(confirmmsg.content) > 200:
            await ctx.send('Your description can\'t be over 200 characters!')
            return await self.buy_description(ctx)
        user.remove_jenny(1000)
        todo_list.set_property('description', confirmmsg.content)
        return await ctx.send(
            'Congrats! You bought a description for your current todo list')
Exemple #3
0
    async def buy_space(self, ctx):
        # This is the best thing to buy for your todo list
        """outsourcing todo buy in smaller functions"""
        list_id = editing[ctx.author.id]
        todo_list = TodoList(list_id)
        user = User(ctx.author.id)

        if user.jenny < (todo_list.spots * 100 * 0.5):
            return await ctx.send(
                f'You don\'t have enough Jenny to buy more space for your todo list. You need {todo_list["spots"]*100} Jenny'
            )

        if todo_list.spots >= 100:
            return await ctx.send('You can\'t buy more than 100 spots')

        view = ConfirmButton(ctx.author.id, timeout=10)
        msg = await ctx.send(
            f'Do you want to buy 10 more to-do spots for this list? \nCurrent spots: {todo_list.spots} \nCost: {int(todo_list.spots*100*0.5)} points',
            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"Alright, see you later then :3")

        user.remove_jenny(int(100 * todo_list.spots * 0.5))
        todo_list.add_spots(10)
        return await ctx.send(
            'Congrats! You just bought 10 more todo spots for the current todo list!'
        )
Exemple #4
0
 async def _eval_outcome(self, winlose: int, choice1, choice2,
                         player1: discord.Member,
                         player2: discord.Member) -> discord.Message:
     """Evaluates the outcome, informs the players and handles the points """
     p1 = User(player1.id)
     p2 = User(player2.id)
     if winlose == -1:
         if self.points:
             p1.add_jenny(self.points)
             if player2 != self.ctx.me:
                 p2.remove_jenny(self.points)
             return await self.ctx.send(
                 f'{self.emotes[choice1]} > {self.emotes[choice2]}: {player1.mention} won against {player2.mention} winning {self.points} Jenny which adds to a total of {p1.jenny}'
             )
         else:
             return await self.ctx.send(
                 f'{self.emotes[choice1]} > {self.emotes[choice2]}: {player1.mention} won against {player2.mention}'
             )
     elif winlose == 0:
         return await self.ctx.send(
             f'{self.emotes[choice1]} = {self.emotes[choice2]}: {player1.mention} tied against {player2.mention}'
         )
     elif winlose == 1:
         if self.points:
             p1.remove_jenny(self.points)
             if player2 != self.ctx.me:
                 p2.add_jenny(self.points)
             return await self.ctx.send(
                 f'{self.emotes[choice1]} < {self.emotes[choice2]}: {player1.mention} lost against {player2.mention} losing {self.points} Jenny which leaves them a total of {p1.jenny}'
             )
         else:
             return await self.ctx.send(
                 f'{self.emotes[choice1]} < {self.emotes[choice2]}: {player1.mention} lost against {player2.mention}'
             )
Exemple #5
0
    async def buy_thumbnail(self, ctx):
        """outsourcing todo buy in smaller functions. Will be rewritten once discord adds text input interaction"""
        list_id = editing[ctx.author.id]
        todo_list = TodoList(list_id)
        user = User(ctx.author.id)
        if user.jenny < 1000:
            return await ctx.send(
                'You don\'t have enough Jenny to buy a thumbnail for your todo list. You need 1000 Jenny'
            )

        if todo_list.thumbnail:
            return await ctx.send(
                f'You already have bought a thumbnail for this list! Update it with `{self.client.command_prefix(self.client, ctx.message)[2]}todo thumbnail <url>`',
                allowed_mentions=discord.AllowedMentions.none())

        step = await ctx.send(
            'Please provide a thumbnail you want your todo list to have, you can always change it later'
        )

        def check(m):
            return m.author.id == ctx.author.id

        confirmmsg = await self._wait_for_response(step, check)
        if not confirmmsg:
            return

        url = re.search(
            r'http[s]?://(?:[a-zA-Z]|[0-9]|[$-_@.&+]|[!*(),]|(?:%[0-9a-fA-F][0-9a-fA-F]))',
            confirmmsg.content)

        if url:
            image = re.search(r'png|jpg|gif|svg', confirmmsg.content)
        else:
            await ctx.send(
                'You didn\'t provide a valid url with an image! Please make sure your url is valid'
            )
            return await self.buy_thumbnail(ctx)

        if image:
            user.remove_jenny(1000)
            todo_list.set_property('thumbnail', confirmmsg.content)
            return await ctx.send(
                f'Successfully bought the thumbmail `{confirmmsg.content}` for your list! You can change it with `{self.client.command_prefix(self.client, ctx.message)[2]}todo thumbnail <url>`',
                allowed_mentions=discord.AllowedMentions.none())
        else:
            await ctx.send(
                'You didn\'t provide a valid url with an image! Please make sure you your url is valid'
            )
            return await self.buy_thumbnail(ctx)
Exemple #6
0
    async def buy_color(self, ctx):
        """outsourcing todo buy in smaller functions. Will be rewritten once discord adds text input interaction"""
        list_id = editing[ctx.author.id]
        todo_list = TodoList(list_id)
        user = User(ctx.author.id)
        if user.jenny < 1000:
            return await ctx.send(
                'You don\'t have enough Jenny to buy a color for your todo list. You need 1000 Jenny'
            )

        if todo_list.color:
            return await ctx.send(
                f'You already have bought a color for this list! Update it with `{self.client.command_prefix(self.client, ctx.message)[2]}todo color <color>`',
                allowed_mentions=discord.AllowedMentions.none())

        step = await ctx.send(
            'Please provide a color you want your todo list to have, you can always change it later'
        )

        def check(m):
            return m.author.id == ctx.author.id

        confirmmsg = await self._wait_for_response(step, check)
        if not confirmmsg:
            return
        c = f'0x{confirmmsg.content}'
        try:
            if not int(c, 16) <= 16777215:
                await ctx.send(
                    'You need to provide a valid color! (Default color is 1400ff f.e.)'
                )
                return await self.buy_color(ctx)
        except Exception:
            await ctx.send(
                'You need to provide a valid color! (Default color is 1400ff f.e.)'
            )
            return await self.buy_color(ctx)

        user.remove_jenny(1000)
        todo_list.set_property('color', int(c, 16))
        return await ctx.send(
            f'Successfully bought the color {confirmmsg.content} for your list! You can change it with `{self.client.command_prefix(self.client, ctx.message)[2]}todo color <color>`',
            allowed_mentions=discord.AllowedMentions.none())