Untested...
-- automatic configuration saver
-- tested on PtokaX 0.4.1.1
-- v 0.2
-- by ATAG
-- 2008.09.02.
-- idea by 11hh
-- Save on startup? (true/false)
SaveonStartup = true
function OnStartup()
tmr = TmrMan.AddTimer(300*1000)
-- create backup from Profiles.xml
local cur = io.open(Core.GetPtokaXPath().."cfg/Profiles.xml")
if not cur then return end
if SaveonStartup then
local back = io.open(Core.GetPtokaXPath().."cfg/Profiles.bak","w+")
if back then
back:write(cur:read("*a"))
back:flush()
back:close()
end
end
cur:close()
end
function OnTimer(tmr)
SetMan.Save()
RegMan.Save()
BanMan.Save()
SaveProfiles()
end
function ChatArrival(tUser,sData)
if not Core.GetUserValue(tUser,11) then return false end
if not sData:find("%b<> %psave|") then return false end
OnTimer()
Core.SendToUser(tUser,"<"..SetMan.GetHubBot().sNick.."> Settings saved. OK|")
return true
end
function ToArrival(tUser,sData)
if not Core.GetUserValue(tUser,11) then return false end
local _,_,to = sData:find("%$To: (.-) From:.-%$%b<> %psave|")
if not to then return false end
if to == SetMan.GetHubBot().sNick then
OnTimer()
Core.SendPmToUser(tUser,SetMan.GetHubBot().sNick, "Settings saved. OK|")
return true
end
end
function SaveProfiles()
local f = io.open( Core.GetPtokaXPath().."cfg/Profiles.xml","w+" )
local buf = {'<?xml version="1.0" encoding="windows-1252" standalone="yes" ?>','<Profiles>'}
local profiles = ProfMan.GetProfiles()
for j in ipairs(profiles) do
table.insert(buf,'\t<Profile>')
table.insert(buf,'\t\t<Name>'..profiles[j].sProfileName..'</Name>')
local profilenumber = profiles[j].iProfileNumber
local permissions = ""
for i = 0, 55 do
permissions = permissions.. (ProfMan.GetProfilePermission(profilenumber,i) and '1' or '0')
end
permissions = permissions..string.rep('0', 200) -- 255 - 55
table.insert(buf,'\t\t<Permissions>'..permissions..'</Permissions>')
table.insert(buf,'\t</Profile>')
end
table.insert(buf,'</Profiles>')
f:write(table.concat(buf,"\n")..'\n')
f:flush()
f:close()
end