PtokaX forum

Archive => Archived 5.0 boards => Help with scripts => Topic started by: nEgativE on 22 March, 2005, 17:38:18

Title: Offline Message Script [L5]
Post by: nEgativE on 22 March, 2005, 17:38:18
Hi there, need more help please, can't get it right.. :<


-- Don't know who made it !

sBot = "Name"

msgtxt = "Messages.dat"

function Main()

end

function NewUserConnected(user, data)
   CheckForMsg(user)
end

OpConnected = NewUserConnected

function ChatArrival(user, data)
   if (string.sub(data,1,1) == "<" or string.sub(data,1,5+string.len(sBot)) == "$To: "..sBot) then
   s,e,cmd = string.find(data, "%b<>%s+(%S+)")
      if (cmd == "!recado") then
         local s,e,who,msg = string.find(data, "%b<>%s+%S+%s+(%S+)%s+(.*)")
         if (who == nil or msg == nil) then
            user:SendData(sBot, ""..user.sName..", voc? tem de digitar assim na janela principal de chat: !recado ")
         else
            if (GetItemByName(who) == nil) then
               WriteMsg(user, who, msg)
appendto("Logs.dat")
file:write("Data: "..os.date("%d").."/"..os.date("%m").."/"..os.date("%Y").." - Horas: "..os.date("%T").." - Usu?rio(a): "..user.sName.." - IP: "..user.sIP.." - Deixou uma mensagem para: "..who.." - Mensagem: "..msg.."\r\n")
file:writeto()
          user:SendData(sBot, ""..user.sName..", a sua mensagem foi guardada no Hub, assim que o usu?rio(a): "..who.." conectar, ir? receber o seu recado.")
            else
               user:SendData(sBot, ""..user.sName..", o usu?rio(a): "..who.." est? conectado(a) no Hub, o recado n?o foi guardado.")
            end
         end
         return 1
      end
   end
end

function WriteMsg(user, who, msg)
local tmp = ""
local time = 0
   if (readfrom(msgtxt) == nil) then
      writeto(msgtxt)
      write(who.." "..user.sName.." "..msg.."\r\n")
      writeto()
   else
      readfrom(msgtxt)
      while 1 do
         local line = read()
         if (line == nil) then
            if (time == 0) then
               tmp = tmp..who.." "..user.sName.." "..msg.."\r\n"
            end
            break
         elseif (line == "") then
            tmp = tmp..who.." "..user.sName.." "..msg.."\r\n"
       time = 1
         else
            tmp = tmp..line.."\r\n"
         end
      end
      readfrom()
      writeto(msgtxt)
      write(tmp)
      writeto()  
   end
end

function CheckForMsg(user)
local tmp = ""
   if (readfrom(msgtxt) ~= nil) then
      readfrom(msgtxt)
      while 1 do
         local line = read()
         if (line == nil) then
            break
         else
            local s,e,towho,fromwho,msg = string.find(line, "(%S+)%s+(%S+)%s+(.*)")
            if (towho ~= nil and string.lower(towho) == string.lower(user.sName)) then
               user:SendPM(sBot, ""..user.sName..", voc? tem um recado no Hub, do usu?rio(a): "..fromwho.." - Recado: "..msg..".")
            else
               tmp = tmp..line.."\r\n"
            end
         end
      end
      readfrom()
      writeto(msgtxt)
      write(tmp)
      writeto()
   end
end

Title:
Post by: jiten on 23 March, 2005, 21:28:44
Can u post all the script in Lua 4 ?

Best regards.
Title:
Post by: nEgativE on 24 March, 2005, 11:43:25
Here it is.. lua4


sBot = "[operserv]"

msgtxt = "Messages.dat"

function Main()

end

function NewUserConnected(user, data)
   CheckForMsg(user)
end

OpConnected = NewUserConnected

function DataArrival(user, data)
   if (strsub(data,1,1) == "<" or strsub(data,1,5+strlen(sBot)) == "$To: "..sBot) then
   s,e,cmd = strfind(data, "%b<>%s+(%S+)")
      if (cmd == "!recado") then
         local s,e,who,msg = strfind(data, "%b<>%s+%S+%s+(%S+)%s+(.*)")
         if (who == nil or msg == nil) then
            user:SendData(sBot, ""..user.sName..", voc? tem de digitar assim na janela principal de chat: !recado ")
         else
            if (GetItemByName(who) == nil) then
               WriteMsg(user, who, msg)
