|
1 | 1 | import dayjs from "dayjs"; |
2 | 2 |
|
3 | | -type Holiday = "halloween" | "christmas" | null; |
| 3 | +const letters = "abcdefghijklmnopqrstuvwxyz".split(""); |
| 4 | +const symbols = "@#$%^&*()_+=-".split(""); |
| 5 | + |
| 6 | +type Holiday = "halloween" | "christmas" | "valentine" | "woman" | "programmer" | "april-fools" | "ukraine" | null; |
4 | 7 |
|
5 | 8 | export function getHolidayStatus(): Holiday { |
6 | 9 | const now = dayjs().set("year", 2000); |
7 | 10 |
|
8 | | - if (now.isAfter("2000-10-25") && now.isBefore("2000-11-4")) { |
9 | | - return "halloween"; |
10 | | - } |
11 | | - |
12 | | - if (now.isAfter("2000-12-19") || now.isBefore("2000-01-15")) { |
13 | | - return "christmas"; |
14 | | - } |
| 11 | + if (now.isAfter("2000-10-24", "day") && now.isBefore("2000-11-5", "day")) return "halloween"; |
| 12 | + if (now.isSame("2000-02-14", "day")) return "valentine"; |
| 13 | + if (now.isSame("2000-03-08", "day")) return "woman"; |
| 14 | + if (now.isSame("2000-01-07", "day")) return "programmer"; |
| 15 | + if (now.isSame("2000-04-01", "day")) return "april-fools"; |
| 16 | + if (now.isSame("2000-08-24")) return "ukraine"; |
| 17 | + if (now.isAfter("2000-12-19") || now.isBefore("2000-01-15")) return "christmas"; |
15 | 18 |
|
16 | 19 | return null; |
17 | 20 | } |
18 | 21 |
|
| 22 | +function getAprilFoolsName(displayName: string): string { |
| 23 | + return displayName |
| 24 | + .split("") |
| 25 | + .map((char) => { |
| 26 | + // Keep spaces |
| 27 | + if (char === " ") return char; |
| 28 | + let newChar = ""; |
| 29 | + |
| 30 | + // Replace on symbols with 7.5% chance |
| 31 | + if (Math.random() < 0.075) newChar = symbols[Math.floor(Math.random() * symbols.length)]; |
| 32 | + else { |
| 33 | + // Generate random letters |
| 34 | + const charID = letters.indexOf(char.toLowerCase()); |
| 35 | + if (charID === -1) newChar = char[Math.floor(Math.random() * char.length)]; |
| 36 | + else newChar = letters[Math.min(Math.max(0, charID + Math.floor(Math.random() * 5) - 2), letters.length - 1)]; |
| 37 | + |
| 38 | + // Random uppercase |
| 39 | + if (Math.random() > 0.5) newChar = newChar.toUpperCase(); |
| 40 | + } |
| 41 | + |
| 42 | + return newChar; |
| 43 | + }) |
| 44 | + .join(""); |
| 45 | +} |
| 46 | + |
19 | 47 | export function getTempVoiceName(displayName: string): string { |
20 | 48 | switch (getHolidayStatus()) { |
21 | 49 | case "halloween": |
22 | | - return `π¦${displayName}`; |
| 50 | + return `π¦γ»${displayName}`; |
23 | 51 | case "christmas": |
24 | | - return `β${displayName}`; |
| 52 | + return `βγ»${displayName}`; |
| 53 | + case "valentine": |
| 54 | + return `β€οΈγ»${displayName}`; |
| 55 | + case "woman": |
| 56 | + return `βοΈγ»${displayName}`; |
| 57 | + case "programmer": |
| 58 | + return `π¨βπ»γ»${displayName}`; |
| 59 | + case "april-fools": |
| 60 | + return `π€‘γ»${getAprilFoolsName(displayName)}`; |
| 61 | + case "ukraine": |
| 62 | + return `πΊπ¦γ»${displayName}`; |
25 | 63 | default: |
26 | | - return `π${displayName}`; |
| 64 | + return `πγ»${displayName}`; |
27 | 65 | } |
28 | 66 | } |
0 commit comments