PtokaX forum

Archive => Archived 4.0 boards => Finished Lua 4 scripts => Topic started by: nErBoS on 15 March, 2004, 14:40:38

Title: (Yes and No) Vote-Poll
Post by: nErBoS on 15 March, 2004, 14:40:38
Hi,

Made it with a request a think that is usefull for all..

--Made by nErBoS

Bot = "Vote-Bot"

vt = {}
nr = {}

votetext = "votepoll.txt" --Will be created in the script folder
oldpolls = "oldpolls.txt" --Will be created in the script folder

function Main()
frmHub:RegBot(Bot)
end

function NewUserConnected(user, data)
if (vt[user.sName] == nil) then
vt[user.sName] = 0
end
if (nr[user.sName] == nil) then
nr[user.sName] = 0
end
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=="+votehelp") then
local msg = ""
if (user.iProfile == 0) then
msg = msg.."Commands to the Vote-Poll:\r\n"
msg = msg.."\r\n"
msg = msg.."+createvote \tCreates a poll (nr = number to give to poll) (q = Poll question)\r\n"
msg = msg.."+stopvote \t\tWill end the vote-poll\r\n"
msg = msg.."+showvote \tShow the vote results of the poll (old = old polls) or (new = polls that haven't been closed)\r\n"
msg = msg.."+svmain \tShow the vote results in the mainchat (old = old polls) or (new = polls that haven't been closed)\r\n"
msg = msg.."+votelist\t\t\tShow all finished polls\r\n"
msg = msg.."+votefor\t\t\tShow the polls that you can vote\r\n"
msg = msg.."+vote \t\tTo vote on the poll (y = yes) (n = no) (nr = number of the poll)\r\n"
msg = msg.."+delvote \t\tTo delete old polls (nr = number of the poll)\r\n"
msg = msg.."\r\n"
user:SendPM(Bot, msg)
else
msg = msg.."Commands to the Vote-Poll:\r\n"
msg = msg.."\r\n"
msg = msg.."+votefor\t\t\tShow the polls that you can vote\r\n"
msg = msg.."+vote \t\tTo vote on the poll (y = yes) (n = no) (nr = number of the poll)\r\n"
msg = msg.."\r\n"
user:SendPM(Bot, msg)
end
return 1
elseif (cmd=="+createvote") then
if (user.iProfile == 0) then
local s,e,number,question = strfind(data,"%b<>%s+%S+%s+(%S+)%s+(.*)")
if (tonumber(number) == nil) then
user:SendPM(Bot, "Syntax error, +createvote , nr must be a number.")
else
number = tonumber(number)
if (question == nil or question == "") then
user:SendPM(Bot, "Syntax error, +createvote , you must write a question to the poll.")
else
if (CreatePoll(user, number, question) == 1) then
user:SendPM(Bot, "The Vote-Poll has been created.")
else
user:SendPM(Bot, "There is a already a Vote-Poll with the number "..number..".")
end
end
end
else
user:SendPM(Bot, "You don?t have permision to this command.")
end
return 1
elseif (cmd=="+stopvote") then
if (user.iProfile == 0) then
local s,e,number = strfind(data,"%b<>%s+%S+%s+(.*)")
if (tonumber(number) == nil or number == "") then
user:SendPM(Bot, "Syntax error, +stopvote , nr must be a number.")
else
number = tonumber(number)
if (OldPoll(user, number) == 1) then
user:SendPM(Bot, "The Vote-Poll has been closed an saved on the Old Polls.")
else
user:SendPM(Bot, "There is no Vote-Poll with the number "..number..".")
end
end
else
user:SendPM(Bot, "You don?t have permision to this command.")
end
return 1
elseif (cmd=="+showvote") then
if (user.iProfile == 0) then
local s,e,number, opt = strfind(data,"%b<>%s+%S+%s+(%S+)%s+(%S+)")
if (tonumber(number) == nil) then
user:SendPM(Bot, "Syntax error, +showvote , nr must be a number.")
else
number = tonumber(number)
if (opt == "old") then
if (CheckPoll(user, number, oldpolls) == "") then
user:SendPM(Bot, "There is no Vote-Poll with the number "..number..".")
else
user:SendPM(Bot, CheckPoll(user, number, oldpolls))
end
elseif(opt == "new") then
if (CheckPoll(user, number, votetext) == "") then
user:SendPM(Bot, "There is no Vote-Poll with the number "..number..".")
else
user:SendPM(Bot, CheckPoll(user, number, votetext))
end
else
user:SendPM(Bot, "Syntax error, +showvote , must be (old = old polls) or (new = polls that haven't been closed)")
end
end
else
user:SendPM(Bot, "You don?t have permision to this command.")
end
return 1
elseif (cmd=="+svmain") then
if (user.iProfile == 0) then
local s,e,number, opt = strfind(data,"%b<>%s+%S+%s+(%S+)%s+(%S+)")
if (tonumber(number) == nil) then
user:SendPM(Bot, "Syntax error, +svmain , nr must be a number.")
else
number = tonumber(number)
if (opt == "old") then
if (CheckPoll(user, number, oldpolls) == "") then
user:SendPM(Bot, "There is no Vote-Poll with the number "..number..".")
else
SendToAll(Bot, CheckPoll(user, number, oldpolls))
end
elseif(opt == "new") then
if (CheckPoll(user, number, votetext) == "") then
user:SendPM(Bot, "There is no Vote-Poll with the number "..number..".")
else
SendToAll(Bot, CheckPoll(user, number, votetext))
end
else
user:SendPM(Bot, "Syntax error, +svmain , must be (old = old polls) or (new = polls that haven't been closed)")
end
end
else
user:SendPM(Bot, "You don?t have permision to this command.")
end
return 1
elseif (cmd=="+votelist") then
if (user.iProfile == 0) then
if (readfrom(oldpolls) == nil or ReadPoll(user, oldpolls) == "") then
user:SendPM(Bot, "There is no closed Vote-Polls")
else
user:SendPM(Bot, ReadPoll(user, oldpolls))
end
else
user:SendPM(Bot, "You don?t have permision to this command.")
end
return 1
elseif (cmd=="+votefor") then
if (readfrom(votetext) == nil or ReadPoll(user, votetext) == "") then
user:SendPM(Bot, "There is no Vote-Polls")
else
user:SendPM(Bot, ReadPoll(user, votetext))
end
return 1
elseif (cmd=="+vote") then
local s,e,number,opt = strfind(data,"%b<>%s+%S+%s+(%S+)%s+(%S+)")
if (tonumber(number) == nil) then
user:SendPM(Bot, "Syntax error, +vote , nr must be a number.")
else
number = tonumber(number)
if (opt == nil or opt == "" or opt ~= "n" and opt ~= "y") then
user:SendPM(Bot, "Syntax error, +vote , must type (y = yes) or (n = no).")
else
if (Vote(user, number, opt) == 1) then
user:SendPM(Bot, "Your Vote has been registered.")
vt[user.sName] = 1
nr[user.sName] = number
elseif(Vote(user, number, opt) == 2) then
user:SendPM(Bot, "You have already made a vote on this Vote-Poll")
else
user:SendPM(Bot, "There isn?t any Vote-Poll with the number "..number..".")
end
end
end
return 1
elseif (cmd=="+delvote") then
if (user.iProfile == 0) then
local s,e,number = strfind(data,"%b<>%s+%S+%s+(%S+)")
if (tonumber(number) == nil) then
user:SendPM(Bot, "Syntax error, +delvote , nr must be a number.")
else
number = tonumber(number)
if (DelOldPoll(user, number) == 0) then
user:SendPM(Bot, "Ther is no Old Polll wtih the number "..number)
else
user:SendPM(Bot, "The Old Poll has been deleted.")
end
end
else
user:SendPM(Bot, "You don?t have permision to this command.")
end
return 1
end
end
end

