RegVardy Votebot by Phatty
 

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

RegVardy Votebot by Phatty

Started by pHaTTy, 16 April, 2004, 03:16:07

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

pHaTTy

request by yepyepyep

work in progess and here is 0.02; :-)

--//RegVardy Voter bot by Phatty *yawn* version 0.02;
--//REquest by someone, update soon when i awake properly no sleep yet lol
--//Untested;

Reg = {}
maxvotes = 11;
_mark = 5;


function Main() BOT = "RegVardy"; hubSD = SendToAll; frmHub:RegBot(BOT); end;

function DataArrival(reg,vardy)
	if strsub(vardy, 1, 4) == "$To:" then
		local s,e,whoto,from,vardy = strfind(vardy, "$To:%s+(%S+)%s+From:%s+(%S+)%s+(.*)") 
		local s,e,old,vardy = strfind(vardy, "(%S+)>(.*)")
		if whoto == BOT then
			local vardy=strsub(vardy,1,strlen(vardy)-1)
			if Reg[reg.sName] == "pass" then
				local s,e,pass = strfind(vardy,"(%S+)")
				AddRegUser(reg.sName,pass,3)
				reg:SendPM(BOT,"You are now registered with the pass: "..pass.." please reconnect and add this hub to favs")
				hubSD(BOT,reg.sName.." is now a registered member with us!")
			return nil; end;
		end;
	elseif strsub(vardy, 1, 1) == "<" then
		local vardy=strsub(vardy,1,strlen(vardy)-1) 
		local s,e,cmd = strfind(vardy, "%b<>%s+(%S+)")

		if cmd == "!voteme" then
			if reg.iProfile == -1 then
				if Reg[reg.sName] then
					reg:SendData(BOT,"You have a vote in progress")
				return nil; end;
				hubSD(BOT,reg.sName.." has requested votes to become a registered user, if u want to vote and let this user be registered here type !vote username yes/no")
				Reg[reg.sName] = {["yes"] = {}, ["no"] = {}, ["total"] = 0}
				return nil; else reg:SendData(BOT,"You are already registered")
				return nil; 
			end;
		elseif cmd == "!vote" then
			local s,e,name,answer = strfind(vardy, "%b<>%s+%S+%s+(%S+)%s+(%S+)")
			if name == nil then
				reg:SendData(BOT,"No such user in vote list!")
				return nil; else if Reg[name] then
					if Reg[name][answer] then
						local checkvote = CheckVoter(name,reg.sName)
						if checkvote == 1 then
							reg:SendData(BOT,"Do NOT try to vote for oneself")
							return nil; elseif checkvote == 2 then
							reg:SendData(BOT,"You have already voted for this user")
							return nil;
						end; Reg[name][answer] = reg.sName;
						if Reg[name]["total"] == maxvotes then
							CountVotes(name) return nil;
						end; hubSD(BOT,reg.sName.." has voted "..answer.." that "..name.." should be registered")
						Reg[name]["total"] = Reg[name]["total"] + 1; else
						reg:SendData(BOT,"Syntax: !vote  ")
					return nil; end;
				end;
			end;
		end;
	end;
end;

function CountVotes(name)
	local count = 0; for i,v in Reg[name]["yes"] do
	local count = count + 1;
	end; if count < _mark then
		SendPmToNick(name,BOT,"You have failed to recieve enough votes to be registered")
		Reg[name] = nil; return nil; else
		Reg[name] = "pass"; SendPmToNick(name,BOT,"You have been voted to be registered, please type your pass now, and u will be auto registered")
	return nil; end;
end;

function CheckVoter(name,sName)
	if name == sName then return 1; else
	for i,v in Reg[name]["yes"] do
		if v == sName then return 2; end;
	end; for i,v in Reg[name]["no"] do
		if v == sName then return 2; end;
	end; return nil; end;
end;
Resistance is futile!

yepyepyep4711

just tested it. Now the voting starts, but after the first person votes, when the others do nothing happens.

Further it would be nice if you'll only allow registered users to vote (I mean any user in the user db, so admin and op as well, but not unregistered users, otherwise they can elect each other :) )

thx

pHaTTy

hmm for the not working bit try this

--//RegVardy Voter bot by Phatty *yawn* version 0.02;
--//Request by yepyepyep, slept now :-P
--//Still Untested ;/

