User voting system
 

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

User voting system

Started by kepp, 05 November, 2004, 03:33:53

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

kepp

Let me know if it works as good for you as it does for me..
Striped it out from bot of mine

-- Vote System by 	:   Kepp
--
-- Description : 
--
-- Let users in your hub vote out other users (Anonymous)
-- A user may only vote once during a specified time (May be misused otherwise)
-- A user must receieve a x amount of votes before he (she) gets kicked for some minutes :)
--
-- Julian Date function from plops Count-Down Script (I think)
--
-- To use this script make a folder called "Warnings" then create two files
-- called "Warns" and "WarnsBy" both with the extension .lst
--
-- Open Warns.lst up and write "WarnedUsers = {}"
-- Open WarnsBy.lst up and write "WarnsBy = {}"
--
-- Thats it, have fun and report bugs

assert(dofile("Warnings/Warns.lst"),"Warnings/Warns.lst could not be found.")
assert(dofile("Warnings/WarnsBy.lst"),"Warnings/WarnsBy.lst could not be found.")

min = 60
hr = min * 60
days = hr * 24

-----------------------------------------------------------------------------------------------------------------------------
-- EDITABLE VARIABLES
-----------------------------------------------------------------------------------------------------------------------------

-- Bot Name (No Spaces)
sBot = "Warnings"

-- Show or hide bot in hub, "true" = show, "false" = hide
bRegBot = "true";

-- user may use the vote command once every 4th hour
iHR = 4 * hr

-- This is how many warnings that shall be delivered before kick.
iMaxWarnings = 5;

-- Kick the user for x amount of minutes
iTimeBan = 20

----------------------------------------------------------------------------------------------------------------------------
-- Snippet Starts Here
----------------------------------------------------------------------------------------------------------------------------

function Main()
   if bRegBot == "true" then
      frmHub:RegBot(sBot);
   else
      frmHub:UnregBot(sBot);
   end
end

-----------------------------------------------------------------------------------------------------------------------------

-----------------------------------------------------------------------------------------------------------------------------

function DataArrival(sUser,sData)
   local sData = strsub(sData,1,-2);
   if (strsub(sData,1,1) == "<") then
      local s,e,cmd = strfind(sData,"^%b<>%s+(%S+)");
      if (cmd == "+vote") then
         local s,e,vic = strfind(sData,"^%b<>%s+%S+%s+(%S+)");
         if vic and GetItemByName(vic) then
            local vic = GetItemByName(vic)
            if (vic.sName == sUser.sName) then
            	vic:SendData(sBot,"If you are stupid enough to vote on yourself the OK; suite yourself.")
            	vic:TimeBan(iTimeBan)
            end
            local iVotes = 0
            local iMode = 0;
            if (HasVoted(sUser) == 1) then
               local name,votes,index = GetWarnedUser(vic)
               if name then iMode = 1 end
               if iMode == 1 then
                  iVotes = WarnUser(vic)
                  VotingUser(sUser,curJul(date("%S") + iHR))
                  if iVotes ~= nil then SendMessage(vic,iVotes) end
                  return 1
               else
                  VotingUser(sUser,curJul(date("%S") + iHR))
                  iVotes = WarnUser(vic)
                  SendMessage(vic,iVotes)
                  return 1
               end
            else
               local name,IP,jul,index = GetWarnsBy(sUser)
               if name then
                  return 1
               else
                  VotingUser(sUser,curJul(date("%S") + iHR))
                  iVotes = WarnUser(vic)
                  SendMessage(vic,iVotes)
                  return 1
               end
            end
         else
            sUser:SendData(sBot,"Please check your spelling.")
            return 1
         end
      end
   end
end

-----------------------------------------------------------------------------------------------------------------------------

-----------------------------------------------------------------------------------------------------------------------------

function SendMessage(vic,votes)
   iLeft = iMaxWarnings - tonumber(votes)
   SendToAll(sBot,vic.sName.." has gotten "..votes.." vote(s), "..iLeft.." more for a "..iTimeBan.." min kick.")
end

-----------------------------------------------------------------------------------------------------------------------------

-----------------------------------------------------------------------------------------------------------------------------

function VotingUser(sUser,jul)
   local name,ip,julian,index = GetWarnsBy(sUser)
   if not name then
      tinsert(WarnsBy,{sUser.sName,sUser.sIP,jul})
      WriteFile(WarnsBy,"WarnsBy","Warnings/WarnsBy.lst")
   else
      WarnsBy[index][3] = 0
      WarnsBy[index][3] = jul
      WarnsBy[index][2] = sUser.sIP
      WriteFile(WarnsBy,"WarnsBy","Warnings/WarnsBy.lst")
   end
