lunarflu HF Staff commited on
Commit
19308af
Β·
1 Parent(s): 1014a85

[reactions] custom emoji, channel check

Browse files
Files changed (1) hide show
  1. app.py +48 -36
app.py CHANGED
@@ -23,6 +23,7 @@ import shutil # for doing image movement magic
23
 
24
  #todo
25
  # 4 -> combined image
 
26
  # tasks for concurrent coroutines
27
  # ratelimits
28
 
@@ -194,7 +195,7 @@ async def deepfloydif(ctx, *, prompt: str):
194
  try:
195
  try:
196
  if await safetychecks(ctx): #βœ…
197
- await ctx.message.add_reaction('πŸ€–')
198
  dfif_command_message_id = ctx.message.id # we will use this in some magic later on
199
  thread = await ctx.message.create_thread(name=f'{ctx.author} DeepfloydIF Image Upscaling Thread ')
200
  # create thread -> send new message inside thread + combined_image -> add reactions -> dfif2
@@ -303,11 +304,18 @@ async def dfif2(index: int, stage_1_result_path, thread, dfif_command_message_id
303
  with open(result_path, 'rb') as f:
304
  await thread.send(f'Here is the upscaled image! :) ', file=discord.File(f, 'result.png'))
305
 
 
 
 
 
 
306
  # assuming dfif2 is always inside a thread, we can always exit the thread to find the channel with the original command,
307
  # which allows us to react confirm on that message.
308
  parent_channel = thread.parent
309
  dfif_command_message = await parent_channel.fetch_message(dfif_command_message_id)
310
- await dfif_command_message.add_reaction('βœ…')
 
 
311
  await thread.send(f"upscale posted")
312
  #await ctx.reply('Here is the result of the second stage', file=discord.File(f, 'result.png'))
313
  #await ctx.message.add_reaction('βœ…') need to fix this
@@ -325,7 +333,7 @@ async def dfif2(index: int, stage_1_result_path, thread, dfif_command_message_id
325
  #await ctx.message.add_reaction('❌')
326
  #----------------------------------------------------------------------------------------------------------------------------
327
  @bot.event
328
- async def on_reaction_add(reaction, user):
329
  try:
330
  # safety checks first ❌
331
  '''
@@ -351,38 +359,39 @@ async def on_reaction_add(reaction, user):
351
 
352
  '''
353
  if not user.bot:
354
- # 811235357663297546 = lunarflu
355
- if reaction.message.attachments:
356
- if user.id == 811235357663297546: # if user.id == reaction.message.mentions[0].id:
357
- # magic begins
358
- await reaction.message.channel.send("reaction detected")
359
- attachment = reaction.message.attachments[0]
360
- image_name = attachment.filename # named something like: tmpgtv4qjix1111269940599738479.png
361
- # remove .png first
362
- partialpathmessageid = image_name[:-4] # should be tmpgtv4qjix1111269940599738479
363
- # extract partialpath, messageid
364
- partialpath = partialpathmessageid[:11] # tmpgtv4qjix
365
- messageid = partialpathmessageid[11:] # 1111269940599738479
366
- # add /tmp/ to partialpath, save as new variable
367
- fullpath = "/tmp/" + partialpath # should be /tmp/tmpgtv4qjix
368
- await reaction.message.channel.send(f"fullpath extracted, {fullpath}")
369
- emoji = reaction.emoji
370
-
371
- if emoji == "1️⃣":
372
- index = 0
373
- elif emoji == "2️⃣":
374
- index = 1
375
- elif emoji == "3️⃣":
376
- index = 2
377
- elif emoji == "4️⃣":
378
- index = 3
379
- await reaction.message.channel.send(f"index extracted, {index}")
380
- index = index
381
- stage_1_result_path = fullpath
382
- thread = reaction.message.channel
383
- dfif_command_message_id = messageid
384
- await reaction.message.channel.send(f"calling dfif2")
385
- await dfif2(index, stage_1_result_path, thread, dfif_command_message_id)
 
386
 
387
  '''
388
 
@@ -414,7 +423,10 @@ async def on_reaction_add(reaction, user):
414
 
415
  #await ctx.reply('An error occured in stage 2') need to fix
416
  #await ctx.message.add_reaction('❌')
417
- #----------------------------------------------------------------------------------------------------------------------------
 
 
 
418
  def run_bot():
419
  bot.run(DISCORD_TOKEN)
420
 
 
23
 
24
  #todo
25
  # 4 -> combined image
26
+ # loading emoji? animated emojis?
27
  # tasks for concurrent coroutines
28
  # ratelimits
29
 
 
195
  try:
196
  try:
197
  if await safetychecks(ctx): #βœ…
198
+ await ctx.message.add_reaction('πŸ€–') # loading emoji?
199
  dfif_command_message_id = ctx.message.id # we will use this in some magic later on
200
  thread = await ctx.message.create_thread(name=f'{ctx.author} DeepfloydIF Image Upscaling Thread ')
201
  # create thread -> send new message inside thread + combined_image -> add reactions -> dfif2
 
304
  with open(result_path, 'rb') as f:
305
  await thread.send(f'Here is the upscaled image! :) ', file=discord.File(f, 'result.png'))
306
 
307
+ # using custom emoji that looks nicer
308
+ emoji_guild = thread.guild
309
+ confirm_emoji_id = 1098629085955113011
310
+ confirm_emoji = discord.utils.get(guild.emojis, id=emoji_id)
311
+
312
  # assuming dfif2 is always inside a thread, we can always exit the thread to find the channel with the original command,
313
  # which allows us to react confirm on that message.
314
  parent_channel = thread.parent
315
  dfif_command_message = await parent_channel.fetch_message(dfif_command_message_id)
316
+
317
+ # reacting to original !deepfloydif command + using a custom emoji to do it
318
+ await dfif_command_message.add_reaction(confirm_emoji)
319
  await thread.send(f"upscale posted")
320
  #await ctx.reply('Here is the result of the second stage', file=discord.File(f, 'result.png'))
321
  #await ctx.message.add_reaction('βœ…') need to fix this
 
333
  #await ctx.message.add_reaction('❌')
334
  #----------------------------------------------------------------------------------------------------------------------------
335
  @bot.event
336
+ async def on_reaction_add(reaction, user): # ctx = await bot.get_context(reaction.message)? could try later, might simplify
337
  try:
338
  # safety checks first ❌
339
  '''
 
359
 
360
  '''
361
  if not user.bot:
362
+ if reaction.message.channel.id == 1100458786826747945:
363
+ # 811235357663297546 = lunarflu
364
+ if reaction.message.attachments:
365
+ if user.id == 811235357663297546: # if user.id == reaction.message.mentions[0].id:
366
+ # magic begins
367
+ await reaction.message.channel.send("reaction detected")
368
+ attachment = reaction.message.attachments[0]
369
+ image_name = attachment.filename # named something like: tmpgtv4qjix1111269940599738479.png
370
+ # remove .png first
371
+ partialpathmessageid = image_name[:-4] # should be tmpgtv4qjix1111269940599738479
372
+ # extract partialpath, messageid
373
+ partialpath = partialpathmessageid[:11] # tmpgtv4qjix
374
+ messageid = partialpathmessageid[11:] # 1111269940599738479
375
+ # add /tmp/ to partialpath, save as new variable
376
+ fullpath = "/tmp/" + partialpath # should be /tmp/tmpgtv4qjix
377
+ await reaction.message.channel.send(f"fullpath extracted, {fullpath}")
378
+ emoji = reaction.emoji
379
+
380
+ if emoji == "1️⃣":
381
+ index = 0
382
+ elif emoji == "2️⃣":
383
+ index = 1
384
+ elif emoji == "3️⃣":
385
+ index = 2
386
+ elif emoji == "4️⃣":
387
+ index = 3
388
+ await reaction.message.channel.send(f"index extracted, {index}")
389
+ index = index
390
+ stage_1_result_path = fullpath
391
+ thread = reaction.message.channel
392
+ dfif_command_message_id = messageid
393
+ await reaction.message.channel.send(f"calling dfif2")
394
+ await dfif2(index, stage_1_result_path, thread, dfif_command_message_id)
395
 
396
  '''
397
 
 
423
 
424
  #await ctx.reply('An error occured in stage 2') need to fix
425
  #await ctx.message.add_reaction('❌')
426
+ #----------------------------------------------------------------------------------------------------------------------------
427
+ async def safetychecks(ctx):
428
+
429
+
430
  def run_bot():
431
  bot.run(DISCORD_TOKEN)
432