Timed message in main
 

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

Timed message in main

Started by Syphrone-NL, 26 April, 2006, 17:31:22

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Syphrone-NL

Hello all

I need a script for a timed message in main
the reads the message from a .txt file
i want to set the time in minutes
so i set 120 minutes the message will appear after 2 hours and then again after 2 hours.
And i want to use it for some profiles not all so i that i can change that which profile the message can see and which profile not
And i want that it can read two .txt files which i can set seppared times:
txt file 1 = 120 minutes
txt file 2 = 210 minutes
if thats possible

Thx in advanced
Syphrone-NL
Owner of 2 public hubs in Palace Network ---> www.palace-network.nl

TiMeTrAVelleR

-- Rotating Message 1.1 by jiten
-- based on Rotating Message 1.0 by Mutor The Ugly
-- Rotates n text files posted to main chat at interval
--
--User Settings---------------------------------------------------------------------
mSet = {
	sBot = frmHub:GetHubBotName(),	-- Bot Name
	RunStatus = 1,			-- Auto Start -> 1=ON 0=OFF
	iDelay = 30,			-- Delay between each text file in minutes
	-- Don't change this
	iCnt = 1,
	tPrefixes = {},
	--------------------
}

sFile = { -- put here the files you want to send
	"txt/file1.txt",
	"txt/file2.txt",
	"txt/file3.txt",
	"txt/file4.txt",
}
--End User Settings-----------------------------------------------------------------

Main = function() 
	for a,b in pairs(frmHub:GetPrefixes()) do mSet.tPrefixes[b] = 1 end
	SetTimer(mSet.iDelay*60*1000) 
	StartTimer() 
end 

ChatArrival = function(sUser, sData)
	sData=string.sub(sData,1,-2) 
	local s,e,sPrefix,cmd = string.find(sData, "%b<>%s*(%S)(%S+)")
	if sPrefix and mSet.tPrefixes[sPrefix] then
		if sUser.bOperator then
			local tCmds = {
			["adon"] =	function(user,data)
						mSet.RunStatus = 1
						user:SendData(mSet.sBot,"Messages started...")
						OnTimer()
					end,
			["adoff"] =	function(user,data)
						mSet.RunStatus = 0
						user:SendData(mSet.sBot,"Messages stopped...")
					end,
			}
			if tCmds[cmd] then
				return tCmds[cmd](sUser,sData),1
			end
		end
	end
end

OnTimer = function()
	if mSet.RunStatus == 1 then
		for i = 1, table.getn(sFile) do
			if i == mSet.iCnt then
				local f,tmp = io.open(sFile[i],"r"),""
				if f then
					tmp = f:read("*a")--
					tmp = string.gsub(tmp,"|",string.char(166))
					tmp = string.gsub(tmp,"\n","\r\n")
					f:close()
					SendToAll(mSet.sBot,"\r\n"..tmp)
				end
				if table.getn(sFile) == i then
					mSet.iCnt = 1
				else
					mSet.iCnt = i + 1
				end
				break
			end
		end
	end
end


greetzz TT

6Marilyn6Manson6

Or this:

-- Rotating Message 1.1 by jiten - for PtokaX 0.3.3.0 build 16.09 or Higher
-- based on Rotating Message 1.0 by Mutor The Ugly
-- Rotates n text files posted to main chat at interval
-- Added: Rotates every .txt file stored in sFolder (by kepp)
-- Added: Text file sending by own trigger (Prefix - Filename)

mSet = {
	sBot = frmHub:GetHubBotName(),	-- Bot Name
	RunStatus = 0,			-- Auto Start -> 1=ON 0=OFF
	iDelay = 30,			-- Delay between each text file in minutes
	sFolder = "txt",		-- Folder where all the .txt files are stored
	-- Don't change this
	iCnt = 1,
}

sFile = {}

Main = function()
	ReloadText()
	SetTimer(mSet.iDelay*60*1000) 
	if (mSet.RunStatus == 1) then
		StartTimer()
	end
end 


