nuova funzione: memoria
This commit is contained in:
parent
ec3531d227
commit
48fddcb144
2
.gitignore
vendored
2
.gitignore
vendored
@ -2,7 +2,7 @@ node_modules
|
||||
hubot.lua
|
||||
.DS_Store*
|
||||
.hubot_history
|
||||
circolari/
|
||||
circolari.json
|
||||
run.sh
|
||||
run_telegram.sh
|
||||
*.pub
|
||||
|
@ -40,7 +40,7 @@ cosaCePerIl = (day,res) ->
|
||||
else
|
||||
res.send "ecco cosa c'è per doma: "+data.join('; ')
|
||||
module.exports = (robot) ->
|
||||
robot.hear /cosa c'è per domani?/i, (res) ->
|
||||
robot.respond /cosa c'è per domani?/i, (res) ->
|
||||
cosaCePerIl moment().add(1, 'days').format('YYYY-MM-DD'), res
|
||||
robot.hear /cosa c'è per il (\d+-\d+-\d+)/i, (res) ->
|
||||
robot.respond /cosa c'è per il (\d+-\d+-\d+)/i, (res) ->
|
||||
cosaCePerIl res.match[1], res
|
||||
|
@ -54,7 +54,7 @@ parseCircolari = (err,data,callback) ->
|
||||
parseHtml data, (err,res) ->
|
||||
#console.log("Done!")
|
||||
circolari = res
|
||||
fs.writeFile 'circolari/circolari.json', JSON.stringify circolari
|
||||
fs.writeFile 'circolari.json', JSON.stringify circolari
|
||||
callback circolari
|
||||
|
||||
module.exports = (robot) ->
|
||||
@ -62,7 +62,7 @@ module.exports = (robot) ->
|
||||
res.send 'controllo circolari...'
|
||||
fs.exists 'circolari/circolari.json', (jsonExists) ->
|
||||
if jsonExists
|
||||
circolari = JSON.parse fs.readFileSync('circolari/circolari.json').toString()
|
||||
circolari = JSON.parse fs.readFileSync('circolari.json').toString()
|
||||
res.send JSON.stringify circolari.slice 0,5
|
||||
else
|
||||
fs.exists 'circolari.html', (htmlExists) ->
|
||||
|
20
scripts/memoria.coffee
Normal file
20
scripts/memoria.coffee
Normal file
@ -0,0 +1,20 @@
|
||||
module.exports = (robot) ->
|
||||
robot.respond /ricorda(?:ti)? (?:che )?(.+) [=è] (.+)/i, (res) ->
|
||||
mem = robot.brain.get('memoria') or {}
|
||||
name = res.match[1]; definition = res.match[2]
|
||||
if mem[name]?
|
||||
res.send 'pensavo che '+name+' fosse '+mem[name]+'. Mi ricorderò che invece è '+definition
|
||||
else
|
||||
res.send 'non sapevo che '+name+' fosse '+definition+'. Me lo ricorderò'
|
||||
mem[name] = definition
|
||||
robot.brain.set 'memoria', mem
|
||||
robot.respond /(?:che )?cos(?:\')?è (.+)/i, (res) ->
|
||||
mem = robot.brain.get('memoria') or {}
|
||||
if mem[res.match[1]]
|
||||
res.send res.match[1]+' è '+mem[res.match[1]]
|
||||
else res.send 'boh'
|
||||
robot.respond /memoria/i, (res) ->
|
||||
m = JSON.stringify robot.brain.get 'memoria'
|
||||
if m isnt 'null'
|
||||
res.send m
|
||||
else res.send 'non so niente...'
|
@ -14,8 +14,27 @@ module.exports = (robot) ->
|
||||
robot.respond /grazie/i, grazie
|
||||
robot.respond /ringraziamenti/i, (res) ->
|
||||
res.send 'voi teneroni mi avete ringraziato ' + (robot.brain.get('ringraziato') or 0) + ' volte :)'
|
||||
robot.respond /saluta (\w+)/i, (res) ->
|
||||
robot.respond /saluta (.+)/i, (res) ->
|
||||
res.send 'ciao ' + res.match[1]
|
||||
robot.respond /ricorda(?:ti)? (?:che )?(.+) [=è] (.+)/i, (res) ->
|
||||
mem = robot.brain.get('memoria') or {}
|
||||
name = res.match[1]; definition = res.match[2]
|
||||
if mem[name]?
|
||||
res.send 'pensavo che '+name+' fosse '+mem[name]+'. Mi ricorderò che invece è '+definition
|
||||
else
|
||||
res.send 'non sapevo che '+name+' fosse '+definition+'. Me lo ricorderò'
|
||||
mem[name] = definition
|
||||
robot.brain.set 'memoria', mem
|
||||
robot.respond /(?:che )?cos(?:\')?è (.+)/i, (res) ->
|
||||
mem = robot.brain.get('memoria') or {}
|
||||
if mem[res.match[1]]
|
||||
res.send res.match[1]+' è '+mem[res.match[1]]
|
||||
else res.send 'boh'
|
||||
robot.respond /memoria/i, (res) ->
|
||||
m = JSON.stringify robot.brain.get 'memoria'
|
||||
if m isnt 'null'
|
||||
res.send m
|
||||
else res.send 'non so niente...'
|
||||
robot.respond /dove sei/i, (res) ->
|
||||
robot.http('http://canihazip.com/s')
|
||||
.get() (err, r, body) ->
|
||||
|
Loading…
Reference in New Issue
Block a user