From 2e5e6760a5b50311f9e9d70e3714c5b1b04c72d5 Mon Sep 17 00:00:00 2001 From: rnhmjoj Date: Wed, 6 May 2015 00:19:05 +0200 Subject: [PATCH] Handle partial name match --- scripts/internamento.coffee | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/scripts/internamento.coffee b/scripts/internamento.coffee index 9ecc45d..b838bdc 100644 --- a/scripts/internamento.coffee +++ b/scripts/internamento.coffee @@ -65,11 +65,12 @@ module.exports = (robot) -> 'va bene, mi hai stancato. vattene ma non dire niente a diliberti'] user = res.message.user.name.toLowerCase().split '_' mem = robot.brain.get 'internati' or {} - vals = user.map (x) -> lev.get name, x for name of mem - if (Math.min.apply @, [].concat.apply([], vals)) < 4 + dists = ([(Math.min.apply @, user.map (x) -> lev.get name, x), name] for name of mem) + [dist, name] = dists.reduce (x, y) -> if x[0] < y[0] then x else y + if dist < 4 if Math.random() < 0.02 res.send res.random ok - delete mem[user.join '_'] + delete mem[name] robot.brain.set 'internati', mem else res.send res.random nope