Reg = {}
maxvotes = 11;
_mark = 5;


function Main() BOT = "RegVardy"; hubSD = SendToAll; frmHub:RegBot(BOT); end;

function DataArrival(reg,vardy)
	if strsub(vardy, 1, 4) == "$To:" then
		local s,e,whoto,from,vardy = strfind(vardy, "$To:%s+(%S+)%s+From:%s+(%S+)%s+(.*)") 
		local s,e,vardy = strfind(vardy, "%S+>(.*)")
		if whoto == BOT then
			local vardy=strsub(vardy,1,strlen(vardy)-1)
			if Reg[reg.sName] == "pass" then
				local s,e,pass = strfind(vardy,"(%S+)")
				AddRegUser(reg.sName,pass,3)
				reg:SendPM(BOT,"You are now registered with the pass: "..pass.." please reconnect and add this hub to favs")
				hubSD(BOT,reg.sName.." is now a registered member with us!")
			return nil; end;
		end; 
	elseif strsub(vardy, 1, 1) == "<" then
		local vardy=strsub(vardy,1,strlen(vardy)-1) 
		local s,e,cmd = strfind(vardy, "%b<>%s+(%S+)")

		if cmd == "!voteme" then
			if reg.iProfile == -1 then
				if Reg[reg.sName] then
					reg:SendData(BOT,"You have a vote in progress")
				return nil; end;
				hubSD(BOT,reg.sName.." has requested votes to become a registered user, if u want to vote and let this user be registered here type !vote username yes/no")
				Reg[reg.sName] = {["yes"] = {}, ["no"] = {}, ["total"] = 0}
				return nil; else reg:SendData(BOT,"You are already registered")
				return nil; 
			end;
		elseif cmd == "!vote" then
			local s,e,name,answer = strfind(vardy, "%b<>%s+%S+%s+(%S+)%s+(%S+)")
			if name == nil then
				reg:SendData(BOT,"No such user in vote list!")
				return nil; else if Reg[name] then
					if Reg[name][answer] then
						local checkvote = CheckVoter(name,reg.sName)
						if checkvote == 1 then
							reg:SendData(BOT,"Do NOT try to vote for oneself")
							return nil; elseif checkvote == 2 then
							reg:SendData(BOT,"You have already voted for this user")
							return nil;
						end; Reg[name][answer][reg.sName] = nil;
						if Reg[name]["total"] == maxvotes then
							CountVotes(name) return nil;
						end; hubSD(BOT,reg.sName.." has voted "..answer.." that "..name.." should be registered")
						Reg[name]["total"] = Reg[name]["total"] + 1; else
						reg:SendData(BOT,"Syntax: !vote  ")
					return nil; end;
				end;
			end;
		end;
	end;
end;

function CountVotes(name)
	local count = 0; for i,v in Reg[name]["yes"] do
	local count = count + 1;
	end; if count < _mark then
		SendPmToNick(name,BOT,"You have failed to recieve enough votes to be registered")
		Reg[name] = nil; return nil; else
		Reg[name] = "pass"; SendPmToNick(name,BOT,"You have been voted to be registered, please type your pass now, and u will be auto registered")
	return nil; end;
end;

function CheckVoter(name,sName)
	if name == sName then return 1; else
	for i,v in Reg[name]["yes"] do
		if v == sName then return 2; end;
	end; for i,v in Reg[name]["no"] do
		if v == sName then return 2; end;
	end; return nil; end;
end;
Resistance is futile!

pHaTTy

ok unregistered cant vote

--//RegVardy Voter bot by Phatty *yawn* version 0.03;
--//Request by yepyepyep, slept now :-P
--//Still Untested ;/

Reg = {}
maxvotes = 11;
_mark = 5;


function Main() BOT = "RegVardy"; hubSD = SendToAll; frmHub:RegBot(BOT); end;

