PtokaX forum

Archive => Archived 4.0 boards => Request for Lua 4 scripts => Topic started by: Tuben on 03 November, 2003, 14:51:54

Title: Vote script.
Post by: Tuben on 03 November, 2003, 14:51:54
Trying too do a Vote script..But have not find any good way..

Is it somone that have a good one ?
Title:
Post by: Ron_Doe on 03 November, 2003, 15:52:10
Found a poll bot  ,    have not tryed this one myself  tho...

-- PollBot by aMutex 12.01.2003

botname = "PollBot"
Poll = {}
PollDescription = ""

function GetArgs(data)
s,e,whoTo,from,cmd,arg = strfind(data,"$To:%s+(%S+)%s+From:%s+(%S+)%s+$%b<>%s+(%S+)%s+(.*)")
return arg
end

function Main()
frmHub:RegBot(botname)
SetTimer(60000)
StartTimer()
end
function DataArrival(user, data)
if(strsub(data, 1, 4) == "$To:") then
 data=strsub(data,1,strlen(data)-1)
 s,e,whoTo = strfind(data,"$To:%s+(%S+)")
 if (whoTo == botname) then
  s,e,whoTo,from,cmd = strfind(data,"$To:%s+(%S+)%s+From:%s+(%S+)%s+$%b<>%s+(%S+)")
  if (user.bOperator) then
  if (cmd=="#createpoll") then
   arg= GetArgs(data)
   PollDescription = arg
   Poll={}
   user:SendPM(botname,"poll succesfully created...")
  end
  if (cmd=="#addpolloption") then
   arg= GetArgs(data)
   Poll[arg]=0
   user:SendPM(botname,"poll option "..arg.."added")
  end
  if (cmd=="#savepoll") then
    remove("poll.dat")
    local handle=openfile("poll.dat","a")
    write(handle,PollDescription.."\n")
    for a,b in Poll do
        write(handle,a.."?"..b.."\n")
    end
    closefile(handle)
    user:SendPM(botname,"Poll has been successfully saved")
  end
  if (cmd=="#loadpoll") then
    local handle=openfile("poll.dat","r")
    PollDescription=read(handle)
    Poll={}
    while 1 do
local line = read(handle)
  if line == nil then break
else
user:SendPM(botname,line.."  ")
       x,y,a=strfind(line,"([^?]*)")
x,y,b=strfind(line,"([^?]*)$")
Poll[a]=b
end
end
    closefile(handle)
    user:SendPM(botname,"Poll has been successfully loaded")
  end

  end
  if (cmd=="#vote") then
   arg= GetArgs(data)
if( Poll[arg] == nil ) then
user:SendPM(botname,"No such poll-option ...")
else
Poll[arg] = Poll[arg] +1
user:SendPM(botname,"Successfully voted for: "..arg)
end
  end
  if (cmd=="#showpoll") then
    user:SendPM(botname,"Current poll is:"..PollDescription)
    for a,b in Poll do
user:SendPM(botname,a..":"..b.." votes")
    end
  end

  if (cmd=="#help") then
    user:SendPM(botname,"This is a pollbot ...")
    user:SendPM(botname,".....................")
    user:SendPM(botname,"commands:")
    user:SendPM(botname,"create a poll: #createpoll description")
    user:SendPM(botname,"add a poll option: #addpolloption option")
    user:SendPM(botname,"load a poll: #loadpoll")
    user:SendPM(botname,"save a poll option: #savepoll")
    user:SendPM(botname,"vote for an option: #vote option")
    user:SendPM(botname,"show the current poll: #showpoll")
  end

 end
end
end

function OnTimer()
    remove("poll.dat")
    local handle=openfile("poll.dat","a")
    write(handle,PollDescription.."\n")
    for a,b in Poll do
        write(handle,a.."?"..b.."\n")
    end
    closefile(handle)
end

thanks  DarkElf  did not notice  that one   :)
Title:
Post by: DarkElf on 03 November, 2003, 16:03:21
Remove the code:--------------------------------
is not a part of script :P

Bye
Title:
Post by: Snoris on 03 November, 2003, 16:50:32
QuoteOriginally posted by DarkElf
Remove the code:--------------------------------
is not a part of script :P

Bye

Erhm....???The -------------------------
comes out when ur writing the LUA codes in [Code] barrels....
*INFO* =p
Title:
Post by: Tuben on 03 November, 2003, 22:42:20
Nice..Checking it out ;)
Title: hum...
Post by: mOrrI on 17 November, 2003, 16:58:08
i got one problem with this bot,....

same user can vote more than 1 time ;)
Title:
Post by: DarkElf on 18 November, 2003, 07:24:17
Snoris: remove the "code:--------------"
not "---------" i know -- is not read from script..