Skip to content

Commit 8e31a6e

Browse files
committed
feat: move processing of msg reaction above the handler condition & replace it with set so only unique emojis can be selected
1 parent 0da6cf1 commit 8e31a6e

1 file changed

Lines changed: 21 additions & 19 deletions

File tree

src/components/events/message.ts

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,27 @@ export default async function (msg: Message, type: string) {
5959
if (!commandPrefixLess && prefix) return;
6060
if (msg.fromMe && prefix) return;
6161

62+
/*
63+
*
64+
* Process msg reaction
65+
*/
66+
if (!msg.fromMe) {
67+
const emojis = [...new Set([...msg.body.matchAll(regex)].map((m) => m[0]))];
68+
if (emojis.length > 0) {
69+
const react = emojis[Math.floor(Math.random() * emojis.length)];
70+
71+
await msg.react(react);
72+
} else if (containsAny(msg.body, funD)) {
73+
await msg.react("🤣");
74+
} else if (containsAny(msg.body, happyEE)) {
75+
await msg.reply(funD[Math.floor(Math.random() * funD.length)]);
76+
} else if (containsAny(msg.body, sadEE)) {
77+
await msg.react("😭");
78+
} else if (containsAny(msg.body, loveEE)) {
79+
await msg.react("❤️");
80+
}
81+
}
82+
6283
/*
6384
* Check if the message starts with the command prefix.
6485
*/
@@ -86,25 +107,6 @@ export default async function (msg: Message, type: string) {
86107
await msg.reply("Please wait a minute or so.");
87108
return;
88109
}
89-
90-
/*
91-
*
92-
* Process msg reaction
93-
*/
94-
const emojis = [...msg.body.matchAll(regex)].map((match) => match[0]);
95-
if (emojis.length > 0) {
96-
const react = emojis[Math.floor(Math.random() * emojis.length)];
97-
98-
await msg.react(react);
99-
} else if (containsAny(msg.body, funD)) {
100-
await msg.react("🤣");
101-
} else if (containsAny(msg.body, happyEE)) {
102-
await msg.reply(funD[Math.floor(Math.random() * funD.length)]);
103-
} else if (containsAny(msg.body, sadEE)) {
104-
await msg.react("😭");
105-
} else if (containsAny(msg.body, loveEE)) {
106-
await msg.react("❤️");
107-
}
108110
}
109111

110112
/*

0 commit comments

Comments
 (0)