not-lain commited on
Commit
d971fec
·
1 Parent(s): 463123f

Synced repo using 'sync_with_huggingface' Github Action

Browse files
Files changed (2) hide show
  1. app.py +37 -0
  2. requirements.txt +5 -1
app.py CHANGED
@@ -1,5 +1,42 @@
1
  import gradio as gr
 
 
 
 
 
 
2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3
 
4
  with gr.Blocks() as iface :
5
  gr.Markdown("# welcome to Tonic-bot")
 
1
  import gradio as gr
2
+ import dotenv
3
+ import discord
4
+ import os
5
+ import threading
6
+ from threading import Event
7
+ event = Event()
8
 
9
+ dotenv.load_dotenv()
10
+
11
+ DISCORD_TOKEN = os.getenv("DISCORD_TOKEN")
12
+
13
+ intents = discord.Intents.default()
14
+ intents.message_content = True
15
+ bot = discord.Bot(intents=intents)
16
+
17
+
18
+ @bot.event
19
+ async def on_ready():
20
+ print(f"logged as {bot.user}")
21
+ event.set()
22
+
23
+
24
+ @bot.slash_command(name='ping',description='ping')
25
+ async def ping(ctx):
26
+ await ctx.respond(f"{bot.latency*1000:.0f}ms")
27
+
28
+
29
+ # running in thread
30
+ def run_bot():
31
+ if not DISCORD_TOKEN:
32
+ print("DISCORD_TOKEN NOT SET")
33
+ event.set()
34
+ else:
35
+ bot.run(DISCORD_TOKEN)
36
+
37
+
38
+ threading.Thread(target=run_bot).start()
39
+ event.wait()
40
 
41
  with gr.Blocks() as iface :
42
  gr.Markdown("# welcome to Tonic-bot")
requirements.txt CHANGED
@@ -1 +1,5 @@
1
- gradio
 
 
 
 
 
1
+ gradio
2
+ python-dotenv
3
+ py-cord
4
+ gradio_client
5
+ asyncio