-
-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathMMM-NFL.js
192 lines (166 loc) · 5.58 KB
/
MMM-NFL.js
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
/* global Module Log moment config */
/* Magic Mirror
* Module: MMM-NFL
*
* By fewieden https://github.com/fewieden/MMM-NFL
* MIT Licensed.
*/
Module.register('MMM-NFL', {
modes: {
PRE: 'Preseason',
REG: 'Regular-Season',
POST: 'Post-Season',
OFF: 'Offseason',
},
details: {
season: new Date().getFullYear(),
stage: 'REG'
},
states: {
1: '1ST_QUARTER',
2: '2ND_QUARTER',
3: '3RD_QUARTER',
4: '4TH_QUARTER',
halftime: 'HALF_TIME',
overtime: 'OVER_TIME',
final: 'FINAL',
'final-overtime': 'FINAL_OVERTIME',
pregame: 'UPCOMING'
},
defaults: {
colored: false,
focus_on: false,
format: 'ddd h:mm',
reloadInterval: 30 * 60 * 1000, // every 30 minutes
reverseTeams: false,
tableSize: 'small'
},
getTranslations() {
return {
en: 'translations/en.json',
de: 'translations/de.json'
};
},
getScripts() {
return ['moment.js'];
},
getStyles() {
return ['font-awesome.css', 'MMM-NFL.css'];
},
getTemplate() {
return `templates/${this.name}.njk`;
},
findTeamInScores(team) {
return this.scores.find(m => team === m.homeTeam || team === m.awayTeam);
},
getFocusedTeamsWithByeWeeks() {
if (!Array.isArray(this.config.focus_on) || !Array.isArray(this.scores)) {
return [];
}
return this.config.focus_on.filter(team => !this.findTeamInScores(team));
},
getFilteredScores() {
if (!Array.isArray(this.config.focus_on) || !Array.isArray(this.scores)) {
return this.scores;
}
return this.scores.filter(m => this.config.focus_on.includes(m.homeTeam) || this.config.focus_on.includes(m.awayTeam));
},
getTemplateData() {
return {
states: this.states,
modes: this.mode,
details: this.details,
config: this.config,
scores: this.getFilteredScores(),
focusedTeamsWithByeWeeks: this.getFocusedTeamsWithByeWeeks()
};
},
getVoiceData() {
return {
mode: 'FOOTBALL',
sentences: [
'OPEN HELP',
'CLOSE HELP',
'SHOW PASSING YARDS STATISTIC',
'SHOW RUSHING YARDS STATISTIC',
'SHOW RECEIVING YARDS STATISTIC',
'SHOW TACKLES STATISTIC',
'SHOW SACKS STATISTIC',
'SHOW KICKOFF YARDS STATISTIC',
'SHOW INTERCEPTIONS STATISTIC',
'SHOW PASSING TOUCHDOWNS STATISTIC',
'SHOW QUARTERBACK RATING STATISTIC',
'SHOW RUSHING TOUCHDOWNS STATISTIC',
'SHOW RECEPTIONS STATISTIC',
'SHOW RECEIVING TOUCHDOWNS STATISTIC',
'SHOW TOTAL POINTS STATISTIC',
'SHOW TOTAL TOUCHDOWNS STATISTIC',
'SHOW PUNT YARDS STATISTIC',
'SHOW PASSES DEFENDED STATISTIC',
'HIDE STATISTIC'
]
};
},
start() {
Log.info(`Starting module: ${this.name}`);
this.addGlobals();
this.addFilters();
this.sendSocketNotification('CONFIG', this.config);
moment.locale(config.locale);
},
suspend() {
this.sendSocketNotification('SUSPEND', this.config);
},
resume() {
this.sendSocketNotification('CONFIG', this.config);
},
notificationReceived(notification, payload, sender) {
if (notification === 'ALL_MODULES_STARTED') {
this.sendNotification('REGISTER_VOICE_MODULE', this.getVoiceData());
} else if (notification === 'VOICE_FOOTBALL' && sender.name === 'MMM-voice') {
this.sendSocketNotification('VOICE_COMMAND', payload);
} else if (notification === 'VOICE_MODE_CHANGED' && sender.name === 'MMM-voice' && payload.old === this.getVoiceData().mode) {
this.sendNotification('CLOSE_MODAL');
}
},
openStatisticsModal({ type, statistics }) {
this.sendNotification('OPEN_MODAL', {
template: 'templates/StatisticsModal.njk',
data: {
type,
statistics,
config: this.config,
fns: { translate: this.translate.bind(this) }
}
});
},
openHelpModal() {
this.sendNotification('OPEN_MODAL', {
template: 'templates/HelpModal.njk',
data: {
...this.getVoiceData(),
fns: { translate: this.translate.bind(this) }
}
});
},
socketNotificationReceived(notification, payload) {
if (notification === 'SCORES') {
this.scores = payload.scores;
this.details = payload.details;
this.updateDom(300);
} else if (notification === 'STATISTICS') {
this.openStatisticsModal(payload);
} else if (notification === 'OPEN_HELP_MODAL') {
this.openHelpModal();
} else if (notification === 'CLOSE_MODAL') {
this.sendNotification('CLOSE_MODAL');
}
},
addGlobals() {
this.nunjucksEnvironment().addGlobal('includes', (array, item) => array.includes(item));
},
addFilters() {
this.nunjucksEnvironment().addFilter('formatDate', timestamp => moment(timestamp).format(this.config.format));
this.nunjucksEnvironment().addFilter('iconUrl', teamName => this.file(`icons/${teamName}${this.config.helmets ? '_helmet' : ''}.png`));
}
});