Handle partial name match

This commit is contained in:
rnhmjoj 2015-05-06 00:19:05 +02:00
parent 5d8add17bd
commit 2e5e6760a5

View File

@ -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