{"name":"반복 방지 양끝 문장 제거 모듈","description":"불필요한 앞뒤 문장은 이제 그만!","id":"cda5b205-dee3-433b-9f14-936b6995863d","hideIcon":false,"trigger":[{"comment":"","type":"start","conditions":[],"effect":[{"type":"triggerlua","code":"function string:split(delimiter)\n    local result = {}\n    local from = 1\n    local delimFrom, delimTo = self:find(delimiter, from)\n\n    while delimFrom do\n        table.insert(result, self:sub(from, delimFrom))\n        from = delimTo + 1\n        delimFrom, delimTo = self:find(delimiter, from)\n    end\n\n    table.insert(result, self:sub(from))\n\n    return result\nend\n\nfunction findPureDataAndIndex(sentences)\n    local Index = {}\n    local Data = {}\n\n    for i, sentence in ipairs(sentences) do\n        if sentence ~= \"\" and not (sentence:match(\"^#\") or \n                sentence:match(\"^%-\") or \n                sentence:match(\"^%$\") or \n                sentence:match(\"^%d\") or \n                sentence:match(\"%b[]\") or \n                sentence:match(\"%b<>\") or \n                sentence:match(\"<(%w+)>.-</%1>\") or\n                sentence:match(\"`\") or\n                sentence:match(\":\")) then\n            table.insert(Index, i)\n            table.insert(Data, sentence)\n        end\n    end\n\n    return Data, Index\nend\n\nfunction extractString(str, startIndex, length)\n    local strLength = #str\n    local endIndex = startIndex + length - 1\n    \n    if startIndex < 1 then\n        startIndex = 1\n    end\n    \n    if endIndex > strLength then\n        endIndex = strLength\n    end\n    \n    return str:sub(startIndex, endIndex)\nend\n\nfunction insertTagAtPunct(str, n, tag)\n    local positions = {}\n    local startPos = 1\n    local function findPositions(char)\n        while true do\n            local s, e = string.find(str, char, startPos)\n            if not s then\n                break\n            end\n            table.insert(positions, s)\n            startPos = e + 1\n        end\n    end\n    \n    findPositions('%.')\n    local targetPos = nil\n    local length = #positions\n    if n > 0 then\n        targetPos = positions[n]\n    elseif n < 0 then\n        targetPos = positions[length + n + 1]\n    end\n\n    local punct1 = targetPos and str:sub(targetPos + 1, targetPos + 1) or \"\"\n    local punct2 = targetPos and str:sub(targetPos + 1, targetPos + 2) or \"\"\n    local punct3 = targetPos and str:sub(targetPos + 1, targetPos + 3) or \"\"\n    local punct4 = targetPos and str:sub(targetPos + 1, targetPos + 4) or \"\"\n\n    if targetPos then\n        if n < 0 and not punct1:match('^%p+$') then\n            str = str:sub(1, targetPos) .. tag .. str:sub(targetPos + 1)\n        elseif n < 0 and punct4:match('^%p+$') then\n            str = str:sub(1, targetPos + 3) .. tag .. str:sub(targetPos + 4)\n        elseif n < 0 and punct3:match('^%p+$') then\n            str = str:sub(1, targetPos + 2) .. tag .. str:sub(targetPos + 3)\n        elseif n < 0 and punct2:match('^%p+$') then\n            str = str:sub(1, targetPos + 1) .. tag .. str:sub(targetPos + 2)\n        elseif n > 0 and not punct1:match('^%p+$') then\n            str = str:sub(1, targetPos) .. tag .. str:sub(targetPos + 1)\n        elseif n > 0 and punct4:match('^%p+$') then\n            str = str:sub(1, targetPos + 4) .. tag .. str:sub(targetPos + 5)\n        elseif n > 0 and punct3:match('^%p+$') then\n            str = str:sub(1, targetPos + 3) .. tag .. str:sub(targetPos + 4)\n        elseif n > 0 and punct2:match('^%p+$') then\n            str = str:sub(1, targetPos + 2) .. tag .. str:sub(targetPos + 3)\n        elseif n > 0 and punct1:match('^%p+$') then\n            str = str:sub(1, targetPos + 1) .. tag .. str:sub(targetPos + 2)\n        end\n    else\n        if n < 0 then\n            str = tag .. str\n        elseif n > 0 then\n            str = str .. tag\n        end\n        targetPos = 1\n    end\n\n    return str, targetPos\nend\n\n--\n--\n--\nnumberOfCuttingTopText = 1 -- 잘라낼 앞문장\nnumberOfCuttingBottomText = 1 -- 잘라낼 뒷문장\n--\n--\n--\n\nfunction processChat(data)\n    local fullText = data:split(\"\\n\\n\")\n    local mainData, mainIndex = findPureDataAndIndex(fullText)\n    local dataWithMargins = {}\n\n    for i= mainIndex[1]-1, mainIndex[#mainIndex]+1 do\n        table.insert(dataWithMargins, fullText[i])\n    end\n\n    local crudeText = table.concat(dataWithMargins, \"\")\n    local fullTextWithMargins = crudeText:split(\"\\n\")\n    local mainDataWithMargins, mainIndexWithMargins = findPureDataAndIndex(fullTextWithMargins)\n\n    local topDataWithTag, topPosWithTag = insertTagAtPunct(mainDataWithMargins[1], numberOfCuttingTopText, \"</removeTop>\")\n    local topString = extractString(topDataWithTag, 1, topPosWithTag)\n    mainDataWithMargins[1] = \"<removeTop>\" .. topDataWithTag\n\n    local bottomDataWithTag, bottomPosWithTag = insertTagAtPunct(mainDataWithMargins[#mainDataWithMargins], -(numberOfCuttingBottomText + 1), \"<removeBottom>\")\n    local bottomString = extractString(bottomDataWithTag, bottomPosWithTag, #bottomDataWithTag)\n    if not bottomString:match('%b\"\"') then\n        mainDataWithMargins[#mainDataWithMargins] = bottomDataWithTag .. \"</removeBottom>\"\n    end\n\n    for i, index in ipairs(mainIndexWithMargins) do\n        fullTextWithMargins[index] = mainDataWithMargins[i]\n    end\n    \n    for i, index in ipairs(mainIndex) do\n        fullText[index] = mainData[i]\n    end\n    \n    local topFullText = {}\n    for i = 1, mainIndex[1]-2 do\n        table.insert(topFullText, fullText[i])\n    end\n    \n    local integratedTopFullText = table.concat(topFullText, \"\\n\")\n    local integratedFullTextWithMargins = table.concat(fullTextWithMargins, \"\\n\")\n    \n    completedText = integratedTopFullText .. \"\\n\" .. integratedFullTextWithMargins\n    return completedText\nend\n\nlistenEdit(\"editOutput\", function(triggerId, data)\n    return processChat(data)\nend)"}],"lowLevelAccess":false}],"lowLevelAccess":false,"regex":[{"comment":"리퀘 수정: 앞문장 제거","in":"<removeTop>([\\s\\S]*)</removeTop>","out":"","type":"editprocess","ableFlag":false},{"comment":"리퀘 수정: 뒷문장 제거","in":"<removeBottom>([\\s\\S]*)</removeBottom>","out":"","type":"editprocess","ableFlag":false}],"type":"risuModule","creator_notes":"불필요한 앞뒤 문장은 이제 그만!","tags":[],"license":"","rtype":"module"}