+
-
+
diff --git a/app.js b/app.js
index 5ff521b..ae732a2 100644
--- a/app.js
+++ b/app.js
@@ -4,6 +4,7 @@ let kara = new Vue({
messages: [],
lastMessage: null,
name: 'Kara',
+ location: null,
chatbox: null,
isTyping: false,
askedForName: false,
@@ -20,7 +21,8 @@ let kara = new Vue({
},
settingsModal: {
name: null,
- username: null
+ username: null,
+ location: ''
},
notes: [],
answers: [
@@ -54,7 +56,8 @@ let kara = new Vue({
this.settingsModal = {
name: this.name,
- username: this.username
+ username: this.username,
+ location: this.location
};
if (!this.username || this.username === "null") {
@@ -131,6 +134,8 @@ let kara = new Vue({
this.saveNote(noteToSave);
} else if (this.checkForCommands(message, 'clear')) {
this.clearChat();
+ } else if (this.checkForCommands(message, 'weather')) {
+ this.checkWeather();
} else if (this.askedForName === true) {
this.setName(message)
} else if (this.takeNote === true) {
@@ -334,6 +339,7 @@ let kara = new Vue({
localStorage.setItem('answers', JSON.stringify(this.answers));
localStorage.setItem('notes', JSON.stringify(this.notes));
localStorage.setItem('lastMessage', JSON.stringify(this.lastMessage));
+ localStorage.setItem('location', JSON.stringify(this.location));
},
getSavedData() {
let savedName = localStorage.getItem('name');
@@ -358,6 +364,9 @@ let kara = new Vue({
let savedLastMessage = JSON.parse(localStorage.getItem('lastMessage'));
this.lastMessage = savedLastMessage ? savedLastMessage : null;
+ let savedLocation = JSON.parse(localStorage.getItem('location'));
+ this.location = savedLocation ? savedLocation : null;
+
this.scrollDown();
},
askForName() {
@@ -407,6 +416,7 @@ let kara = new Vue({
saveSettings() {
this.name = this.settingsModal.name;
this.username = this.settingsModal.username;
+ this.location = this.settingsModal.location;
this.updateStorage();
this.botMessage('Settings saved! :)');
@@ -417,6 +427,28 @@ let kara = new Vue({
this.botMessage('Chat cleared.');
this.updateStorage();
},
+ checkWeather() {
+ let vue = this;
+
+ if (!vue.location) {
+ vue.botMessage('Please set your location in the settings.');
+ return;
+ }
+
+ let city = this.location.toLowerCase();
+ let url = 'http://api.openweathermap.org/data/2.5/weather?q=' + city + '&appid=8a1aa336da8899c1038bf6bd808d8961&units=metric';
+
+ axios.get(url)
+ .then(function (response) {
+ vue.botMessage('In ' + response.data.name + ' it\'s ' + response.data.main.temp.toFixed() + '°C with ' + response.data.weather[0].description + '.');
+ })
+ .catch(function (error) {
+ console.log(error);
+ vue.botMessage('I couldn\'t check the weather for your location.');
+ })
+
+ this.updateStorage();
+ },
clearStorage() {
localStorage.clear();
location.reload();
diff --git a/index.html b/index.html
index 988762d..4f2b2f2 100644
--- a/index.html
+++ b/index.html
@@ -4,6 +4,7 @@
Kara
+
@@ -151,6 +152,10 @@
+
+
+
+