Rotating Message
 

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

Rotating Message

Started by jiten, 03 May, 2005, 20:45:25

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

jiten

-- Rotating Message 1.1 by jiten for PtokaX 0.3.3.0 build 17.02 or Higher
-- 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

Dessamator

hmmm, well done, very compact, ;)
Ignorance is Bliss.

dkt

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 = 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,"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

---------------
i get this error
---------------

Syntax E:\0.3.3.0.B16.09.9X.RLS\scripts\rm.lua:20: attempt to call method `GetPrefixes' (a nil value)

Dessamator

#3
that script only works with the newest ptokax, upgrade and try again !!
Ignorance is Bliss.

jiten

QuoteOriginally posted by dkt
---------------
i get this error
---------------

Syntax E:\0.3.3.0.B16.09.9X.RLS\scripts\rm.lua:20: attempt to call method `GetPrefixes' (a nil value)
As Dessamator said, u should get at least PtokaX 0.3.3.0 build 17.02 for this script.

Cheers

jiten

Well, made a working one for ur PtokaX version:
-- Rotating Message 1.1 by jiten - for PtokaX 0.3.3.0 build 16.09
-- 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,
	--------------------
}

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() 
	SetTimer(mSet.iDelay*60*1000) 
	StartTimer() 
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...")
					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

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
Cheers

kepp

-- Rotating Message 1.1 by jiten - for PtokaX 0.3.3.0 build 16.09
-- based on Rotating Message 1.0 by Mutor The Ugly
-- Rotates n text files posted to main chat at interval

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,
}

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
		end
	end
end

OnTimer = function()
	local TableSize = table.getn(sFile)
	for i=1,TableSize do
		if (i == mSet.iCnt) then
			local sContent = FileExist(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,sMsg,line = io.open(sFile,"r"),"","";
	if (oFile) then
		line = oFile:read()
		while line do
			sMsg = sMsg..line
		end
		oFile:close();
		return sMsg;
	else
		return nil;
	end
end

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

	--// Load up files to table from folder \\--
	os.execute("dir /b txt\\*.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
Modified a little, untested, place all text files in folder called 'txt'
Guarding    

jiten

Haven't tested it, but, looks good ;)

Best regards.

BeeR

Hi folks

Is it possible to modify this bot to grab the textfiles randomly
in a folder insted of calling it for file1.txt?? (not rename all my textfiles)
it would be nice if i can add a direction to that folder so i can manage all my files where i want to store them

Best Regards :]
A cold BeeR is stunning !!

kepp

It's exactly what the above should do, not random, much better, it goes throught them all..

hmm, didn't i add this to guarding? :P
Guarding    

BeeR

#10
QuoteOriginally posted by kepp
It's exactly what the above should do, not random, much better, it goes throught them all..

hmm, didn't i add this to guarding? :P

yes u did :>
but i want 1 bot to all my jokes and 1 to all my infofiles

BTW

gonna take a look now at your new Guarding !!
A cold BeeR is stunning !!

kepp

QuoteOriginally posted by BeeR
QuoteOriginally posted by kepp
It's exactly what the above should do, not random, much better, it goes throught them all..

hmm, didn't i add this to guarding? :P

yes u did :>
but i want 1 bot to all my jokes and 1 to all my infofiles

BTW

gonna take a look now at your new Guarding !!

The above should work, i just stripped out things
you can have as many textfiles as wanted in a folder called txt and script reads them up automatically
and iterates over them one by one
Guarding    

kepp

#12
-- Rotating Message 1.1 by jiten - for PtokaX 0.3.3.0 build 16.09
-- based on Rotating Message 1.0 by Mutor The Ugly
-- Rotates n text files posted to main chat at interval

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,
}

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
		end
	end
end

OnTimer = function()
	local TableSize = table.getn(sFile)
	for i=1,TableSize do
		if (i == mSet.iCnt) then
			local sContent = FileExists(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,sMsg,line = io.open(sFile,"r"),"","";
	if (oFile) then
		line = oFile:read()
		while line do
			sMsg = sMsg..line
		end
		oFile:close();
		return sMsg;
	else
		return nil;
	end
end



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

	--// Load up files to table from folder \\--
	os.execute("dir /b txt\\*.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

Just an error fix reported in wrong thread
Guarding    

jiten

Fixed the FileExist part and added some stuff:
-- 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)

mSet = {
	sBot = frmHub:GetHubBotName(),	-- Bot Name
	RunStatus = 1,			-- 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
		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
Cheers

kepp

Ah, read it all at once :)
Nice Jiten :D
Guarding    

Syphrone-NL

#15
One question

How can i change bot name??

sBot = frmHub:GetHubBotName(),	-- Bot Name

I want to change that to Disneys_Diner
Owner of 2 public hubs in Palace Network ---> www.palace-network.nl

Dessamator

#16
QuoteOriginally posted by Syphrone-NL
One question

How can i change bot name??


put it like this ::

sBot = "Disneys_diner", -- Bots Name
Ignorance is Bliss.

jiten

Kepp, it was missing a "break" :D
That was the reason why it didn't work.
function FileExists(sFile)
	local oFile,sMsg,line = io.open(sFile,"r"),"","";
	if (oFile) then
		line = oFile:read()
		while line do
			sMsg = sMsg..line
			[COLOR=red]break[/COLOR] 		
		end
		oFile:close();
		return sMsg;
	else
		return nil;
	end
end
Cheers

kepp

it should have had the same in the loop too
line = oFile:read()

because when line turns nil loop breaks if im not too wrong here
Guarding    

kepp

-- 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)

mSet = {
	sBot = frmHub:GetHubBotName(),	-- Bot Name
	RunStatus = 1,			-- Auto Start -> 1=ON 0=OFF
	iDelay = 30,			-- Delay between each text file in minutes
	sFolder = "Text",		-- 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
		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();
	table.sort(sFile);
	os.remove("files.txt");
end

It sorts it :)
Guarding    

BeeR

#20
hehe
a weird thing did happend when i test your bot above kepp

i made a folder named humor and put some jokes init,
after bot was finnished - it reads my txt files from ptokax texts folder

is that correct ??
i though the bot only should reading files from the folder i named humor

[[:

sorry ,, i found that a i did copy another textfile in humorfolder

it works correct now :>
A cold BeeR is stunning !!

~~~~?Master?~~~~

i'm keep getting this msg function arguments expected near `=' in line 8


can you help me??



thnx greetzz

jiten

QuoteOriginally posted by ~~~~?Master?~~~~
i'm keep getting this msg function arguments expected near `=' in line 8


can you help me??



thnx greetzz
What PtokaX version are you using?
Btw, the code to copy is the one between the
Best regards,

jiten

~~~~?Master?~~~~

ptokax 16.09......
 and i know..... i always copy that....


 i think i found the problem... maybe its jumble that keeps interfering with other scripts???

jiten

QuoteOriginally posted by ~~~~?Master?~~~~
ptokax 16.09......
 and i know..... i always copy that....


 i think i found the problem... maybe its jumble that keeps interfering with other scripts???
Nope, that's not the reason.
Just copy the from and including
-- Rotating Message 1.1 by jiten - for PtokaX 0.3.3.0 build 16.09 or Higher
to:
end
Cheers
PS: Do not copy the horizontal lines and the "code:"

SMF spam blocked by CleanTalk