From 1234d6c55555c3701a689a5da3d2b1e0761882fe Mon Sep 17 00:00:00 2001 From: zoltan Date: Sat, 14 Oct 2023 03:53:59 +0000 Subject: [PATCH] change work request function to work with new ipfs logic --- skynet/frontend/discord/__init__.py | 40 ++++++++++++----------------- skynet/frontend/discord/utils.py | 11 +++++--- 2 files changed, 24 insertions(+), 27 deletions(-) diff --git a/skynet/frontend/discord/__init__.py b/skynet/frontend/discord/__init__.py index 66bde29..74675d7 100644 --- a/skynet/frontend/discord/__init__.py +++ b/skynet/frontend/discord/__init__.py @@ -265,7 +265,8 @@ class SkynetDiscordFrontend: results[link] = png_img except UnidentifiedImageError: - logging.warning(f'couldn\'t get ipfs binary data at {link}!') + logging.warning( + f'couldn\'t get ipfs binary data at {link}!') tasks = [ get_and_set_results(ipfs_link), @@ -281,32 +282,25 @@ class SkynetDiscordFrontend: png_img = results[ipfs_link] if not png_img: - await self.update_status_message( - status_msg, - caption, - reply_markup=build_redo_menu(), - parse_mode='HTML' - ) + logging.error(f'couldn\'t get ipfs hosted image at {ipfs_link}!') + embed.add_field( + name='Error', value=f'couldn\'t get ipfs hosted image [**here**]({ipfs_link})!') + await message.edit(embed=embed, view=SkynetView(self)) return True # reword this function, may not need caption caption, embed = generate_reply_caption( - user, params, tx_hash, worker, reward) + user, params, tx_hash, worker, reward, self.explorer_domain) - if not resp or resp.status_code != 200: - logging.error(f'couldn\'t get ipfs hosted image at {ipfs_link}!') - embed.add_field(name='Error', value=f'couldn\'t get ipfs hosted image [**here**]({ipfs_link})!') - await message.edit(embed=embed, view=SkynetView(self)) - else: - logging.info(f'success! sending generated image') - await message.delete() - if file_id: # img2img - embed.set_thumbnail( - url='https://ipfs.skygpu.net/ipfs/' + binary_data + '/image.png') - embed.set_image(url=ipfs_link) - await send(embed=embed, view=SkynetView(self)) - else: # txt2img - embed.set_image(url=ipfs_link) - await send(embed=embed, view=SkynetView(self)) + logging.info(f'success! sending generated image') + await message.delete() + if file_id: # img2img + embed.set_thumbnail( + url='https://ipfs.skygpu.net/ipfs/' + binary_data + '/image.png') + embed.set_image(url=ipfs_link) + await send(embed=embed, view=SkynetView(self)) + else: # txt2img + embed.set_image(url=ipfs_link) + await send(embed=embed, view=SkynetView(self)) return True diff --git a/skynet/frontend/discord/utils.py b/skynet/frontend/discord/utils.py index 6156384..36ac820 100644 --- a/skynet/frontend/discord/utils.py +++ b/skynet/frontend/discord/utils.py @@ -32,7 +32,8 @@ class SKYExceptionHandler(ExceptionHandler): def build_redo_menu(): - btn_redo = InlineKeyboardButton("Redo", callback_data=json.dumps({'method': 'redo'})) + btn_redo = InlineKeyboardButton( + "Redo", callback_data=json.dumps({'method': 'redo'})) inline_keyboard = InlineKeyboardMarkup() inline_keyboard.add(btn_redo) return inline_keyboard @@ -42,7 +43,7 @@ def prepare_metainfo_caption(user, worker: str, reward: str, meta: dict, embed) prompt = meta["prompt"] if len(prompt) > 256: prompt = prompt[:256] - + gen_str = f'generated by {user.name}\n' gen_str += f'performed by {worker}\n' gen_str += f'reward: {reward}\n' @@ -89,7 +90,8 @@ def generate_reply_caption( url=f'https://{explorer_domain}/v2/explore/transaction/{tx_hash}', color=discord.Color.blue()) - meta_info = prepare_metainfo_caption(user, worker, reward, params, explorer_link) + meta_info = prepare_metainfo_caption( + user, worker, reward, params, explorer_link) # why do we have this? final_msg = '\n'.join([ @@ -98,7 +100,7 @@ def generate_reply_caption( f'PARAMETER INFO:\n{meta_info}' ]) - final_msg = '\n'.join([ + final_msg += '\n'.join([ # f'***{explorer_link}***', f'{meta_info}' ]) @@ -112,6 +114,7 @@ async def get_global_config(cleos): return (await cleos.aget_table( 'telos.gpu', 'telos.gpu', 'config'))[0] + async def get_user_nonce(cleos, user: str): return (await cleos.aget_table( 'telos.gpu', 'telos.gpu', 'users',