From f4943c12542ca067f6be3eb185a9f1debd66498a Mon Sep 17 00:00:00 2001 From: flifloo Date: Wed, 8 Apr 2020 22:58:52 +0200 Subject: [PATCH] Setup level up and level up message --- extensions/xp.py | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/extensions/xp.py b/extensions/xp.py index c6fc717..e0a6279 100644 --- a/extensions/xp.py +++ b/extensions/xp.py @@ -1,8 +1,8 @@ from discord.ext import commands -from discord import Embed, Message +from discord import Embed, Message, User from threading import RLock from shelve import open -from datetime import datetime, timedelta +from datetime import timedelta from re import compile from bot_bde.logger import logger @@ -16,6 +16,8 @@ XP = {"message": 2, "image": 15, "file": 20, "link": 10} +LEVEL_RATIO = 350 + class Xp(commands.Cog): def __init__(self, bot: commands.Bot): @@ -62,7 +64,7 @@ class Xp(commands.Cog): "file": 0, "link": 0, "last_message": message.created_at} - if message.created_at - data[str(message.author.id)]["last_message"] >= timedelta(minutes=5): + if message.created_at - data[str(message.author.id)]["last_message"] >= timedelta(minutes=2): can_xp = True data[str(message.author.id)]["message"] += 1 if can_xp: @@ -82,6 +84,17 @@ class Xp(commands.Cog): if can_xp: data[str(message.author.id)]["xp"] += XP["file"] data[str(message.author.id)]["last_message"] = message.created_at + await self.level_up(message, data) + + async def level_up(self, message: Message, data): + level_cap = data[str(message.author.id)]["level"] + 1 * LEVEL_RATIO + if data[str(message.author.id)]["xp"] >= level_cap: + data[str(message.author.id)]["xp"] = data[str(message.author.id)]["xp"] - level_cap + data[str(message.author.id)]["level"] += 1 + embed = Embed(title="Level ! \U0001F389") + embed.add_field(name="You gain one level !", + value=f"You reach level {data[str(message.author.id)]['level']}") + await message.channel.send(embed=embed) def setup(bot):