Spaces:
Running
on
CPU Upgrade
Running
on
CPU Upgrade
Update app.py
Browse files
app.py
CHANGED
|
@@ -17,6 +17,8 @@ bot = commands.Bot(command_prefix='!', intents=intents)
|
|
| 17 |
|
| 18 |
XP_PER_MESSAGE = 10
|
| 19 |
|
|
|
|
|
|
|
| 20 |
|
| 21 |
def load_xp_data():
|
| 22 |
try:
|
|
@@ -38,18 +40,24 @@ async def on_ready():
|
|
| 38 |
|
| 39 |
@bot.event
|
| 40 |
async def on_message(message):
|
|
|
|
|
|
|
| 41 |
if message.author.bot:
|
| 42 |
return
|
| 43 |
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
|
|
|
|
|
|
| 49 |
|
|
|
|
|
|
|
| 50 |
save_xp_data(xp_data)
|
| 51 |
|
| 52 |
-
|
| 53 |
|
| 54 |
|
| 55 |
def calculate_level(xp):
|
|
@@ -58,12 +66,14 @@ def calculate_level(xp):
|
|
| 58 |
|
| 59 |
@bot.command()
|
| 60 |
async def level(ctx):
|
|
|
|
| 61 |
if ctx.author.id == 811235357663297546: # lunarflu
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
level = calculate_level(
|
| 66 |
-
|
|
|
|
| 67 |
# progress bar with ascii? could be nice, easy
|
| 68 |
else:
|
| 69 |
await ctx.send('You have not earned any XP yet.')
|
|
|
|
| 17 |
|
| 18 |
XP_PER_MESSAGE = 10
|
| 19 |
|
| 20 |
+
xp_data = {}
|
| 21 |
+
|
| 22 |
|
| 23 |
def load_xp_data():
|
| 24 |
try:
|
|
|
|
| 40 |
|
| 41 |
@bot.event
|
| 42 |
async def on_message(message):
|
| 43 |
+
global xp_data
|
| 44 |
+
|
| 45 |
if message.author.bot:
|
| 46 |
return
|
| 47 |
|
| 48 |
+
if message.author.id not in xp_data:
|
| 49 |
+
xp_data[message.author.id] = 0
|
| 50 |
+
|
| 51 |
+
old = xp_data[message.author.id]
|
| 52 |
+
new = old + XP_PER_MESSAGE
|
| 53 |
+
xp_data[message.author.id] = new
|
| 54 |
+
level = calculate_level(new)
|
| 55 |
|
| 56 |
+
print(f"{message.author.mention} xp: {xp_data[message.author.id]}")
|
| 57 |
+
print(f"{message.author.mention} level: {level}")
|
| 58 |
save_xp_data(xp_data)
|
| 59 |
|
| 60 |
+
|
| 61 |
|
| 62 |
|
| 63 |
def calculate_level(xp):
|
|
|
|
| 66 |
|
| 67 |
@bot.command()
|
| 68 |
async def level(ctx):
|
| 69 |
+
global xp_data
|
| 70 |
if ctx.author.id == 811235357663297546: # lunarflu
|
| 71 |
+
if ctx.author.id in xp_data:
|
| 72 |
+
|
| 73 |
+
xp = xp_data[ctx.author.id]
|
| 74 |
+
level = calculate_level(xp)
|
| 75 |
+
|
| 76 |
+
await ctx.send(f'You are at level {level} with {xp} total XP.')
|
| 77 |
# progress bar with ascii? could be nice, easy
|
| 78 |
else:
|
| 79 |
await ctx.send('You have not earned any XP yet.')
|