Skip to content
This repository was archived by the owner on Sep 25, 2024. It is now read-only.

Commit ce492ef

Browse files
committed
Fix custom message not working error
1 parent 54fc812 commit ce492ef

File tree

1 file changed

+36
-6
lines changed

1 file changed

+36
-6
lines changed

scripts/cmds/rankup.js

Lines changed: 36 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ const { drive } = global.utils;
55
module.exports = {
66
config: {
77
name: "rankup",
8-
version: "1.3",
8+
version: "1.4",
99
author: "NTKhang",
1010
countDown: 5,
1111
role: 0,
@@ -52,20 +52,50 @@ module.exports = {
5252
const { exp } = await usersData.get(event.senderID);
5353
const currentLevel = expToLevel(exp);
5454
if (currentLevel > expToLevel(exp - 1)) {
55-
const forMessage = {
56-
body: getLang("notiMessage", currentLevel)
57-
};
55+
let customMessage = await threadsData.get(event.threadID, "data.rankup.message");
56+
let isTag = false;
57+
let userData;
58+
const formMessage = {};
59+
60+
if (customMessage) {
61+
userData = await usersData.get(event.senderID);
62+
customMessage = customMessage
63+
// .replace(/{userName}/g, userData.name)
64+
.replace(/{oldRank}/g, currentLevel - 1)
65+
.replace(/{currentRank}/g, currentLevel);
66+
if (customMessage.includes("{userNameTag}")) {
67+
isTag = true;
68+
customMessage = customMessage.replace(/{userNameTag}/g, `@${userData.name}`);
69+
}
70+
else {
71+
customMessage = customMessage.replace(/{userName}/g, userData.name);
72+
}
73+
74+
formMessage.body = customMessage;
75+
}
76+
else {
77+
formMessage.body = getLang("notiMessage", currentLevel);
78+
}
79+
5880
if (threadData.data.rankup?.attachments?.length > 0) {
5981
const files = threadData.data.rankup.attachments;
6082
const attachments = files.reduce((acc, file) => {
6183
acc.push(drive.getFile(file, "stream"));
6284
return acc;
6385
}, []);
64-
forMessage.attachment = (await Promise.allSettled(attachments))
86+
formMessage.attachment = (await Promise.allSettled(attachments))
6587
.filter(({ status }) => status == "fulfilled")
6688
.map(({ value }) => value);
6789
}
68-
message.reply(forMessage);
90+
91+
if (isTag) {
92+
formMessage.mentions = [{
93+
tag: `@${userData.name}`,
94+
id: event.senderID
95+
}];
96+
}
97+
98+
message.reply(formMessage);
6999
}
70100
}
71101
};

0 commit comments

Comments
 (0)