Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
@@ -1,24 +1,27 @@
|
|
1 |
-
import asyncio
|
2 |
import os
|
3 |
-
import
|
4 |
-
from
|
5 |
-
from
|
6 |
-
|
7 |
import datetime
|
8 |
import requests
|
9 |
-
import discord
|
10 |
import gradio as gr
|
11 |
import gradio_client as grc
|
12 |
-
|
13 |
-
|
14 |
-
from
|
15 |
-
from
|
16 |
|
17 |
event = Event()
|
18 |
|
19 |
DISCORD_TOKEN = os.getenv("DISCORD_TOKEN")
|
20 |
HF_TOKEN = os.getenv("HF_TOKEN")
|
21 |
|
|
|
|
|
|
|
|
|
|
|
22 |
async def wait(job):
|
23 |
while not job.done():
|
24 |
await asyncio.sleep(0.2)
|
@@ -36,11 +39,11 @@ def truncate_response(response: str) -> str:
|
|
36 |
else:
|
37 |
return response
|
38 |
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
async def uptime(ctx):
|
44 |
"""Displays the uptime of the bot."""
|
45 |
delta = datetime.datetime.utcnow() - bot.start_time
|
46 |
hours, remainder = divmod(int(delta.total_seconds()), 3600)
|
@@ -54,8 +57,11 @@ async def uptime(ctx):
|
|
54 |
|
55 |
await ctx.send(embed=embed)
|
56 |
|
57 |
-
@
|
58 |
-
|
|
|
|
|
|
|
59 |
"""Returns a random Bible verse."""
|
60 |
# Fetch a random Bible verse
|
61 |
bible_api_url = "https://labs.bible.org/api/?passage=random&type=json"
|
@@ -71,8 +77,11 @@ async def verse(ctx):
|
|
71 |
embed.set_footer(text="Created by Cosmos")
|
72 |
await ctx.send(embed=embed)
|
73 |
|
74 |
-
@
|
75 |
-
|
|
|
|
|
|
|
76 |
"""Returns a list of commands and bot information."""
|
77 |
# Get list of commands
|
78 |
command_list = [f"{command.name}: {command.help}" for command in bot.commands]
|
@@ -126,7 +135,6 @@ async def on_member_join(member):
|
|
126 |
|
127 |
await channel.send(embed=embed)
|
128 |
|
129 |
-
|
130 |
# running in thread
|
131 |
def run_bot():
|
132 |
if not DISCORD_TOKEN:
|
|
|
|
|
1 |
import os
|
2 |
+
import discord
|
3 |
+
from discord.ext import commands
|
4 |
+
from discord_slash import SlashCommand, SlashContext
|
5 |
+
from discord_slash.utils.manage_commands import create_option
|
6 |
import datetime
|
7 |
import requests
|
|
|
8 |
import gradio as gr
|
9 |
import gradio_client as grc
|
10 |
+
import asyncio
|
11 |
+
import threading
|
12 |
+
from threading import Event
|
13 |
+
from typing import Optional
|
14 |
|
15 |
event = Event()
|
16 |
|
17 |
DISCORD_TOKEN = os.getenv("DISCORD_TOKEN")
|
18 |
HF_TOKEN = os.getenv("HF_TOKEN")
|
19 |
|
20 |
+
# Initialize bot and slash commands
|
21 |
+
intents = discord.Intents.all()
|
22 |
+
bot = commands.Bot(command_prefix="$", intents=intents)
|
23 |
+
slash = SlashCommand(bot, sync_commands=True) # Sync commands on start-up
|
24 |
+
|
25 |
async def wait(job):
|
26 |
while not job.done():
|
27 |
await asyncio.sleep(0.2)
|
|
|
39 |
else:
|
40 |
return response
|
41 |
|
42 |
+
@slash.slash(
|
43 |
+
name="uptime",
|
44 |
+
description="Displays the uptime of the bot.",
|
45 |
+
)
|
46 |
+
async def uptime(ctx: SlashContext):
|
47 |
"""Displays the uptime of the bot."""
|
48 |
delta = datetime.datetime.utcnow() - bot.start_time
|
49 |
hours, remainder = divmod(int(delta.total_seconds()), 3600)
|
|
|
57 |
|
58 |
await ctx.send(embed=embed)
|
59 |
|
60 |
+
@slash.slash(
|
61 |
+
name="verse",
|
62 |
+
description="Returns a random Bible verse."
|
63 |
+
)
|
64 |
+
async def verse(ctx: SlashContext):
|
65 |
"""Returns a random Bible verse."""
|
66 |
# Fetch a random Bible verse
|
67 |
bible_api_url = "https://labs.bible.org/api/?passage=random&type=json"
|
|
|
77 |
embed.set_footer(text="Created by Cosmos")
|
78 |
await ctx.send(embed=embed)
|
79 |
|
80 |
+
@slash.slash(
|
81 |
+
name="cmds",
|
82 |
+
description="Returns a list of commands and bot information."
|
83 |
+
)
|
84 |
+
async def cmds(ctx: SlashContext):
|
85 |
"""Returns a list of commands and bot information."""
|
86 |
# Get list of commands
|
87 |
command_list = [f"{command.name}: {command.help}" for command in bot.commands]
|
|
|
135 |
|
136 |
await channel.send(embed=embed)
|
137 |
|
|
|
138 |
# running in thread
|
139 |
def run_bot():
|
140 |
if not DISCORD_TOKEN:
|