PtokaX forum

Archive => Archived 4.0 boards => Finished Lua 4 scripts => Topic started by: pHaTTy on 16 April, 2004, 03:16:07

Title: RegVardy Votebot by Phatty
Post by: pHaTTy on 16 April, 2004, 03:16:07
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;

Title:
Post by: yepyepyep4711 on 16 April, 2004, 12:47:34
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
Title:
Post by: pHaTTy on 18 April, 2004, 03:56:52
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;
Title:
Post by: pHaTTy on 18 April, 2004, 04:00:53
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
Title:
Post by: pHaTTy on 18 April, 2004, 04:03:47
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;
Title:
Post by: yepyepyep4711 on 18 April, 2004, 21:31:58
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
Title:
Post by: pHaTTy on 19 April, 2004, 11:23:08
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;
Title:
Post by: yepyepyep4711 on 19 April, 2004, 12:35:25
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 ,
Title:
Post by: pHaTTy on 20 April, 2004, 11:18:58
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 =)
Title:
Post by: yepyepyep4711 on 20 April, 2004, 18:09:57
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.