PtokaX forum

Archive => Archived 4.0 boards => Request for Lua 4 scripts => Topic started by: Malcon on 21 July, 2004, 14:47:25

Title: Vote for hub VIP
Post by: Malcon on 21 July, 2004, 14:47:25
hi .

i?m looking for a script
where users in the hub ,can vote for a user to become a new VIP in the hub.

users that vote can only vote one time.

maybe a timeline for how long the voting is open ..
say 3-5days

if its possible , it would be a funny thing for the users

running Ptokax TD4

 :rolleyes:  /m

Title:
Post by: nErBoS on 21 July, 2004, 17:11:08
Hi,

Hope it helps...

--## VIP Vote-Bot
--## Made by nErBoS
--## Requested by
--## Commands:
--## +addvoter - Adds a nick to be voted to becamea VIP
--## +delvoter - Removes a nick from been voted to became a VIP
--## +votelist - Shows All users the are been voeted and the number of votes to became a VIP
--## +vote - Register a vote for a nick to became a VIP


sBot = "VIP-Vote"

arrVoter = {
["user"] = {},
["ip"] = {},
["voter"] = {},
}

fVoter= "voter.dat"

--## Configuration ##--

verPtokax = 1 --## Choose 0 for ptokax version lower then 0.3.3.0
--## Choose 1 for ptokax versions 0.3.3.0 or higher
iDays = 5 --## Number of days that a user can vote again

--## END of Configuration ##--

function Main()
frmHub:RegBot(sBot)
LoadFromFile(fVoter)
RefreshVotes()
end

function OnExit()
SaveToFile(fVoter , arrVoter , "arrVoter")
end

function DataArrival(user, data)
if (strsub(data,1,1) == "<" or strsub(data,1,5+strlen(sBot)) == "$To: "..sBot) then
data = strsub(data,1,strlen(data)-1)
s,e,cmd = strfind(data, "%b<>%s+(%S+)")
if (cmd == "+addvoter" and user.bOperator) then
local s,e,nick = strfind(data, "%b<>%s+%S+%s+(%S+)")
if (nick == nil) then
user:SendPM(sBot, "Syntax Error, +addvoter , you must write a nick.")
elseif (arrVoter["voter"][strlower(nick)] ~= nil) then
user:SendPM(sBot, "The user "..nick.." is already been voted.")
else
arrVoter["voter"][strlower(nick)] = 0
user:SendPM(sBot, "The user "..nick.." has been added in the Vote To Be VIP.")
if (verPtokax == 0) then
OnExit()
end
end
return 1
elseif (cmd == "+delvoter" and user.bOperator) then
local s,e,nick = strfind(data, "%b<>%s+%S+%s+(%S+)")
if (nick == nil) then
user:SendPM(sBot, "Syntax Error, +delvoter , you must write a nick.")
elseif (arrVoter["voter"][strlower(nick)] == nil) then
user:SendPM(sBot, "The user "..nick.." is not been voted.")
else
arrVoter["voter"][strlower(nick)] = nil
user:SendPM(sBot, "The user "..nick.." has been removed from the Vote To Be VIP.")
if (verPtokax == 0) then
OnExit()
end
end
return 1
elseif (cmd == "+votelist") then
ListOfVoter(user)
return 1
elseif (cmd == "+vote") then
local s,e,nick = strfind(data, "%b<>%s+%S+%s+(%S+)")
if (nick == nil) then
user:SendPM(sBot, "Syntax Error, +vote , you must write a nick.")
elseif (arrVoter["voter"][strlower(nick)] == nil) then
user:SendPM(sBot, "The user "..nick.." is not been voted.")
elseif (arrVoter["user"][user.sName] ~= nil) then
RefreshVotes()
if (tonumber(arrVoter["user"][user.sName]) + iDays <= tonumber(GetTime())) then
arrVoter["user"][user.sName] = GetTime()
arrVoter["ip"][user.sIP] = GetTime()
arrVoter["user"][strlower(nick)] = arrVoter["user"][strlower(nick)] + 1
user:SendPM(sBot, "Your vote for the user "..nick.." has been register, you only can vote again in the next "..iDays.." days.")
if (verPtokax == 0) then
OnExit()
end
else
user:SendPM(sBot, "You can't vote because your "..iDays.." hasn't passed yet.")
end
elseif (arrVoter["ip"][user.sIP] ~= nil) then
RefreshVotes()
if (tonumber(arrVoter["ip"][user.sIP]) + iDays <= tonumber(GetTime())) then
arrVoter["user"][user.sName] = GetTime()
arrVoter["ip"][user.sIP] = GetTime()
arrVoter["user"][strlower(nick)] = arrVoter["user"][strlower(nick)] + 1
user:SendPM(sBot, "Your vote for the user "..nick.." has been register, you only can vote again in the next "..iDays.." days.")
if (verPtokax == 0) then
OnExit()
end
else
user:SendPM(sBot, "You can't vote because your "..iDays.." hasn't passed yet.")
end
else
arrVoter["user"][user.sName] = GetTime()
arrVoter["ip"][user.sIP] = GetTime()
arrVoter["user"][strlower(nick)] = arrVoter["user"][strlower(nick)] + 1
user:SendPM(sBot, "Your vote for the user "..nick.." has been register, you only can vote again in the next "..iDays.." days.")
if (verPtokax == 0) then
OnExit()
end
end
return 1
end
end
end

function RefreshVotes()
local date,ip,usr
for usr, date in arrVoter["user"] do
if (tonumber(arrVoter["user"][usr]) + iDays <= tonumber(GetTime())) then
arrVoter["user"][usr] = nil
end
end
for ip, date in arrVoter["ip"] do
if (tonumber(arrVoter["ip"][ip]) + iDays <= tonumber(GetTime())) then
arrVoter["ip"][ip] = nil
end
end
if (verPtokax == 0) then
OnExit()
end
end

function ListOfVoter(user)
local sTmp,usr,vote = "List of users to be voted to became VIPs:\r\n\r\n"
for usr, vote in arrVoter["voter"] do
sTmp = sTmp.."User: "..usr.."\tVotes: "..vote.."\r\n"
end
user:SendPM(sBot, stmp)
end


function GetTime()
d = date("%d")
mm = date("%m")
y = date("%y")
local Date = "20"..y..mm..d
return Date
end

function Serialize(tTable, sTableName, sTab)
assert(tTable, "tTable equals nil");
assert(sTableName, "sTableName equals nil");

assert(type(tTable) == "table", "tTable must be a table!");
assert(type(sTableName) == "string", "sTableName must be a string!");

sTab = sTab or "";
sTmp = ""

sTmp = sTmp..sTab..sTableName.." = {\n"

for key, value in tTable do
local sKey = (type(key) == "string") and format("[%q]",key) or format("[%d]",key);

if(type(value) == "table") then
sTmp = sTmp..Serialize(value, sKey, sTab.."\t");
else
local sValue = (type(value) == "string") and format("%q",value) or tostring(value);
sTmp = sTmp..sTab.."\t"..sKey.." = "..sValue
end

sTmp = sTmp..",\n"
end

sTmp = sTmp..sTab.."}"
return sTmp
end

function SaveToFile(file , table , tablename)
writeto(file)
write(Serialize(table, tablename))
writeto()
end

function LoadFromFile(file)
if (readfrom(file) ~= nil) then
readfrom(file)
dostring(read("*all"))
readfrom()
end
end

Best regards, nErBoS