PtokaX forum

Archive => Archived 4.0 boards => Help with Lua 4 scripts => Topic started by: Falken on 09 June, 2004, 11:40:58

Title: Texter
Post by: Falken on 09 June, 2004, 11:40:58
how to change this script so the txt shows in mainchat?

-- texter bot by plop
-- shows text files from a folder named text.
-- doesn't mather what prefix is used.
-- if the file excist it shows.

Bot = "textbot"

function Main()
   frmHub:RegBot(Bot)
end

function DataArrival(user, data)
   data=strsub(data,1,strlen(data)-1)
   if( strsub(data, 1, 1) == "<" ) then
      s,e,cmd = strfind(data,"%b<>%s+(%S+)")
      cmd = strsub(cmd, 2,strlen(cmd))
      if readfrom("text/"..cmd..".txt") then
         showtext(user, cmd)
         return 1
      end
   elseif(strsub(data, 1, 4) == "$To:") then
      s,e,cmd = strfind(data,"$To:%s+%S+%s+From:%s+%S+%s+$%b<>%s+(%S+)")
      cmd = strsub(cmd, 2,strlen(cmd))
      if readfrom("text/"..cmd..".txt") then
         showtext(user, cmd)
         return 1
      end
   end
end


function showtext(user, cmd)
   lines = "\r\n\r\n"
   readfrom("text/"..cmd..".txt")
   while 1 do
      local line = read()
      if line == nil then
         readfrom()
         break
      end
      lines = lines..line.."\r\n"
   end
   user:SendPM(Bot, lines.." |")
end
Title:
Post by: nErBoS on 09 June, 2004, 12:01:14
Hi,

Done...

-- texter bot by plop
-- shows text files from a folder named text.
-- doesn't mather what prefix is used.
-- if the file excist it shows.

Bot = "textbot"

function Main()
frmHub:RegBot(Bot)
end

function DataArrival(user, data)
data=strsub(data,1,strlen(data)-1)
if( strsub(data, 1, 1) == "<" ) then
s,e,cmd = strfind(data,"%b<>%s+(%S+)")
cmd = strsub(cmd, 2,strlen(cmd))
if readfrom("text/"..cmd..".txt") then
showtext(user, cmd)
return 1
end
elseif(strsub(data, 1, 4) == "$To:") then
s,e,cmd = strfind(data,"$To:%s+%S+%s+From:%s+%S+%s+$%b<>%s+(%S+)")
cmd = strsub(cmd, 2,strlen(cmd))
if readfrom("text/"..cmd..".txt") then
showtext(user, cmd)
return 1
end
end
end


function showtext(user, cmd)
lines = "\r\n\r\n"
readfrom("text/"..cmd..".txt")
while 1 do
local line = read()
if line == nil then
readfrom()
break
end
lines = lines..line.."\r\n"
end
[b]user:SendData(Bot, lines.." |")[/b]
end

Best regards, nErBoS
Title: hi
Post by: Falken on 09 June, 2004, 13:56:17
thx a lot m8
:)