From 9b30af2d7bb3a27b208ee53c3601d3a7f2f85302 Mon Sep 17 00:00:00 2001 From: Enrico Fasoli Date: Sun, 26 Apr 2015 16:26:33 +0200 Subject: [PATCH] fix #15, fix #4 --- scripts/internamento.coffee | 34 +++++++++++++++++++++------------- scripts/memoria.coffee | 18 +++++++++++------- 2 files changed, 32 insertions(+), 20 deletions(-) diff --git a/scripts/internamento.coffee b/scripts/internamento.coffee index 09a7013..f557ca8 100644 --- a/scripts/internamento.coffee +++ b/scripts/internamento.coffee @@ -7,7 +7,7 @@ # Commands: # hubot interna - interna una persona # hubot libera - libera una persona -# hubot lista/mostrami internati - mostra la lista di internati +# hubot lista/mostrami (gli) internati - mostra la lista di internati # # Author: # Ravinder Pal Singh @@ -16,36 +16,44 @@ module.exports = (robot) -> robot.respond /interna (.+)/i, (res) -> mem = robot.brain.get('internati') or {} - name = res.match[1].toLowerCase(); - exp1 = ['ho sbattuto dentro', 'come vuoi, sbattiamo dentro', 'è la tua fine']; + name = res.match[1].toLowerCase() + exp1 = ['ho sbattuto dentro', 'come vuoi, sbattiamo dentro', 'è la tua fine'] if mem[name]? - res.send 'Mi dispiace ma '+name+' è già stato internato...' + if mem[name].da + intern = mem[name].da.name + res.send 'Mi dispiace ma '+name+' è già stato internato su ordine di '+intern + else res.send 'Mi dispiace ma '+name+' è già stato internato...' else - if name is 'dili' or name is 'diliberti' + if name.match /(?:dili(?:bert(?:i)?)?)|(?:ros(?:y|ario))|dre/i + # Diliberti res.send 'non posso internare il mio padrone...' - else if name is 'fazo' or name is 'fasoli' + else if name.match /fa(?:zo|soli)/i + # Fasoli res.send 'ciccio, io internerei te al posto suo' - else if name is 'assa' or name is 'asjon' + else if name.match /as(?:sa|jon|sion(?:e|i))/i + # Asjon res.send 'ma sei scemo????' else res.send res.random(exp1)+' '+name - mem[name] = name + # Salvo chi ha internato + mem[name] = { da: res.message.user } + console.log res.message.user, mem[name] robot.brain.set 'internati', mem - robot.respond /libera? (.+)/i, (res) -> + robot.respond /libera (.+)/i, (res) -> mem = robot.brain.get('internati') or {} m = res.match[1].toLowerCase() - boh = ['non so chi sia','sorry non è qui','troppo tardi','ti piacerebbe, eh?', 'scordatelo'] + boh = ['sorry non è qui','troppo tardi','ti piacerebbe, eh?', 'scordatelo'] if mem[m]? - res.send 'ho liberato "'+mem[m]+'" ma ricordate che potete sbatterlo dentro quando volete ;)' + res.send 'ho liberato '+m+' ma ricordate che potete sbatterlo dentro quando volete ;)' delete mem[m] robot.brain.set 'internati', mem else res.send res.random boh - robot.respond /memory-dump/i, (res) -> + robot.respond /internati-dump/i, (res) -> res.send JSON.stringify robot.brain.get('internati') - robot.respond /(?:mostrami )|(?:lista )?internati(?:\?)?/i, (res) -> + robot.respond /(?:(?:(?:dimmi|mostrami) )|(?:lista ))?(?:gli )?internat(?:i|o)(?:\?)?/i, (res) -> m = robot.brain.get 'internati' if m isnt null r = ['ho internato', 'ho preso', 'ho catturato', 'sbattuto dentro'] diff --git a/scripts/memoria.coffee b/scripts/memoria.coffee index 0df0bf6..91eab63 100644 --- a/scripts/memoria.coffee +++ b/scripts/memoria.coffee @@ -19,6 +19,12 @@ moment = require 'moment' moment.locale 'it' +dateFormatsA = ['YYYY-MM-DD','DD-MM-YYYY',"DD MMMM YYYY", "DD MMMM","DD"] + +toDate = (d) -> + dat = d.replace /(?:l'|il )/i, '' + moment dat, dateFormatsA + module.exports = (robot) -> robot.respond /ricorda(?:ti)? (?:che )?(.+) ([=è]|sono) (.+)/i, (res) -> mem = robot.brain.get('memoria') or {} @@ -63,10 +69,9 @@ module.exports = (robot) -> # non rispondo return # Controllo se l'argomento è data - argIsDate = arg.trim().match(/^(?:il )?\d{4}-\d{1,2}-\d{1,2}$/i) and moment(arg,'YYYY-MM-DD').isValid() - if argIsDate and (query is 'quand' or query is 'cos') + data = toDate arg + if data.isValid() and (query is 'quand' or query is 'cos') # chiesto una data - data = moment(arg,'[il] YYYY-MM-DD') res.send arg+' è '+data.format('dddd Do MMMM YYYY')+' ovvero '+data.fromNow() else # chiesto qualcosa che non è una data @@ -76,11 +81,10 @@ module.exports = (robot) -> if query is 'qual' then verbo = 'è' else if !query? then verbo = 'sono' if mem[arg] # controllo se è salvata una data nell'argomento chiesto - data = moment(mem[arg],'[il] YYYY-MM-DD') - contentIsDate = mem[arg].trim().match(/^(?:il )?\d{4}-\d{1,2}-\d{1,2}$/i) and data.isValid() - if contentIsDate + odata = toDate mem[arg] + if odata.isValid() # nella memoria era salvata una data - res.send arg+' è '+data.format('dddd Do MMMM YYYY')+' ovvero '+data.fromNow() + res.send arg+' è '+odata.format('dddd Do MMMM YYYY')+' ovvero '+odata.fromNow() else res.send arg+' '+verbo+' '+mem[arg] else res.send res.random ['boh','mistero','se qualcuno me lo spiegasse magari','BZBZ 404-NOT-FOUND']