lunarflu HF staff commited on
Commit
0aa104b
1 Parent(s): 4024d3d

hybrid command

Browse files
Files changed (1) hide show
  1. app.py +43 -19
app.py CHANGED
@@ -12,8 +12,20 @@ from gradio_client import Client
12
 
13
 
14
  DISCORD_TOKEN = os.environ.get("DISCORD_TOKEN", None)
15
- intents = discord.Intents.all()
16
- bot = commands.Bot(command_prefix='!', intents=intents)
 
 
 
 
 
 
 
 
 
 
 
 
17
 
18
  XP_PER_MESSAGE = 10
19
 
@@ -66,19 +78,23 @@ def calculate_level(xp):
66
 
67
  @bot.command()
68
  async def level(ctx):
69
- global xp_data
70
- print(ctx.author.id)
71
- print(ctx.author.mention)
72
- if ctx.author.id == 811235357663297546: # lunarflu
73
- if ctx.author.id in xp_data:
74
-
75
- xp = xp_data[ctx.author.id]
76
- level = calculate_level(xp)
 
 
 
 
 
 
77
 
78
- await ctx.send(f'You are at level {level} with {xp} total XP.')
79
- # progress bar with ascii? could be nice, easy
80
- else:
81
- await ctx.send('You have not earned any XP yet.')
82
 
83
 
84
  @bot.command()
@@ -132,9 +148,17 @@ async def load_xp(ctx):
132
 
133
  """"""
134
  def run_bot():
135
- bot.run(DISCORD_TOKEN)
 
 
136
  threading.Thread(target=run_bot).start()
137
- def greet(name):
138
- return "Hello " + name + "!"
139
- demo = gr.Interface(fn=greet, inputs="text", outputs="text")
140
- demo.launch()
 
 
 
 
 
 
 
12
 
13
 
14
  DISCORD_TOKEN = os.environ.get("DISCORD_TOKEN", None)
15
+ MY_GUILD_ID = 879548962464493619
16
+
17
+ class Bot(commands.Bot):
18
+ """This structure allows slash commands to work instantly."""
19
+
20
+ def __init__(self):
21
+ super().__init__(command_prefix="/", intents=discord.Intents.all())
22
+
23
+ async def setup_hook(self):
24
+ await self.tree.sync(guild=discord.Object(MY_GUILD_ID))
25
+ print(f"Synced slash commands for {self.user}.")
26
+
27
+
28
+ bot = Bot()
29
 
30
  XP_PER_MESSAGE = 10
31
 
 
78
 
79
  @bot.command()
80
  async def level(ctx):
81
+ try:
82
+ global xp_data
83
+ print(ctx.author.id)
84
+ print(ctx.author.mention)
85
+ if ctx.author.id == 811235357663297546: # lunarflu
86
+ if ctx.author.id in xp_data:
87
+
88
+ xp = xp_data[ctx.author.id]
89
+ level = calculate_level(xp)
90
+
91
+ await ctx.send(f'You are at level {level} with {xp} total XP.')
92
+ # progress bar with ascii? could be nice, easy
93
+ else:
94
+ await ctx.send('You have not earned any XP yet.')
95
 
96
+ except Exception as e:
97
+ print(f"Error: {e}")
 
 
98
 
99
 
100
  @bot.command()
 
148
 
149
  """"""
150
  def run_bot():
151
+ client.run(DISCORD_TOKEN)
152
+
153
+
154
  threading.Thread(target=run_bot).start()
155
+ """This allows us to run the Discord bot in a Python thread"""
156
+ with gr.Blocks() as demo:
157
+ gr.Markdown("""
158
+ # Huggingbots Server
159
+ This space hosts the huggingbots discord bot.
160
+ Currently supported models are Falcon and DeepfloydIF
161
+ """)
162
+ demo.queue(concurrency_count=100)
163
+ demo.queue(max_size=100)
164
+ demo.launch()