appendto("Logs.dat")
write("DC:CLP - Data: "..date("%d").."/"..date("%m").."/"..date("%Y").." - Horas: "..date("%T").." - Usu?rio(a): "..user.sName.." - IP: "..user.sIP.." - Deixou uma mensagem para: "..who.." - Mensagem: "..msg.."\r\n")
writeto()
          user:SendData(sBot, ""..user.sName..", a sua mensagem foi guardada no Hub, assim que o usu?rio(a): "..who.." conectar, ir? receber o seu recado.")
            else
               user:SendData(sBot, ""..user.sName..", o usu?rio(a): "..who.." est? conectado(a) no Hub, o recado n?o foi guardado.")
            end
         end
         return 1
      end
   end
end

function WriteMsg(user, who, msg)
local tmp = ""
local time = 0
   if (readfrom(msgtxt) == nil) then
      writeto(msgtxt)
      write(who.." "..user.sName.." "..msg.."\r\n")
      writeto()
   else
      readfrom(msgtxt)
      while 1 do
         local line = read()
         if (line == nil) then
            if (time == 0) then
               tmp = tmp..who.." "..user.sName.." "..msg.."\r\n"
            end
            break
         elseif (line == "") then
            tmp = tmp..who.." "..user.sName.." "..msg.."\r\n"
       time = 1
         else
            tmp = tmp..line.."\r\n"
         end
      end
      readfrom()
      writeto(msgtxt)
      write(tmp)
      writeto()  
   end
end

function CheckForMsg(user)
local tmp = ""
   if (readfrom(msgtxt) ~= nil) then
      readfrom(msgtxt)
      while 1 do
         local line = read()
         if (line == nil) then
            break
         else
            local s,e,towho,fromwho,msg = strfind(line, "(%S+)%s+(%S+)%s+(.*)")
            if (towho ~= nil and strlower(towho) == strlower(user.sName)) then
               user:SendPM(sBot, ""..user.sName..", voc? tem um recado no Hub, do usu?rio(a): "..fromwho.." - Recado: "..msg..".")
            else
               tmp = tmp..line.."\r\n"
            end
         end
      end
      readfrom()
      writeto(msgtxt)
      write(tmp)
      writeto()
   end
end

Title:
Post by: jiten on 24 March, 2005, 14:38:04
Well, try this one:

-- Converted to Lua 5 by jiten

sBot = "[operserv]"

msgtxt = "Messages.dat"

function Main()
frmHub:RegBot(sBot)
end

function NewUserConnected(user, data)
   CheckForMsg(user)
end

OpConnected = NewUserConnected

function ChatArrival(user, data)
s,e,cmd = string.find(data, "%b<>%s+(%S+)")
if (cmd == "!recado") then
local s,e,who,msg = string.find(data, "%b<>%s+%S+%s+(%S+)%s+(.*)")
if (who == nil or msg == nil) then
user:SendData(sBot, ""..user.sName..", voc? tem de digitar assim na janela principal de chat: !recado ")
else
if (GetItemByName(who) == nil) then
WriteMsg(user, who, msg)
local c = io.open("logs.dat", "a+") -- "a+"
c:write("DC:CLP - Data: "..os.date("%d").."/"..os.date("%m").."/"..os.date("%Y").." - Horas: "..os.date("%T").." - Usu?rio(a): "..user.sName.." - IP: "..user.sIP.." - Deixou uma mensagem para: "..who.." - Mensagem: "..msg.."\r\n")
c:close()
user:SendData(sBot, ""..user.sName..", a sua mensagem foi guardada no Hub, assim que o usu?rio(a): "..who.." conectar, ir? receber o seu recado.")
else
user:SendData(sBot, ""..user.sName..", o usu?rio(a): "..who.." est? conectado(a) no Hub, o recado n?o foi guardado.")
end
end
return 1
end
end

ToArrival = ChatArrival

function WriteMsg(user, who, msg)
local tmp = ""
local time = 0
local a = io.open(msgtxt, "w+")
if not a then
a:write(who.." "..user.sName.." "..msg.."\r\n")
a:close()
else
dofile(msgtxt)
while 1 do

