nodebb-plugin-discord-onekite 1.0.14 → 1.0.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +6 -8
- package/library.js +17 -17
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,10 +1,8 @@
|
|
|
1
|
-
# nodebb-plugin-discord-onekite v1.1.
|
|
1
|
+
# nodebb-plugin-discord-onekite v1.1.4
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
-
|
|
5
|
-
-
|
|
3
|
+
Discord:
|
|
4
|
+
- Always sends the forum topic link (example: https://www.onekite.com/topic/16024/test-discord)
|
|
5
|
+
- First line is the raw URL, then a Markdown clickable link `[title](url)`
|
|
6
|
+
- Still sends an embed (title clickable via embed.url) + fallback to plain content if embeds are rejected
|
|
6
7
|
|
|
7
|
-
|
|
8
|
-
- Notification content starts with the direct post URL
|
|
9
|
-
- Includes an excerpt of the post content (truncated)
|
|
10
|
-
- Keeps embed minimal + fallback to plain content if Discord rejects embeds
|
|
8
|
+
ACP remains with the "disk" save button and NodeBB toast.
|
package/library.js
CHANGED
|
@@ -122,7 +122,7 @@ async function getPostExcerpt(pid) {
|
|
|
122
122
|
try {
|
|
123
123
|
const p = await posts.getPostFields(pid, ['content']);
|
|
124
124
|
const text = stripHtml(p && p.content);
|
|
125
|
-
return truncate(text,
|
|
125
|
+
return truncate(text, 500);
|
|
126
126
|
} catch {
|
|
127
127
|
return '';
|
|
128
128
|
}
|
|
@@ -134,33 +134,32 @@ async function buildPayload({ tid, pid, isReply }) {
|
|
|
134
134
|
const topicData = await topics.getTopicFields(tid, ['tid', 'uid', 'cid', 'title', 'slug', 'mainPid']);
|
|
135
135
|
if (!topicData) return null;
|
|
136
136
|
|
|
137
|
+
// Always build the forum link like the example: https://www.onekite.com/topic/<tid or slug>
|
|
137
138
|
const topicUrl = ensureAbsoluteUrl(baseUrl, `/topic/${topicData.slug || topicData.tid}`);
|
|
138
|
-
|
|
139
|
+
|
|
140
|
+
// For replies, link directly to the post if possible
|
|
141
|
+
const postUrl = (isReply && pid) ? `${topicUrl}/${pid}` : topicUrl;
|
|
139
142
|
|
|
140
143
|
const u = await user.getUserFields(topicData.uid, ['username']);
|
|
141
144
|
const title = (topicData.title || (isReply ? 'Nouvelle réponse' : 'Nouveau sujet')).toString().slice(0, 256);
|
|
142
145
|
const authorName = (u && u.username ? String(u.username) : 'Utilisateur').slice(0, 256);
|
|
143
146
|
|
|
144
147
|
const excerpt = await getPostExcerpt(isReply ? pid : topicData.mainPid);
|
|
145
|
-
const description = truncate(excerpt || (isReply ? `Réponse de ${authorName}` : `Sujet créé par ${authorName}`),
|
|
148
|
+
const description = truncate(excerpt || (isReply ? `Réponse de ${authorName}` : `Sujet créé par ${authorName}`), 500);
|
|
146
149
|
|
|
150
|
+
// Minimal embed but with URL so the title is clickable
|
|
147
151
|
const embed = {
|
|
148
152
|
title,
|
|
149
153
|
description,
|
|
150
154
|
};
|
|
155
|
+
if (isValidHttpUrl(postUrl)) embed.url = postUrl;
|
|
151
156
|
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
postUrl,
|
|
159
|
-
isReply ? `🗨️ Nouvelle réponse : ${title}` : `🆕 Nouveau sujet : ${title}`,
|
|
160
|
-
];
|
|
161
|
-
if (description) contentLines.push(description);
|
|
162
|
-
|
|
163
|
-
const content = contentLines.join('\n');
|
|
157
|
+
// Ensure the message is clickable: markdown link + also raw URL in first line
|
|
158
|
+
const content = [
|
|
159
|
+
postUrl, // raw URL first line
|
|
160
|
+
isReply ? `🗨️ Nouvelle réponse : [${title}](${postUrl})` : `🆕 Nouveau sujet : [${title}](${topicUrl})`,
|
|
161
|
+
description ? description : '',
|
|
162
|
+
].filter(Boolean).join('\n');
|
|
164
163
|
|
|
165
164
|
return { topicData, embed, content };
|
|
166
165
|
}
|
|
@@ -222,7 +221,8 @@ Plugin.onTopicPost = async (data) => {
|
|
|
222
221
|
|
|
223
222
|
if (!cidAllowed(built.topicData.cid, settings.cids)) return;
|
|
224
223
|
|
|
225
|
-
|
|
224
|
+
// Send content + embed (content ensures clickable link always)
|
|
225
|
+
await sendDiscord(settings.webhookUrl, { content: built.content, embeds: [built.embed] }, built.content);
|
|
226
226
|
};
|
|
227
227
|
|
|
228
228
|
Plugin.onTopicReply = async (data) => {
|
|
@@ -240,7 +240,7 @@ Plugin.onTopicReply = async (data) => {
|
|
|
240
240
|
|
|
241
241
|
if (!cidAllowed(built.topicData.cid, settings.cids)) return;
|
|
242
242
|
|
|
243
|
-
await sendDiscord(settings.webhookUrl, { embeds: [built.embed] }, built.content);
|
|
243
|
+
await sendDiscord(settings.webhookUrl, { content: built.content, embeds: [built.embed] }, built.content);
|
|
244
244
|
};
|
|
245
245
|
|
|
246
246
|
module.exports = Plugin;
|