nodebb-plugin-discord-onekite 1.1.16 → 1.1.17
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 +7 -10
- package/library.js +0 -43
- package/package.json +1 -1
- package/static/lib/admin.js +9 -52
- package/templates/admin/plugins/discord-onekite.tpl +4 -7
package/README.md
CHANGED
|
@@ -1,12 +1,9 @@
|
|
|
1
|
-
# nodebb-plugin-discord-onekite v1.1.4.
|
|
1
|
+
# nodebb-plugin-discord-onekite v1.1.4.9
|
|
2
2
|
|
|
3
|
-
ACP
|
|
4
|
-
-
|
|
5
|
-
-
|
|
6
|
-
- GET /api/plugins/discord-onekite/settings
|
|
7
|
-
- POST /api/plugins/discord-onekite/settings
|
|
8
|
-
- Shows NodeBB toast on save
|
|
3
|
+
ACP uses official NodeBB approach (quickstart):
|
|
4
|
+
- `settings.sync()` + `settings.persist()`
|
|
5
|
+
- save button partial (bottom-right)
|
|
9
6
|
|
|
10
|
-
Discord:
|
|
11
|
-
-
|
|
12
|
-
-
|
|
7
|
+
Discord embed:
|
|
8
|
+
- clickable title (embed.url)
|
|
9
|
+
- description = message excerpt only
|
package/library.js
CHANGED
|
@@ -183,50 +183,7 @@ Plugin.init = async ({ router }) => {
|
|
|
183
183
|
controllers.renderAdminPage
|
|
184
184
|
);
|
|
185
185
|
|
|
186
|
-
// API routes for ACP (client calls /api/plugins/discord-onekite/settings)
|
|
187
|
-
routeHelpers.setupApiRoute(router, 'get', '/plugins/discord-onekite/settings', [middleware.admin.checkPrivileges], async (req, res) => {
|
|
188
|
-
const s = await meta.settings.get(SETTINGS_KEY);
|
|
189
|
-
res.json({
|
|
190
|
-
settings: {
|
|
191
|
-
webhookUrl: (s && s.webhookUrl) ? String(s.webhookUrl).trim() : '',
|
|
192
|
-
notifyReplies: !!(s && (s.notifyReplies === true || s.notifyReplies === 'on' || s.notifyReplies === 'true')),
|
|
193
|
-
cids: (() => {
|
|
194
|
-
const v = s && s.cids;
|
|
195
|
-
if (!v) return [];
|
|
196
|
-
if (Array.isArray(v)) return v.map(String).filter(Boolean);
|
|
197
|
-
if (typeof v === 'string') return v.split(',').map(x => x.trim()).filter(Boolean);
|
|
198
|
-
return [];
|
|
199
|
-
})(),
|
|
200
|
-
},
|
|
201
|
-
});
|
|
202
|
-
});
|
|
203
|
-
|
|
204
|
-
routeHelpers.setupApiRoute(router, 'post', '/plugins/discord-onekite/settings', [middleware.admin.checkPrivileges], async (req, res) => {
|
|
205
|
-
try {
|
|
206
|
-
const payload = {
|
|
207
|
-
webhookUrl: req.body.webhookUrl || '',
|
|
208
|
-
notifyReplies: req.body.notifyReplies ? 'on' : '',
|
|
209
|
-
cids: req.body.cids || '',
|
|
210
|
-
};
|
|
211
|
-
await meta.settings.set(SETTINGS_KEY, payload);
|
|
212
|
-
res.json({ ok: true });
|
|
213
|
-
} catch (e) {
|
|
214
|
-
console.error('[discord-onekite] save failed', e);
|
|
215
|
-
res.status(500).json({ ok: false });
|
|
216
|
-
}
|
|
217
|
-
});
|
|
218
|
-
|
|
219
186
|
// AJAX save endpoint for ACP (used by admin.js)
|
|
220
|
-
router.post('/api/admin/plugins/discord-onekite/save',
|
|
221
|
-
middleware.admin.checkPrivileges,
|
|
222
|
-
async (req, res) => {
|
|
223
|
-
try {
|
|
224
|
-
const payload = {
|
|
225
|
-
webhookUrl: req.body.webhookUrl || '',
|
|
226
|
-
notifyReplies: req.body.notifyReplies ? 'on' : '',
|
|
227
|
-
cids: req.body.cids || '',
|
|
228
|
-
};
|
|
229
|
-
await meta.settings.set(SETTINGS_KEY, payload);
|
|
230
187
|
res.json({ ok: true });
|
|
231
188
|
} catch (e) {
|
|
232
189
|
console.error('[discord-onekite] save failed', e);
|
package/package.json
CHANGED
package/static/lib/admin.js
CHANGED
|
@@ -1,65 +1,22 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
/* global $, app */
|
|
3
3
|
|
|
4
|
-
define('admin/plugins/discord-onekite', ['
|
|
4
|
+
define('admin/plugins/discord-onekite', ['settings'], function (settings) {
|
|
5
5
|
const ACP = {};
|
|
6
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
|
-
function setMultiSelectValues(selector, values) {
|
|
14
|
-
const el = document.querySelector(selector);
|
|
15
|
-
if (!el) return;
|
|
16
|
-
const set = new Set((values || []).map(String));
|
|
17
|
-
Array.from(el.options).forEach(opt => { opt.selected = set.has(String(opt.value)); });
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
async function loadSettings() {
|
|
21
|
-
try {
|
|
22
|
-
const res = await api.get('/plugins/discord-onekite/settings');
|
|
23
|
-
if (res && res.settings) {
|
|
24
|
-
$('#webhookUrl').val(res.settings.webhookUrl || '');
|
|
25
|
-
$('#notifyReplies').prop('checked', !!res.settings.notifyReplies);
|
|
26
|
-
setMultiSelectValues('#cids', res.settings.cids || []);
|
|
27
|
-
}
|
|
28
|
-
} catch (err) {
|
|
29
|
-
// eslint-disable-next-line no-console
|
|
30
|
-
console.error(err);
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
async function saveSettings() {
|
|
35
|
-
const payload = {
|
|
36
|
-
webhookUrl: String($('#webhookUrl').val() || '').trim(),
|
|
37
|
-
notifyReplies: $('#notifyReplies').is(':checked'),
|
|
38
|
-
cids: getMultiSelectValues('#cids'),
|
|
39
|
-
};
|
|
40
|
-
|
|
41
|
-
try {
|
|
42
|
-
await api.post('/plugins/discord-onekite/settings', payload);
|
|
43
|
-
if (window.app && typeof app.alertSuccess === 'function') {
|
|
44
|
-
app.alertSuccess('Paramètres enregistrés !');
|
|
45
|
-
}
|
|
46
|
-
} catch (err) {
|
|
47
|
-
// eslint-disable-next-line no-console
|
|
48
|
-
console.error(err);
|
|
49
|
-
if (window.app && typeof app.alertError === 'function') {
|
|
50
|
-
app.alertError('Erreur lors de l’enregistrement');
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
|
|
55
7
|
ACP.init = function () {
|
|
56
|
-
|
|
8
|
+
const $form = $('.discord-onekite-settings');
|
|
9
|
+
if (!$form.length) return;
|
|
57
10
|
|
|
58
|
-
|
|
11
|
+
settings.sync('discord-onekite', $form);
|
|
59
12
|
|
|
60
13
|
$('#save').off('click.discordOnekite').on('click.discordOnekite', function (e) {
|
|
61
14
|
e.preventDefault();
|
|
62
|
-
|
|
15
|
+
settings.persist('discord-onekite', $form, function () {
|
|
16
|
+
if (window.app && typeof app.alertSuccess === 'function') {
|
|
17
|
+
app.alertSuccess('Paramètres enregistrés !');
|
|
18
|
+
}
|
|
19
|
+
});
|
|
63
20
|
});
|
|
64
21
|
};
|
|
65
22
|
|
|
@@ -1,11 +1,6 @@
|
|
|
1
1
|
<div class="acp-page-container">
|
|
2
|
-
<
|
|
3
|
-
|
|
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" type="button" class="btn btn-primary">Enregistrer les paramètres</button>
|
|
8
|
-
</div>
|
|
2
|
+
<h4>Discord Onekite</h4>
|
|
3
|
+
<p class="text-muted">Notifications Discord via webhook.</p>
|
|
9
4
|
|
|
10
5
|
<form role="form" class="discord-onekite-settings">
|
|
11
6
|
<div class="mb-3">
|
|
@@ -31,5 +26,7 @@
|
|
|
31
26
|
Si aucune catégorie n’est sélectionnée : <strong>toutes les catégories</strong> seront notifiées.
|
|
32
27
|
</p>
|
|
33
28
|
</div>
|
|
29
|
+
|
|
30
|
+
<!-- IMPORT admin/partials/save_button.tpl -->
|
|
34
31
|
</form>
|
|
35
32
|
</div>
|