nodebb-plugin-discord-onekite 1.1.7 → 1.1.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/README.md +4 -9
- package/lib/controllers.js +1 -0
- package/library.js +2 -6
- package/package.json +1 -1
- package/plugin.json +1 -4
- package/templates/admin/plugins/discord-onekite.tpl +9 -5
- package/static/lib/admin.js +0 -40
package/README.md
CHANGED
|
@@ -1,10 +1,5 @@
|
|
|
1
|
-
# nodebb-plugin-discord-onekite v1.1.
|
|
1
|
+
# nodebb-plugin-discord-onekite v1.1.8
|
|
2
2
|
|
|
3
|
-
This
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
- Standard NodeBB save disk button
|
|
7
|
-
- AJAX save endpoint + NodeBB toast
|
|
8
|
-
|
|
9
|
-
Discord:
|
|
10
|
-
- Single clickable line "Nouveau sujet : [Titre](URL)" then excerpt below
|
|
3
|
+
This variant avoids RequireJS admin modules (no `modules` / no AMD) to prevent requirejs build failures.
|
|
4
|
+
ACP saves with a normal POST + redirect and shows a success banner.
|
|
5
|
+
Discord notifications unchanged.
|
package/lib/controllers.js
CHANGED
|
@@ -40,6 +40,7 @@ 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'),
|
|
43
44
|
});
|
|
44
45
|
};
|
|
45
46
|
|
package/library.js
CHANGED
|
@@ -94,7 +94,6 @@ 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.
|
|
98
97
|
if (e && e.statusCode === 400 && payload && payload.content) {
|
|
99
98
|
try {
|
|
100
99
|
await postToDiscord(webhookUrl, { content: payload.content });
|
|
@@ -130,14 +129,13 @@ async function buildPayload({ tid, pid, isReply }) {
|
|
|
130
129
|
const title = (topicData.title || (isReply ? 'Nouvelle réponse' : 'Nouveau sujet')).toString().slice(0, 256);
|
|
131
130
|
const excerpt = await getPostExcerpt(isReply ? pid : topicData.mainPid);
|
|
132
131
|
|
|
133
|
-
// Single clickable link line + excerpt below
|
|
134
132
|
const linkLine = isReply
|
|
135
133
|
? `🗨️ Nouvelle réponse : [${title}](${targetUrl})`
|
|
136
134
|
: `🆕 Nouveau sujet : [${title}](${topicUrl})`;
|
|
137
135
|
|
|
138
136
|
const content = [linkLine, excerpt].filter(Boolean).join('\n');
|
|
139
137
|
|
|
140
|
-
const embed = { title, description: excerpt || ''
|
|
138
|
+
const embed = { title, description: excerpt || '', url: targetUrl };
|
|
141
139
|
|
|
142
140
|
return { topicData, content, embed };
|
|
143
141
|
}
|
|
@@ -158,7 +156,6 @@ Plugin.init = async ({ router }) => {
|
|
|
158
156
|
controllers.renderAdminPage
|
|
159
157
|
);
|
|
160
158
|
|
|
161
|
-
// AJAX save endpoint (used by admin.js via api.post)
|
|
162
159
|
router.post('/admin/plugins/discord-onekite/save',
|
|
163
160
|
middleware.admin.checkPrivileges,
|
|
164
161
|
async (req, res) => {
|
|
@@ -169,11 +166,10 @@ Plugin.init = async ({ router }) => {
|
|
|
169
166
|
cids: req.body.cids || '',
|
|
170
167
|
};
|
|
171
168
|
await meta.settings.set(SETTINGS_KEY, payload);
|
|
172
|
-
res.json({ ok: true });
|
|
173
169
|
} catch (e) {
|
|
174
170
|
console.error('[discord-onekite] save failed', e);
|
|
175
|
-
res.status(500).json({ ok: false });
|
|
176
171
|
}
|
|
172
|
+
res.redirect('/admin/plugins/discord-onekite?saved=1');
|
|
177
173
|
}
|
|
178
174
|
);
|
|
179
175
|
};
|
package/package.json
CHANGED
package/plugin.json
CHANGED
|
@@ -1,10 +1,14 @@
|
|
|
1
1
|
<div class="acp-page-container">
|
|
2
2
|
<h4>Discord Onekite</h4>
|
|
3
|
-
<p class="text-muted">
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
<p class="text-muted">Notifications Discord via webhook.</p>
|
|
4
|
+
|
|
5
|
+
<!-- IF saved -->
|
|
6
|
+
<div class="alert alert-success" role="alert">Paramètres enregistrés !</div>
|
|
7
|
+
<!-- ENDIF saved -->
|
|
8
|
+
|
|
9
|
+
<form role="form" method="post" action="/admin/plugins/discord-onekite/save">
|
|
10
|
+
<input type="hidden" name="_csrf" value="{config.csrf_token}" />
|
|
6
11
|
|
|
7
|
-
<form role="form" class="discord-onekite-settings">
|
|
8
12
|
<div class="mb-3">
|
|
9
13
|
<label class="form-label" for="webhookUrl">Discord Webhook URL</label>
|
|
10
14
|
<input type="text" class="form-control" id="webhookUrl" name="webhookUrl" value="{settings.webhookUrl}" placeholder="https://discord.com/api/webhooks/..." />
|
|
@@ -29,6 +33,6 @@
|
|
|
29
33
|
</p>
|
|
30
34
|
</div>
|
|
31
35
|
|
|
32
|
-
|
|
36
|
+
<button type="submit" class="btn btn-primary"><i class="fa fa-save"></i> Enregistrer</button>
|
|
33
37
|
</form>
|
|
34
38
|
</div>
|
package/static/lib/admin.js
DELETED
|
@@ -1,40 +0,0 @@
|
|
|
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
|
-
});
|