Vote for hub VIP
 

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

Vote for hub VIP

Started by Malcon, 21 July, 2004, 14:47:25

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Malcon

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


nErBoS

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

SMF spam blocked by CleanTalk