improve weather regex

This commit is contained in:
Michele Guerini Rocco 2018-09-15 13:19:43 +02:00
parent 77027c1478
commit 4934996654
Signed by: rnhmjoj
GPG Key ID: 91BE884FBA4B591A

View File

@ -16,7 +16,7 @@
moment = require 'moment' moment = require 'moment'
regex = /(?:(?:d(?:a|i)mmi il )?meteo(?: per (.+))?|che tempo (?:fa|c'è)(?: (?:a|in) (.+))?)\??$/i regex = /(?:(?:(?:mi (?:dici|dai)|dammi) (?:il (?:tempo|meteo)|(?:le previsioni)))(?: ?(?:(?:per ?(?:(?:l')|il |lo |la |i |gli |le )?)|di |a ))?|(?:che tempo (?:fa|(?:c'?(?:è|e|e')))(?: ?(?:in|a) )?))([^?!]+)?.*$/i
url1 = 'http://ip-api.com/json/' url1 = 'http://ip-api.com/json/'
url2 = 'http://api.openweathermap.org/data/2.5/weather?lang=it&units=metric' url2 = 'http://api.openweathermap.org/data/2.5/weather?lang=it&units=metric'
@ -64,7 +64,7 @@ module.exports = (robot) ->
tramonto alle #{dusk}" tramonto alle #{dusk}"
robot.respond regex, (res) -> robot.respond regex, (res) ->
city = res.match[1] || res.match[2] city = res.match[1]
if city? if city?
get_weather city, send_weather res get_weather city, send_weather res
else else