hey all
i've been using 2 useful scprits for my PtokaX 0.3.2.6 hub and have had no problems but yesterday i switched to PtokaX 0.3.3.0 build 17.02 (great hubsoft!) and my old scripts were not working properly.
Read from text file:MOTD = "MOTD.txt" -- textfile
function TextFile(file)
readfrom(file, "r")
local message = ""
while 1 do
local line = read()
if line == nil then break
else
message = message..line.."\n"
end
end
readfrom()
return message
end
Hub commands:botname = "YourBotsName"
current = date("%H:%M")
Text1 = "the text for +r command"
Text2 = "the text for +t command"
function DataArrival(user, data)
if (strsub(data, 1, 1) == "<") then
data = strsub(data,1,strlen(data)-1)
local s,e,cmd = strfind(data,"%b<>%s+(%S+)")
if (cmd=="+r") then
user:SendData(botname, ""..Text1.." - The time now is: "..current)
return 1
end
if (cmd=="+t") then
user:SendData(botname, ""..Text2.." - The time now is: "..current)
return 1
end
end
end
for the read from text file script, PtokaX 0.3.3.0 doesn't seem recongnize the readfrom function.
for the hub command script, i know they changed DataArrival to ChatArrival in 0.3.3.0 but it doesn't seem to recongnize the date or strsub functions.
any help rewriting these scripts for 0.3.3.0 would be much appreciated!
thanks!
Try these:
MOTD = "MOTD.txt" -- textfile
function TextFile(file)
local f = io.open(file,"r")
if f then
local message = ""
while 1 do
local line = f:read("*l")
if line == nil then
break
else
message = message..line.."\n"
end
end
f:close()
return message
end
end
botname = "YourBotsName"
current = os.date("%H:%M")
Text1 = "the text for +r command"
Text2 = "the text for +t command"
function ChatArrival(user, data)
data = string.sub(data,1,-2)
local s,e,cmd = string.find(data,"%b<>%s+(%S+)")
if (cmd=="+r") then
user:SendData(botname, ""..Text1.." - The time now is: "..current)
return 1
end
if (cmd=="+t") then
user:SendData(botname, ""..Text2.." - The time now is: "..current)
return 1
end
end
Best regards.
optimized the 1st 1 a bit.
function TextFile(file)
local fFile = io.open(file)
if fFile then
local message = ""
for line in io.lines(file)
message = message..line.."\n"
end
fFile:close()
return message
else
return file.." not found!"
end
end
plop
wow. this forum is very helpful! thanks a lot for rewriting the scripts jiten and plop! it seems that PtokaX 0.3.3.0 scripting is more object oriented than 0.3.2.6.
anyways, thanks again for the help!
anytime :]
QuoteOriginally posted by plop
optimized the 1st 1 a bit.
function TextFile(file)
local fFile = io.open(file)
if fFile then
local message = ""
for line in io.lines(file)
message = message..line.."\n"
end
fFile:close()
return message
else
return file.." not found!"
end
end
plop
maybe this is a lil better ?
function TextFile( file )
local f = io.open( file )
if f then
local content = fFile:read("*all");
fFile:close()
return string.gsub( content, "\n", "\r\n" )
end
return file.." not found!"
end
Found a small typo. Here it goes:
function TextFile( file )
local f = io.open( file )
if f then
local content = f:read("*all");
f:close()
return string.gsub( content, "\n", "\r\n" )
end
return file.." not found!"
end
Cheers