 # Author:
 #   sshirokov
 
-## Dat state
-current = null
-
 ## Dat model
 class Vote
+  @current = null
+
   length: 30 * 1000
 
 
   finish: () =>
     # Close the gate, and update the current vote
     @finished = true
-    current = null
+    Vote.current = null
 
     if @expired
       @msg.send "Vote failed, time's up!"

    msg.send "Voting is a lie, and you can't do it yet."

  robot.respond /voting\??$/i, (msg) ->
    sure_am = "Yep, for #{current?.duration()} seconds now. #{current?.votes.yes.length} vs #{current?.votes.no.length}"
    nope = "Nope, democracy has totally failed."
    msg.reply if current then sure_am else nope

  # Election driver
  robot.respond /vote ([^\s]+)\s?(.*)?$/, (msg) ->

      @finish()
    @timeout = setTimeout fn, @length
    # Note myself if I haven't been yet
    Vote.current ?= this

  yes: (who) =>
    @_vote 'yes', who