function CreatePoll(user, number, question)
local tmp = ""
local time = 0

   readfrom(oldpolls)
   while 1 do
      local line = read()
      if (line == nil) then
break
      else
local s,e,num = strfind(line,"Nr:%s+(%S+)%s+")
if (tonumber(num) ~= nil and tonumber(num) == number) then
time = 2
else
end
      end
   end
readfrom()

   readfrom(votetext)
   while 1 do
      local line = read()
      if (line == nil) then
if (time == 2) then
         break
else
tmp = tmp.."Nr: "..number.." Question: "..question.." Yes: 0 No: 0 Active: Yes\r\n"
time = 1
         break
         end
      else
local s,e,num = strfind(line,"Nr:%s+(%S+)%s+")
if (tonumber(num) ~= nil and tonumber(num) == number) then
tmp = tmp..line.."\r\n"
time = 2
else
tmp = tmp..line.."\r\n"
end
      end
   end
readfrom()
writeto(votetext)
write(tmp)
writeto()
return time
end

function OldPoll(user, number)
local tmp = ""
local tmp2 = ""
local time = 0
   readfrom(votetext)
   while 1 do
      local line = read()
      if (line == nil) then
      break
      else
local s,e, num, question, ny, nn = strfind(line,"Nr:%s+(%S+)%s+(.*)Yes:%s+(%S+)%s+No:%s+(%S+)%s+Active:")
if (tonumber(num) ~= nil and tonumber(num) == number) then
tmp2 = tmp2.."Nr: "..number.." "..question.."Yes: "..ny.." No: "..nn.." Active: No\r\n"
         time = 1
