nodebb-plugin-discord-onekite 1.1.9 → 1.1.10
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 +4 -4
- package/lib/controllers.js +0 -1
- package/library.js +6 -2
- package/package.json +1 -1
- package/plugin.json +4 -1
- package/static/lib/admin.js +40 -0
- package/templates/admin/plugins/discord-onekite.tpl +10 -11
package/README.md
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
# nodebb-plugin-discord-onekite v1.1.
|
|
1
|
+
# nodebb-plugin-discord-onekite v1.1.7
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
Fixes webpack template build errors by removing `<!-- IMPORT admin/partials/save_button.tpl -->` and using an inline save button.
|
|
4
|
+
|
|
5
|
+
Everything else unchanged from v1.1.6.
|
package/lib/controllers.js
CHANGED
|
@@ -40,7 +40,6 @@ controllers.renderAdminPage = async function (req, res) {
|
|
|
40
40
|
res.render('admin/plugins/discord-onekite', {
|
|
41
41
|
settings: settings || {},
|
|
42
42
|
categories: categoriesForTpl,
|
|
43
|
-
saved: req.query && (req.query.saved === '1' || req.query.saved === 'true'),
|
|
44
43
|
});
|
|
45
44
|
};
|
|
46
45
|
|
package/library.js
CHANGED
|
@@ -94,6 +94,7 @@ async function sendDiscord(webhookUrl, payload) {
|
|
|
94
94
|
try {
|
|
95
95
|
await postToDiscord(webhookUrl, payload);
|
|
96
96
|
} catch (e) {
|
|
97
|
+
// If Discord rejects embeds, retry with plain content only.
|
|
97
98
|
if (e && e.statusCode === 400 && payload && payload.content) {
|
|
98
99
|
try {
|
|
99
100
|
await postToDiscord(webhookUrl, { content: payload.content });
|
|
@@ -129,13 +130,14 @@ async function buildPayload({ tid, pid, isReply }) {
|
|
|
129
130
|
const title = (topicData.title || (isReply ? 'Nouvelle réponse' : 'Nouveau sujet')).toString().slice(0, 256);
|
|
130
131
|
const excerpt = await getPostExcerpt(isReply ? pid : topicData.mainPid);
|
|
131
132
|
|
|
133
|
+
// Single clickable link line + excerpt below
|
|
132
134
|
const linkLine = isReply
|
|
133
135
|
? `🗨️ Nouvelle réponse : [${title}](${targetUrl})`
|
|
134
136
|
: `🆕 Nouveau sujet : [${title}](${topicUrl})`;
|
|
135
137
|
|
|
136
138
|
const content = [linkLine, excerpt].filter(Boolean).join('\n');
|
|
137
139
|
|
|
138
|
-
const embed = { title, description: excerpt || '', url: targetUrl };
|
|
140
|
+
const embed = { title, description: excerpt || '' , url: targetUrl };
|
|
139
141
|
|
|
140
142
|
return { topicData, content, embed };
|
|
141
143
|
}
|
|
@@ -156,6 +158,7 @@ Plugin.init = async ({ router }) => {
|
|
|
156
158
|
controllers.renderAdminPage
|
|
157
159
|
);
|
|
158
160
|
|
|
161
|
+
// AJAX save endpoint (used by admin.js via api.post)
|
|
159
162
|
router.post('/admin/plugins/discord-onekite/save',
|
|
160
163
|
middleware.admin.checkPrivileges,
|
|
161
164
|
async (req, res) => {
|
|
@@ -166,10 +169,11 @@ Plugin.init = async ({ router }) => {
|
|
|
166
169
|
cids: req.body.cids || '',
|
|
167
170
|
};
|
|
168
171
|
await meta.settings.set(SETTINGS_KEY, payload);
|
|
172
|
+
res.json({ ok: true });
|
|
169
173
|
} catch (e) {
|
|
170
174
|
console.error('[discord-onekite] save failed', e);
|
|
175
|
+
res.status(500).json({ ok: false });
|
|
171
176
|
}
|
|
172
|
-
res.redirect('/admin/plugins/discord-onekite?saved=1');
|
|
173
177
|
}
|
|
174
178
|
);
|
|
175
179
|
};
|
package/package.json
CHANGED
package/plugin.json
CHANGED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
/* global $, app */
|
|
3
|
+
|
|
4
|
+
define('admin/plugins/discord-onekite', ['api'], function (api) {
|
|
5
|
+
const ACP = {};
|
|
6
|
+
|
|
7
|
+
function getMultiSelectValues(selector) {
|
|
8
|
+
const el = document.querySelector(selector);
|
|
9
|
+
if (!el) return [];
|
|
10
|
+
return Array.from(el.selectedOptions || []).map(o => o.value);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
ACP.init = function () {
|
|
14
|
+
const $form = $('.discord-onekite-settings');
|
|
15
|
+
if (!$form.length) return;
|
|
16
|
+
|
|
17
|
+
$('#save').off('click.discordOnekite').on('click.discordOnekite', function () {
|
|
18
|
+
const payload = {
|
|
19
|
+
webhookUrl: String($('#webhookUrl').val() || '').trim(),
|
|
20
|
+
notifyReplies: $('#notifyReplies').is(':checked'),
|
|
21
|
+
cids: getMultiSelectValues('#cids'),
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
// api.post prefixes /api automatically, so server route must be /admin/...
|
|
25
|
+
api.post('/admin/plugins/discord-onekite/save', payload).then(function () {
|
|
26
|
+
if (window.app && typeof app.alertSuccess === 'function') {
|
|
27
|
+
app.alertSuccess('Paramètres enregistrés !');
|
|
28
|
+
}
|
|
29
|
+
}).catch(function (err) {
|
|
30
|
+
// eslint-disable-next-line no-console
|
|
31
|
+
console.error(err);
|
|
32
|
+
if (window.app && typeof app.alertError === 'function') {
|
|
33
|
+
app.alertError('Erreur lors de l’enregistrement');
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
});
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
return ACP;
|
|
40
|
+
});
|
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
<div class="acp-page-container">
|
|
2
|
-
<
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
2
|
+
<div class="d-flex justify-content-between align-items-start mb-3">
|
|
3
|
+
<div>
|
|
4
|
+
<h4 class="mb-1">Discord Onekite</h4>
|
|
5
|
+
<p class="text-muted mb-0">Notifications Discord via webhook.</p>
|
|
6
|
+
</div>
|
|
7
|
+
<button id="save" class="btn btn-primary">
|
|
8
|
+
<i class="fa fa-save"></i> Enregistrer
|
|
9
|
+
</button>
|
|
10
|
+
</div>
|
|
11
11
|
|
|
12
|
+
<form role="form" class="discord-onekite-settings">
|
|
12
13
|
<div class="mb-3">
|
|
13
14
|
<label class="form-label" for="webhookUrl">Discord Webhook URL</label>
|
|
14
15
|
<input type="text" class="form-control" id="webhookUrl" name="webhookUrl" value="{settings.webhookUrl}" placeholder="https://discord.com/api/webhooks/..." />
|
|
@@ -32,7 +33,5 @@
|
|
|
32
33
|
Si aucune catégorie n’est sélectionnée : <strong>toutes les catégories</strong> seront notifiées.
|
|
33
34
|
</p>
|
|
34
35
|
</div>
|
|
35
|
-
|
|
36
|
-
<button type="submit" class="btn btn-primary"><i class="fa fa-save"></i> Enregistrer</button>
|
|
37
36
|
</form>
|
|
38
37
|
</div>
|