This commit is contained in:
justumen
2025-05-01 18:55:01 +02:00
parent e4ab8a25be
commit 0555362521
7 changed files with 276 additions and 6 deletions

View File

@@ -104,4 +104,79 @@ class IfElse:
@classmethod
def IS_CHANGED(cls, input, send_if_true, compare_with, input_type, send_if_false=None):
return float("NaN")
return float("NaN")
import re
class MatchTextToInput:
@classmethod
def INPUT_TYPES(cls):
inputs = {
"required": {
"input_text": ("STRING", {"forceInput": True}),
},
"optional": {
"input_1": (Everything("*"), {"forceInput": True}),
"input_2": (Everything("*"), {"forceInput": True}),
"input_3": (Everything("*"), {"forceInput": True}),
"input_4": (Everything("*"), {"forceInput": True}),
"input_5": (Everything("*"), {"forceInput": True}),
"input_6": (Everything("*"), {"forceInput": True}),
"input_7": (Everything("*"), {"forceInput": True}),
"input_8": (Everything("*"), {"forceInput": True}),
"input_9": (Everything("*"), {"forceInput": True}),
"input_10": (Everything("*"), {"forceInput": True}),
"text_1": ("STRING", {"default": ""}),
"text_2": ("STRING", {"default": ""}),
"text_3": ("STRING", {"default": ""}),
"text_4": ("STRING", {"default": ""}),
"text_5": ("STRING", {"default": ""}),
"text_6": ("STRING", {"default": ""}),
"text_7": ("STRING", {"default": ""}),
"text_8": ("STRING", {"default": ""}),
"text_9": ("STRING", {"default": ""}),
"text_10": ("STRING", {"default": ""}),
"use_regex": ("BOOLEAN", {"default": True}),
}
}
return inputs
RETURN_TYPES = (Everything("*"),)
FUNCTION = "match_text"
CATEGORY = "text"
def match_text(self, input_text, input_1=None, input_2=None, input_3=None, input_4=None, input_5=None,
input_6=None, input_7=None, input_8=None, input_9=None, input_10=None,
text_1="", text_2="", text_3="", text_4="", text_5="",
text_6="", text_7="", text_8="", text_9="", text_10="",
use_regex=True):
# Collect inputs and texts in lists
inputs = [input_1, input_2, input_3, input_4, input_5, input_6, input_7, input_8, input_9, input_10]
texts = [text_1, text_2, text_3, text_4, text_5, text_6, text_7, text_8, text_9, text_10]
# Find matching text and return corresponding input
for i, text in enumerate(texts):
if text == "": # Skip empty patterns
continue
if use_regex:
# Convert wildcard pattern to regex pattern
# Replace * with .* for regex
pattern = text.replace("*", ".*")
# Ensure it's a full match by adding ^ and $
pattern = f"^{pattern}$"
try:
if re.match(pattern, input_text):
return (inputs[i],)
except re.error:
# If there's an error in the regex pattern, try exact match instead
if input_text == text:
return (inputs[i],)
else:
# Use exact matching
if input_text == text:
return (inputs[i],)
# If no match found, return input_1
return (input_1,)