else
tmp = tmp..line.."\r\n"
end
      end
   end
readfrom()
writeto(votetext)
write(tmp)
writeto()
if (time == 0) then
else
appendto(oldpolls)
write(tmp2)
writeto()
end
return time
end

function CheckPoll(user, number, file)
local tmp = ""
   readfrom(file)
   while 1 do
      local line = read()
      if (line == nil) then
      break
      else
local s,e, num, question, ny, nn = strfind(line,"Nr:%s+(%S+)%s+(.*)Yes:%s+(%S+)%s+No:%s+(%S+)%s+Active:")
if (tonumber(num) ~= nil and tonumber(num) == number) then
tmp = tmp.."\r\n-------------------- Vote Poll --------------------\r\n"
tmp = tmp.."Results of Vote-Poll Nr: "..num.."\r\n"
tmp = tmp.."Vote "..question.."\r\n"
tmp = tmp.."------------------------------\r\n"
tmp = tmp.."Yes: "..ny.."\r\n"
tmp = tmp.."No: "..nn.."\r\n"
tmp = tmp.."------------------------------\r\n"
if (tonumber(ny) > tonumber(nn)) then
tmp = tmp.."Yes is Winnig."
elseif (tonumber(ny) < tonumber(nn)) then
tmp = tmp.."No is Winnig."
elseif (tonumber(ny) == tonumber(nn)) then
tmp = tmp.."Yes and No is equal."
end
break
else
end
      end
   end
readfrom()
return tmp
end

function ReadPoll(user, file)
local tmp = ""
   readfrom(file)
   while 1 do
      local line = read()
      if (line == nil or line == "") then
      break
      else
local s,e, num, question, ny, nn = strfind(line,"Nr:%s+(%S+)%s+(.*)Yes:%s+(%S+)%s+No:%s+(%S+)%s+Active:")
if (num == nil) then
else
tmp = tmp.."\r\n-------------------- Vote Poll --------------------\r\n"
tmp = tmp.."Results of Vote-Poll Nr: "..num.."\r\n"
tmp = tmp.."Vote "..question.."\r\n"
tmp = tmp.."------------------------------\r\n"
tmp = tmp.."Yes: "..ny.."\r\n"
tmp = tmp.."No: "..nn.."\r\n"
tmp = tmp.."------------------------------\r\n"
if (file == oldpolls) then
tmp = tmp.."Closed Vote-Poll\r\n"
elseif (file == votetext) then
tmp = tmp.."Active Vote-Poll\r\n"
end
end
      end
   end
readfrom()
return tmp
end

function Vote(user, number, opt)
local tmp = ""
local time = 0
if (vt[user.sName] == 1 and nr[user.sName] == number) then
   time = 2
else
   readfrom(votetext)
   while 1 do
      local line = read()
      if (line == nil) then
      break
      else
local s,e, num, question, ny, nn = strfind(line,"Nr:%s+(%S+)%s+(.*)Yes:%s+(%S+)%s+No:%s+(%S+)%s+Active:")
if (tonumber(num) ~= nil and tonumber(num) == number) then
if (opt == "y") then
ny = tonumber(ny) + 1
elseif (opt == "n") then
nn = tonumber(nn) + 1
end
tmp = tmp.."Nr: "..number.." "..question.."Yes: "..ny.." No: "..nn.." Active: Yes\r\n"
         time = 1
else
tmp = tmp..line.."\r\n"
end
      end
   end
readfrom()
writeto(votetext)
write(tmp)
writeto()
end
return time
end

function DelOldPoll(user, number)
local tmp = ""
local time = 0
   readfrom(oldpolls)
   while 1 do
      local line = read()
      if (line == nil) then
      break
      else
local s,e, num, question, ny, nn = strfind(line,"Nr:%s+(%S+)%s+(.*)Yes:%s+(%S+)%s+No:%s+(%S+)%s+Active:")
if (tonumber(num) ~= nil and tonumber(num) == number) then
         time = 1
else
tmp = tmp..line.."\r\n"
end
      end
   end
readfrom()
writeto(oldpolls)
write(tmp)
writeto()
return time
end

Best regards, nErBoS
Title:
Post by: nErBoS on 27 April, 2004, 02:13:06
Hi,

