PtokaX forum

Archive => Archived 4.0 boards => Finished Lua 4 scripts => Topic started by: MDFP on 27 July, 2005, 23:38:35

Title: Read from file to Main
Post by: MDFP on 27 July, 2005, 23:38:35
Hi Guys

Here's is a script to read from .txt file to main chat.

Just complete the 2 "????" fields and enjoy





-- Comando read file to main feito por MDFP
-- Thanks to CONEJODELMAL
-- 27-07-2005

-- Place a .txt file on scripts folder


sConf = {
   sBot = frmHub:GetHubBotName(),
   sFile1 = "???.txt",                                            --## file name ##--
}
 
function ChatArrival(user,data)
   local data = string.sub(data,1,-2)
   local s,e,cmd = string.find (data, "%b<>%s+[%!%?%+%#](%S+)" )
   if cmd then
      local tCmds =    {
         ["???"] =    function(user,data)            --## Command Name ##--
                  SendToAll(sConf.sBot,ReadFile(sConf.sFile1))
               end,
      }
      if tCmds[cmd] then  
         return tCmds[cmd](user,data), 1
      end
   end
end
 
function ReadFile(file)
   local fFile = io.open(file)
   if fFile then
      local message = ""
      for line in io.lines(file) do
         message = message..line.."\n"
      end
      fFile:close()
      return message
   else
      return file.." not found!"
   end
end


Title:
Post by: aL1en on 29 July, 2005, 20:56:06
can you make it show only to the user that types the command?

thanks!!
Title:
Post by: aL1en on 30 July, 2005, 00:10:38
QuoteOriginally posted by Mutor
SendToAll(sConf.sBot,ReadFile(sConf.sFile1))
to

user:SendData(sConf.sBot,ReadFile(sConf.sFile1))


thanks ;)
Title: jooooo mutor
Post by: aL1en on 30 July, 2005, 07:20:51
do you think its possible to make this script read multiple txt's?

for exemple
sFile2 = "!sfv.txt"
sFile3 = "!activedc.txt"
sFile4 = "!rar.txt"


i dont like the idea of having one for each.. big waste..
this script very educative ;)
Title:
Post by: James on 30 July, 2005, 07:40:19
LOL  MDFP...Your Script is old. Rules Script by Jiten  :D

-- rules by jiten

sConf = {
sBot = frmHub:GetHubBotName(),
sFile1 = "file1.txt",
ShowAll = true -- true/false to show all
}

function Main()
frmHub:RegBot(sConf.sBot)
end

function ChatArrival(user,data)
local data = string.sub(data,1,-2)
local s,e,cmd = string.find (data, "%b<>%s+[%!%?%+%#](%S+)" )
if cmd then
local tCmds = {
["rules"] = function(user,data)
if sConf.ShowAll then
SendToAll(sConf.sBot,ReadFile(sConf.sFile1))
else
user:SendData(sConf.sBot,ReadFile(sConf.sFile1))
end
end,
}
if tCmds[cmd] then
tCmds[cmd](user,data)
end
end
end

function ReadFile(file)
local fFile = io.open(file)
if fFile then
local message = ""
for line in io.lines(file) do
message = message..line.."\n"
end
fFile:close()
return message
else
return file.." not found!"
end
end
Title:
Post by: aL1en on 30 July, 2005, 17:25:57
QuoteOriginally posted by aL1en
do you think its possible to make this script read multiple txt's?

for exemple
sFile2 = "!sfv.txt"
sFile3 = "!activedc.txt"
sFile4 = "!rar.txt"


i dont like the idea of having one for each.. big waste..
this script very educative ;)


got jitens fixed..
if anyone needs drop me a PM
Title: needed
Post by: MDFP on 14 September, 2005, 02:41:03
Hi James


If you dont mind i need theoriginal script from Jiten.
Can you post it?


Thanks

(http://img225.imageshack.us/my.php?image=musica5rs.jpg)