nodebb-plugin-discord-onekite 1.0.4 → 1.0.5
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
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
# nodebb-plugin-discord-onekite (NodeBB v4.x) — v1.0.
|
|
1
|
+
# nodebb-plugin-discord-onekite (NodeBB v4.x) — v1.0.4
|
|
2
2
|
|
|
3
|
-
This version
|
|
4
|
-
- uses `modules` mapping (no leading ./) to expose `admin/plugins/discord-onekite`
|
|
5
|
-
- template has no inline script
|
|
6
|
-
- admin.js logs `[discord-onekite] admin init` when loaded
|
|
3
|
+
This version follows the most compatible ACP pattern used by many official/community plugins:
|
|
7
4
|
|
|
8
|
-
|
|
5
|
+
- Templates are in `templates/` (not `static/templates/`)
|
|
6
|
+
- ACP script is loaded via `acpScripts` and runs globally on `action:ajaxify.end`
|
|
7
|
+
- No reliance on `modules` name matching
|
package/package.json
CHANGED
package/plugin.json
CHANGED
|
@@ -2,15 +2,13 @@
|
|
|
2
2
|
"id": "nodebb-plugin-discord-onekite",
|
|
3
3
|
"name": "Discord Onekite Notifier",
|
|
4
4
|
"description": "Notifie Discord via webhook pour nouveaux sujets et/ou réponses, filtrable par catégories (NodeBB v4.x uniquement).",
|
|
5
|
-
"library": "library.js",
|
|
5
|
+
"library": "./library.js",
|
|
6
6
|
"hooks": [
|
|
7
7
|
{ "hook": "static:app.load", "method": "init" },
|
|
8
8
|
{ "hook": "filter:admin.header.build", "method": "addAdminNavigation" },
|
|
9
9
|
{ "hook": "action:topic.save", "method": "onTopicSave" },
|
|
10
10
|
{ "hook": "action:post.save", "method": "onPostSave" }
|
|
11
11
|
],
|
|
12
|
-
"templates": "
|
|
13
|
-
"
|
|
14
|
-
"../admin/plugins/discord-onekite.js": "static/lib/admin.js"
|
|
15
|
-
}
|
|
12
|
+
"templates": "templates",
|
|
13
|
+
"acpScripts": ["static/lib/admin.js"]
|
|
16
14
|
}
|
package/static/lib/admin.js
CHANGED
|
@@ -1,70 +1,67 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
/* global $, app, ajaxify */
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
(function () {
|
|
5
|
+
function initOnekiteACP() {
|
|
6
|
+
if (!ajaxify || !ajaxify.data || ajaxify.data.template !== 'admin/plugins/discord-onekite') {
|
|
7
|
+
return;
|
|
8
|
+
}
|
|
6
9
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
return [];
|
|
12
|
-
}
|
|
10
|
+
// Use NodeBB's AMD loader to access core helpers
|
|
11
|
+
require(['settings', 'api'], function (settings, api) {
|
|
12
|
+
const $form = $('.discord-onekite-settings');
|
|
13
|
+
if (!$form.length) return;
|
|
13
14
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
return (res && res.categories) ? res.categories : [];
|
|
18
|
-
}
|
|
15
|
+
// Avoid double-binding
|
|
16
|
+
if ($form.data('onekite-initialized')) return;
|
|
17
|
+
$form.data('onekite-initialized', true);
|
|
19
18
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
19
|
+
function normalizeCids(v) {
|
|
20
|
+
if (!v) return [];
|
|
21
|
+
if (Array.isArray(v)) return v.map(String).filter(Boolean);
|
|
22
|
+
if (typeof v === 'string') return v.split(',').map(s => s.trim()).filter(Boolean);
|
|
23
|
+
return [];
|
|
24
|
+
}
|
|
24
25
|
|
|
25
|
-
|
|
26
|
-
|
|
26
|
+
// Load saved settings into the form
|
|
27
|
+
settings.load('discord-onekite', $form);
|
|
27
28
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
29
|
+
// Get raw settings so we can pre-select categories
|
|
30
|
+
settings.get('discord-onekite', function (saved) {
|
|
31
|
+
saved = saved || {};
|
|
32
|
+
const savedCids = normalizeCids(saved.cids);
|
|
32
33
|
|
|
33
|
-
|
|
34
|
-
|
|
34
|
+
// Load categories (admin should have access)
|
|
35
|
+
api.get('/categories').then(function (res) {
|
|
36
|
+
const categories = (res && res.categories) ? res.categories : [];
|
|
37
|
+
const $select = $('#cids');
|
|
38
|
+
$select.empty();
|
|
35
39
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
40
|
+
categories
|
|
41
|
+
.filter(c => c && typeof c.cid !== 'undefined' && c.name)
|
|
42
|
+
.forEach(c => {
|
|
43
|
+
const cid = String(c.cid);
|
|
44
|
+
const $opt = $('<option/>').val(cid).text(c.name);
|
|
45
|
+
if (savedCids.includes(cid)) $opt.prop('selected', true);
|
|
46
|
+
$opt.appendTo($select);
|
|
47
|
+
});
|
|
48
|
+
}).catch(function (e) {
|
|
49
|
+
// eslint-disable-next-line no-console
|
|
50
|
+
console.error('[discord-onekite] GET /api/categories failed', e);
|
|
51
|
+
if (app && app.alertError) app.alertError('Impossible de charger les catégories (GET /api/categories).');
|
|
48
52
|
});
|
|
49
|
-
|
|
50
|
-
console.error('[discord-onekite] failed to fetch categories', e);
|
|
51
|
-
if (app && app.alertError) app.alertError('Impossible de charger la liste des catégories (GET /api/categories).');
|
|
52
|
-
}
|
|
53
|
+
});
|
|
53
54
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
55
|
+
// Save
|
|
56
|
+
$('#save').off('click.discordOnekite').on('click.discordOnekite', function () {
|
|
57
|
+
settings.save('discord-onekite', $form, function () {
|
|
58
|
+
if (app && app.alertSuccess) app.alertSuccess('Paramètres enregistrés !');
|
|
59
|
+
});
|
|
58
60
|
});
|
|
59
61
|
});
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
// Fallback for ajaxified ACP navigation
|
|
63
|
-
$(window).off('action:ajaxify.end.discordOnekite').on('action:ajaxify.end.discordOnekite', function (ev, data) {
|
|
64
|
-
if (data && data.template === 'admin/plugins/discord-onekite') {
|
|
65
|
-
ACP.init();
|
|
66
|
-
}
|
|
67
|
-
});
|
|
62
|
+
}
|
|
68
63
|
|
|
69
|
-
|
|
70
|
-
|
|
64
|
+
// Run on initial load and after ajax navigation in ACP
|
|
65
|
+
$(window).on('action:ajaxify.end', initOnekiteACP);
|
|
66
|
+
$(initOnekiteACP);
|
|
67
|
+
})();
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
<div class="acp-page-container">
|
|
2
2
|
<h4>Discord Onekite</h4>
|
|
3
3
|
<p class="text-muted">
|
|
4
|
-
|
|
4
|
+
Notifications Discord via webhook.
|
|
5
5
|
</p>
|
|
6
6
|
|
|
7
7
|
<form role="form" class="discord-onekite-settings">
|
|
@@ -23,9 +23,6 @@
|
|
|
23
23
|
<p class="form-text text-muted">
|
|
24
24
|
Si aucune catégorie n’est sélectionnée : <strong>toutes les catégories</strong> seront notifiées.
|
|
25
25
|
</p>
|
|
26
|
-
<p class="form-text">
|
|
27
|
-
<em>Astuce debug :</em> ouvre la console navigateur, tu dois voir <code>[discord-onekite] admin init</code>.
|
|
28
|
-
</p>
|
|
29
26
|
</div>
|
|
30
27
|
|
|
31
28
|
<!-- IMPORT admin/partials/save_button.tpl -->
|