Пример #1
0
 async def predicate(ctx: Context) -> bool:
     if not hasattr(ctx, "character_data"):
         ctx.character_data = await ctx.bot.cache.get_profile(ctx.author.id)
     if (
         check := ctx.bot.in_class_line(ctx.character_data["class"], class_)
     ) and class_ == "Ranger":
         ctx.pet_data = await ctx.bot.pool.fetchrow(
             'SELECT * FROM pets WHERE "user"=$1;', ctx.author.id
         )
Пример #2
0
 async def predicate(ctx: Context) -> bool:
     async with ctx.bot.pool.acquire() as conn:
         ret = await conn.fetchval(
             'SELECT class FROM profile WHERE "user"=$1;', ctx.author.id
         )
         if (check := ctx.bot.in_class_line(ret, class_)) and class_ == "Ranger":
             ctx.pet_data = await conn.fetchrow(
                 'SELECT * FROM pets WHERE "user"=$1;', ctx.author.id
             )
Пример #3
0
 async def predicate(ctx: Context) -> bool:
     if not ctx.pet_data:
         raise PetGone()
     diff = (
         (now := datetime.datetime.now(pytz.utc)) - ctx.pet_data["last_update"]
     ) // datetime.timedelta(hours=2)
     if diff >= 1:
         # Pets loose 2 food, 4 drinks, 1 joy and 1 love
         async with ctx.bot.pool.acquire() as conn:
             data = await conn.fetchrow(
                 'UPDATE pets SET "food"="food"-$1, "drink"="drink"-$2, "joy"=CASE'
                 ' WHEN "joy"-$3>=0 THEN "joy"-$3 ELSE 0 END, "love"=CASE WHEN'
                 ' "love"-$4>=0 THEN "love"-$4 ELSE 0 END, "last_update"=$5 WHERE'
                 ' "user"=$6 RETURNING *;',
                 diff * 2,
                 diff * 4,
                 diff,
                 diff,
                 now,
                 ctx.author.id,
             )
             ctx.pet_data = data
             classes = ctx.character_data["class"]
             for evolve in ["Caretaker"] + ctx.bot.get_class_evolves()["Ranger"]:
                 if evolve in classes:
                     idx = classes.index(evolve)
                     break
             if data["food"] < 0 or data["drink"] < 0:
                 classes[idx] = "No Class"
                 await conn.execute(
                     'DELETE FROM pets WHERE "user"=$1;', ctx.author.id
                 )
                 await conn.execute(
                     'UPDATE profile SET "class"=$1 WHERE "user"=$2;',
                     classes,
                     ctx.author.id,
                 )
                 await ctx.bot.cache.update_profile_cols_abs(
                     ctx.author.id, class_=classes
                 )
                 raise PetDied()
             elif data["love"] < 75 and random.randint(0, 99) > data["love"]:
                 classes[idx] = "No Class"
                 await conn.execute(
                     'DELETE FROM pets WHERE "user"=$1;', ctx.author.id
                 )
                 await conn.execute(
                     'UPDATE profile SET "class"=$1 WHERE "user"=$2;',
                     classes,
                     ctx.author.id,
                 )
                 await ctx.bot.cache.update_profile_cols_abs(
                     ctx.author.id, class_=classes
                 )
                 raise PetRanAway()
     return True