aboutsummaryrefslogtreecommitdiffstats
path: root/src/helpers/scoreToEmoji.ts
blob: 5af102686c8dccf37fa631efeac9337952aa0a3c (plain) (blame)
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
import { GuessType, GuessState } from "../types/guess";
import { appName } from "../constants";
import { fetchInfo } from "./fetchInfo";

export async function scoreToEmoji(guesses: GuessType[]): Promise<string> {
  const msInDay = 86400000;
  const todaysDate = new Date();
  const info = await fetchInfo();
  const startDate = new Date(info.startDate);
  const index = Math.floor((todaysDate.getTime() - startDate.getTime() )/msInDay) + 1
  const emojis = {
    incorrect: "🟥",
    partiallyCorrect: "🟨",
    correct: "🟩",
    skip: "⬜",
    empty: "⬛️",
  };
  const prefix = `${appName} - #${index}`;

  let scoreEmoji = "";

  guesses.forEach((guess: GuessType) => {
    if (guess.state === GuessState.Correct) {
      scoreEmoji += emojis.correct;
    } else if (guess.state === GuessState.Skipped) {
      scoreEmoji += emojis.skip;
    } else if (guess.state === GuessState.PartiallyCorrect) {
      scoreEmoji += emojis.partiallyCorrect;
    } else if (guess.state === GuessState.Incorrect) {
      scoreEmoji += emojis.incorrect;
    } else {
      scoreEmoji += emojis.empty;
    }
  });

  return `${prefix}\n${scoreEmoji}`;
}
send patches to the email below
yukais@pinapelz.com
include the subject [PATCH repo_name]
pinapelz.com
homepage