forked from uzyovoys/tadhack
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtimebot.xml
51 lines (45 loc) · 1.66 KB
/
timebot.xml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
<context>
<pattern name="EnCity" value="entity://cities"/>
<pattern name="RuCity" value="entity://rucities"/>
<pattern name="City" value="($EnCity|$RuCity)"/>
<input pattern="(hi|hello|привет*) *">
<output value="I can tell you a current time in any city."/>
</input>
<input pattern="[time] [in] $City *">
<var name="City">
<script>
<![CDATA[
var city;
for (var i = 0; i < City.length; i++) {
var c = City[i];
city = !city || city.population < c.population ? c : city;
}
if (!city) city = City;
city;
]]>
</script>
</var>
<var name="CityName" value='get("name", $City)'/>
<var name="CityCountry" value='get("country", $City)'/>
<get var="ts" url="http://api.timezonedb.com">
<param name="key" value="FRV82TNBHN8K"/>
<param name="format" value="json"/>
<param name="lat" value='get("lat", $City)'/>
<param name="lng" value='get("lon", $City)'/>
</get>
<var name="Time">
<script>
<![CDATA[
var date = new Date(ts.timestamp * 1000);
var hh = date.getUTCHours();
var mm = date.getUTCMinutes();
var p = hh > 12 ? 'PM' : 'AM';
if (hh > 12) hh -= 12;
if (mm < 10) mm = '0' + mm;
hh + ':' + mm + ' ' + p;
]]>
</script>
</var>
<output value="$CityName ($CityCountry) - $Time"/>
</input>
</context>