ChatArrival = function(sUser, sData)
	sData=string.sub(sData,1,-2)
	local s,e,cmd = string.find(sData, "%b<>%s+[%!%?%+%#](%S+)" )
	if sUser.bOperator then
		local tCmds = {
		["adon"] =	function(user,data)
					mSet.RunStatus = 1
					user:SendData(mSet.sBot,"Messages started...")
					StartTimer()
				end,
		["adoff"] =	function(user,data)
					mSet.RunStatus = 0
					user:SendData(mSet.sBot,"Messages stopped...")
					StopTimer()
				end,
		["reload"] =	function(user,data)
					ReloadText()
					user:SendData(mSet.sBot,"Textfiles loaded...")
				end,
		}
		if tCmds[cmd] then
			return tCmds[cmd](sUser,sData),1
		else
			local sContent = FileExists(mSet.sFolder.."/"..cmd..".txt")
			if (sContent) then
				return sUser:SendData(mSet.sBot,"\r\n"..sContent),1 
			end
		end
	end
end

OnTimer = function()
	local TableSize = table.getn(sFile)
	for i=1,TableSize do
		if (i == mSet.iCnt) then
			local sContent = FileExists(mSet.sFolder.."/"..sFile[i])
			if (sContent) then
				SendToAll(mSet.sBot,"\r\n"..sContent)
			end
			if (TableSize == i) then mSet.iCnt = 1 else mSet.iCnt = mSet.iCnt + 1 end
			break
		end
	end
end

function FileExists(sFile)
	local oFile = io.open(sFile,"r");
	if (oFile) then
		local line = oFile:read("*all");
		oFile:close();
		return string.gsub(line,"\r","\r\n");
	else
		return nil;
	end
end

function ReloadText()
	sFile = nil;
	sFile = {};
	collectgarbage();

	--// Load up files to table from folder \\--
	os.execute("dir /b "..mSet.sFolder.."\\*.txt > files.txt");
	local hFile = io.open("files.txt","r");
	local line = hFile:read();
	while line do
		table.insert(sFile,1,line)
		line = hFile:read();
	end
	hFile:close();
	os.remove("files.txt");
end

Syphrone-NL

But now i cant set 2 times only one

I want to set time for message 1 in main to 120 minutes
and the message 2 for 210 minutes

so after 120 minutes message 1 appears and 120 minutes later again and 120 minutes later again
and message 2 appears after 210 minutes and 210 minutes later again and 210 minutes later again

if this possible
Owner of 2 public hubs in Palace Network ---> www.palace-network.nl

Thor

Try this:
-- Txtshow by bastya_elvtars
-- At preconfigured times it shows a text file.

Botname="Texter"

HubAD=
 ?{
 ? ?["18:00"]="blabla.txt",
 ? ?["22:33"]="thx.txt",
 ? ?["01:21"]="ReadMe.txt",
 ?}
--[[["HH:MM"]="filename.txt",

Can even be 18:33 if this is your perversion :)
Does not have to be a textfile reachable by command as well. :)
A textfile can be bound to any number of timestamps.
Just comment a line if you do not need it any longer, or rename the file to a non-existant.
Or, delete the file (if a file does not exist, there are gonna be no errors).
]] ?

-- The folder where your text files reside
-- Warning: NOT \ but /
folder="I:/!!!px2!!!"

-- // Don't edit below.

Timer=0

function OnTimer()
 ?local now=os.date("%H:%M")
 ?if Timer~=60 then
 ? ?Timer=Timer+1
 ?else
 ? ?if HubAD[now] then
	local f=io.open(folder.."/"..HubAD[now],"r")
	if f then
	local contents = string.gsub(f:read("*a"),string.char(10), "\r\n")
	SendToAll(Botname,"\r\n"..contents.."\r\n")
	 ?f:close()
	end
 ? ?end
 ? ?Timer=0
 ?end
end

function Main()
 ?SetTimer(1000)
 ?StartTimer()
end

Syphrone-NL

gonna try it Hungarista
if it works its very cool with the time
Owner of 2 public hubs in Palace Network ---> www.palace-network.nl

Psycho_Chihuahua

it should work - it's also used as a plugin for lawmaker and works fine there
PtokaxWiki ?PtokaX Mirror + latest Libs

01100001011011000111001101101111001000000110101101101110011011110111011101101110001000000110000101110011001000000101010001101111011010110110111101101100011011110111001101101000

Syphrone-NL

Thx Hungarista

Works fantastic many thx
Owner of 2 public hubs in Palace Network ---> www.palace-network.nl

SMF spam blocked by CleanTalk