PtokaX forum

Archive => Archived 5.1 boards => Conversion Requests => Topic started by: rolipoli on 29 March, 2008, 18:18:00

Title: script manger conversion help
Post by: rolipoli on 29 March, 2008, 18:18:00
Hello all!Please help me to convert this script for the new API.Here is the script:

-- modified Textfile manager to Scripts manager by Achiever 21/05/2007
-- added right click functions also
-- also change a bit of pattern matching
-- main chat block bug fixed thks to brock for report 24/05/2007

-- TEXtfile Manager
-- Made by Madman

-- Fixed: small path bug
-- Added: Syntax error to addscript
-- Changed: better pattern matching, thanks bastya
-- Revision by Mutor [ mod by achiever as 'Scripts Mgr.']

-- Commands
-- addscript NewFile [New script to add]
-- delscript DelFile
-- showtxt

local HUB = frmHub:GetHubName()
local sBot = "[ScriptManager]"

function Main()
frmHub:RegBot(sBot)
end

local tCmds = {
["addscript"] = function(curUser,data)
local method = "added"
local _,_,flag = data:lower():find("%b<> %p%a+ %S+ (%/o)")
local _,_,file,script = data:find("%b<> %p%a+ (%S+) [%/o ]*(.+)")
if file and script then
--Add more codes to replace here, if needed
local t = {
[1] = {"\r\n","\n"},
[2] = {"&amp;","&"},
}
for i, v in pairs(t) do
script = script:gsub(v[1],v[2])
end
for code in script:gmatch("&#(%d+);") do
code = tonumber(code)
if code ~= 124 then
script = script:gsub("%&%#"..code.."%;",string.char(code))
end
end
file = file:gsub("%.lua","")..".lua"
local r,e = os.rename(file,file)
if r then
if not flag then
return curUser:SendPM(sBot,file.." exists, syntax: !addscript"..
" filename script [filename /o script  to overwrite])")
else
method = "updated"
end
end
local txt = io.open(file,"w+")
txt:write(script)
txt:flush()
txt:close()
curUser:SendPM(sBot,file.." "..method..", please reload scripts")
else
curUser:SendPM(sBot,"syntax: !addscript filename [script to add]")
end
end,
["delscript"] = function(curUser,data)
local s,e,file = data:find("%b<>%s+%S+%s+(%w+)%.*.*")
if file then
os.remove(file..".lua")
curUser:SendPM(sBot,file.. ".lua removed, please reload scripts")
end
end,
}

function ChatArrival(curUser,data)
if curUser.iProfile == 0 then
data = data:sub(1,-2)
local s,e,cmd = data:find("%b<> %p(%S+)")
if cmd and tCmds[cmd] then
return tCmds[cmd](curUser,data),1
end
end
end
ToArrival = ChatArrival

function OpConnected(user)
if user.iProfile == 0 then
user:SendData("$UserCommand 1 3 "..HUB.."\\Script Commands\\"..sBot.."\\Add Script$<%[mynick]> +addscript %[line:Filename (filename -o  to overwrite))] %[line:Script body]&#124;")
user:SendData("$UserCommand 1 3 "..HUB.."\\Script Commands\\"..sBot.."\\Delete Script$<%[mynick]> +delscript %[line:Filename]&#124;")
user:SendData("$UserCommand 1 3 "..HUB.."\\Script Commands\\"..sBot.."\\Restart Script$<%[mynick]> +restartscript %[line:Filename]&#124;")
user:SendData("$UserCommand 1 3 "..HUB.."\\Script Commands\\"..sBot.."\\Start Script$<%[mynick]> +startscript %[line:Filename]&#124;")
user:SendData("$UserCommand 1 3 "..HUB.."\\Script Commands\\"..sBot.."\\Stop Script$<%[mynick]> +stopscript %[line:Filename]&#124;")
--user:SendData("$UserCommand 1 3 "..HUB.."\\Script Commands\\"..sBot.."\\Restart All Scripts$ <%[mynick]> +restartscripts&#124;")
user:SendData("$UserCommand 1 3 "..HUB.."\\Script Commands\\"..sBot.."\\Get Scripts$<%[mynick]> +getscripts&#124;")
end
end

I tried to convert it,but in the converted version didn't appear the right click menu,and the "delscript" command didn't work.I attached the converted version to.Please help!Sorry for my bad english.
Thanks in advance. rolipoli
Title: Re: script manger conversion help
Post by: rolipoli on 30 March, 2008, 13:01:16
Thank you Sir for the quick answer :) ,but unfortunately there are some problems :
1.when i give the "restartscripts"from the rightclickmenu its disconnect me from the hub.
2.on the "addscript"command which i give in private to the bot the script it stops and the error message is:Syntax scriptmanager.lua:60: bad argument count to 'SendPmToUser'(3 expected,got 4).
3.and these error message appear: Syntax scriptmanager.lua:69: bad argument count to 'SendPmToUser'(3 expected,got 4)
on the "delscript" commnad from the right clicker, and in private, if i use the command nothing happend
What is the cause of this errors,and can be fixed it? ???
Title: Re: script manger conversion help
Post by: Tw?sT?d-d?v on 30 March, 2008, 14:25:47
having a quick look at script shouldnt Core:  be  Core.  ?
And the restartallscript in the first script is stoped/commeted   


user:SendData("$UserCommand 1 3 "..HUB.."\\Script Commands\\"..sBot.."\\Stop Script$<%[mynick]> +stopscript %[line:Filename]&#124;")
--user:SendData("$UserCommand 1 3 "..HUB.."\\Script Commands\\"..sBot.."\\Restart All Scripts$ <%[mynick]> +restartscripts&#124;")
user:SendData("$UserCommand 1 3 "..HUB.."\\Script Commands\\"..sBot.."\\Get Scripts$<%[mynick]> +getscripts&#124;")


That might be cause it didnt work b4  ??
Title: Re: script manger conversion help
Post by: Madman on 30 March, 2008, 14:33:51
Yes. Core: should be Core.
Change that and it should work.
Title: Re: script manger conversion help
Post by: rolipoli on 31 March, 2008, 12:20:58
Quote from: Tw?sT?d-d?v?l on 30 March, 2008, 14:25:47
having a quick look at script shouldnt Core:  be  Core.  ?
And the restartallscript in the first script is stoped/commeted   


user:SendData("$UserCommand 1 3 "..HUB.."\\Script Commands\\"..sBot.."\\Stop Script$<%[mynick]> +stopscript %[line:Filename]&#124;")
--user:SendData("$UserCommand 1 3 "..HUB.."\\Script Commands\\"..sBot.."\\Restart All Scripts$ <%[mynick]> +restartscripts&#124;")
user:SendData("$UserCommand 1 3 "..HUB.."\\Script Commands\\"..sBot.."\\Get Scripts$<%[mynick]> +getscripts&#124;")


That might be cause it didnt work b4  ??
Hello all!It was my mistake to forgot to mention, in the first(unconverted) script the"restartscripts" command was commented/stoped by me because,it disconnect me too,and i decide to use the inbuild ptx commands instead of that.
Mutor!In the script revised by you the "delscript" command still Not working, ??? I tried to give in pm to the bot,in the main,and in the rightclicker but whitout any results ,the rest of the commands are working fine now.
Title: Re: script manger conversion help
Post by: rolipoli on 01 April, 2008, 12:13:50
Quote from: Mutor on 31 March, 2008, 22:33:48
Sure it is, use simple filename without spaces.
File extension is not required.
I'm so stupid :D because i forgot to use just the filename without extensions in command.You have perfectly right ,now the script works fine thanks to You!
Thanks again Mutor!
rolipoli