async def add_default_drinks(guild):
    server = get_server_or_create(guild.id, guild.preferred_locale)
    default_drinks = conf.lang_raw(server.lang, "default_drinks")
    with db.atomic():
        for default_drink in default_drinks:
            Drink.create(server=server, name=default_drink.name, intoxication=default_drink.intoxication,
                         portion_size=default_drink.portion, portions_per_day=default_drink.portions_per_day,
                         portions_left=default_drink.portions_per_day)
    log.info("Added drinks to {0}".format(guild.id))
示例#2
0
async def add_default_drinks(guild):
    default_drinks = conf.lang_raw("ru_RU", "default_drinks")
    with db.atomic():
        for default_drink in default_drinks:
            Drink.create(server=guild.id,
                         name=default_drink.name,
                         intoxication=default_drink.intoxication,
                         portion_size=default_drink.portion,
                         portions_per_day=default_drink.portions_per_day,
                         portions_left=default_drink.portions_per_day)
    log.info("Added drinks to {0}".format(guild.id))
示例#3
0
    async def add(self,
                  ctx: Context,
                  drink_name: str,
                  intoxication: int = DEFAULT_INTOXICATION,
                  portion_size: int = DEFAULT_PORTION_SIZE,
                  portions_per_day: int = DEFAULT_PORTIONS_PER_DAY):
        """
        Add a new drink to the bar. Barman role required.

        Parameters:
        drink_name: name of the drink, not empty
        intoxication: percent of intoxication (0-100). When man drinks a drink, this value will
        be appended to the level of intoxication.
        portion_size: size of portion, in milliliters, greater than 0 and less than 10000 (10l).
        portions_per_day: portions of this drink available for one day, greater than 0 and less
        than 10000.
        """
        if not 0 <= intoxication <= 100:
            await ctx.send(conf.lang("ru_RU", "wrong_intoxication"))
        elif not 0 < portion_size <= PORTION_MAX_SIZE:
            await ctx.send(
                conf.lang("ru_RU",
                          "wrong_portion_size").format(PORTION_MAX_SIZE))
        elif not 0 < portions_per_day <= PORTIONS_PER_DAY:
            await ctx.send(
                conf.lang("ru_RU",
                          "wrong_portions_per_day").format(PORTIONS_PER_DAY))
        elif 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))
        elif not check_guild_drink_count(ctx.guild.id):
            await ctx.send(
                conf.lang("ru_RU",
                          "too_many_drinks").format(DRINKS_PER_SERVER))
        elif Drink.select().where(Drink.server == ctx.guild.id
                                  and Drink.name == drink_name).count() > 0:
            await ctx.send(
                conf.lang("ru_RU", "duplicate_drink").format(drink_name))
        else:
            Drink.create(server=ctx.guild.id,
                         name=drink_name,
                         intoxication=intoxication,
                         portion_size=portion_size,
                         portions_per_day=portions_per_day,
                         portions_left=portions_per_day)
            await ctx.send(
                conf.lang("ru_RU", "drink_added").format(drink_name))
            log.info("Added drink \"{0}\" on {1}".format(
                drink_name, ctx.guild.id))
示例#4
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))
示例#5
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)