Fix a bug that occurs when userscript doesn't have all 3 modifiers

This commit is contained in:
Gnome Ann 2021-12-13 11:50:10 -05:00
parent 34c52a1a23
commit ed9c2a4d52
2 changed files with 6 additions and 12 deletions

View File

@ -1584,9 +1584,9 @@ return function(_python, _bridged)
local _userscript = old_loadfile(join_folder_and_filename(bridged.userscript_path, filename), "t", koboldbridge.get_universe(filename))() local _userscript = old_loadfile(join_folder_and_filename(bridged.userscript_path, filename), "t", koboldbridge.get_universe(filename))()
koboldbridge.logging_name = nil koboldbridge.logging_name = nil
local userscript = deepcopy(KoboldUserScriptModule) local userscript = deepcopy(KoboldUserScriptModule)
rawset(userscript, "_inmod", function() koboldbridge.logging_name = modulenames[i]; _userscript.inmod() end) rawset(userscript, "_inmod", function() koboldbridge.logging_name = modulenames[i]; if _userscript.inmod ~= nil then _userscript.inmod() end end)
rawset(userscript, "_genmod", function() koboldbridge.logging_name = modulenames[i]; _userscript.genmod() end) rawset(userscript, "_genmod", function() koboldbridge.logging_name = modulenames[i]; if _userscript.genmod ~= nil then _userscript.genmod() end end)
rawset(userscript, "_outmod", function() koboldbridge.logging_name = modulenames[i]; _userscript.outmod() end) rawset(userscript, "_outmod", function() koboldbridge.logging_name = modulenames[i]; if _userscript.outmod ~= nil then _userscript.outmod() end end)
rawset(userscript, "_filename", filename) rawset(userscript, "_filename", filename)
rawset(userscript, "_modulename", modulenames[i]) rawset(userscript, "_modulename", modulenames[i])
rawset(userscript, "_description", descriptions[i]) rawset(userscript, "_description", descriptions[i])

View File

@ -12,27 +12,21 @@ local corescript = {}
function corescript.inmod() function corescript.inmod()
for i = #koboldcore.userscripts, 1, -1 do for i = #koboldcore.userscripts, 1, -1 do
local userscript = koboldcore.userscripts[i] local userscript = koboldcore.userscripts[i]
if userscript.inmod ~= nil then userscript.inmod()
userscript.inmod()
end
end end
end end
-- Run all the generation modifiers from top to bottom -- Run all the generation modifiers from top to bottom
function corescript.genmod() function corescript.genmod()
for i, userscript in ipairs(koboldcore.userscripts) do for i, userscript in ipairs(koboldcore.userscripts) do
if userscript.genmod ~= nil then userscript.genmod()
userscript.genmod()
end
end end
end end
-- Run all the generation modifiers from top to bottom -- Run all the generation modifiers from top to bottom
function corescript.outmod() function corescript.outmod()
for i, userscript in ipairs(koboldcore.userscripts) do for i, userscript in ipairs(koboldcore.userscripts) do
if userscript.outmod ~= nil then userscript.outmod()
userscript.outmod()
end
end end
end end