⏳,❌ (1+2)
Browse filesemoji_guild = ctx.guild
failure_emoji_id = 1098628957521313892
failure_emoji = discord.utils.get(emoji_guild.emojis, id=failure_emoji_id)
app.py
CHANGED
@@ -64,15 +64,19 @@ async def on_ready():
|
|
64 |
async def commands(ctx):
|
65 |
try:
|
66 |
if await safetychecks(ctx):
|
67 |
-
await ctx.reply(f"Use !deepfloydif [prompt], !jojo !
|
68 |
except Exception as e:
|
69 |
print(f"Error: unable to help :(")
|
70 |
#---------------------------------------------------------------------------------------------------------------------------------------------
|
71 |
async def safetychecks(ctx):
|
72 |
try:
|
|
|
|
|
|
|
|
|
73 |
if ctx.author.bot:
|
74 |
print(f"Error: The bot is not allowed to use its own commands.")
|
75 |
-
await ctx.message.add_reaction(
|
76 |
return False
|
77 |
|
78 |
#✅✅ check if the bot is offline
|
@@ -80,9 +84,9 @@ async def safetychecks(ctx):
|
|
80 |
bot_member = ctx.guild.get_member(bot.user.id)
|
81 |
if any(role.id == offline_bot_role_id for role in bot_member.roles):
|
82 |
print(f"Error: {ctx.author} The bot is offline or under maintenance. (Remove the offline-bot role to bring it online)")
|
83 |
-
thread = await ctx.message.create_thread(name=f'
|
84 |
await thread.send(f"Error: {ctx.author.mention} The bot is offline or under maintenance. (Remove the offline-bot role to bring it online)")
|
85 |
-
await ctx.message.add_reaction(
|
86 |
return False
|
87 |
|
88 |
#✅✅ check if the command is in the allowed channel(s)
|
@@ -91,9 +95,9 @@ async def safetychecks(ctx):
|
|
91 |
channel_ids = [bot_test, testing_the_bot]
|
92 |
if ctx.channel.id not in channel_ids:
|
93 |
print(f"{ctx.author}, commands are not permitted in {ctx.channel}")
|
94 |
-
thread = await ctx.message.create_thread(name=f'
|
95 |
await thread.send(f"Error: {ctx.author.mention} commands are not permitted in {ctx.channel}")
|
96 |
-
await ctx.message.add_reaction(
|
97 |
return False
|
98 |
|
99 |
#✅✅ check if the user has the required role(s)
|
@@ -110,9 +114,9 @@ async def safetychecks(ctx):
|
|
110 |
has_allowed_role = any(role.id in allowed_role_ids for role in user_roles)
|
111 |
if not has_allowed_role:
|
112 |
print(f"Error: {ctx.author} does not have any of the required roles to use that command.")
|
113 |
-
thread = await ctx.message.create_thread(name=f'
|
114 |
await thread.send(f"Error: {ctx.author.mention} does not have any of the required roles to use that command.")
|
115 |
-
await ctx.message.add_reaction(
|
116 |
return False
|
117 |
|
118 |
|
@@ -262,7 +266,7 @@ def inference(prompt):
|
|
262 |
|
263 |
return [stage_1_results, stage_1_param_path, stage_1_result_path]
|
264 |
#----------------------------------------------------------------------------------------------------------------------------------------------
|
265 |
-
# deepfloydif stage 2 upscaling
|
266 |
def inference2(index, stage_1_result_path):
|
267 |
selected_index_for_stage_2 = index
|
268 |
seed_2 = 0
|
@@ -282,10 +286,14 @@ async def react1234(reaction_emojis, combined_image_dfif):
|
|
282 |
# Stage 1 ✅
|
283 |
@bot.command()
|
284 |
async def deepfloydif(ctx, *, prompt: str):
|
|
|
|
|
|
|
285 |
try:
|
286 |
try:
|
287 |
if await safetychecks(ctx): #✅
|
288 |
-
await ctx.message.add_reaction('🤖')
|
|
|
289 |
dfif_command_message_id = ctx.message.id # we will use this in some magic later on
|
290 |
thread = await ctx.message.create_thread(name=f'{ctx.author} DeepfloydIF Image Upscaling Thread ')
|
291 |
# create thread -> send new message inside thread + combined_image -> add reactions -> dfif2
|
@@ -306,8 +314,10 @@ async def deepfloydif(ctx, *, prompt: str):
|
|
306 |
|
307 |
except Exception as e:
|
308 |
print(f"Error: {e}")
|
309 |
-
|
310 |
-
await ctx.
|
|
|
|
|
311 |
|
312 |
#generation✅-------------------------------------------------------
|
313 |
try:
|
@@ -326,8 +336,10 @@ async def deepfloydif(ctx, *, prompt: str):
|
|
326 |
|
327 |
except Exception as e:
|
328 |
print(f"Error: {e}")
|
329 |
-
|
330 |
-
await ctx.
|
|
|
|
|
331 |
#posting images✅----------------------------------------------------------------
|
332 |
try:
|
333 |
#await thread.send(f'✅combining images...')
|
@@ -382,14 +394,18 @@ async def deepfloydif(ctx, *, prompt: str):
|
|
382 |
|
383 |
except Exception as e:
|
384 |
print(f"Error: {e}")
|
385 |
-
|
386 |
-
await ctx.
|
|
|
|
|
387 |
|
388 |
#deepfloydif try/except
|
389 |
except Exception as e:
|
390 |
print(f"Error: {e}")
|
391 |
-
|
392 |
-
await ctx.
|
|
|
|
|
393 |
|
394 |
#----------------------------------------------------------------------------------------------------------------------------
|
395 |
# Stage 2 ✅
|
@@ -439,16 +455,15 @@ async def dfif2(index: int, stage_1_result_path, thread, dfif_command_message_id
|
|
439 |
failure_emoji = discord.utils.get(emoji_guild.emojis, id=failure_emoji_id)
|
440 |
parent_channel = thread.parent
|
441 |
dfif_command_message = await parent_channel.fetch_message(dfif_command_message_id)
|
442 |
-
await dfif_command_message.add_reaction(failure_emoji)
|
443 |
-
|
444 |
-
#await ctx.message.add_reaction('❌')
|
445 |
#----------------------------------------------------------------------------------------------------------------------------
|
446 |
-
# react detector for stage 2
|
447 |
@bot.event
|
448 |
async def on_reaction_add(reaction, user): # ctx = await bot.get_context(reaction.message)? could try later, might simplify
|
449 |
try:
|
450 |
#ctx = await bot.get_context(reaction.message)
|
451 |
-
# safety checks first
|
452 |
thread = reaction.message.channel
|
453 |
threadparentid = thread.parent.id
|
454 |
|
@@ -488,40 +503,16 @@ async def on_reaction_add(reaction, user): # ctx = await bot.get_context(reac
|
|
488 |
ctx = await bot.get_context(reaction.message)
|
489 |
#await reaction.message.channel.send(f"✅calling dfif2")
|
490 |
await dfif2(index, stage_1_result_path, thread, dfif_command_message_id)
|
491 |
-
|
492 |
-
'''
|
493 |
-
|
494 |
-
if reaction.message.attachments:
|
495 |
-
if user.id == reaction.message.mentions[0].id: # all we care about is upscaling whatever image this is
|
496 |
-
|
497 |
-
# magic begins
|
498 |
-
attachment = reaction.message.attachments[0]
|
499 |
-
image_name = attachment.filename
|
500 |
-
# we know image_name will be something like 1tmpgtv4qjix.png
|
501 |
-
# remove .png first
|
502 |
-
indexpartialpath = image_name[:-4] # should be 1tmpgtv4qjix
|
503 |
-
# extract index as an integer (dfif2 needs integer)
|
504 |
-
index = int(indexpartialpath[0]) - 1# should be 1
|
505 |
-
# extract partialpath
|
506 |
-
partialpath = indexpartialpath[1:] # should be tmpgtv4qjix
|
507 |
-
# add /tmp/ to partialpath, save as new variable
|
508 |
-
fullpath = "/tmp/" + partialpath # should be /tmp/tmpgtv4qjix
|
509 |
-
|
510 |
-
stage_1_result_path = fullpath
|
511 |
-
index = index
|
512 |
-
await dfif2(index, stage_1_result_path, thread)
|
513 |
-
|
514 |
-
'''
|
515 |
|
516 |
-
|
517 |
except Exception as e:
|
518 |
print(f"Error: {e}")
|
519 |
-
|
520 |
-
|
521 |
-
|
|
|
|
|
522 |
#----------------------------------------------------------------------------------------------------------------------------
|
523 |
|
524 |
-
|
525 |
def run_bot():
|
526 |
bot.run(DISCORD_TOKEN)
|
527 |
|
|
|
64 |
async def commands(ctx):
|
65 |
try:
|
66 |
if await safetychecks(ctx):
|
67 |
+
await ctx.reply(f"Use !deepfloydif [prompt], !jojo !spidey or !sketch. Have fun! 🤗💖")
|
68 |
except Exception as e:
|
69 |
print(f"Error: unable to help :(")
|
70 |
#---------------------------------------------------------------------------------------------------------------------------------------------
|
71 |
async def safetychecks(ctx):
|
72 |
try:
|
73 |
+
emoji_guild = ctx.guild
|
74 |
+
failure_emoji_id = 1098628957521313892
|
75 |
+
failure_emoji = discord.utils.get(emoji_guild.emojis, id=failure_emoji_id)
|
76 |
+
|
77 |
if ctx.author.bot:
|
78 |
print(f"Error: The bot is not allowed to use its own commands.")
|
79 |
+
await ctx.message.add_reaction(failure_emoji)
|
80 |
return False
|
81 |
|
82 |
#✅✅ check if the bot is offline
|
|
|
84 |
bot_member = ctx.guild.get_member(bot.user.id)
|
85 |
if any(role.id == offline_bot_role_id for role in bot_member.roles):
|
86 |
print(f"Error: {ctx.author} The bot is offline or under maintenance. (Remove the offline-bot role to bring it online)")
|
87 |
+
thread = await ctx.message.create_thread(name=f'Offline Error')
|
88 |
await thread.send(f"Error: {ctx.author.mention} The bot is offline or under maintenance. (Remove the offline-bot role to bring it online)")
|
89 |
+
await ctx.message.add_reaction(failure_emoji)
|
90 |
return False
|
91 |
|
92 |
#✅✅ check if the command is in the allowed channel(s)
|
|
|
95 |
channel_ids = [bot_test, testing_the_bot]
|
96 |
if ctx.channel.id not in channel_ids:
|
97 |
print(f"{ctx.author}, commands are not permitted in {ctx.channel}")
|
98 |
+
thread = await ctx.message.create_thread(name=f'Channel Error')
|
99 |
await thread.send(f"Error: {ctx.author.mention} commands are not permitted in {ctx.channel}")
|
100 |
+
await ctx.message.add_reaction(failure_emoji)
|
101 |
return False
|
102 |
|
103 |
#✅✅ check if the user has the required role(s)
|
|
|
114 |
has_allowed_role = any(role.id in allowed_role_ids for role in user_roles)
|
115 |
if not has_allowed_role:
|
116 |
print(f"Error: {ctx.author} does not have any of the required roles to use that command.")
|
117 |
+
thread = await ctx.message.create_thread(name=f'Perms Error')
|
118 |
await thread.send(f"Error: {ctx.author.mention} does not have any of the required roles to use that command.")
|
119 |
+
await ctx.message.add_reaction(failure_emoji)
|
120 |
return False
|
121 |
|
122 |
|
|
|
266 |
|
267 |
return [stage_1_results, stage_1_param_path, stage_1_result_path]
|
268 |
#----------------------------------------------------------------------------------------------------------------------------------------------
|
269 |
+
# deepfloydif stage 2 upscaling ✅
|
270 |
def inference2(index, stage_1_result_path):
|
271 |
selected_index_for_stage_2 = index
|
272 |
seed_2 = 0
|
|
|
286 |
# Stage 1 ✅
|
287 |
@bot.command()
|
288 |
async def deepfloydif(ctx, *, prompt: str):
|
289 |
+
emoji_guild = ctx.guild
|
290 |
+
failure_emoji_id = 1098628957521313892
|
291 |
+
failure_emoji = discord.utils.get(emoji_guild.emojis, id=failure_emoji_id)
|
292 |
try:
|
293 |
try:
|
294 |
if await safetychecks(ctx): #✅
|
295 |
+
await ctx.message.add_reaction('🤖')
|
296 |
+
await ctx.message.add_reaction('⏳')
|
297 |
dfif_command_message_id = ctx.message.id # we will use this in some magic later on
|
298 |
thread = await ctx.message.create_thread(name=f'{ctx.author} DeepfloydIF Image Upscaling Thread ')
|
299 |
# create thread -> send new message inside thread + combined_image -> add reactions -> dfif2
|
|
|
314 |
|
315 |
except Exception as e:
|
316 |
print(f"Error: {e}")
|
317 |
+
thread = await ctx.message.create_thread(name=f'DFIF1 Error')
|
318 |
+
await thread.send(f"{ctx.author.mention} Error during stage 1 pre-generation.")
|
319 |
+
await ctx.message.remove_reaction('⏳')
|
320 |
+
await ctx.message.add_reaction(failure_emoji)
|
321 |
|
322 |
#generation✅-------------------------------------------------------
|
323 |
try:
|
|
|
336 |
|
337 |
except Exception as e:
|
338 |
print(f"Error: {e}")
|
339 |
+
thread = await ctx.message.create_thread(name=f'Generation Error')
|
340 |
+
await thread.send(f"{ctx.author.mention} Error during stage 1 generation.")
|
341 |
+
await ctx.message.remove_reaction('⏳')
|
342 |
+
await ctx.message.add_reaction(failure_emoji)
|
343 |
#posting images✅----------------------------------------------------------------
|
344 |
try:
|
345 |
#await thread.send(f'✅combining images...')
|
|
|
394 |
|
395 |
except Exception as e:
|
396 |
print(f"Error: {e}")
|
397 |
+
thread = await ctx.message.create_thread(name=f'Posting Error')
|
398 |
+
await thread.send(f"{ctx.author.mention} Encountered error while posting combined image in thread.")
|
399 |
+
await ctx.message.remove_reaction('⏳')
|
400 |
+
await ctx.message.add_reaction(failure_emoji)
|
401 |
|
402 |
#deepfloydif try/except
|
403 |
except Exception as e:
|
404 |
print(f"Error: {e}")
|
405 |
+
thread = await ctx.message.create_thread(name=f'deepfloydif Error')
|
406 |
+
await thread.send(f"{ctx.author.mention} Overall error with deepfloydif.")
|
407 |
+
await ctx.message.remove_reaction('⏳')
|
408 |
+
await ctx.message.add_reaction(failure_emoji)
|
409 |
|
410 |
#----------------------------------------------------------------------------------------------------------------------------
|
411 |
# Stage 2 ✅
|
|
|
455 |
failure_emoji = discord.utils.get(emoji_guild.emojis, id=failure_emoji_id)
|
456 |
parent_channel = thread.parent
|
457 |
dfif_command_message = await parent_channel.fetch_message(dfif_command_message_id)
|
458 |
+
await dfif_command_message.add_reaction(failure_emoji)
|
459 |
+
await thread.send(f"Error during stage 2 upscaling.")
|
|
|
460 |
#----------------------------------------------------------------------------------------------------------------------------
|
461 |
+
# react detector for stage 2 ✅
|
462 |
@bot.event
|
463 |
async def on_reaction_add(reaction, user): # ctx = await bot.get_context(reaction.message)? could try later, might simplify
|
464 |
try:
|
465 |
#ctx = await bot.get_context(reaction.message)
|
466 |
+
# safety checks first ✅
|
467 |
thread = reaction.message.channel
|
468 |
threadparentid = thread.parent.id
|
469 |
|
|
|
503 |
ctx = await bot.get_context(reaction.message)
|
504 |
#await reaction.message.channel.send(f"✅calling dfif2")
|
505 |
await dfif2(index, stage_1_result_path, thread, dfif_command_message_id)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
506 |
|
|
|
507 |
except Exception as e:
|
508 |
print(f"Error: {e}")
|
509 |
+
emoji_guild = reaction.message.guild
|
510 |
+
failure_emoji_id = 1098628957521313892
|
511 |
+
failure_emoji = discord.utils.get(emoji_guild.emojis, id=failure_emoji_id)
|
512 |
+
await reaction.message.add_reaction(failure_emoji)
|
513 |
+
await reaction.message.channel.send(f"Error during reactions.")
|
514 |
#----------------------------------------------------------------------------------------------------------------------------
|
515 |
|
|
|
516 |
def run_bot():
|
517 |
bot.run(DISCORD_TOKEN)
|
518 |
|