(Yes and No) Vote-Poll
 

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

(Yes and No) Vote-Poll

Started by nErBoS, 15 March, 2004, 14:40:38

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

nErBoS

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
--## nErBoS Spot ##--

nErBoS

#1
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
--## nErBoS Spot ##--

Skyhawk

well it still is possible to vote several times
you must use a log file  where nick poll on opt is saved

Skyhawk

Delay that i was stilln using the old version

nErBoS

Hi,

Vote-Poll v.: 0.1

Notes:

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

Download HERE.

Best regards, nErBoS
--## nErBoS Spot ##--

Skyhawk

hmmm

+showvote (user not master) doesn't show anything just the name of the Bot

nErBoS

Hi,

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

Best regards, nErBoS
--## nErBoS Spot ##--

OneHero

could u cut out the nr, dont want that...

nErBoS

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
--## nErBoS Spot ##--

OneHero

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

FrAcTi0n

good scipt nerbos, but is there a way that only registered users can vote?

nErBoS

Hi,

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

Best regards, nErBoS
--## nErBoS Spot ##--

TTB

#12
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.
TTB

(? ?.??.-> Admin @ Surfnet hubs <-.??.???)

TTB

#13
nErBoS,

can you modify the script that there can be only one poll at the time is active (so people can vote with +vote
TTB

(? ?.??.-> Admin @ Surfnet hubs <-.??.???)

nErBoS

Hi,

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

Best regards, nErBoS
--## nErBoS Spot ##--

TTB

Hi nErBoS,

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

Thanx  :D
TTB

(? ?.??.-> Admin @ Surfnet hubs <-.??.???)

nErBoS

Hi,

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

Best regards, nErBoS
--## nErBoS Spot ##--

TTB

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
TTB

(? ?.??.-> Admin @ Surfnet hubs <-.??.???)

nErBoS

Hi,

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

Best regards, nErBoS
--## nErBoS Spot ##--

TTB

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

TTB

(? ?.??.-> Admin @ Surfnet hubs <-.??.???)

SMF spam blocked by CleanTalk