示例#1
0
 async def on_reaction_add(self, reaction, user):
     log.debug("Got reaction {0} by {1} on {2}".format(
         str(reaction), user, str(reaction.message.guild)))
     message = reaction.message
     mid = message.id
     if mid not in message_dict:
         return
     ctx, _, expected_all, _, drink = message_dict[mid]
     if user not in expected_all or message.id not in message_dict:
         return
     if str(reaction) == conf.lang("ru_RU", "ok-emoji"):
         expected_all.remove(user)
         log.debug("Parsed as OK")
         ctx.author = user
         await self.drink(ctx, drink_name=drink.name)
         if not len(expected_all):
             try:
                 await message.delete()
             except Forbidden or NotFound or HTTPException:
                 pass
             finally:
                 del message_dict[message.id]
             log.info("Removed message {0}".format(message.id, ))
     elif str(reaction) == conf.lang("ru_RU", "no-emoji"):
         log.debug("Parsed as NO")
         expected_all.remove(user)
         if not len(expected_all):
             try:
                 await message.delete()
             except Forbidden or NotFound or HTTPException:
                 pass
             finally:
                 del message_dict[message.id]
             log.info("Removed message {0}".format(message.id, ))
示例#2
0
    async def restock(self, ctx: Context, *, drink_name: Optional[str]):
        """
        Restock the bar or only one drink. Barman role required.

        Parameters:
        drink_name: name of the drink
        """
        if drink_name is not None and len(drink_name) > DRINK_NAME_LENGTH:
            await ctx.send(
                conf.lang("ru_RU",
                          "wrong_drink_name").format(DRINK_NAME_LENGTH))
            return
        if drink_name is None:
            (Drink.update(portions_left=Drink.portions_per_day).where(
                Drink.server == ctx.guild.id)).execute()
            await ctx.send(conf.lang("ru_RU", "restocked_all"))
            log.info("Restocked all drinks on {1}".format(
                drink_name, ctx.guild.id))
        else:
            (Drink.update(portions_left=Drink.portions_per_day).where(
                Drink.server == ctx.guild.id
                and Drink.server == drink_name)).execute()
            await ctx.send(
                conf.lang("ru_RU", "restocked_single").format(drink_name))
            log.info("Restocked drink \"{0}\" on {1}".format(
                drink_name, ctx.guild.id))
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))
示例#4
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))
示例#5
0
async def erase():
    now = datetime.today()
    for mid, tpl in message_dict.items():
        ctx, message, user, time, drink = tpl
        if now > time:
            try:
                await message.delete()
            except Forbidden or NotFound or HTTPException:
                pass
            finally:
                del message_dict[mid]
                log.info("Deleted message {0} on {1} by time exceeding".format(
                    message.id, ctx.guild.id))
示例#6
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))
示例#7
0
async def consume_drink(ctx: Context, person: Person, drink: Drink):
    if person.intoxication > 100 or person.intoxication < 0:
        person.intoxication = 0
    guild: Guild = ctx.guild
    member: Member = guild.get_member(person.uid)

    if drink.portions_left <= 0:
        await ctx.send(
            conf.lang("ru_RU", "no_portions_left").format(drink.name))
    else:
        if drink.portions_left == 1:
            await ctx.send(
                conf.lang("ru_RU", "last_portion").format(drink.name))
        person.intoxication += drink.intoxication
        drink.portions_left -= 1
        if person.intoxication >= 100:
            try:
                await member.move_to(None, reason="Drank too much")
                await ctx.send(
                    conf.lang("ru_RU",
                              "overdrink_kick_message").format(member.mention))
            except Forbidden:
                log.info("Can't kick an alcoholic: no permissions in " +
                         guild.id)
                await ctx.send(
                    conf.lang("ru_RU", "overdrink_no_kick_message").format(
                        member.mention))
            finally:
                person.intoxication = 0
        elif person.intoxication > 80:
            await ctx.send(
                conf.lang("ru_RU",
                          "pre_overdrink").format(member.display_name))
        log.info("{0} consumed drink \"{1}\" on {2}".format(
            member.display_name, drink.name, guild.id))
    with db.atomic():
        person.save()
        drink.save()
示例#8
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
        """
        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)
            drink.delete_instance()
            await ctx.send(
                conf.lang("ru_RU", "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("ru_RU", "drink_not_found").format(drink_name))
示例#9
0
async def restock():
    (Drink.update(portions_left=Drink.portions_per_day)).execute()
    log.info("Restocked every server")
示例#10
0
 async def on_guild_join(self, guild):
     log.info("Joined guild {0}".format(guild.id))
     await add_default_drinks(guild)
     return True
示例#11
0
 async def on_ready(self):
     log.info("Successfully connected and ready")