nodebb-plugin-onekite-discord 1.0.7 → 1.0.9
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/library.js +40 -1
- package/package.json +1 -1
- package/plugin.json +1 -1
package/library.js
CHANGED
|
@@ -1,5 +1,44 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Discord doesn't support masked links like [text](url) inside embed descriptions.
|
|
7
|
+
* To keep links clickable, convert them to plain URLs (Discord auto-linkifies).
|
|
8
|
+
*/
|
|
9
|
+
function formatDiscordLinks(str) {
|
|
10
|
+
if (!str || typeof str !== 'string') return str;
|
|
11
|
+
|
|
12
|
+
const normalizeUrl = (u) => {
|
|
13
|
+
if (!u) return u;
|
|
14
|
+
let url = String(u).trim();
|
|
15
|
+
|
|
16
|
+
// Strip wrapping <> if present
|
|
17
|
+
url = url.replace(/^<(.+)>$/, '$1');
|
|
18
|
+
|
|
19
|
+
// Fix common "https:/" typo
|
|
20
|
+
url = url.replace(/^https:\//i, 'https://');
|
|
21
|
+
url = url.replace(/^http:\//i, 'http://');
|
|
22
|
+
|
|
23
|
+
// If it's a bare domain starting with www., add scheme
|
|
24
|
+
if (/^www\./i.test(url)) url = 'https://' + url;
|
|
25
|
+
|
|
26
|
+
return url;
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
// HTML links -> URL
|
|
30
|
+
str = str.replace(/<a\s+[^>]*href=["']([^"']+)["'][^>]*>(.*?)<\/a>/gi, (_m, href, _text) => {
|
|
31
|
+
return normalizeUrl(href);
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
// Markdown links [text](url) -> URL
|
|
35
|
+
str = str.replace(/\[([^\]]+)\]\(([^)]+)\)/g, (_m, _text, url) => {
|
|
36
|
+
return normalizeUrl(url);
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
return str;
|
|
40
|
+
}
|
|
41
|
+
|
|
3
42
|
const { request } = require('undici');
|
|
4
43
|
|
|
5
44
|
const routeHelpers = require.main.require('./src/routes/helpers');
|
|
@@ -201,7 +240,7 @@ async function buildEmbed({ tid, pid, isReply }) {
|
|
|
201
240
|
const embedTitle = `${replyIcon}${safeTitle} – ${username}`.slice(0, 256);
|
|
202
241
|
|
|
203
242
|
// Embed title becomes clickable via embed.url
|
|
204
|
-
return { topicData, content: '', embed: { title: embedTitle, url: targetUrl, description: excerpt || '' } };
|
|
243
|
+
return { topicData, content: '', embed: { title: embedTitle, url: targetUrl, description: formatDiscordLinks(excerpt || '') } };
|
|
205
244
|
}
|
|
206
245
|
|
|
207
246
|
function extractTidPid(data) {
|
package/package.json
CHANGED
package/plugin.json
CHANGED