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))
async def list(self, ctx: Context): """ Returns the list with available drinks """ server = get_server_from_context(ctx) lang = server.lang drinks = Drink.select().where(Drink.server == server) out = "\n".join([ conf.lang(lang, "drink_info").format(drink.name, drink.portion_size, drink.portions_left, drink.portions_per_day) for drink in drinks ]) if out != "": await ctx.send(out) else: await ctx.send(conf.lang(lang, "no_drinks"))
async def list(self, ctx: Context): """ Returns the list with available drinks """ drinks = Drink.select().where(Drink.server == ctx.guild.id) # out = "" # for drink in drinks: # out += conf.lang("ru_RU", "drink_info").format(str(drink.name), str(drink.portion_size)) # out += '\n' out = "\n".join([ conf.lang("ru_RU", "drink_info").format(drink.name, drink.portion_size, drink.portions_left, drink.portions_per_day) for drink in drinks ]) if out != "": await ctx.send(out) else: await ctx.send(conf.lang("ru_RU", "no_drinks"))
def check_guild_drink_count(gid: int): return Drink.select(Drink).join(Server).where( Server.sid == gid).count() < DRINKS_PER_SERVER
def check_guild_drink_count(gid: int): return Drink.select().where( Drink.server == gid).count() < DRINKS_PER_SERVER