add support for sequential compliments usage

This commit is contained in:
Sam Detweiler 2019-12-08 09:28:50 -06:00
parent 5e4d25b957
commit 0cb377618e

View File

@ -36,9 +36,10 @@ Module.register("compliments", {
morningStartTime: 3, morningStartTime: 3,
morningEndTime: 12, morningEndTime: 12,
afternoonStartTime: 12, afternoonStartTime: 12,
afternoonEndTime: 17 afternoonEndTime: 17,
random: true
}, },
lastIndexUsed:-1,
// Set currentweather from module // Set currentweather from module
currentWeatherType: "", currentWeatherType: "",
@ -147,8 +148,20 @@ Module.register("compliments", {
* return compliment string - A compliment. * return compliment string - A compliment.
*/ */
randomCompliment: function() { randomCompliment: function() {
// get the current time of day compliments list
var compliments = this.complimentArray(); var compliments = this.complimentArray();
var index = this.randomIndex(compliments); variable for index to next message to display
let index=0
// are we randomizing
if(this.config.random){
// yes
index = this.randomIndex(compliments);
}
else{
// no, sequetial
// if doing sequential, don't fall off the end
index = (this.lastIndexUsed >= (compliments.length-1))?0: ++this.lastIndexUsed
}
return compliments[index]; return compliments[index];
}, },