Пример #1
0
async def on_message(message: Message):
    if message.author.bot:
        return

    if message.author.id == 136999062519021568:
        await message.channel.send("I am beyond your commands")
        return

    user = get_or_create_user(message.author, message.guild)
    old_level = xp_to_level(user.xp)
    message_contains_image = bool(message.attachments) or bool(message.embeds)
    user = add_xp(user, 5 if message_contains_image else 1)
    new_level = xp_to_level(user.xp)
    if new_level > old_level:
        await message.channel.send(
            f"Congrats {message.author.mention}! You leveled up to level {new_level} 🎉"
        )

    await bot.process_commands(message)
Пример #2
0
def test_add_xp_respects_cooldown(user: User):
    user = add_xp(user, XP_COUNT, cooldown=timedelta(days=1))

    assert user.xp == User.xp.default
Пример #3
0
def test_add_xp_sets_user_new_xp_update_time(user: User):
    old_update_time = user.xp_last_update_time
    user = add_xp(user, XP_COUNT, cooldown=timedelta(0))

    assert user.xp_last_update_time > old_update_time
Пример #4
0
def test_add_xp_only_adds_xp_to_correct_guild(user: User,
                                              user_in_other_guild: User):
    user = add_xp(user, XP_COUNT, cooldown=timedelta(0))
    user_in_other_guild = User.get_by_id(user_in_other_guild.id)

    assert user.xp != user_in_other_guild.xp
Пример #5
0
def test_add_xp_adds_correct_amount_of_xp(user: User):
    user.xp = 100
    user = add_xp(user, XP_COUNT, cooldown=timedelta(0))
    assert user.xp == 100 + XP_COUNT
Пример #6
0
def test_add_xp_adds_xp_to_correct_user(user: User):
    add_xp(user, XP_COUNT, cooldown=timedelta(0))
    user = User.get_by_id(user.id)
    assert user.xp == XP_COUNT