Refactor code

This commit is contained in:
rejas
2020-03-10 10:45:09 +01:00
parent cafa4211a6
commit 2a31ece0c6

View File

@@ -29,10 +29,12 @@ Module.register("compliments", {
"You look nice!", "You look nice!",
"Hi, sexy!" "Hi, sexy!"
], ],
date: [ 1403 : [
["03-14", "Happy birthday, Albert Einstein!"], "Happy birthday, Albert Einstein!"
["12-10", "Happy birthday, Ada Lovelace!"]
], ],
1012: [
"Happy birthday, Ada Lovelace!"
]
}, },
updateInterval: 30000, updateInterval: 30000,
remoteFile: null, remoteFile: null,
@@ -106,8 +108,7 @@ Module.register("compliments", {
*/ */
complimentArray: function() { complimentArray: function() {
var hour = moment().hour(); var hour = moment().hour();
var year = moment().year(); var date = moment().format("DDMM");
var today = moment(new Date());
var compliments; var compliments;
if (hour >= this.config.morningStartTime && hour < this.config.morningEndTime && this.config.compliments.hasOwnProperty("morning")) { if (hour >= this.config.morningStartTime && hour < this.config.morningEndTime && this.config.compliments.hasOwnProperty("morning")) {
@@ -128,11 +129,9 @@ Module.register("compliments", {
compliments.push.apply(compliments, this.config.compliments.anytime); compliments.push.apply(compliments, this.config.compliments.anytime);
this.config.compliments.date.forEach(d => { if (date in this.config.compliments) {
if (today.isSame(year + "-" + d[0], "month")) { compliments.push.apply(compliments, this.config.compliments[date]);
compliments.push(d[1]);
} }
});
return compliments; return compliments;
}, },