PtokaX forum

Archive => Archived 4.0 boards => Request for Lua 4 scripts => Topic started by: OneHero on 08 July, 2004, 01:17:12

Title: Vote-bot
Post by: OneHero on 08 July, 2004, 01:17:12
can someone help me remove so that i dont have to have nr on the votes, i only want one vote like this :

+creatvote do u like pizza?

code
--Requested by (=CyberPimp=)
--Made by nErBoS

Bot = "Vote-Bot"

vt = {}
nr = {}

votetext = "votepoll.txt" --Will be created in the script folder
oldpolls = "oldpolls.txt" --Will be created in the script folder

function Main()
frmHub:RegBot(Bot)
end

function NewUserConnected(user, data)
if (vt[user.sName] == nil) then
vt[user.sName] = 0
end
if (nr[user.sName] == nil) then
nr[user.sName] = 0
end
end

function DataArrival(user, data)

if (strsub(data,1,1)=="<") or (strsub(data,1,5+strlen(Bot))=="$To: "..Bot) then
   data=strsub(data,1,strlen(data)-1)
   s,e,cmd = strfind(data,"%b<>%s+(%S+)")
      if (cmd=="+votehelp") then
         local msg = ""
         if (user.iProfile == 0) then
         msg = msg.."Commands to the Vote-Poll:\r\n"
         msg = msg.."\r\n"
         msg = msg.."+createvote \tCreates a poll (nr = number to give to poll) (q = Poll question)\r\n"
         msg = msg.."+stopvote \t\tWill end the vote-poll\r\n"
         msg = msg.."+showvote \tShow the vote results of the poll (old = old polls) or (new = polls that haven't been closed)\r\n"
         msg = msg.."+svmain \tShow the vote results in the mainchat (old = old polls) or (new = polls that haven't been closed)\r\n"
         msg = msg.."+votelist\t\t\tShow all finished polls\r\n"
         msg = msg.."+votefor\t\t\tShow the polls that you can vote\r\n"
         msg = msg.."+vote \t\tTo vote on the poll (y = yes) (n = no) (nr = number of the poll)\r\n"
         msg = msg.."\r\n"
         user:SendPM(Bot, msg)
         else
         msg = msg.."Commands to the Vote-Poll:\r\n"
         msg = msg.."\r\n"
         msg = msg.."+votefor\t\t\tShow the polls that you can vote\r\n"
         msg = msg.."+vote \t\tTo vote on the poll (y = yes) (n = no) (nr = number of the poll)\r\n"
         msg = msg.."\r\n"
         user:SendPM(Bot, msg)
         end
         return 1
      elseif (cmd=="+createvote") then
         if (user.iProfile == 0) then
         local s,e,number,question = strfind(data,"%b<>%s+%S+%s+(%S+)%s+(.*)")
         if (tonumber(number) == nil) then
            user:SendPM(Bot, "Syntax error, +createvote , nr must be a number.")
         else
            number = tonumber(number)
            if (question == nil or question == "") then
               user:SendPM(Bot, "Syntax error, +createvote , you must write a question to the poll.")
            else
               if (CreatePoll(user, number, question) == 1) then
               user:SendPM(Bot, "The Vote-Poll has been created.")
               else
               user:SendPM(Bot, "There is a already a Vote-Poll with the number "..number..".")
               end
            end
         end
         else
            user:SendPM(Bot, "You don?t have permision to this command.")
         end
         return 1
      elseif (cmd=="+stopvote") then
         if (user.iProfile == 0) then
         local s,e,number = strfind(data,"%b<>%s+%S+%s+(.*)")
         if (tonumber(number) == nil or number == "") then
            user:SendPM(Bot, "Syntax error, +stopvote , nr must be a number.")
         else
            number = tonumber(number)
            if (OldPoll(user, number) == 1) then
               user:SendPM(Bot, "The Vote-Poll has been closed an saved on the Old Polls.")
            else
               user:SendPM(Bot, "There is no Vote-Poll with the number "..number..".")
            end
         end
         else
            user:SendPM(Bot, "You don?t have permision to this command.")
         end
         return 1
      elseif (cmd=="+showvote") then
         if (user.iProfile == 0) then
         local s,e,number, opt = strfind(data,"%b<>%s+%S+%s+(%S+)%s+(%S+)")
         if (tonumber(number) == nil) then
            user:SendPM(Bot, "Syntax error, +showvote , nr must be a number.")
         else
            number = tonumber(number)
            if (opt == "old") then
            if (CheckPoll(user, number, oldpolls) == "") then
               user:SendPM(Bot, "There is no Vote-Poll with the number "..number..".")
            else
               user:SendPM(Bot, CheckPoll(user, number, oldpolls))
            end
            elseif(opt == "new") then
            if (CheckPoll(user, number, votetext) == "") then
               user:SendPM(Bot, "There is no Vote-Poll with the number "..number..".")
            else
               user:SendPM(Bot, CheckPoll(user, number, votetext))
            end
            else
            user:SendPM(Bot, "Syntax error, +showvote , must be (old = old polls) or (new = polls that haven't been closed)")
            end
         end
         else
            user:SendPM(Bot, "You don?t have permision to this command.")
         end
         return 1
      elseif (cmd=="+svmain") then
         if (user.iProfile == 0) then
         local s,e,number, opt = strfind(data,"%b<>%s+%S+%s+(%S+)%s+(%S+)")
         if (tonumber(number) == nil) then
            user:SendPM(Bot, "Syntax error, +svmain , nr must be a number.")
         else
            number = tonumber(number)
            if (opt == "old") then
            if (CheckPoll(user, number, oldpolls) == "") then
               user:SendPM(Bot, "There is no Vote-Poll with the number "..number..".")
            else
               SendToAll(Bot, CheckPoll(user, number, oldpolls))
            end
            elseif(opt == "new") then
            if (CheckPoll(user, number, votetext) == "") then
               user:SendPM(Bot, "There is no Vote-Poll with the number "..number..".")
            else
               SendToAll(Bot, CheckPoll(user, number, votetext))
            end
            else
            user:SendPM(Bot, "Syntax error, +svmain , must be (old = old polls) or (new = polls that haven't been closed)")
            end
         end
         else
            user:SendPM(Bot, "You don?t have permision to this command.")
         end
         return 1
      elseif (cmd=="+votelist") then
         if (user.iProfile == 0) then
         if (readfrom(oldpolls) == nil or ReadPoll(user, oldpolls) == "") then
            user:SendPM(Bot, "There is no closed Vote-Polls")
         else
            user:SendPM(Bot, ReadPoll(user, oldpolls))
         end
         else
            user:SendPM(Bot, "You don?t have permision to this command.")
         end
         return 1
      elseif (cmd=="+votefor") then
         if (readfrom(votetext) == nil or ReadPoll(user, votetext) == "") then
            user:SendPM(Bot, "There is no Vote-Polls")
         else
            user:SendPM(Bot, ReadPoll(user, votetext))
         end
         return 1
      elseif (cmd=="+vote") then
         local s,e,number,opt = strfind(data,"%b<>%s+%S+%s+(%S+)%s+(%S+)")
         if (tonumber(number) == nil) then
            user:SendPM(Bot, "Syntax error, +vote , nr must be a number.")
         else
            number = tonumber(number)
            if (opt == nil or opt == "" or opt ~= "n" and opt ~= "y") then
               user:SendPM(Bot, "Syntax error, +vote , must type (y = yes) or (n = no).")
            else
               if (Vote(user, number, opt) == 1) then
                  user:SendPM(Bot, "Your Vote has been registered.")
                  vt[user.sName] = 1
                  nr[user.sName] = number
               elseif(Vote(user, number, opt) == 2) then
                  user:SendPM(Bot, "You have already made a vote on this Vote-Poll")
               else
               user:SendPM(Bot, "There isn?t any Vote-Poll with the number "..number..".")
               end
            end
         end
         return 1            
      end
