PtokaX forum

Archive => Archived 4.0 boards => Request for Lua 4 scripts => Topic started by: Pieltre on 24 November, 2003, 21:49:22

Title: voting scritp - pollbot
Post by: Pieltre on 24 November, 2003, 21:49:22
Hi,

I'm using the voting script named by default pollbot (in may case Voting_bot), that you can find pretty much everywhere (I'll paste it below in any case).  The problem with the script is that any user, who doesn't understand very well how it works can easily delete any ongoing poll, since the creation and deletion command are available to all, and not only to OPs.  Also, the script is blind to who gets to vote and, consequently, how many times they get to vote... Another major problem is the fact that the bot only logs the poll presently running and overwrites the old poll in the log...

If any of your talented guys could correct any of those bugs or direct me to a script that doesn't suffer from those bugs, I'd be very happy.  Pieltre

Here's the script I use:

botname = "Voting_bot"
Poll = {}
PollDescription = ""

function GetArgs(data)
s,e,whoTo,from,cmd,arg = strfind(data,"$To:%s+(%S+)%s+From:%s+(%S+)%s+$%b<>%s+(%S+)%s+(.*)")
return arg
end

function Main()
frmHub:RegBot(botname)
end
function DataArrival(user, data)
if(strsub(data, 1, 4) == "$To:") then
data=strsub(data,1,strlen(data)-1)
s,e,whoTo = strfind(data,"$To:%s+(%S+)")
if (whoTo == botname) then
s,e,whoTo,from,cmd = strfind(data,"$To:%s+(%S+)%s+From:%s+(%S+)%s+$%b<>%s+(%S+)")
if (user.bOperator) then
if (cmd=="+createpoll") then
arg= GetArgs(data)
PollDescription = arg
Poll={}
user:SendPM(botname,"poll succesfully created...")
end
if (cmd=="+addpolloption") then
arg= GetArgs(data)
Poll[arg]=0
user:SendPM(botname,"poll option "..arg.."added")
end
if (cmd=="+savepoll") then
local handle=openfile("poll.dat","a")
write(handle,PollDescription.."\n")
for a,b in Poll do
write(handle,a.."?"..b.."\n")
end
closefile(handle)
user:SendPM(botname,"Poll has been successfully saved")
end
if (cmd=="+loadpoll") then
local handle=openfile("poll.dat","r")
PollDescription=read(handle)
while 1 do
local line = read(handle)
if line == nil then break
else
user:SendPM(botname,line.." ")
x,y,a=strfind(line,"([^?]*)")
x,y,b=strfind(line,"([^?]*)$")
Poll[a]=b
end
end

closefile(handle)
user:SendPM(botname,"Poll has been successfully loaded")
end
Title: idem...
Post by: Fire Koboy on 26 November, 2003, 00:27:50
I would be very interested too to get this final script....
Thanx to work on it guys....
:)
Tcho
Title:
Post by: pHaTTy on 26 November, 2003, 00:53:45
hmm this looks weird to me, different style to how i script but here goes my attemp loool


botname = "Voting_bot"
Poll = {}
PollDescription = ""

function GetArgs(data)
s,e,whoTo,from,cmd,arg = strfind(data,"$To:%s+(%S+)%s+From:%s+(%S+)%s+$%b<>%s+(%S+)%s+(.*)")
return arg
end

function Main()
frmHub:RegBot(botname)
end

function DataArrival(user, data)
if(strsub(data, 1, 4) == "$To:") then
data=strsub(data,1,strlen(data)-1)
s,e,whoTo = strfind(data,"$To:%s+(%S+)")

if (whoTo == botname) then
s,e,whoTo,from,cmd = strfind(data,"$To:%s+(%S+)%s+From:%s+(%S+)%s+$%b<>%s+(%S+)")
if (user.bOperator) then
if (cmd=="+createpoll") then
arg= GetArgs(data)
PollDescription = arg
Poll={}
user:SendPM(botname,"poll succesfully created...")
return 1
elseif (cmd=="+addpolloption") then
arg= GetArgs(data)
Poll[arg]=0
user:SendPM(botname,"poll option "..arg.."added")
return 1
elseif (cmd=="+savepoll") then
local handle=openfile("poll.dat","a")
write(handle,PollDescription.."\n")
for a,b in Poll do
write(handle,a.."?"..b.."\n")
end
closefile(handle)
user:SendPM(botname,"Poll has been successfully saved")
return 1
elseif (cmd=="+loadpoll") then
local handle=openfile("poll.dat","r")
PollDescription=read(handle)
while 1 do
local line = read(handle)
if line == nil then break
else
user:SendPM(botname,line.." ")
x,y,a=strfind(line,"([^?]*)")
x,y,b=strfind(line,"([^?]*)$")
Poll[a]=b
closefile(handle)
user:SendPM(botname,"Poll has been successfully loaded")
return 1
end
end
end
end
end
end
end



try that :)

-phatty
Title: thanx....
Post by: Fire Koboy on 26 November, 2003, 06:28:10
Thanx a lot for this script....I will try it when finishing job thursday...and keep you aware if working well or not...

sorry for my bad english....