Ejemplo n.º 1
0
    async def serve(self, ctx: Context, drink_name: str,
                    to: commands.Greedy[Member]):
        """
        Trying to give a drink to the member.

        This command will send a message, where the member can choose to drink or not.
        Parameters:
        drink_name: name of the drink
        to: member (can be mention)
        """
        gid = ctx.guild.id
        server = get_server_from_context(ctx)
        lang = server.lang
        try:
            drink = Drink.get(Drink.server == server
                              and Drink.name == drink_name)
        except DoesNotExist:
            if not check_guild_drink_count(gid):
                await ctx.send(
                    conf.lang(lang,
                              "too_many_drinks").format(DRINKS_PER_SERVER))
                return
            drink = Drink.create(server=server,
                                 name=drink_name,
                                 intoxication=DEFAULT_INTOXICATION,
                                 portion_size=DEFAULT_PORTION_SIZE,
                                 portions_per_day=DEFAULT_PORTIONS_PER_DAY,
                                 portions_left=DEFAULT_PORTIONS_PER_DAY)
        msg = await ctx.send(
            conf.lang(lang,
                      "serve_message").format(author=ctx.author.mention,
                                              drink=drink_name,
                                              portion_size=drink.portion_size))

        await msg.add_reaction(conf.lang(lang, "ok-emoji"))
        await msg.add_reaction(conf.lang(lang, "no-emoji"))
        expected = set(to)

        def check(reaction, user):
            return user in expected and str(reaction.emoji) in {
                conf.lang(lang, "ok-emoji"),
                conf.lang(lang, "no-emoji")
            }

        while len(expected):
            try:
                reaction, user = await self.bot.wait_for(
                    "reaction_add",
                    timeout=conf.limitation("serve_timeout"),
                    check=check)
            except asyncio.TimeoutError:
                break
            else:
                expected.remove(user)
                if str(reaction) == conf.lang(lang, "ok-emoji"):
                    await give_a_drink(ctx, user, drink)
        await msg.delete()
        log.info("Deleted message {0} on {1} by time exceeding".format(
            msg.id, ctx.guild.id))
Ejemplo n.º 2
0
    async def drink(self, ctx: Context, *, drink_name: str):
        """
        Drinks a drink and tails some random joke.

        Parameters:
        drink_name: name of the drink, not empty
        """
        server = get_server_from_context(ctx)
        lang = server.lang
        if drink_name is None or len(drink_name) > DRINK_NAME_LENGTH:
            await ctx.send(
                conf.lang(lang, "wrong_drink_name").format(DRINK_NAME_LENGTH))
            return
        try:
            drink = Drink.get(Drink.server == server
                              and Drink.name == drink_name)
        except DoesNotExist:
            await ctx.send(
                conf.lang(lang, "drink_not_found").format(drink_name))
        else:
            await give_a_drink(ctx, ctx.author, drink)
Ejemplo n.º 3
0
    async def serve(self, ctx: Context, drink_name: str,
                    to: commands.Greedy[Member]):
        """
        Trying to give a drink to the member.

        This command will send a message, where the member can choose to drink or not.
        Parameters:
        drink_name: name of the drink
        to: member (can be mention)
        """
        gid = ctx.guild.id
        try:
            drink = Drink.get(Drink.server == gid and Drink.name == drink_name)
        except DoesNotExist:
            if not check_guild_drink_count(gid):
                await ctx.send(
                    conf.lang("ru_RU",
                              "too_many_drinks").format(DRINKS_PER_SERVER))
                return
            drink = Drink.create(server=gid,
                                 name=drink_name,
                                 intoxication=DEFAULT_INTOXICATION,
                                 portion_size=DEFAULT_PORTION_SIZE,
                                 portions_per_day=DEFAULT_PORTIONS_PER_DAY,
                                 portions_left=DEFAULT_PORTIONS_PER_DAY)
        msg = await ctx.send(
            conf.lang("ru_RU",
                      "serve_message").format(author=ctx.author.mention,
                                              drink=drink_name,
                                              portion_size=drink.portion_size))

        await asyncio.wait({
            msg.add_reaction(conf.lang("ru_RU", "ok-emoji")),
            msg.add_reaction(conf.lang("ru_RU", "no-emoji"))
        })
        message_dict[msg.id] = (ctx, msg, set(to),
                                datetime.today() + timedelta(0, 60 * 10),
                                drink)
Ejemplo n.º 4
0
    async def remove(self, ctx: Context, *, drink_name: str):
        """
        Remove the drink from the bar. Barman role required.

        Parameters:
        drink_name: name of the drink, not empty
        """
        server = get_server_from_context(ctx)
        lang = server.lang
        if drink_name is None or len(drink_name) > DRINK_NAME_LENGTH:
            await ctx.send(
                conf.lang(lang, "wrong_drink_name").format(DRINK_NAME_LENGTH))
            return
        try:
            drink = Drink.get(Drink.server == server
                              and Drink.name == drink_name)
            drink.delete_instance()
            await ctx.send(conf.lang(lang, "drink_deleted").format(drink_name))
            log.info("Removed drink \"{0}\" from {1}".format(
                drink_name, ctx.guild.id))
        except DoesNotExist:
            await ctx.send(
                conf.lang(lang, "drink_not_found").format(drink_name))
Ejemplo n.º 5
0
    async def drink(self, ctx: Context, *, drink_name: str):
        """
        Drinks a drink and tails some random joke.

        Parameters:
        drink_name: name of the drink, not empty
        """
        if drink_name is None or len(drink_name) > DRINK_NAME_LENGTH:
            await ctx.send(
                conf.lang("ru_RU",
                          "wrong_drink_name").format(DRINK_NAME_LENGTH))
            return
        try:
            drink = Drink.get(Drink.server == ctx.guild.id
                              and Drink.name == drink_name)
            person = get_person_or_create(ctx.guild.id, ctx.author.id)
            await consume_drink(ctx, person, drink)
            async with ctx.typing():
                joke = get_joke("ru_RU")
            await ctx.send(joke or conf.lang("ru_RU", "joke_not_loaded"))
        except DoesNotExist:
            await ctx.send(
                conf.lang("ru_RU", "drink_not_found").format(drink_name))