]> git.localhorst.tv Git - alttp.git/blob - resources/js/helpers/Channel.js
add known bot
[alttp.git] / resources / js / helpers / Channel.js
1 export const hasActiveGuessing = channel =>
2         channel && channel.guessing_start;
3
4 export const isAcceptingGuesses = channel =>
5         channel && channel.guessing_start && !channel.guessing_end;
6
7 export const patchGuess = (guesses, guess) =>
8         [guess, ...(guesses || []).filter(g => g.uid !== guess.uid)];
9
10 export const patchWinner = (winners, winner) =>
11         [winner, ...(winners || []).filter(w => w.uid !== winner.uid)];
12
13 export const compareLive = (a, b) => {
14         const a_live = a && a.twitch_live;
15         const b_live = b && b.twitch_live;
16         if (a_live) {
17                 if (b_live) {
18                         return 0;
19                 }
20                 return -1;
21         }
22         if (b_live) {
23                 return 1;
24         }
25         return 0;
26 };
27
28 export const compareName = (a, b) => {
29         const a_name = (a && (a.short_name || a.title)) || '';
30         const b_name = (b && (b.short_name || b.title)) || '';
31         return a_name.localeCompare(b_name);
32 };
33
34 export const compareTitle = (a, b) => {
35         const a_title = (a && a.title) || '';
36         const b_title = (b && b.title) || '';
37         return a_title.localeCompare(b_title);
38 };
39
40 export const compareViewers = (a, b) => {
41         const a_viewers = (a && a.twitch_live && a.twitch_viewers) || 0;
42         const b_viewers = (b && b.twitch_live && b.twitch_viewers) || 0;
43         return b_viewers - a_viewers;
44 };
45
46 export const compareHorstieLog = (a, b) => {
47         const live = compareLive(a, b);
48         if (live) return live;
49         const viewers = compareViewers(a, b);
50         if (viewers) return viewers;
51         return compareName(a, b);
52 };