PtokaX forum

Archive => Archived 5.0 boards => Finished Scripts => Topic started by: -SkA- on 20 March, 2006, 10:08:49

Title: Timed mass message
Post by: -SkA- on 20 March, 2006, 10:08:49
I've tried to convert this script:

--Lua 5 By Dessamator(added message To Profile)
-- timed mass message from text by ??????Hawk??????
-- create a massmessage.txt file in the scripts directory
-- containing your message


CanDo = {
[0] = 1, -- Master
[1] = 1, -- Operator
[2] = 1, -- VIP
[3] = 1, -- Reg
[4] = 1, -- Moderator
[5] = 1, -- Netfounder
[-1] =0, -- User
}

SendEvery = 1   ----  time in Mins
textfile = "massmessage.txt"
bot = frmHub:GetHubBotName()
hrs = 1000 * 60 * SendEvery


function Main()
SetTimer(hrs)
StartTimer()
end





function OnTimer()
local handle = io.open(textfile, "r")
if (handle ~= nil) then
                 Temptimerfile = "\r\n"
for line in (io.lines(textfile)) do
Temptimerfile = Temptimerfile.."\r\n"..line
io.read()
end
for prf,sw in ipairs(CanDo) do
if sw == 1 then
for pos,user in pairs (frmHub:GetOnlineUsers(prf)) do
user:SendPM(bot, Temptimerfile)
end
end
end
end
io.close()
end


but I got this error:

timedoriginal.lua:48: attempt to use a closed file

Any idea?

Title: Re: Timed mass message
Post by: bastya_elvtars on 20 March, 2006, 10:31:00
--Lua 5 By Dessamator(added message To Profile)
-- cleanup/optimization by bastya_elvtars
-- timed mass message from text by ?~??o?Hawk?o??~?
-- create a massmessage.txt file in the scripts directory
-- containing your message

CanDo =
{
[0] = 1, -- Master
[1] = 1, -- Operator
[2] = 1, -- VIP
[3] = 1, -- Reg
[4] = 1, -- Moderator
[5] = 1, -- Netfounder
[-1] =0, -- User
}

SendEvery = 1   ----  time in Mins

textfile = "massmessage.txt"

bot = frmHub:GetHubBotName()

hrs = 1000 * 60 * SendEvery
-------------------------------------------------------------
-------------------------------------------------------------
function Main()
SetTimer(hrs)
StartTimer()
end

function OnTimer()
local handle = io.open(textfile, "r")
if handle then
Temptimerfile = "\r\n"..string.gsub(handle:read("*a"),string.char(10), "\r\n")
for _,user in ipairs (frmHub:GetOnlineUsers()) do
if CanDo[user.iProfile]==1 then
user:SendPM(bot, Temptimerfile)
end
end
handle:close()
end
end
Title: Re: Timed mass message
Post by: -SkA- on 20 March, 2006, 11:01:58
Uhm... no errors from gui but I can't receive any mass message? ???

Edit: If I login with profile 0 it doesn't works, but with profile 1 it works well
Title: Re: Timed mass message
Post by: bastya_elvtars on 20 March, 2006, 11:15:37
Try the above again, edited & optimized.
Title: Re: Timed mass message
Post by: -SkA- on 20 March, 2006, 11:21:51
timedmessage.lua:35: attempt to index global 'f' (a nil value)
Title: Re: Timed mass message
Post by: bastya_elvtars on 20 March, 2006, 11:45:36
Copy & paste again.
Title: Re: Timed mass message
Post by: -SkA- on 20 March, 2006, 11:57:29
Well done  ;)

Thanks
Title: Re: Timed mass message
Post by: ((KMN))Gazza-95 on 26 June, 2006, 17:55:24
is there any way you can have more than 1 timed mass message
Title: Re: Timed mass message
Post by: Dessamator on 26 June, 2006, 19:27:48
Yes..
Title: Re: Timed mass message
Post by: Thor on 26 June, 2006, 19:42:45
Here is the extended version of TXT-show by bastya elvtars.
-- Txtshow by bastya_elvtars
-- At preconfigured times it shows a text file.
Botname = frmHub:GetHubBotName()
command = "!getmass"
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 = frmHub:GetPtokaXLocation().."scripts/massmessages/"

-- // 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")
SendPmToAll(Botname,"\r\n"..contents.."\r\n")
f:close()
end
end
Timer=0
end
end

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

function ChatArrival(curUser,data)
data = string.sub(data,1,string.len(data)-1)
local s,e,cmd = string.find(data,"%b<>%s(%S+)")
if cmd == command and curUser.bOperator then
local lista = "\r\n\tMass messages:\r\n"
for key,value in HubAD do
lista = lista.."\r\n\tTime: "..key.."\tFilename:\t"..value..""
end
curUser:SendPM(Botname, lista)
return 1
end
end

Just make a massmessages folder into the scripts folder, then put all txt files what you want to send. Then in the start of the script set up the messages in ["when"] = "what" format. I put the code the !getmass command to easily check when will send what.
Title: Re: Timed mass message
Post by: ((KMN))Gazza-95 on 27 June, 2006, 18:50:38
thx