var moment = require('moment')
require('moment-countdown')
module.exports = {
  commands: {
    a50: {
      help: 'Gets the time until the UK Article 50 procedure expires',
      command: function () {
        return 'Article 50 expires in ' + moment('2019-03-29T23:00:00Z').countdown().toString()
      }
    },
    python2: {
      help: 'Gets the time until Python 2 support is dropped',
      command: function () {
        return 'Python 2.7 support ends in ' + moment('2020-01-01T00:00:00Z').countdown().toString()
      }
    }
  },
  onload: function (bot) {
    function autoCount (bot, lastTick) {
      const thisTick = moment('2019-03-29T23:00:00Z').countdown().toString().split(/, | and /)[0]
      if (thisTick !== lastTick) {
        bot.broadcast('Article 50 expires in ' + lastTick)
      }
      setTimeout(autoCount, 1000, bot, thisTick)
    }
    autoCount(bot)
  }
}

@@ -52,16 +52,336 @@
 tdown')%0A
+%0Alet timeout = null%0A%0Afunction autoCount (bot, lastTick) %7B%0A  const thisTick = moment('2019-03-29T23:00:00Z').countdown().toString().split(/, %7C and /)%5B0%5D%0A  if (lastTick != null && thisTick !== lastTick) %7B%0A    bot.broadcast('Article 50 expires in ' + thisTick)%0A  %7D%0A  timeout = setTimeout(autoCount, 1000, bot, thisTick)%0A%7D%0A%0A
 module.e
@@ -860,347 +860,116 @@
 ,%0A  
-onload: function (bot) %7B%0A    function autoCount (bot, lastTick) %7B%0A      const thisTick = moment('2019-03-29T23:00:00Z').countdown().toString().split(/, %7C and /)%5B0%5D%0A      if (thisTick !== lastTick) %7B%0A        bot.broadcast('Article 50 expires in ' + lastTick)%0A      %7D%0A      setTimeout(autoCount, 1000, bot, thisTick)%0A    %7D%0A    autoCount(bot)
+events: %7B%0A    selfjoin: function (bot) %7B%0A      if (timeout !== null) return%0A      autoCount(bot, null)%0A    %7D
 %0A  %7D

Improve countdown annocement with on selfjoin event