local line = a:read()
if (line == nil) then
if (time == 0) then
tmp = tmp..who.." "..user.sName.." "..msg.."\r\n"
end
break
elseif (line == "") then
tmp = tmp..who.." "..user.sName.." "..msg.."\r\n"
time = 1
else
tmp = tmp..line.."\r\n"
end
end
local b = io.open(msgtxt,"w+")
b:write(tmp)
b:flush()
b:close()
end
end

function CheckForMsg(user)
local tmp = ""
local d = io.open(msgtxt, "r")
if d then
while 1 do
local line = d:read()
if (line == nil) then
break
else
local s,e,towho,fromwho,msg = string.find(line, "(%S+)%s+(%S+)%s+(.*)")
if (towho ~= nil and string.lower(towho) == string.lower(user.sName)) then
user:SendPM(sBot, ""..user.sName..", voc? tem um recado no Hub, do usu?rio(a): "..fromwho.." - Recado: "..msg..".")
else
tmp = tmp..line.."\r\n"
end
end
end
d:read("*a")
d:close()
local e = io.open(msgtxt,"w+")
e:write(tmp)
e:flush()
e:close()
else
return d.." doesnt exist"
end
end


Best regards,

jiten
Title:
Post by: nEgativE on 28 March, 2005, 12:47:22
Tks again jiten, working perfect !
Title:
Post by: jiten on 28 March, 2005, 12:58:38
yw  :]
Title:
Post by: jiten on 30 March, 2005, 11:10:37
As requested, here's the English version of this script:

-- Converted to Lua 5 by jiten
-- English version

sBot = "[operserv]"

msgtxt = "Messages.dat"

function Main()
frmHub:RegBot(sBot)
end

function NewUserConnected(user, data)
   CheckForMsg(user)
end

OpConnected = NewUserConnected

function ChatArrival(user, data)
s,e,cmd = string.find(data, "%b<>%s+(%S+)")
if (cmd == "!offline") then
local s,e,who,msg = string.find(data, "%b<>%s+%S+%s+(%S+)%s+(.*)")
if (who == nil or msg == nil) then
user:SendData(sBot, ""..user.sName..", you have to type this: !offline ")
else
if (GetItemByName(who) == nil) then
WriteMsg(user, who, msg)
local c = io.open("logs.dat", "a+") -- "a+"
c:write("DC:CLP - Date: "..os.date("%d").."/"..os.date("%m").."/"..os.date("%Y").." - Time: "..os.date("%T").." - User: "..user.sName.." - IP: "..user.sIP.." - Left this message for: "..who.." - Message: "..msg.."\r\n")
c:close()
user:SendData(sBot, ""..user.sName..", your message has been saved. When user: "..who.." log in, he/she'll receive your message.")
else
user:SendData(sBot, ""..user.sName..", the User : "..who.." is on the Hub. Your message wasn't saved.")
end
end
return 1
end
end

ToArrival = ChatArrival

function WriteMsg(user, who, msg)
local tmp = ""
local time = 0
local a = io.open(msgtxt, "w+")
if not a then
a:write(who.." "..user.sName.." "..msg.."\r\n")
a:close()
else
dofile(msgtxt)
while 1 do

local line = a:read()
if (line == nil) then
if (time == 0) then
tmp = tmp..who.." "..user.sName.." "..msg.."\r\n"
end
break
elseif (line == "") then
tmp = tmp..who.." "..user.sName.." "..msg.."\r\n"
time = 1
else
tmp = tmp..line.."\r\n"
end
end
local b = io.open(msgtxt,"w+")
b:write(tmp)
b:flush()
b:close()
end
end

function CheckForMsg(user)
local tmp = ""
local d = io.open(msgtxt, "r")
if d then
while 1 do
local line = d:read()
if (line == nil) then
break
else
local s,e,towho,fromwho,msg = string.find(line, "(%S+)%s+(%S+)%s+(.*)")
if (towho ~= nil and string.lower(towho) == string.lower(user.sName)) then
user:SendPM(sBot, ""..user.sName..", you have a message from: "..fromwho.." - Message: "..msg..".")
else
tmp = tmp..line.."\r\n"
end
end
end
d:read("*a")
d:close()
local e = io.open(msgtxt,"w+")
e:write(tmp)
e:flush()
e:close()
else
return d.." doesnt exist"
end
end


Best regards,

jiten