function DataArrival(reg,vardy)
	if strsub(vardy, 1, 4) == "$To:" then
		local s,e,whoto,from,vardy = strfind(vardy, "$To:%s+(%S+)%s+From:%s+(%S+)%s+(.*)") 
		local s,e,vardy = strfind(vardy, "%S+>(.*)")
		if whoto == BOT then
			local vardy=strsub(vardy,1,strlen(vardy)-1)
			if Reg[reg.sName] == "pass" then
				local s,e,pass = strfind(vardy,"(%S+)")
				AddRegUser(reg.sName,pass,3)
				reg:SendPM(BOT,"You are now registered with the pass: "..pass.." please reconnect and add this hub to favs")
				hubSD(BOT,reg.sName.." is now a registered member with us!")
			return nil; end;
		end; 
	elseif strsub(vardy, 1, 1) == "<" then
		local vardy=strsub(vardy,1,strlen(vardy)-1) 
		local s,e,cmd = strfind(vardy, "%b<>%s+(%S+)")

		if cmd == "!voteme" then
			if reg.iProfile == -1 then
				if Reg[reg.sName] then
					reg:SendData(BOT,"You have a vote in progress")
				return nil; end;
				hubSD(BOT,reg.sName.." has requested votes to become a registered user, if u want to vote and let this user be registered here type !vote username yes/no")
				Reg[reg.sName] = {["yes"] = {}, ["no"] = {}, ["total"] = 0}
				return nil; else reg:SendData(BOT,"You are already registered")
				return nil; 
			end;
		elseif cmd == "!vote" then
			if reg.iProfile == -1 then
				local s,e,name,answer = strfind(vardy, "%b<>%s+%S+%s+(%S+)%s+(%S+)")
				if name == nil then
					reg:SendData(BOT,"No such user in vote list!")
					return nil; else if Reg[name] then
						if Reg[name][answer] then
							local checkvote = CheckVoter(name,reg.sName)
							if checkvote == 1 then
								reg:SendData(BOT,"Do NOT try to vote for oneself")
								return nil; elseif checkvote == 2 then
								reg:SendData(BOT,"You have already voted for this user")
								return nil;
							end; Reg[name][answer][reg.sName] = nil;
							if Reg[name]["total"] == maxvotes then
								CountVotes(name) return nil;
							end; hubSD(BOT,reg.sName.." has voted "..answer.." that "..name.." should be registered")
							Reg[name]["total"] = Reg[name]["total"] + 1; else
							reg:SendData(BOT,"Syntax: !vote  ")
						return 1; end;
					end;
				end; else reg:SendData(BOT,"You are not qualified to vote, reg+ to vote ;-)")
			return 1; end;
		end;
	end;
end;

function CountVotes(name)
	local count = 0; for i,v in Reg[name]["yes"] do
	local count = count + 1;
	end; if count < _mark then
		SendPmToNick(name,BOT,"You have failed to recieve enough votes to be registered")
		Reg[name] = nil; return nil; else
		Reg[name] = "pass"; SendPmToNick(name,BOT,"You have been voted to be registered, please type your pass now, and u will be auto registered")
	return nil; end;
end;

function CheckVoter(name,sName)
	if name == sName then return 1; else
	for i,v in Reg[name]["yes"] do
		if v == sName then return 2; end;
	end; for i,v in Reg[name]["no"] do
		if v == sName then return 2; end;
	end; return nil; end;
end;

technically no point checking if the user is same but, dont matta it goes along with the return 2 check so i'll leave it
Resistance is futile!

pHaTTy

wait change

function CountVotes(name)
	local count = 0; for i,v in Reg[name]["yes"] do
	local count = count + 1;
	end; if count < _mark then
		SendPmToNick(name,BOT,"You have failed to recieve enough votes to be registered")
		Reg[name] = nil; return nil; else
		Reg[name] = "pass"; SendPmToNick(name,BOT,"You have been voted to be registered, please type your pass now, and u will be auto registered")
	return nil; end;
end;

function CheckVoter(name,sName)
	if name == sName then return 1; else
	for i,v in Reg[name]["yes"] do
		if i == sName then return 2; end;
	end; for i,v in Reg[name]["no"] do
		if i == sName then return 2; end;
	end; return nil; end;
end;
Resistance is futile!

yepyepyep4711

#5
I think you got the levelproofing the wrong way round, admin, op and reg can't vote, but unregged can   :D

I'm using admin=0, op=1, reg=3.

And you got the vote counting wrong as well. :D
I let 11 users vote for another one, and it still says he hasn't got enough votes, lol

but thx for working on it

pHaTTy

yep forgot about that am still tired lol gone in 3 days too =)

