Spaces:
Running
on
CPU Upgrade
Running
on
CPU Upgrade
File size: 2,623 Bytes
7187a61 6d949e0 ee7844e 7187a61 6d949e0 a5603d3 6d949e0 7187a61 a5603d3 6c5f294 6d949e0 714224b 6d949e0 6c5f294 6d949e0 6c5f294 6d949e0 0aa83ad 6d949e0 ee7844e 6d949e0 0aa83ad 6d949e0 6c5f294 6d949e0 6c5f294 6d949e0 714224b 6d949e0 2eddccf 714224b 6d949e0 6c5f294 7187a61 79a1edd 6d949e0 6c5f294 d2beb75 6d949e0 d2beb75 6d949e0 d2beb75 79a1edd 6d949e0 3b06990 79a1edd 7187a61 6d949e0 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 |
import os
import threading
import discord
import matplotlib.pyplot as plt
from io import BytesIO
import gradio_client
import gradio as gr
from gradio_client import Client
import json
import time
from discord import app_commands
from discord.ext import commands
# HF GUILD SETTINGS
MY_GUILD_ID = 879548962464493619
MY_GUILD = discord.Object(id=MY_GUILD_ID)
DISCORD_TOKEN = os.environ.get("DISCORD_TOKEN", None)
class Bot(commands.Bot):
"""This structure allows slash commands to work instantly."""
def __init__(self):
super().__init__(command_prefix="/", intents=discord.Intents.all())
async def setup_hook(self):
await self.tree.sync(guild=discord.Object(MY_GUILD_ID))
print(f"Synced slash commands for {self.user}.")
client = Bot()
XP_PER_MESSAGE = 10
xp_data = {}
@client.event
async def on_ready():
print(f"Logged in as {client.user} (ID: {client.user.id})")
print("------")
@client.event
async def on_message(message):
try:
global xp_data
if message.author.bot:
return
if message.author.id not in xp_data:
xp_data[message.author.id] = 0
old = xp_data[message.author.id]
new = old + XP_PER_MESSAGE
xp_data[message.author.id] = new
level = calculate_level(new)
print(f"{message.author} xp: {xp_data[message.author.id]}")
print(f"{message.author} level: {level}")
print(f"xp_data: {xp_data}")
except Exception as e:
print(f"Error: {e}")
def calculate_level(xp):
return int(xp ** (1.0 / 3.0)) # 100k messages = lvl 100, good for super long term plan
@client.command()
async def level(ctx):
global xp_data
print(ctx.author.id)
print(ctx.author.mention)
if ctx.author.id == 811235357663297546:
if ctx.author.id in xp_data:
print(f"{ctx.author} is in xp_data")
xp = xp_data[ctx.author.id]
level = calculate_level(xp)
await ctx.send(f'You are at level {level} with {xp} total XP.')
# progress bar with ascii? could be nice, easy
else:
await ctx.send('You have not earned any XP yet.')
def run_bot():
client.run(DISCORD_TOKEN)
threading.Thread(target=run_bot).start()
"""This allows us to run the Discord bot in a Python thread"""
with gr.Blocks() as demo:
gr.Markdown("""
# Huggingbots Server
This space hosts the huggingbots discord bot.
Currently supported models are Falcon and DeepfloydIF
""")
demo.queue(concurrency_count=100)
demo.queue(max_size=100)
demo.launch() |