end
end

function CreatePoll(user, number, question)
local tmp = ""
local time = 0
   readfrom(votetext)
   while 1 do
      local line = read()
      if (line == nil) then
    if (time == 2) then
         break
    else
    tmp = tmp.."Nr: "..number.." Question: "..question.." Yes: 0 No: 0 Active: Yes\r\n"
    time = 1
         break
         end
      else
    local s,e,num = strfind(line,"Nr:%s+(%S+)%s+")
    if (tonumber(num) == number) then
    tmp = tmp..line.."\r\n"
    time = 2
    else
    tmp = tmp..line.."\r\n"
    end
      end
   end
readfrom()
writeto(votetext)
write(tmp)
writeto()
return time
end

function OldPoll(user, number)
local tmp = ""
local tmp2 = ""
local time = 0
   readfrom(votetext)
   while 1 do
      local line = read()
      if (line == nil) then
      break
      else
    local s,e, num, question, ny, nn = strfind(line,"Nr:%s+(%S+)%s+(.*)Yes:%s+(%S+)%s+No:%s+(%S+)%s+Active:")
    if (tonumber(num) == number) then
    tmp2 = tmp2.."Nr: "..number.." "..question.."Yes: "..ny.." No: "..nn.." Active: No\r\n"
         time = 1
    else
    tmp = tmp..line.."\r\n"
    end
      end
   end