function DataArrival(reg,vardy)
	if strsub(vardy, 1, 4) == "$To:" then
		local s,e,whoto,from,vardy = strfind(vardy, "$To:%s+(%S+)%s+From:%s+(%S+)%s+(.*)") 
		local s,e,vardy = strfind(vardy, "%S+>(.*)")
		if whoto == BOT then
			local vardy=strsub(vardy,1,strlen(vardy)-1)
			if Reg[reg.sName] == "pass" then
				local s,e,pass = strfind(vardy,"(%S+)")
				AddRegUser(reg.sName,pass,3)
				reg:SendPM(BOT,"You are now registered with the pass: "..pass.." please reconnect and add this hub to favs")
				hubSD(BOT,reg.sName.." is now a registered member with us!")
			return nil; end;
		end; 
	elseif strsub(vardy, 1, 1) == "<" then
		local vardy=strsub(vardy,1,strlen(vardy)-1) 
		local s,e,cmd = strfind(vardy, "%b<>%s+(%S+)")

		if cmd == "!voteme" then
			if reg.iProfile == -1 then
				if Reg[reg.sName] then
					reg:SendData(BOT,"You have a vote in progress")
				return nil; end;
				hubSD(BOT,reg.sName.." has requested votes to become a registered user, if u want to vote and let this user be registered here type !vote username yes/no")
				Reg[reg.sName] = {["yes"] = {}, ["no"] = {}, ["total"] = 0}
				return nil; else reg:SendData(BOT,"You are already registered")
				return nil; 
			end;
		elseif cmd == "!vote" then
			if reg.iProfile ~= -1 then
				local s,e,name,answer = strfind(vardy, "%b<>%s+%S+%s+(%S+)%s+(%S+)")
				if name == nil then
					reg:SendData(BOT,"No such user in vote list!")
					return nil; else if Reg[name] then
						if Reg[name][answer] then
							local checkvote = CheckVoter(name,reg.sName)
							if checkvote == 1 then
								reg:SendData(BOT,"Do NOT try to vote for oneself")
								return nil; elseif checkvote == 2 then
								reg:SendData(BOT,"You have already voted for this user")
								return nil;
							end; Reg[name][answer][reg.sName] = nil;
							if Reg[name]["total"] == maxvotes then
								CountVotes(name) return nil;
							end; hubSD(BOT,reg.sName.." has voted "..answer.." that "..name.." should be registered")
							Reg[name]["total"] = Reg[name]["total"] + 1; else
							reg:SendData(BOT,"Syntax: !vote  ")
						return 1; end;
					end;
				end; else reg:SendData(BOT,"You are not qualified to vote, reg+ to vote ;-)")
			return 1; end;
		end;
	end;
end;
Resistance is futile!

yepyepyep4711

then I'd better reply quick :)

now the levelproofing functions, but it still says "not enough votes" in the end.

An idea: instead of needing maxvotes, with _mark of them positive, how about letting the vote run for a configurable length of time (I'd choose a day) and then count up, user with more than a configurable percentage  of positives gets elected.

Like in
!vote me
Testuser has requested votes to become a registered user, if u want to vote and let this user be registered here type !vote username yes/no. The vote will run until ,

pHaTTy

QuoteOriginally posted by yepyepyep4711
then I'd better reply quick :)

now the levelproofing functions, but it still says "not enough votes" in the end.

An idea: instead of needing maxvotes, with _mark of them positive, how about letting the vote run for a configurable length of time (I'd choose a day) and then count up, user with more than a configurable percentage  of positives gets elected.

Like in
!vote me
Testuser has requested votes to become a registered user, if u want to vote and let this user be registered here type !vote username yes/no. The vote will run until ,


only prob is checking the time n date, hmmm altho come to think of it, its on local comp in memory sowont affect, yup i thnk that cud be much better, the _mark was being pain in the ass anyways, i will re-do the tables so its all in one, thats if i get time, i wil start now, 2 more days left =)


altho come to think about it, if ya got alot of users in the table, checking them for if the toime has expired each, cud be pretty resource usage, unless its done every hour, cud be less usage, like if time is above certain time n date hmmmm, me will go see =)
Resistance is futile!

yepyepyep4711

QuoteOriginally posted by (uk-kingdom)pH?tt??
me will go see =)

that's great :)

the table shouldn't become to big, as there should be only the votes still running in it.
I guess a good idea would also be to let the script check if the user is online before asking him to enter password, upon deadline, and postponing the announcement for another hour during a day or so.

SMF spam blocked by CleanTalk