PtokaX forum

Archive => Archived 4.0 boards => Request for Lua 4 scripts => Topic started by: BlazeXxX on 23 March, 2004, 01:21:53

Title: Subscribe / Unsubscribe Bot?
Post by: BlazeXxX on 23 March, 2004, 01:21:53
Hey folks,
I am planning to have a Messaging list a.k.a mailing list on web. I need a script that allows anyone from Unreged users to SU to subscribe them self to this system. Only People who are ops and Higher should be able to message to those subscribers. Its more like mass messaging to specific profile, but this one is going to read from a text file or some sort.

So for e.g.

!subscribe me      - this shud subscribe whoever is typing the command

!unsubscribe me  - This shud remove them from the messaging list

!subscribe   - This is for ops and higher to add ppl in the list manually

!unsubscribe - This shud remove them from messaing list, again only for ops and above.

The nick name should be there even if its 200 days, only it shud be removed upon unsubscribing.

The reason i am needing this script is, I have users who wants upto date news on things like whats happenig around, what site updates i made etc.. So this shud allow me to  mass msg those who are in the list.

I am pretty sure this can be done on hub side, so please cud someone give it a try? I don't want it taking too much memory, so must be pretty good for general usuage :)

Thanks in advance!

-BlazeXxX
Title:
Post by: nErBoS on 23 March, 2004, 15:27:38
Hi,

Hope it helps...

--Requested by BlazeXxX
--Made by nErBoS

Bot = "Submiter-Bot"

masstxt = "mass.txt" --Put where the text to be read
submiters = "submiters.txt" --Will be created in the script folder
mass = nil

function Main()
frmHub:RegBot(Bot)
end

function DataArrival(user, data)
if (strsub(data,1,1)=="<") or (strsub(data,1,5+strlen(Bot))=="$To: "..Bot) then
data=strsub(data,1,strlen(data)-1)
s,e,cmd = strfind(data,"%b<>%s+(%S+)")
if (cmd=="!subscribe") then
local s,e,who = strfind(data,"%b<>%s+(%S+)%s+(%S+)")
if (who == nil or who == "") then
WriteUser(user, user.sName)
else
if (user.bOpertor) then
WriteUser(user, who)
else
user:SendPM(Bot, "You don't have permission to put users in the submiters list.")
end
end
return 1
elseif (cmd=="!unsubscribe") then
local s,e,who = strfind(data,"%b<>%s+(%S+)%s+(%S+)")
if (who == nil or who == "") then
RemoveUser(user, user.sName)
else
if (user.bOpertor) then
RemoveUser(user, who)
else
user:SendPM(Bot, "You don't have permission to remove users from the submiters list.")
end
end
return 1
elseif (cmd=="!massnews") then
if (user.bOperator) then
MassMess(user)
else
user:SendPM(Bot, "You don't have permission to use this command.")
end
end
end
end

function WriteUser(user, whoto)
local tmp = ""
local time = 0
if (readfrom(submiters) == nil) then
writeto(submiters)
write(usr.."\r\n")
writeto()
else
readfrom(submiters)
while 1 do
local line = read()
if (line == nil) then
if (time == 0) then
user:SendPM(Bot, "The user "..whoto.." has been added to the list.")
tmp = tmp..usr.."\r\n"
else
user:SendPM(Bot, "The user "..whoto.." is already in the list.")
end
break
else
local s,e,who = strfind(line, "(%S+)")
if (who ~= nil and who == whoto) then
time = 1
else
tmp = tmp..line.."\r\n"
end
end
end
readfrom()
end
end

function RemoveUser(user, whoto)
local tmp = ""
local time = 0
if (readfrom(submiters) == nil) then
user:SendPM(Bot, "The file with the submitted users was not found.")
else
readfrom(submiters)
while 1 do
local line = read()
if (line == nil) then
if (time == 0) then
user:SendPM(Bot, "The user "..whoto.." wasn?t found in the list.")
else
user:SendPM(Bot, "The user "..whoto.." was removed from the list.")
end
break
else
local s,e,who = strfind(line, "(%S+)")
if (who ~= nil and who == whoto) then
time = 1
else
tmp = tmp..line.."\r\n"
end
end
end
readfrom()
writeto(submiters)
write(tmp)
writeto()
end
end

function MassMess(user)
local tmp = ""
if (readfrom(masstxt) == nil) then
user:SendPM(Bot, "The file with the news wasn't found.")
else
readfrom(submiters)
while 1 do
local line = read()
if (line == nil) then
break
else
local s,e,who = strfind(line, "(%S+)")
if (GetItemByName(who) ~= nil) then
if (mass == nil) then
mass = ReadText()
end
GetItemByName(who):SendPM(Bot, mass)
end
end
end
readfrom()
user:SendPM(Bot, "Message sent.")
end
end

function ReadText()
local tmp = ""
readfrom(masstxt)
while 1 do
local line = read()
if (line == nil) then
break
else
tmp = tmp..line.."\r\n"
end
end
return tmp
end

I haven?t tested it. But think that will work :)

Best regards, nErBoS
Title:
Post by: BlazeXxX on 25 March, 2004, 02:24:51
wow that was fast. I will test it tommorow and let u know. thx in advance, looks like it will work :D.