Ejemplo n.º 1
0
 async def offered_pokemon(self):
     listingmsg = await self.get_listmsg()
     ctx = await self.bot.get_context(listingmsg)
     return Pokemon.get_pokemon(ctx, self._data['offered_pokemon'])
Ejemplo n.º 2
0
    async def accept_offer(self, offer_id):
        offer = self.offers[offer_id]
        trader = self.guild.get_member(offer_id)
        lister = self.lister
        listingmsg = await self.get_listmsg()

        ctx = await self.bot.get_context(listingmsg)
        offer = Pokemon.get_pokemon(ctx, offer)
        offered_pokemon = await self.offered_pokemon()

        acceptedmsg = (
            "{} has agreed to trade their {} for {}'s {}\n\n"
            "Please DM them to coordinate the trade! "
            "React with :ballot_box_with_check: when the trade has been "
            "completed! To reject or cancel this offer, react with "
            ":stop_button:").format(self.lister.display_name, offered_pokemon,
                                    trader.display_name, offer)

        special_check = [
            offered_pokemon.shiny, offered_pokemon.legendary, offer.shiny,
            offer.legendary
        ]

        if any(special_check):
            acceptedmsg += (
                "\n\nThis is a Special Trade! These can only be "
                "completed once per day and can cost up to 1 million "
                "stardust! Significant discounts can be earned by leveling "
                "up your friendship before the trade is made!")

        tradermsg = await trader.send(acceptedmsg)
        listermsg = await lister.send(acceptedmsg)

        await tradermsg.add_reaction('\u2611')
        await tradermsg.add_reaction('\u23f9')
        await listermsg.add_reaction('\u2611')
        await listermsg.add_reaction('\u23f9')

        for offerid in self.offers.keys():
            if offerid != offer_id:
                reject = self.guild.get_member(offerid)
                try:
                    await reject.send(
                        ("{} accepted a competing offer for their {}."
                         "").format(self.lister.display_name, offered_pokemon))
                except discord.HTTPException:
                    pass

        await listingmsg.edit(content="{} has accepted an offer!".format(
            self.lister.display_name), )

        await listingmsg.clear_reactions()

        trader_confirms = False
        lister_confirms = False

        def check(r, u):
            user_check = [u == trader, u == lister]
            msg_check = [
                r.message.id == tradermsg.id, r.message.id == listermsg.id
            ]
            emoji_check = [r.emoji == '\u2611', r.emoji == '\u23f9']
            if not any(msg_check) or not any(user_check) or not any(
                    emoji_check):
                return False
            else:
                return True

        while True:
            reaction, user = await self.bot.wait_for('reaction_add',
                                                     check=check)
            if user.id == trader.id:
                if reaction.emoji == '\u2611':
                    trader_confirms = True
                elif reaction.emoji == '\u23f9':
                    await tradermsg.delete()
                    return await self.withdraw_offer(trader.id)
            elif user.id == lister.id:
                if reaction.emoji == '\u2611':
                    lister_confirms = True
                elif reaction.emoji == '\u23f9':
                    await listermsg.delete()
                    return await self.reject_offer(trader.id)
            if trader_confirms and lister_confirms:
                await listermsg.delete()
                await tradermsg.delete()
                return await self.confirm_trade()
            else:
                continue