readfrom()
writeto(votetext)
write(tmp)
writeto()
if (time == 0) then
else
appendto(oldpolls)
write(tmp2)
writeto()
end
return time
end

function CheckPoll(user, number, file)
local tmp = ""
   readfrom(file)
   while 1 do
      local line = read()
      if (line == nil) then
      break
      else
    local s,e, num, question, ny, nn = strfind(line,"Nr:%s+(%S+)%s+(.*)Yes:%s+(%S+)%s+No:%s+(%S+)%s+Active:")
    if (tonumber(num) == number) then
    tmp = tmp.."\r\n-------------------- Vote Poll --------------------\r\n"
    tmp = tmp.."Results of Vote-Poll Nr: "..num.."\r\n"
    tmp = tmp.."Vote "..question.."\r\n"
    tmp = tmp.."------------------------------\r\n"
    tmp = tmp.."Yes: "..ny.."\r\n"
    tmp = tmp.."No: "..nn.."\r\n"
    tmp = tmp.."------------------------------\r\n"
      if (tonumber(ny) > tonumber(nn)) then
      tmp = tmp.."Yes is Winnig."
      elseif (tonumber(ny) < tonumber(nn)) then
      tmp = tmp.."No is Winnig."
      elseif (tonumber(ny) == tonumber(nn)) then
      tmp = tmp.."Yes and No is equal."
      end
    break
    else
    end
      end
   end
readfrom()
return tmp
end

function ReadPoll(user, file)
local tmp = ""
   readfrom(file)
   while 1 do
      local line = read()
      if (line == nil) then
      break
      else
    local s,e, num, question, ny, nn = strfind(line,"Nr:%s+(%S+)%s+(.*)Yes:%s+(%S+)%s+No:%s+(%S+)%s+Active:")
    tmp = tmp.."\r\n-------------------- Vote Poll --------------------\r\n"
    tmp = tmp.."Results of Vote-Poll Nr: "..num.."\r\n"
    tmp = tmp.."Vote "..question.."\r\n"
    tmp = tmp.."------------------------------\r\n"
    tmp = tmp.."Yes: "..ny.."\r\n"
    tmp = tmp.."No: "..nn.."\r\n"
    tmp = tmp.."------------------------------\r\n"
      if (file == oldpolls) then
      tmp = tmp.."Closed Vote-Poll\r\n"
      elseif (file == votetext) then
      tmp = tmp.."Active Vote-Poll\r\n"
      end
      end
   end
readfrom()
return tmp
end

function Vote(user, number, opt)
local tmp = ""
local time = 0
if (vt[user.sName] == 1 and nr[user.sName] == number) then
   time = 2
else
   readfrom(votetext)
   while 1 do
      local line = read()
      if (line == nil) then
      break
      else
    local s,e, num, question, ny, nn = strfind(line,"Nr:%s+(%S+)%s+(.*)Yes:%s+(%S+)%s+No:%s+(%S+)%s+Active:")
    if (tonumber(num) == number) then
    if (opt == "y") then
       ny = tonumber(ny) + 1
    elseif (opt == "n") then
       nn = tonumber(nn) + 1
    end
    tmp = tmp.."Nr: "..number.." "..question.."Yes: "..ny.." No: "..nn.." Active: Yes\r\n"
         time = 1
    else
    tmp = tmp..line.."\r\n"
    end
      end
   end
readfrom()
writeto(votetext)
write(tmp)
writeto()
end
return time
end
the end
Title:
Post by: OneHero on 08 July, 2004, 01:20:19
jeje, whatever...

how kan i copy and paste all the script in the code, it will only cope the last line...
Title:
Post by: Corayzon on 08 July, 2004, 01:41:09
it didnt copy properly because at the top of your post
u put then code end [/code]. And at the end you do it again but with the last line.

Note:: when adding code use 'code' followed by '/code' (replace ' ' with [ ])

noza
Title:
Post by: nErBoS on 08 July, 2004, 14:26:21
Hi,

That script was been improved take a look HERE (http://board.univ-angers.fr/thread.php?threadid=1606&boardid=12&styleid=1&sid=2fe0e6568fcd9dc930a6033ba377a0c2) . Use this topic also to request please.

Best regards, nErBoS