--Vote-Poll made by nErBoS
--Creates Vote Poll with Yes and No or add Option by Master's
--User?s Can only vote one time in a Poll
--Option to have Old Polls saved
--Option to show old and new Poll on the main-chat to every one
-- +votehelp Shows All Vote Commands

Have Fun.

Best regards, nErBoS
Title:
Post by: Skyhawk on 30 April, 2004, 20:52:41
well it still is possible to vote several times
you must use a log file  where nick poll on opt is saved
Title:
Post by: Skyhawk on 01 May, 2004, 00:08:06
Delay that i was stilln using the old version
Title:
Post by: nErBoS on 01 May, 2004, 01:24:09
Hi,

Vote-Poll v.: 0.1

Notes:

--Vote-Poll commands to be show with timers.

Download HERE (http://nerbos.no.sapo.pt/Vote-Poll%200.1a.zip).

Best regards, nErBoS
Title:
Post by: Skyhawk on 01 May, 2004, 01:40:38
hmmm

+showvote (user not master) doesn't show anything just the name of the Bot
Title:
Post by: nErBoS on 01 May, 2004, 23:43:46
Hi,

Yes you are right little bug fixed just downlad the script again.

Best regards, nErBoS
Title:
Post by: OneHero on 09 July, 2004, 16:21:44
could u cut out the nr, dont want that...
Title:
Post by: nErBoS on 10 July, 2004, 01:13:57
Hi,

It could be cut but the number is very useful to delete or to vote on the pole, how do you suggest to handle that, for eg to vote on the poll ??

Best regards, nErBoS
Title:
Post by: OneHero on 10 July, 2004, 02:54:41
i just wanna +createvote and if i wanna change it i could type delvote, and then aplly new one, or createvote and it will overwrite the old one

then the users could have a vote yes or no, but only one time pr user
Title:
Post by: FrAcTi0n on 07 December, 2004, 14:13:20
good scipt nerbos, but is there a way that only registered users can vote?
Title:
Post by: nErBoS on 08 December, 2004, 22:12:52
Hi,

Yes it is possible. I have to rewrite this script, its code its very bad :P

Best regards, nErBoS
Title:
Post by: TTB on 09 December, 2004, 00:27:00
Hi Nerbos...

Again a wonderfull script you've made!

Was just thinking... I have seen in a hub (DCH++ 0.33) a vote bot where OP/SU's can create a poll. Well... I paste the text of it, then you know what I mean:

<[BOT]RulezPatrol>
Wie gaat er donderdag stemmen?
210(65.62%) votes for A) Ik, tuurlijk
 47(14.69%) votes for B) nee, echt niet
 47(14.69%) votes for C) weet nog niet
 16(5.00%) votes for D) I don't like polls  [[kun.nl]Zipkid, 10-06-2004]


I must say... this bot they made, is a really a kick ass BOT...

They can add options for the vote, beginning with A and ending with Z (or so)...

Maybe you can build something like that... I think it will cost a lot (to much?!) of time....

Well.. greetz again!

TTB

>> I don't want to take the point away...! I know the thread is about a yes/no vote bot... I was just thinking.... just an idea.
Title:
Post by: TTB on 16 December, 2004, 15:09:51
nErBoS,

can you modify the script that there can be only one poll at the time is active (so people can vote with +vote
Title:
Post by: nErBoS on 17 December, 2004, 14:48:53
Hi,

When i start re-written the script i will see what i can do.

Best regards, nErBoS
Title:
Post by: TTB on 31 December, 2004, 16:35:42
Hi nErBoS,

just wondering if you already have rewritten the script...

Thanx  :D
Title:
Post by: nErBoS on 04 January, 2005, 01:26:45
Hi,

No, I am having a lot of work to do, i will do it as soon as i can.

Best regards, nErBoS
Title:
Post by: TTB on 19 January, 2005, 02:43:45
Hi...

Again just wondering if you almost have finished the script... :)

I don't want to push or something... I just can't wait  :D

I will now keep my mouth shut till you have finished it...  :P
Title:
Post by: nErBoS on 20 January, 2005, 01:13:44
Hi,

In Febuary i will have some vacations, i hope to make the new version of this BOT.

Best regards, nErBoS
Title: Re: (Yes and No) Vote-Poll
Post by: TTB on 25 September, 2006, 19:11:11
IN the beginning, I was a n00b... now I'm more like a newbie. Well... it is funny to check a request of your own when I couldn't script at all. Now I created it on my own ( http://forum.ptokax.org/index.php?topic=6138.0 ). I hope nErBoS will return some day. Haven't seen him for a big while... To all n00b scripters: JUST TRY! Some day you can create your own requests on your own :)