end

-----------------------------------------------------------------------------------------------------------------------------

-----------------------------------------------------------------------------------------------------------------------------

function VotingUserExist(sUser)
   local name,ip = GetWarnsBy(sUser)
   if name then
      return 1
   end
end

-----------------------------------------------------------------------------------------------------------------------------

-----------------------------------------------------------------------------------------------------------------------------

function GetWarnsBy(sUser)
   for i=1,getn(WarnsBy) do
      if WarnsBy[i][1] == sUser.sName then
         return WarnsBy[i][1],WarnsBy[i][2],WarnsBy[i][3],i
      elseif WarnsBy[i][2] == sUser.sIP then
         return WarnsBy[i][1],WarnsBy[i][2],WarnsBy[i][3],i
      end
   end
end

-----------------------------------------------------------------------------------------------------------------------------

-----------------------------------------------------------------------------------------------------------------------------

function GetWarnedUser(sUser)
   for i=1,getn(WarnedUsers) do
      if WarnedUsers[i][1] == sUser.sName then
         return WarnedUsers[i][1],WarnedUsers[i][2],i
      end
   end
end

-----------------------------------------------------------------------------------------------------------------------------

-----------------------------------------------------------------------------------------------------------------------------

function WarnUser(sUser)
   local iMode = 0
   local name,votes,index = GetWarnedUser(sUser)
   if name then iMode = 1 end
   if (iMode == 0) then
      tinsert(WarnedUsers,{sUser.sName,1})
      WriteFile(WarnedUsers,"WarnedUsers","Warnings/Warns.lst")
      return 1
   else
      if (tonumber(WarnedUsers[index][2]) == tonumber(iMaxWarnings) - 1) then
         SendToAll(sBot,sUser.sName.." has been voted out by users of this hub.")
         sUser:SendPM(sBot,"You have been voted out, you are now kicked for "..iTimeBan.." Minutes.")
         sUser:TimeBan(iTimeBan)
         tremove(WarnedUsers,index)
         WriteFile(WarnedUsers,"WarnedUsers","Warnings/Warns.lst")
      else
         WarnedUsers[index][2] = WarnedUsers[index][2] + 1
         WriteFile(WarnedUsers,"WarnedUsers","Warnings/Warns.lst")
         return WarnedUsers[index][2]
      end
   end
end

-----------------------------------------------------------------------------------------------------------------------------

-----------------------------------------------------------------------------------------------------------------------------

function HasVoted(sUser)
   for i=1,getn(WarnsBy) do
      if WarnsBy[i][1] == sUser.sName then
         if WarnsBy[i][3] - curJul(date("%S")) <= 0 then
            return 1 
         end
      end
   end
end

-----------------------------------------------------------------------------------------------------------------------------

-----------------------------------------------------------------------------------------------------------------------------

function curJul(Sec)
   local a,b = jdatehms(tonumber(date("%d")),tonumber(date("%m")),tonumber(date("%y")),tonumber(date("%H")),tonumber(date("%M")),tonumber(Sec))
   return b
end

-----------------------------------------------------------------------------------------------------------------------------

-----------------------------------------------------------------------------------------------------------------------------

function jdatehms(d, m, y,ho,mi,se)
   local a, b, c = 0, 0, 0
   if m <= 2 then
      y = y - 1
      m = m + 12
   end
   if (y*10000 + m*100 + d) >= 15821015 then
      a = floor(y/100)
      b = 2 - a + floor(a/4)
   end
   if y <= 0 then c = 0.75 end
   return floor(365.25*y - c) + floor(30.6001*(m+1) + d + 1720994 + b),ho*3600+mi*60+se
end

-----------------------------------------------------------------------------------------------------------------------------

-----------------------------------------------------------------------------------------------------------------------------

function WriteFile(table, tablename, file)
	local handle = openfile(file, "w")
	Serialize(table, tablename, handle)
  	closefile(handle)
end

-----------------------------------------------------------------------------------------------------------------------------

-----------------------------------------------------------------------------------------------------------------------------

function Serialize(tTable, sTableName, hFile, sTab)
	sTab = sTab or "";
	write(hFile, 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
			Serialize(value, sKey, hFile, sTab.."\t");
		else
			local sValue = (type(value) == "string") and format("%q",value) or tostring(value);
			write(hFile, sTab.."\t"..sKey.." = "..sValue);
		end
		write(hFile, ",\n");
	end
	write(hFile, sTab.."}");
end
Guarding    

SMF spam blocked by CleanTalk