🚧 [WIP/TEST] プレースホルダーの形式を修正 ex) " <$ 0x1000> " -> " $ 0x1000 "

$と0x1000の間にスペースが入る事があるため、それを考慮して正規表現を修正
This commit is contained in:
misyaguziya
2024-09-08 05:48:46 +09:00
parent 619532f03b
commit 5c6f51bdaa

View File

@@ -3,8 +3,6 @@ from time import sleep
from subprocess import Popen from subprocess import Popen
from threading import Thread from threading import Thread
import re import re
import random
import string
from config import config from config import config
from model import model from model import model
from utils import getKeyByValue, isUniqueStrings, printLog, printResponse from utils import getKeyByValue, isUniqueStrings, printLog, printResponse
@@ -297,10 +295,10 @@ def replaceExclamationsWithRandom(text):
def replace(match): def replace(match):
original = match.group(1) original = match.group(1)
nonlocal num nonlocal num
rand_value = f" <$ {hex(num)}> " rand_value = hex(num)
replacement_dict[rand_value] = original replacement_dict[rand_value] = original
num += 1 num += 1
return str(rand_value) return f" ${rand_value} "
# 文章内の ![] の部分を置換 # 文章内の ![] の部分を置換
replaced_text = re.sub(pattern, replace, text) replaced_text = re.sub(pattern, replace, text)
@@ -310,8 +308,9 @@ def replaceExclamationsWithRandom(text):
def restoreText(escaped_text, escape_dict): def restoreText(escaped_text, escape_dict):
# 大文字小文字を無視して置換するために、正規表現を使う # 大文字小文字を無視して置換するために、正規表現を使う
for escape_seq, char in escape_dict.items(): for escape_seq, char in escape_dict.items():
# escape_seq の部分を case-insensitive で置換 # escaped_text の部分を pattern で置換
escaped_text = re.sub(re.escape(escape_seq[1:-1]), char, escaped_text, flags=re.IGNORECASE) pattern = re.escape(f"${escape_seq}") + r"|\$\s+" + re.escape(escape_seq)
escaped_text = re.sub(pattern, char, escaped_text, flags=re.IGNORECASE)
return escaped_text return escaped_text
def removeExclamations(text): def removeExclamations(text):