heist.py 文件源码

python
阅读 23 收藏 0 点赞 0 评论 0

项目:jose 作者: lnmds 项目源码 文件源码
def heist(self, ctx,
                    target: GuildConverter, amount: CoinConverter):
        """Heist a server.

        This works better if you have more people joining in your heist.

         - As soon as you use this command, a heist join session will start.
         - This session requires that all other people that want to join the
            heist to use the "j!heist join" command

         - There is a timeout of 3 minutes on the heist join session.
         - If your heist fails, all participants of the heist will be sentenced
            to jail or not, its random.

         - If your heist succeedes, you get a type 1 cooldown of 7 hours.
           it will show you are "regenerating your steal points".
        """
        if amount > 200:
            return await ctx.send('Cannot heist more than 200JC.')

        account = await self.coins.get_account(ctx.author.id)
        if amount > account['amount']:
            raise self.SayException('You cant heist more than'
                                    ' what you currently hold.')

        for session in self.sessions.values():
            if session.target.id == target.id:
                raise self.SayException('An already existing session '
                                        'exists with the same target')

        if target == ctx.guild:
            raise self.SayException('stealing from the same guild? :thinking:')

        taxbank = await self.coins.get_account(target.id)
        if not taxbank:
            raise self.SayException('Guild taxbank account not found')

        if amount > taxbank['amount']:
            raise self.SayException('You cannot steal more than the '
                                    'guild taxbank currently holds.')

        session = self.get_sess(ctx, target, True)
        try:
            await self.check_user(ctx, session)
        except self.SayException as err:
            self.sessions.pop(ctx.guild.id)
            raise err

        session.amount = amount
        session.add_member(ctx.author.id)
        session.task = self.loop.create_task(session.do_heist(ctx))

        await ctx.send('Join session started!')

        # timeout of 5 minutes accepting members
        # OR "j!heist raid"
        await asyncio.sleep(300)
        if not session.finish.is_set():
            await session.process_heist(await session.force_finish())
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号