Skip to content

Commit 4110649

Browse files
committed
fix: handle emojis properly (#105)
1 parent dc03f34 commit 4110649

File tree

5 files changed

+50
-8
lines changed

5 files changed

+50
-8
lines changed

src/__tests__/regex.spec.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { describe, expect, it } from 'vitest';
22

3+
import { EMOJI } from '../helpers/emoji';
34
import { isASocialNetworkUrl, removeEmoji, removeMarkdown } from '../helpers/regex.helper';
45

56
describe('Helpers: Regex', () => {
@@ -17,7 +18,7 @@ describe('Helpers: Regex', () => {
1718
});
1819
describe('Rule: removeEmoji should remove all emojis from a string', () => {
1920
it('removeEmoji() should remove all emojis from a string', () => {
20-
const text = '👋 Hello, World!<:SpongebobMock:1136008737669259407>';
21+
const text = `${EMOJI.WAVE} Hello, World!<:SpongebobMock:1136008737669259407>`;
2122
const result = removeEmoji(text);
2223
expect(result).toBe(' Hello, World!');
2324
});

src/helpers/emoji.ts

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
export const EMOJI = {
2+
A: '🇦',
3+
B: '🇧',
4+
C: '🇨',
5+
D: '🇩',
6+
E: '🇪',
7+
F: '🇫',
8+
G: '🇬',
9+
H: '🇭',
10+
I: '🇮',
11+
J: '🇯',
12+
K: '🇰',
13+
L: '🇱',
14+
M: '🇲',
15+
N: '🇳',
16+
O: '🇴',
17+
P: '🇵',
18+
Q: '🇶',
19+
R: '🇷',
20+
S: '🇸',
21+
T: '🇹',
22+
U: '🇺',
23+
V: '🇻',
24+
W: '🇼',
25+
X: '🇽',
26+
Y: '🇾',
27+
Z: '🇿',
28+
MUTED: '🔇',
29+
PUT_LITTER_IN_ITS_PLACE: '🚮',
30+
DASH: '💨',
31+
WAVE: '👋',
32+
OK: '✅',
33+
NOT_OK: '❌',
34+
} as const;
35+
36+
export type Emoji = (typeof EMOJI)[keyof typeof EMOJI];

src/modules/coolLinksManagement/coolLinksManagement.module.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import ogs from 'open-graph-scraper';
33
import { z } from 'zod';
44

55
import { createModule } from '../../core/createModule';
6+
import { EMOJI } from '../../helpers/emoji';
67
import { isASocialNetworkUrl } from '../../helpers/regex.helper';
78
import { getPageSummary } from './summarizeCoolPages';
89
import { getVideoSummary } from './summarizeCoolVideos';
@@ -54,8 +55,8 @@ export const coolLinksManagement = createModule({
5455
return;
5556
}
5657

57-
await message.react('✅');
58-
await message.react('❌');
58+
await message.react(EMOJI.OK);
59+
await message.react(EMOJI.NOT_OK);
5960

6061
const url = detectedURLs[0];
6162
const threadName = await getThreadNameFromOpenGraph(url);

src/modules/fixEmbedTwitterVideo/fixEmbedTwitterVideo.module.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { ActionRowBuilder, ButtonBuilder, ButtonStyle, MessageType } from 'disco
22
import { z } from 'zod';
33

44
import { createModule } from '../../core/createModule';
5+
import { EMOJI } from '../../helpers/emoji';
56
import { resolveCatch } from '../../helpers/resolveCatch.helper';
67

78
const FXTwitterResponseSchema = z.object({
@@ -109,13 +110,13 @@ export const fixEmbedTwitterVideo = createModule({
109110
const cancel = new ButtonBuilder()
110111
.setCustomId(deleteBotAnswerButtonId)
111112
.setLabel('Remove bot answer')
112-
.setEmoji('🚮')
113+
.setEmoji(EMOJI.PUT_LITTER_IN_ITS_PLACE)
113114
.setStyle(ButtonStyle.Primary);
114115

115116
const ignore = new ButtonBuilder()
116117
.setCustomId(ignoreBotButtonsButtonId)
117118
.setLabel('Ignore bot buttons')
118-
.setEmoji('💨')
119+
.setEmoji(EMOJI.DASH)
119120
.setStyle(ButtonStyle.Primary);
120121

121122
const row = new ActionRowBuilder<ButtonBuilder>().addComponents(cancel, ignore);

src/modules/quoiFeur/quoiFeur.helpers.ts

+6-3
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import {
77
} from 'discord.js';
88

99
import { cache } from '../../core/cache';
10+
import type { Emoji } from '../../helpers/emoji';
11+
import { EMOJI } from '../../helpers/emoji';
1012
import {
1113
removeEmoji,
1214
removeMarkdown,
@@ -20,16 +22,17 @@ const quoiDetectorRegex = /\bquoi\s*$/i;
2022
const endWithQuoi = (text: string) =>
2123
quoiDetectorRegex.test(removeNonASCII(removeEmoji(removePunctuation(removeMarkdown(text)))));
2224

23-
const reactWith = async (message: Message, reactions: string[]) => {
25+
const reactWith = async (message: Message, reactions: Emoji[]) => {
2426
for (const reaction of reactions) {
2527
await message.react(reaction);
2628
}
2729
};
2830

2931
const reactWithCoubeh = async (message: Message) =>
30-
reactWith(message, ['🇨', '🇴', '🇺', '🇧', '🇪', '🇭', '🔇']);
32+
reactWith(message, [EMOJI.C, EMOJI.O, EMOJI.U, EMOJI.B, EMOJI.E, EMOJI.H, EMOJI.MUTED]);
3133

32-
const reactWithFeur = async (message: Message) => reactWith(message, ['🇫', '🇪', '🇺', '🇷']);
34+
const reactWithFeur = async (message: Message) =>
35+
reactWith(message, [EMOJI.F, EMOJI.E, EMOJI.U, EMOJI.R]);
3336

3437
export const reactOnEndWithQuoi = async (message: Message) => {
3538
if (!endWithQuoi(message.content)) return;

0 commit comments

Comments
 (0)