Skip to content

Commit 0fb51e0

Browse files
feat: improve quoi detection
1 parent e065591 commit 0fb51e0

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

src/helpers/regex.helper.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
const socialNetworksUrlRegex = new RegExp(
22
'^(https?://)?(www.)?(facebook.com|fb.me|twitter.com|vxtwitter.com|instagram.com|linkedin.com|youtube.com|youtu.be|pinterest.com|snapchat.com|tiktok.com)/[a-zA-Z0-9.-/?=&#_]+$',
33
);
4+
const quoiDetectorRegex = new RegExp(/\b\s*[q][u][o][i]\s*([.,!?]*\s*)*$/i);
5+
const emojiRegex = new RegExp(/(\p{Extended_Pictographic}|\p{Emoji_Component})/gu);
6+
47
export const isASocialNetworkUrl = (url: string): boolean => {
58
return socialNetworksUrlRegex.test(url);
69
};
10+
11+
export const removeEmoji = (text: string) => text.replaceAll(emojiRegex, '');
12+
export const endWithQuoi = (text: string) => quoiDetectorRegex.test(removeEmoji(text));

src/quoi-feur.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ import { type ChatInputCommandInteraction, type Message, TextChannel } from 'dis
22

33
import { MUTED_BY_BOT } from './constants/roles';
44
import { cache } from './helpers/cache';
5+
import { endWithQuoi } from './helpers/regex.helper';
56

6-
const quoiDetector = new RegExp(/\b\s*[qQ][uU][oO][iI]\s*[.,!?]*\s*$/i);
77
const ONE_MINUTE = 1 * 60 * 1000;
88

99
const reactWithFeur = async (message: Message) => {
@@ -38,7 +38,7 @@ export const quoiFeurReact = async (message: Message) => {
3838
const channelHasGame = channelIds.find((channelId) => channelId === message.channelId);
3939
if (!channelHasGame) return;
4040

41-
if (!quoiDetector.test(message.content)) return;
41+
if (!endWithQuoi(message.content)) return;
4242

4343
const probability = 1 / 20;
4444

0 commit comments

Comments
 (0)