From 013fd615624d02ca461ad0d0f7cc237eb1db0101 Mon Sep 17 00:00:00 2001 From: gmorks Date: Tue, 28 Jan 2025 00:20:06 -0600 Subject: [PATCH] Removed __pycache__ from the repository --- __pycache__/__init__.cpython-310.pyc | Bin 275 -> 0 bytes __pycache__/send_to_discord.cpython-310.pyc | Bin 4360 -> 0 bytes send_to_discord.py | 63 +++++++++++++++++++- 3 files changed, 61 insertions(+), 2 deletions(-) delete mode 100644 __pycache__/__init__.cpython-310.pyc delete mode 100644 __pycache__/send_to_discord.cpython-310.pyc diff --git a/__pycache__/__init__.cpython-310.pyc b/__pycache__/__init__.cpython-310.pyc deleted file mode 100644 index b094a32cdd47c03bc26d1dd3cd1ce6ee510e877b..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 275 zcmd1j<>g`k0>1N;()xk)V-N=!FabFZKwK;XBvKes7;_kM8KW3;nWC5&8B&;1nA4e} zm{VAS88lg6G6I!oGTjpP^LKHLclL1%4vzPA3<&V_a}T~H1r~Ji3=Z&djEwhl^mT>H z6@lz1Vg?d^nk-TL#i@BI@g@23DVfE|`9&!R*<0-K@rgM(@$oAeidaEfK*TRgH>()u z{M@w4P|uj;(&Cc*-1xlwl+r+IrhSsfXskYFmuPjL;qw z+67f-q0@HMykfhk%2KzrHhi?`&<)MZ2jf?*Dh^ci3i=i zTdP~0QIf_3H;TER9Clt<_anX$&&;%ypyj5q%X70W4fka6a?g+adqeTwJSj|?>-W!S zyCV_G^3g_V+ehP@(c>d7swh4gzut~gAgdt`v9MkR%#zG&JOg6p0Q~m(+?QaGS+tp zpajoP4PeA>j!T_5>IS_f7`|PY-KBU5n~DMiPULjGFx>V!w;M%S$tMpzk@!MZuBfH0 zyrsv9H0eUbX)KflSU&OwJ{`Urgud%aQ}`a225zfih*xNmo$n{hd8zL6nDGR`oOVnc z2#1}9z2@2Y&F5L{_{}|IIfBnq%Uwi+7=#-=9TqVH*42--tVafi({ksL&Wn$9Sge%O z)s5xrE7JBOZ#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discord.py b/send_to_discord.py index 2b6b84e..1bbee03 100644 --- a/send_to_discord.py +++ b/send_to_discord.py @@ -10,8 +10,28 @@ import folder_paths import configparser class PreviewImageWithDiscord: + """ + A class to handle the preview image generation and sending it to Discord via webhook. + + Attributes: + output_dir (str): The directory where temporary images are stored. + type (str): The type of the generated images, default is 'temp'. + prefix_append (str): A random string appended to image filenames for uniqueness. + compress_level (int): Compression level for saving images. + webhook_url (str): URL for Discord webhook to send the image. + batch_size (int): Number of images to accumulate before sending a batch to Discord. + image_queue (list): A list to hold paths of images waiting to be sent to Discord. + """ + def __init__(self): - self.output_dir = folder_paths.get_temp_directory() + """ + Initializes the PreviewImageWithDiscord class with default values and settings. + + - Sets the output directory for temporary images using `folder_paths.get_temp_directory()`. + - Defines a prefix to be appended to image filenames for uniqueness. + - Loads the webhook URL from a configuration file. + """ + self.output_dir = folder_paths.get_temp_directory() # Ensure this is thread-safe if used in a multithreaded environment self.type = "temp" self.prefix_append = "_temp_" + ''.join(random.choice("abcdefghijklmnopqrstupvxyz") for x in range(5)) self.compress_level = 1 @@ -20,13 +40,27 @@ class PreviewImageWithDiscord: self.image_queue = [] def load_webhook_url(self): + """ + Loads the webhook URL from a configuration file. + + Returns: + str: The webhook URL if found, otherwise an empty string. + """ config = configparser.ConfigParser() config_path = os.path.join(os.path.dirname(__file__), 'config.ini') config.read(config_path) - return config.get('Discord', 'webhook_url', fallback='') + # Retrieve the webhook URL from the Discord section in the configuration file + webhook_url = config.get('Discord', 'webhook_url', fallback='') + return webhook_url @classmethod def INPUT_TYPES(s): + """ + Defines the input types for the node. + + Returns: + dict: A dictionary specifying required and hidden inputs. + """ return {"required": {"images": ("IMAGE", ), "send_to_discord": (["enable", "disable"], {"default": "disable"}), @@ -40,6 +74,19 @@ class PreviewImageWithDiscord: CATEGORY = "image" def preview_images(self, images, send_to_discord="disable", batch_mode="disable", prompt=None, extra_pnginfo=None): + """ + Previews images and optionally sends them to Discord. + + Args: + images (list): List of images to preview. + send_to_discord (str): Whether to send images to Discord ("enable" or "disable"). + batch_mode (str): Whether to send images in batch mode ("enable" or "disable"). + prompt (str, optional): Prompt text to add as metadata. + extra_pnginfo (dict, optional): Additional PNG info to add as metadata. + + Returns: + dict: A dictionary containing the UI results with image details. + """ full_output_folder, filename, counter, subfolder, filename_prefix = folder_paths.get_save_image_path("ComfyUI", self.output_dir, images[0].shape[1], images[0].shape[0]) results = list() for image in images: @@ -63,6 +110,7 @@ class PreviewImageWithDiscord: "type": self.type }) + # Send image to Discord if enabled if send_to_discord == "enable" and self.webhook_url: if batch_mode == "enable": self.image_queue.append(full_path) @@ -80,6 +128,13 @@ class PreviewImageWithDiscord: return { "ui": { "images": results } } def send_to_discord(self, image_path, filename): + """ + Sends a single image to Discord. + + Args: + image_path (str): The path to the image file. + filename (str): The name of the image file. + """ with open(image_path, 'rb') as img_file: files = { 'file': (filename, img_file, 'image/png') @@ -95,6 +150,9 @@ class PreviewImageWithDiscord: print(f"Error sending image to Discord: {e}") def send_batch_to_discord(self): + """ + Sends a batch of images to Discord. + """ files = {} for i, image_path in enumerate(self.image_queue): with open(image_path, 'rb') as img_file: @@ -117,6 +175,7 @@ NODE_CLASS_MAPPINGS = { "PreviewImageWithDiscord": PreviewImageWithDiscord } +# Node display name mappings NODE_DISPLAY_NAME_MAPPINGS = { "PreviewImageWithDiscord": "Preview Image (with Discord option)" } \ No newline at end of file