Spaces:
Running
on
CPU Upgrade
Running
on
CPU Upgrade
nroggendorff
commited on
patched issue where you could earn infinite exp if you send messages in bot dms, other changes are commentated
Browse files
app.py
CHANGED
@@ -3,6 +3,7 @@ import re
|
|
3 |
import csv
|
4 |
import json
|
5 |
import time
|
|
|
6 |
import random
|
7 |
import asyncio
|
8 |
import discord
|
@@ -44,6 +45,8 @@ GRADIO_APP_URL = "https://huggingface.co/spaces/discord-community/LevelBot"
|
|
44 |
# Dictionary to store user IDs and their corresponding unique strings
|
45 |
user_tokens = {}
|
46 |
|
|
|
|
|
47 |
|
48 |
""""""
|
49 |
XP_PER_MESSAGE = 10 # 100k messages = 1M exp = lvl 100
|
@@ -244,12 +247,13 @@ scheduler.start()
|
|
244 |
#asyncio.get_event_loop().run_forever()
|
245 |
|
246 |
|
247 |
-
def calculate_level(xp):
|
248 |
-
return int(xp ** (1
|
249 |
|
250 |
|
251 |
-
def calculate_xp(
|
252 |
-
|
|
|
253 |
|
254 |
|
255 |
async def add_exp(member_id):
|
@@ -336,6 +340,8 @@ async def add_exp(member_id):
|
|
336 |
cell_value = str(cell_value)
|
337 |
if cell_value.startswith("L") and cell_value.endswith("L"):
|
338 |
cell_value_clipped = cell_value[1:-1]
|
|
|
|
|
339 |
if cell_value_clipped == str(member_id): # str(member_id) needed, it is int by default
|
340 |
print("test4")
|
341 |
# if found, update that row...
|
@@ -352,6 +358,7 @@ async def add_exp(member_id):
|
|
352 |
|
353 |
# str -> int temporarily for adding
|
354 |
new_xp = int(old_xp) + XP_PER_MESSAGE
|
|
|
355 |
|
356 |
total_exp = global_df.loc[index, 'total_exp']
|
357 |
hub_xp = global_df.loc[index, 'hub_exp']
|
@@ -375,7 +382,7 @@ async def add_exp(member_id):
|
|
375 |
total_exp = int(new_xp)
|
376 |
|
377 |
# total v
|
378 |
-
current_level = calculate_level(total_exp)
|
379 |
|
380 |
# convert back to string + google sheet proofing
|
381 |
new_xp = str(new_xp)
|
@@ -546,29 +553,36 @@ async def on_message(message):
|
|
546 |
invite_message = "Click to join our community org on the HF Hub!"
|
547 |
try:
|
548 |
if message.author.id not in bot_ids: # could change to if author does not have bot role (roleid)
|
549 |
-
|
550 |
-
|
551 |
-
|
552 |
-
|
553 |
-
|
554 |
-
|
555 |
-
await
|
556 |
-
|
557 |
-
)
|
558 |
await bot.process_commands(message)
|
559 |
except Exception as e:
|
560 |
print(f"on_message Error: {e}")
|
561 |
|
562 |
-
|
563 |
@bot.event
|
564 |
async def on_reaction_add(reaction, user):
|
565 |
try:
|
566 |
if user.id not in bot_ids:
|
567 |
-
|
568 |
await asyncio.sleep(0.1)
|
569 |
-
if
|
570 |
-
|
571 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
572 |
|
573 |
except Exception as e:
|
574 |
print(f"on_reaction_add Error: {e}")
|
|
|
3 |
import csv
|
4 |
import json
|
5 |
import time
|
6 |
+
import math
|
7 |
import random
|
8 |
import asyncio
|
9 |
import discord
|
|
|
45 |
# Dictionary to store user IDs and their corresponding unique strings
|
46 |
user_tokens = {}
|
47 |
|
48 |
+
EXPONENT = 3
|
49 |
+
|
50 |
|
51 |
""""""
|
52 |
XP_PER_MESSAGE = 10 # 100k messages = 1M exp = lvl 100
|
|
|
247 |
#asyncio.get_event_loop().run_forever()
|
248 |
|
249 |
|
250 |
+
def calculate_level(xp, n=EXPONENT):
|
251 |
+
return int(xp ** (1 / n))
|
252 |
|
253 |
|
254 |
+
def calculate_xp(old_xp, n=EXPONENT):
|
255 |
+
new_level = (old_xp ** (1 / 3)) ** n
|
256 |
+
return new_level
|
257 |
|
258 |
|
259 |
async def add_exp(member_id):
|
|
|
340 |
cell_value = str(cell_value)
|
341 |
if cell_value.startswith("L") and cell_value.endswith("L"):
|
342 |
cell_value_clipped = cell_value[1:-1]
|
343 |
+
isnt_samusenps = member_id != 981178585790423060
|
344 |
+
EXPONEND = 3 if isnt_samusenps else 3 - 5e-2 # give samu a boost :spinnyhat:
|
345 |
if cell_value_clipped == str(member_id): # str(member_id) needed, it is int by default
|
346 |
print("test4")
|
347 |
# if found, update that row...
|
|
|
358 |
|
359 |
# str -> int temporarily for adding
|
360 |
new_xp = int(old_xp) + XP_PER_MESSAGE
|
361 |
+
new_xp = calculate_xp(new_xp, EXPONEND)
|
362 |
|
363 |
total_exp = global_df.loc[index, 'total_exp']
|
364 |
hub_xp = global_df.loc[index, 'hub_exp']
|
|
|
382 |
total_exp = int(new_xp)
|
383 |
|
384 |
# total v
|
385 |
+
current_level = calculate_level(total_exp, EXPONEND)
|
386 |
|
387 |
# convert back to string + google sheet proofing
|
388 |
new_xp = str(new_xp)
|
|
|
553 |
invite_message = "Click to join our community org on the HF Hub!"
|
554 |
try:
|
555 |
if message.author.id not in bot_ids: # could change to if author does not have bot role (roleid)
|
556 |
+
if message.guild is not None: # can't earn exp from messaging in bot DMs, which is harder to track
|
557 |
+
print(f"adding exp from message {message.author}")
|
558 |
+
await add_exp(message.author.id)
|
559 |
+
await asyncio.sleep(0.1)
|
560 |
+
else:
|
561 |
+
print("Messaged in DM channel, skipping..")
|
562 |
+
await asyncio.sleep(0.1)
|
563 |
+
|
|
|
564 |
await bot.process_commands(message)
|
565 |
except Exception as e:
|
566 |
print(f"on_message Error: {e}")
|
567 |
|
568 |
+
|
569 |
@bot.event
|
570 |
async def on_reaction_add(reaction, user):
|
571 |
try:
|
572 |
if user.id not in bot_ids:
|
573 |
+
message = reaction.message
|
574 |
await asyncio.sleep(0.1)
|
575 |
+
if message.guild is not None: # can't earn exp from reacting in bot DMs, which is harder to track
|
576 |
+
if message.author.id != user.id: # can't earn while self-reacting, which is abuseable
|
577 |
+
print(f"adding exp from react {user}")
|
578 |
+
await add_exp(message.author.id)
|
579 |
+
await asyncio.sleep(0.1)
|
580 |
+
else:
|
581 |
+
print("Self-reacted, skipping..")
|
582 |
+
await asyncio.sleep(0.1)
|
583 |
+
else:
|
584 |
+
print("Reacted in DM channel, skipping..")
|
585 |
+
await asyncio.sleep(0.1)
|
586 |
|
587 |
except Exception as e:
|
588 |
print(f"on_reaction_add Error: {e}")
|