   constructor: (@brain) ->
 
   find: (trigger) ->
-    @swapLegacy(trigger)
     @brainTrigger(trigger) || @hardcodedTrigger(trigger)
 
   save: (name, phrase, author = 'Liona') ->
     trigger = name: name, phrase: phrase, author: author
-    triggers = @brainTriggers()
+    triggers = @brainTriggers().filter (t) -> t.name isnt name
     triggers.push trigger
 
     @brain.set KEY, triggers
     trigger
 
   remove: (trigger) ->
-    triggerObj = @find(trigger) # Cleans up any legacy triggers
-    triggers = @brainTriggers()
-    index = triggers.indexOf triggerObj
-    triggers.splice(triggerObj, 1) unless index is -1
-    @brain.set KEY, triggers
+    @brain.set KEY, @brainTriggers().filter (t) -> t.name isnt trigger
 
   all: ->
     all = (@hardcodedTrigger(trigger) for trigger, phrase of HARDCODED_TRIGGERS)

hardcodedTriggers = require '../support/hardcoded_triggers'

class TriggerRepository
  LEGACY_KEY         = 'trigger'
  KEY                = 'triggers'
  HARDCODED_TRIGGERS = hardcodedTriggers


  brainTrigger: (trigger) ->
    @brainTriggers().filter((t) -> t.name is trigger)?[0]

  hardcodedTrigger: (trigger) ->
    phrase = HARDCODED_TRIGGERS[trigger]
    return unless phrase?
    name: trigger, phrase: phrase, author: 'Liona'

module.exports = TriggerRepository
