 # 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!"

    switch action
      # Vote on a current issue
      when "yes"
        return msg.reply "There's no vote going on." unless current?
        result = current?.yes msg.message.user.name
        reply = "Your vote " +
          (if result then "totally counted." else "was absolutely worthless!")
        msg.reply reply
      when "no"
        return msg.reply "There's nothing to disagree with." unless current?
        result = current?.no msg.message.user.name
        reply = "Your vote " +
          (if result then "totally counted." else "was absolutely worthless!")
        msg.reply reply

      # Super Important Issues to vote about
      when "poop"
        if current
          msg.reply "A vote is already in progress, hold up."
          return
        current = new Vote robot, msg, ->
          msg.send msg.random [
            "Poop is coming out",
            "I am pooping"
            "Butt evacuation in progress.",
          ]
        current.start()
        msg.send "New Vote: Should I poop!?"

      # Shut up, loony bin

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

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