PtokaX forum

Archive => Archived 5.1 boards => Request for scripts => Topic started by: achiever on 18 May, 2007, 13:13:53

Title: Textfile manager for PtokaX
Post by: achiever on 18 May, 2007, 13:13:53
Quote from: bastya_elvtars on 18 May, 2007, 00:24:10
I am not sure how !addtxt should work, though.
bastya i think it would be the same as changetxt,
!addtxt <name> <body>

i kno this is not the forum for script requests but, can some 1 plzz make a script for this.

thks,


thks bastya  ;)
Title: Re: Textfile manager for PtokaX
Post by: Madman on 18 May, 2007, 16:29:33
If the changetxt and addtxt gonna have same syntax, why have changetxt at all?
addtxt overwrites the old txt file.

Tested some, but should work...

Code (lua) Select

-- Textfile Manager
-- Made by Madman

-- Fixed: small path bug
-- Added: Syntax error to addtxt
-- Changed: better pattern matching, thanks basta

-- Commands
-- addtxt NewFile [New text to add]
-- deltxt DelFile
-- showtxt

function ChatArrival(curUser,data)
local data = string.sub(data,1,-2)
local s,e,cmd = string.find(data,"%b<>%s+[%!%#](%S+)")
if cmd then
tCmds = {
["addtxt"] = function(curUser,data)
local s,e,file,text = string.find(data,"%b<>%s+%S+%s+(%S+)%s+%[(.+)%]")
if file and text then
local txt = io.open(frmHub:GetPtokaXLocation().."/texts/" ..file.. ".txt","w+")
txt:write(text)
txt:close()
curUser:SendData(frmHub:GetHubBotName(),file.. ".txt added, please reload text files")
else
curUser:SendData(frmHub:GetHubBotName(),"syntax: !addtxt filename [text to add]")
end
end,
["deltxt"] = function(curUser,data)
local s,e,file = string.find(data,"%b<>%s+%S+%s+(%S+)")
if file then
os.remove(file..".txt")
curUser:SendData(frmHub:GetHubBotName(),file.. ".txt removed, please reload text files")
end
end,
["showtxt"] = function(curUser,data)
os.execute("dir /b ..\\texts > tmp.txt")
local file = io.open("tmp.txt")
local line = string.gsub(file:read("*a"), "\n", "\r\n")
curUser:SendPM(frmHub:GetHubBotName(),"\r\n\r\ncurrent text files\r\n\r\n"..line)
file:close()
os.remove("tmp.txt")
end,
}
if tCmds[cmd] then
return tCmds[cmd](curUser,data),1
end
end
end
Title: Re: Textfile manager for PtokaX
Post by: achiever on 18 May, 2007, 16:49:15
i m getting 1 error
[20:09] Syntax ...ads\MY Hub\scripts\textfile maneger.lua:16: bad argument #1 to 'gsub' (string expected, got nil)
Title: Re: Textfile manager for PtokaX
Post by: Madman on 18 May, 2007, 17:50:33
You are useing wrong syntax, it's !addtext filename [new text]

Script updated, to show when using wrong syntax
Title: Re: Textfile manager for PtokaX
Post by: bastya_elvtars on 18 May, 2007, 17:57:16
Why not use %[(.+)%] for capturing instead?
Title: Re: Textfile manager for PtokaX
Post by: Madman on 18 May, 2007, 18:21:17
Beacuse i didn't think of it ;)

Script updated once again