Offline Message Script [L5]
 

News:

29 December 2022 - PtokaX 0.5.3.0 (20th anniversary edition) released...
11 April 2017 - PtokaX 0.5.2.2 released...
8 April 2015 Anti child and anti pedo pr0n scripts are not allowed anymore on this board!
28 September 2015 - PtokaX 0.5.2.1 for Windows 10 IoT released...
3 September 2015 - PtokaX 0.5.2.1 released...
16 August 2015 - PtokaX 0.5.2.0 released...
1 August 2015 - Crowdfunding for ADC protocol support in PtokaX ended. Clearly nobody want ADC support...
30 June 2015 - PtokaX 0.5.1.0 released...
30 April 2015 Crowdfunding for ADC protocol support in PtokaX
26 April 2015 New support hub!
20 February 2015 - PtokaX 0.5.0.3 released...
13 April 2014 - PtokaX 0.5.0.2 released...
23 March 2014 - PtokaX testing version 0.5.0.1 build 454 is available.
04 March 2014 - PtokaX.org sites were temporary down because of DDOS attacks and issues with hosting service provider.

Main Menu

Offline Message Script [L5]

Started by nEgativE, 22 March, 2005, 17:38:18

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

nEgativE

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

jiten

#1
Can u post all the script in Lua 4 ?

Best regards.

nEgativE

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

jiten

#3
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

nEgativE

Tks again jiten, working perfect !

jiten


jiten

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

SMF spam blocked by CleanTalk