diff --git a/scripts/memoria.coffee b/scripts/memoria.coffee index d68a4fe..e941989 100644 --- a/scripts/memoria.coffee +++ b/scripts/memoria.coffee @@ -33,8 +33,9 @@ module.exports = (robot) -> else if res.match[3] and res.match[1] then query = res.match[1] # Estrazione argomento della query arg = (res.match[3] or res.match[2] or res.match[1]).toLowerCase() - # Controllo data - if moment(arg,'YYYY-MM-DD').isValid() and (query is 'quand' or query is 'cos') + # 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') # chiesto una data data = moment(arg,'[il] YYYY-MM-DD') res.send arg+' è '+data.format('dddd Do MMMM YYYY')+' ovvero '+data.fromNow() @@ -45,7 +46,8 @@ module.exports = (robot) -> if mem[arg] # controllo se è salvata una data nell'argomento chiesto data = moment(mem[arg],'[il] YYYY-MM-DD') - if data.isValid() + contentIsDate = mem[arg].trim().match(/^(?:il )?\d{4}-\d{1,2}-\d{1,2}$/i) and data.isValid() + if contentIsDate # nella memoria era salvata una data res.send arg+' è '+data.format('dddd Do MMMM YYYY')+' ovvero '+data.fromNow() else res.send arg+' '+verbo+' '+mem[arg] diff --git a/scripts/tempo.coffee b/scripts/tempo.coffee index cb2938f..5014154 100644 --- a/scripts/tempo.coffee +++ b/scripts/tempo.coffee @@ -1,7 +1,5 @@ moment = require 'moment' -moment.locale 'it' module.exports = (robot) -> - robot.respond /quanto manca (?:al)? (\d+-\d+-\d+)(?:\?)?/, (res) -> - m = moment(res.match[1],'YYYY-MM-DD').fromNow() - res.send 'il '+res.match[1]+' è '+m + robot.respond /che ore sono(?:\?)?/i, (res) -> + res.send moment().format('dddd Do MMMM YYYY H:MM:SS') diff --git a/scripts/time.coffee b/scripts/time.coffee deleted file mode 100644 index 5014154..0000000 --- a/scripts/time.coffee +++ /dev/null @@ -1,5 +0,0 @@ -moment = require 'moment' - -module.exports = (robot) -> - robot.respond /che ore sono(?:\?)?/i, (res) -> - res.send moment().format('dddd Do MMMM YYYY H:MM:SS')