PtokaX forum

Archive => Archived 5.1 boards => Help with scripts => Topic started by: Envinyatar on 08 April, 2007, 02:22:32

Title: Help with optimus's simple release scrip.
Post by: Envinyatar on 08 April, 2007, 02:22:32
I guess you see that Ive modded this script (poorly).
Ive made it write 2 txtfiles, one is working with the script, and the one called release1.txt is used with "Rotating Message 1.1 by jiten for PtokaX 0.3.3.0 build 17.02 or Higher".
The reason why I have it write 2 txt files is so that I can go in release1.txt and remove old entries, so that the mainchatmsg wont totally flood my mainchat.
What I ask is: can someone help me fix a "cleaner" or something for this script, so that release.txt shows ALL releases and release1.txt only shows the last 10/15 or 20 releases?
I should also mention that I got some infotxt in the beginning of the release1.txt file, so that the script starts writing from line 5 in the release1.txt file.

-- Verry simple release script nothing fancy
-- Make a file called releases.txt in \Scripts Folder
-- Made By Optimus
-- Converted the script into LUA 5 by 6Marilyn6Manson6
-- Filehandling problem fixed by Madman
-- Requested by Shalla
-- Fixed so anyone can use !write not just vips and above

sBot = frmHub:GetHubBotName()

timedate = os.date()
file = "releases.txt"
file1 = "releases1.txt"

display1 = "? Release"
display2 = "Genre"
display3 = "Releases"

function Main()
frmHub:RegBot(sBot)
end

function ChatArrival(user, data)
if (string.sub(data, 1, 1) == "<" ) then
data=string.sub(data,1,string.len(data)-1)
s,e,cmd=string.find(data, "%b<>%s+(%S+)")

if (cmd=="!read") then
ReadRelease(user, data, cmd)
return 1

elseif (cmd=="!add") then
local s,e,cmd,release,desc = string.find( data, "%b<>%s+(%S+)%s+(%S+)%s+(.+)" )

if desc == nil then
description = "No "..display2.." specified!"
local s,e,cmd,release = string.find( data, "%b<>%s+(%S+)%s+(%S+)" )
else
description = desc
end
if release == nil then
user:SendData(sBot, "*** No "..display1.." specified!")
return 1
end

News(""..display1..": "..release.."\r\n" ..display2..": "..description.."\t By: "..user.sName.."\t Date: "..timedate.."")
SendToAll(sBot, "A New "..display3.." Is Added By <"..user.sName.."> Type !read in mainchat to read!")
return 1
end
end
end

function ReadRelease(user, data, cmd)
local release = ""
-- readfrom(file)
local file = io.input(file);
while 1 do
local line = io.read()
if (line == nil) then
break
else
release = release.." "..line.."\r\n"
end
end
user:SendPM(sBot, "\r\n\r\n".."       "..display3.."s posted by users: ".."\r\n\r\n"..release)
-- readfrom()
file:read()
end

function News(what)
-- appendto(file)
-- write(what.."\n")
-- writeto()
local file = io.open(file, "a+") -- "a+"
file:write(what.."\n")
file:close()
end

function News(what)
-- appendto(file1)
-- write(what.."\n")
-- writeto()
local file = io.open(file1, "a+") -- "a+"
file:write(what.."\n")
file:close()

end