Esempio n. 1
0
 def get_human_item(self, user, code=None):
     #TODO: optimize
     human_item = HumanItem.get_or_none(human=self.bot.get_human(user=user),
                                        item=Item.get(code=code))
     if human_item is None or human_item.amount == 0:
         raise SendableException(self.bot.translate("no_" + code))
     return human_item
    async def item_use(self, ctx, *, name):
        if name == "":
            raise commands.errors.MissingRequiredArgument("name")

        try:
            item = Item.get(name=name)
        except Item.DoesNotExist:
            raise SendableException("Item not found.")

        if not item.usable:
            raise SendableException(ctx.translate("item_not_usable"))

        waiter = BoolWaiter(
            ctx,
            prompt=
            f"`{item.description}`\nAre you sure you want to use this item?")
        if not await waiter.wait():
            return await ctx.send(ctx.translate("canceled"))

        human = ctx.get_human()
        human_item, created = HumanItem.get_or_create(item=item, human=human)
        if created or human_item.amount == 0:
            raise SendableException(ctx.translate("you_missing_item"))

        used = False

        if item.code == "ban_hammer":
            await ctx.author.ban(reason="Ban hammer item was used.",
                                 delete_message_days=0)
            used = True

        elif item.code in ("big_bath", "big_snack", "big_toy"):
            pigeon = Pigeon.get_or_none(human=human,
                                        condition=Pigeon.Condition.active)
            if pigeon is None:
                raise SendableException(ctx.translate("you_no_pigeon"))
            used = True
            stat = {
                "big_bath": "cleanliness",
                "big_snack": "food",
                "big_toy": "happiness"
            }[item.code]
            data = {stat: 100}
            pigeon.update_stats(data, increment=False)
            pigeon.save()
        elif item.code == "milky_way":
            return await self.bot.get_command("milkyway create")(ctx)
        elif item.code == "jester_hat":
            member = await MemberWaiter(
                ctx, prompt=ctx.translate("prank_member_prompt")).wait()
            return await self.bot.get_command("prank nickname")(ctx, member)

        if used:
            human_item.amount -= 1
            human_item.save()
            await ctx.success("Item has been successfully used.")
Esempio n. 3
0
    def __init__(self, ctx, in_inventory=True, **kwargs):
        super().__init__(ctx, max_words=None, **kwargs)
        self.show_instructions = False
        self.case_sensitive = False

        if in_inventory:
            query = HumanItem.select()
            query = query.where(HumanItem.human == ctx.get_human())
            query = query.where(HumanItem.amount > 0)
            self.inventory = list(query)
            self.items = [x.item for x in self.inventory]
        else:
            self.items = list(Item.select())

        self.allowed_words = [x.name.lower() for x in self.items]
Esempio n. 4
0
    async def prank_check(self, ctx, member, name="human"):
        if member.bot:
            raise SendableException(ctx.translate("cannot_prank_bot"))
        if member.id == ctx.author.id:
            raise SendableException(ctx.translate("cannot_prank_self"))

        ctx.prankster, _ = Prankster.get_or_create(user_id=ctx.author.id,
                                                   guild_id=ctx.guild.id)
        if not ctx.prankster.enabled:
            raise SendableException(
                ctx.translate("prankster_pranking_disabled"))

        ctx.victim, _ = Prankster.get_or_create(user_id=member.id,
                                                guild_id=ctx.guild.id)
        if not ctx.victim.enabled:
            raise SendableException(ctx.translate("victim_pranking_disabled"))
        if ctx.victim.pranked:
            raise SendableException(ctx.translate("already_pranked"))

        if ctx.command.name == "nickname":
            cls = NicknamePrank
        elif ctx.command.name == "emoji":
            cls = EmojiPrank
        elif ctx.command.name == "role":
            cls = RolePrank
        else:
            cls = None
        ctx.prank_class = cls
        ctx.human = ctx.get_human()
        ctx.has_item = False
        if cls.item_code is not None:
            ctx.human_item = HumanItem.get_or_none(
                human=ctx.human, item=Item.get(Item.code == cls.item_code))
            ctx.has_item = ctx.human_item is not None and ctx.human_item.amount > 0

        ctx.cost = cls.cost

        if not ctx.has_item:
            ctx.raise_if_not_enough_gold(ctx.cost, ctx.human)
            waiter = BoolWaiter(
                ctx,
                prompt=ctx.translate("gold_verification_check").format(
                    gold=ctx.cost))
            if not await waiter.wait():
                raise SendableException(ctx.translate("canceled"))
