Spaces:
Running
on
CPU Upgrade
Running
on
CPU Upgrade
Update app.py
Browse files
app.py
CHANGED
|
@@ -2,6 +2,7 @@ import discord
|
|
| 2 |
import os
|
| 3 |
import threading
|
| 4 |
from discord.ext import commands
|
|
|
|
| 5 |
|
| 6 |
import gradio_client
|
| 7 |
import gradio as gr
|
|
@@ -11,14 +12,77 @@ DISCORD_TOKEN = os.environ.get("DISCORD_TOKEN", None)
|
|
| 11 |
intents = discord.Intents.all()
|
| 12 |
bot = commands.Bot(command_prefix='!', intents=intents)
|
| 13 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
@bot.event
|
| 15 |
async def on_message(message):
|
| 16 |
try:
|
| 17 |
if message.author != bot.user:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
|
| 19 |
except Exception as e:
|
| 20 |
print(f"Error: {e}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
|
|
|
|
| 22 |
DISCORD_TOKEN = os.environ.get("DISCORD_TOKEN", None)
|
| 23 |
def run_bot():
|
| 24 |
bot.run(DISCORD_TOKEN)
|
|
|
|
| 2 |
import os
|
| 3 |
import threading
|
| 4 |
from discord.ext import commands
|
| 5 |
+
import json
|
| 6 |
|
| 7 |
import gradio_client
|
| 8 |
import gradio as gr
|
|
|
|
| 12 |
intents = discord.Intents.all()
|
| 13 |
bot = commands.Bot(command_prefix='!', intents=intents)
|
| 14 |
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
""""""
|
| 20 |
+
XP_PER_MESSAGE = 10
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
""""""
|
| 29 |
+
@bot.event
|
| 30 |
+
async def on_ready():
|
| 31 |
+
print(f'Logged in as {bot.user.name}')
|
| 32 |
+
|
| 33 |
+
|
| 34 |
+
|
| 35 |
+
|
| 36 |
+
|
| 37 |
+
try:
|
| 38 |
+
with open('xp_data.json', 'r') as f:
|
| 39 |
+
xp_data = json.load(f)
|
| 40 |
+
except FileNotFoundError:
|
| 41 |
+
xp_data = {}
|
| 42 |
+
|
| 43 |
+
|
| 44 |
+
def save_xp_data():
|
| 45 |
+
with open('xp_data.json', 'w') as f:
|
| 46 |
+
json.dump(xp_data, f)
|
| 47 |
+
|
| 48 |
+
|
| 49 |
+
|
| 50 |
+
|
| 51 |
+
|
| 52 |
@bot.event
|
| 53 |
async def on_message(message):
|
| 54 |
try:
|
| 55 |
if message.author != bot.user:
|
| 56 |
+
"""AWAIT LEVEL ALGORITM OR SOMETHING (MULTIPLE FILES?)"""
|
| 57 |
+
author_id = str(message.author.id) # dictionary pairs (ID -> TOTAL XP)
|
| 58 |
+
xp_data.setdefault(author_id, 0) # default if it doesn't already exist
|
| 59 |
+
|
| 60 |
+
xp_data[author_id] += XP_PER_MESSAGE
|
| 61 |
+
save_xp_data()
|
| 62 |
+
|
| 63 |
+
await bot.process_commands(message)
|
| 64 |
|
| 65 |
except Exception as e:
|
| 66 |
print(f"Error: {e}")
|
| 67 |
+
|
| 68 |
+
|
| 69 |
+
|
| 70 |
+
# Calculate the level based on XP
|
| 71 |
+
def calculate_level(xp):
|
| 72 |
+
return int(xp ** 0.5)
|
| 73 |
+
|
| 74 |
+
|
| 75 |
+
@bot.command()
|
| 76 |
+
async def level(ctx):
|
| 77 |
+
author_id = str(ctx.author.id)
|
| 78 |
+
if author_id in xp_data:
|
| 79 |
+
xp = xp_data[author_id]
|
| 80 |
+
level = calculate_level(xp)
|
| 81 |
+
await ctx.send(f'You are at level {level} with {xp} XP.')
|
| 82 |
+
else:
|
| 83 |
+
await ctx.send('You have not earned any XP yet.')
|
| 84 |
|
| 85 |
+
""""""
|
| 86 |
DISCORD_TOKEN = os.environ.get("DISCORD_TOKEN", None)
|
| 87 |
def run_bot():
|
| 88 |
bot.run(DISCORD_TOKEN)
|