Spaces:
Running
Running
Fixed tree.command request timeout
Browse files- discord_bot.py +27 -27
- horde.py +3 -3
discord_bot.py
CHANGED
@@ -26,36 +26,36 @@ async def greet(interaction: discord.Interaction, name: str):
|
|
26 |
|
27 |
@tree.command(name="get-kudos", description="The amount of Kudos this user has.")
|
28 |
async def getKudos(interaction: discord.Interaction):
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
|
35 |
@tree.command(name="generate-status", description="Retrieve the status of an Asynchronous generation request.")
|
36 |
async def generateStatus(interaction: discord.Interaction, id: str):
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
|
60 |
@bot.command()
|
61 |
async def ping(ctx):
|
|
|
26 |
|
27 |
@tree.command(name="get-kudos", description="The amount of Kudos this user has.")
|
28 |
async def getKudos(interaction: discord.Interaction):
|
29 |
+
async with horde.getUserDetails() as details:
|
30 |
+
if "kudos" not in details:
|
31 |
+
await interaction.response.send_message(f'Error: {details["code"]} {details["reason"]} {details["rc"]}')
|
32 |
+
return
|
33 |
+
await interaction.response.send_message(f'The amount of Kudos this user has is {details["kudos"]}')
|
34 |
|
35 |
@tree.command(name="generate-status", description="Retrieve the status of an Asynchronous generation request.")
|
36 |
async def generateStatus(interaction: discord.Interaction, id: str):
|
37 |
+
async with horde.generateCheck(id) as details:
|
38 |
+
if "kudos" not in details:
|
39 |
+
await interaction.response.send_message(f'Check Error: {details["code"]} {details["reason"]} {details["rc"]}')
|
40 |
+
return
|
41 |
+
if bool(details["is_possible"]) == False:
|
42 |
+
await interaction.response.send_message("This generation is impossible.")
|
43 |
+
return
|
44 |
+
if bool(details["faulted"]) == True:
|
45 |
+
await interaction.response.send_message("This generation is faulted.")
|
46 |
+
return
|
47 |
+
if bool(details["done"]) == True:
|
48 |
+
async with horde.generateStatus(id) as generationDetail:
|
49 |
+
if "generations" not in generationDetail:
|
50 |
+
await interaction.response.send_message(f'Status Error: {generationDetail["code"]} {generationDetail["reason"]} {generationDetail["rc"]}')
|
51 |
+
for i in range(len(generationDetail["generations"])):
|
52 |
+
await interaction.response.send_message(generationDetail["generations"][i]["img"])
|
53 |
+
return
|
54 |
+
if int(details["processing"]) > 0:
|
55 |
+
total = int(details["finished"]) + int(details["processing"]) + int(details["queue_position"]) + int(details["restarted"]) + int(details["waiting"])
|
56 |
+
await interaction.response.send_message(f'Processing image: {details["processing"]}/{total}')
|
57 |
+
return
|
58 |
+
await interaction.response.send_message(f'Position in queue: {details["queue_position"]}, wait time: {details["wait_time"]}s')
|
59 |
|
60 |
@bot.command()
|
61 |
async def ping(ctx):
|
horde.py
CHANGED
@@ -34,15 +34,15 @@ def getResponseByPost(url):
|
|
34 |
"rc": response.rc
|
35 |
}
|
36 |
|
37 |
-
def getUserDetails():
|
38 |
url = f"{baseUrl}find_user"
|
39 |
return getResponseByGet(url)
|
40 |
|
41 |
-
def generateCheck(id):
|
42 |
url = f"{baseUrl}generate/check/{id}"
|
43 |
return getResponseByGet(url)
|
44 |
|
45 |
-
def generateStatus(id):
|
46 |
url = f"{baseUrl}generate/status/{id}"
|
47 |
return getResponseByGet(url)
|
48 |
|
|
|
34 |
"rc": response.rc
|
35 |
}
|
36 |
|
37 |
+
async def getUserDetails():
|
38 |
url = f"{baseUrl}find_user"
|
39 |
return getResponseByGet(url)
|
40 |
|
41 |
+
async def generateCheck(id):
|
42 |
url = f"{baseUrl}generate/check/{id}"
|
43 |
return getResponseByGet(url)
|
44 |
|
45 |
+
async def generateStatus(id):
|
46 |
url = f"{baseUrl}generate/status/{id}"
|
47 |
return getResponseByGet(url)
|
48 |
|