Esempio n. 5
0
    async def inbox(self, ctx):
        """Check your inbox."""
        human = ctx.get_human()
        unread_mail = human.inbox.where(Mail.read == False).where(
            Mail.finished == True)
        if len(unread_mail) == 0:
            return await ctx.send(ctx.translate("no_unread_mail"))

        for mail in list(unread_mail):
            embed = self.get_base_embed(ctx.guild)
            embed.set_author(
                name=f"You've got mail from {mail.sender.human.user}!",
                icon_url=mail.sender.human.user.avatar_url)

            if mail.message is not None:
                embed.add_field(name="📜 message",
                                value=mail.message,
                                inline=False)
            if mail.gold > 0:
                embed.add_field(name=f"{Pigeon.emojis['gold']} gold",
                                value=f"{mail.gold}",
                                inline=False)
            if mail.item is not None:
                lines = []
                lines.append(mail.item.name)
                if mail.item.usable:
                    lines.append(f"*{mail.item.description}*")
                embed.add_field(name="🎁 gift",
                                value="\n".join(lines),
                                inline=False)
                embed.set_thumbnail(url=mail.item.image_url)

            await ctx.send(embed=embed)

            mail.read = True
            mail.save()
            if mail.gold > 0:
                human.gold += mail.gold
                human.save()
            if mail.item is not None:
                human_item, _ = HumanItem.get_or_create(item=mail.item,
                                                        human=mail.recipient)
                human_item.amount += 1
                human_item.save()
    async def farm_harvest(self, ctx):
        farm_crop = self.get_farm_crop_query(ctx.farm, due=True).first()
        if farm_crop is None:
            raise SendableException(ctx.translate("nothing_to_harvest"))
        farm_crop.finished = True
        farm_crop.save()
        crop = farm_crop.crop
        item = crop.product_item

        human_item, _ = HumanItem.get_or_create(item=item,
                                                human=ctx.get_human())
        products_gained = random.randint(2, 6)

        human_item.amount += products_gained
        human_item.save()

        embed = discord.Embed(color=discord.Color.green())
        embed.description = f"You have successfully harvested {products_gained} {item.name}s!"
        embed.set_image(url=item.image_url)
        await ctx.send(embed=embed)
    async def farm_plant(self, ctx,
                         crop_name: StringConverter(Crop.pluck("name"))):
        farm_crop = self.get_farm_crop_query(ctx.farm).first()
        if farm_crop is not None:
            raise SendableException(ctx.translate("already_planted"))

        crop = Crop.get(name=crop_name)
        item = crop.seed_item

        human_item = HumanItem.get_or_none(item=item, human=ctx.get_human())
        if human_item is None or human_item.amount <= 0:
            raise SendableException(
                ctx.translate("item_not_enough").format(item=item, amount=1))

        ctx.farm.plant(crop=crop)

        human_item.amount -= 1
        human_item.save()

        await ctx.success(ctx.translate("crop_planted").format(crop=crop))
Esempio n. 8
0
    async def pigeon_mail(self, ctx, user: discord.User):
        """Sending someone a letter."""
        if user.id == ctx.author.id:
            raise SendableException(ctx.translate("cannot_send_to_self"))

        sender = ctx.pigeon

        await ctx.send(ctx.translate("check_dms"))
        ctx.channel = ctx.author.dm_channel
        if ctx.channel is None:
            ctx.channel = await ctx.author.create_dm()

        recipient = ctx.get_human(user=user)
        human = ctx.get_human()

        mail = Mail(recipient=recipient, sender=sender, read=False)

        await mail.editor_for(ctx, "message")
        await mail.editor_for(ctx,
                              "gold",
                              min=0,
                              max=human.gold,
                              skippable=True)

        waiter = ItemWaiter(ctx,
                            prompt=ctx.translate("mail_item_prompt"),
                            skippable=True)
        try:
            mail.item = await waiter.wait()
        except Skipped:
            pass

        if mail.item is not None:
            human_item, _ = HumanItem.get_or_create(item=mail.item,
                                                    human=human)
            if human_item.amount < 1:
                raise SendableException(ctx.translate("item_not_found"))

            human_item.amount -= 1
            human_item.save()

        mail.residence = human.country
        mail.destination = recipient.country
        mail.end_date = mail.start_date + datetime.timedelta(
            minutes=mail.calculate_duration())
        human.gold -= mail.gold or 0
        sender.status = Pigeon.Status.mailing

        mail.save()
        human.save()
        sender.save()

        remind_emoji = "❗"
        embed = self.get_base_embed(ctx.guild)
        embed.description = f"Okay. Your pigeon is off to send a package to {recipient.mention}!"
        embed.set_footer(
            text=
            f"React with {remind_emoji} to get reminded when available.\n'{ctx.prefix}pigeon retrieve' to check on your pigeon"
        )
        message = await ctx.send(embed=embed)

        waiter = ReactionWaiter(ctx,
                                message,
                                emojis=(remind_emoji, ),
                                members=(ctx.author, ))
        await waiter.add_reactions()
        emoji = await waiter.wait(remove=True)
        if emoji is not None:
            Reminder.create(user_id=ctx.author.id,
                            channel_id=ctx.channel.id,
                            text=ctx.translate("pigeon_ready_to_be_retrieved"),
                            due_date=mail.end_date)
            asyncio.gather(ctx.success(ctx.translate("reminder_created")))