Skip to content

Commit a2f026f

Browse files
committed
feat: update reactions
1 parent f34f7f0 commit a2f026f

7 files changed

Lines changed: 61 additions & 23 deletions

File tree

package-lock.json

Lines changed: 10 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
"axios": "^1.10.0",
3535
"cli-progress": "^3.12.0",
3636
"dotenv": "^17.2.0",
37+
"emoji-regex": "^10.5.0",
3738
"fb-downloader-scrapper": "^3.0.1",
3839
"google-tts-api": "^2.0.2",
3940
"groq-sdk": "^0.27.0",

src/components/client.ts

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -47,30 +47,24 @@ client.on("qr", (qr: string) => {
4747
qrcode.generate(qr, { small: true });
4848
});
4949

50-
client.on("ready", async () => ready());
50+
client.on("ready", () => ready());
5151

52-
client.on("message_reaction", async (react: Reaction) =>
53-
reaction(client, react),
54-
);
52+
client.on("message_reaction", (react: Reaction) => reaction(client, react));
5553

5654
// client.on("message", (msg) => messageEvent(msg));
57-
client.on("message_create", async (msg: Message) => messageEvent(msg, "create"));
55+
client.on("message_create", (msg: Message) => messageEvent(msg, "create"));
5856

59-
client.on(
60-
"message_edit",
61-
async (msg: Message, newBody: string, prevBody: string) => {
62-
msg.body = newBody;
63-
await Promise.all([messageEdit(msg, newBody, prevBody), messageEvent(msg, "edit")]);
64-
},
65-
);
57+
client.on("message_edit", (msg: Message, newBody: string, prevBody: string) => {
58+
msg.body = newBody;
59+
Promise.all([messageEdit(msg, newBody, prevBody), messageEvent(msg, "edit")]);
60+
});
6661

67-
client.on(
68-
"message_revoke_everyone",
69-
async (msg: Message, revoked_msg?: Message) => revoke(msg, revoked_msg),
62+
client.on("message_revoke_everyone", (msg: Message, revoked_msg?: Message) =>
63+
revoke(msg, revoked_msg),
7064
);
7165

72-
client.on("group_join", async (notif: GroupNotification) => groupJoin(notif));
73-
client.on("group_leave", async (notif: GroupNotification) => groupLeave(notif));
66+
client.on("group_join", (notif: GroupNotification) => groupJoin(notif));
67+
client.on("group_leave", (notif: GroupNotification) => groupLeave(notif));
7468
client.on("auth_failure", (msg: string) => {
7569
loadingBar.stop();
7670
log.error("Auth", "Authentication failed. Please try again.");

src/components/events/message.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,11 @@ import { client } from "../client";
1313
import Font from "../utils/font";
1414
import quiz from "./quiz";
1515
import { errors } from "../utils/data";
16+
import emojiRegex from "emoji-regex";
17+
import { funD, happyEE, sadEE, loveEE } from "../../data/reaction";
18+
import { containsAny } from "../utils/string";
1619

20+
const regex = emojiRegex();
1721
const commandPrefix = process.env.COMMAND_PREFIX || "!";
1822
const commandPrefixLess = process.env.COMMAND_PREFIX_LESS === "true";
1923
const debug = process.env.DEBUG === "true";
@@ -86,6 +90,25 @@ export default async function (msg: Message, type: string) {
8690
msg.reply("Please wait a minute or so.");
8791
return;
8892
}
93+
94+
/*
95+
*
96+
* Process msg reaction
97+
*/
98+
const emojis = [...msg.body.matchAll(regex)].map((match) => match[0]);
99+
if (emojis.length > 0) {
100+
const react = emojis[Math.floor(Math.random() * emojis.length)];
101+
102+
await msg.react(react);
103+
} else if (containsAny(msg.body, funD)) {
104+
await msg.react("🤣");
105+
} else if (containsAny(msg.body, happyEE)) {
106+
await msg.reply(funD[Math.floor(Math.random() * funD.length)]);
107+
} else if (containsAny(msg.body, sadEE)) {
108+
await msg.react("😭");
109+
} else if (containsAny(msg.body, loveEE)) {
110+
await msg.react("❤️");
111+
}
89112
}
90113

91114
/*

src/components/events/reaction.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,7 @@ export default async function (client: Client, react: Reaction) {
1111

1212
const senderId = react.senderId.split("@")[0];
1313
const isBlockedUser = await isBlocked(senderId);
14-
if (isBlockedUser) {
15-
return;
16-
}
14+
if (isBlockedUser) return;
1715

1816
try {
1917
const message = await client.getMessageById(react.msgId._serialized);

src/components/utils/string.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
export function containsAny(str: string, substrings: string[]) {
2+
for (let i in substrings) {
3+
let substring = substrings[i];
4+
if (str.indexOf(substring) != -1) {
5+
return true;
6+
}
7+
}
8+
return false;
9+
}

src/data/reaction.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
const funD = ["🤣🤣🤣", "🤣", "😆😆", "😂😂🤣🤣", "😆😆🤣", "😂😆", "😆", "ahahaahh", "hahahahhah", "haahaaa", "ahhaa😂", "hhahahah😆", "🤣🤣hahaahhaha", "hahaa😆🤣", "hahahah funny."];
2+
const happyEE = ["haha", "ahah", "ahha", "funny ", "insane ", "lol", "lmao", "lmfao", "silly ", "laugh ", "hilarious", "absurd", "ridicolous"];
3+
const sadEE = ["pain", "painful", "cry ", "crying ", "sad ", "tired", "sick ", "depressed", "miserable ", "heartbroken", "sorry", "traumatic", "truma", "pitiful", "depressing", "depress", "unfortunate", "awful"];
4+
const loveEE = ["love", "thank", "delight", "pleasure", "regards", "respect", "dear", "darling", "boyfriend", "girlfriend", "sweetheart", "angel", "honey", "adore", "treasure", "devotion", "friend"];
5+
6+
export { funD, happyEE, sadEE, loveEE }

0 commit comments

Comments
 (0)