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.3
1
+ # nodebb-plugin-discord-onekite (NodeBB v4.x) — v1.0.4
2
2
 
3
- This version aligns more closely with the official Quickstart pattern:
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
- If you still don't see that log, NodeBB isn't loading the module, so we can narrow it down quickly.
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nodebb-plugin-discord-onekite",
3
- "version": "1.0.4",
3
+ "version": "1.0.5",
4
4
  "description": "Discord webhook notifier for Onekite (NodeBB v4.x only)",
5
5
  "main": "library.js",
6
6
  "license": "MIT",
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": "static/templates",
13
- "modules": {
14
- "../admin/plugins/discord-onekite.js": "static/lib/admin.js"
15
- }
12
+ "templates": "templates",
13
+ "acpScripts": ["static/lib/admin.js"]
16
14
  }
@@ -1,70 +1,67 @@
1
1
  'use strict';
2
2
  /* global $, app, ajaxify */
3
3
 
4
- define('admin/plugins/discord-onekite', ['settings', 'api'], function (settings, api) {
5
- const ACP = {};
4
+ (function () {
5
+ function initOnekiteACP() {
6
+ if (!ajaxify || !ajaxify.data || ajaxify.data.template !== 'admin/plugins/discord-onekite') {
7
+ return;
8
+ }
6
9
 
7
- function normalizeCids(v) {
8
- if (!v) return [];
9
- if (Array.isArray(v)) return v.map(String).filter(Boolean);
10
- if (typeof v === 'string') return v.split(',').map(s => s.trim()).filter(Boolean);
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
- async function fetchCategories() {
15
- // In NodeBB, api.get('/categories') => GET /api/categories
16
- const res = await api.get('/categories');
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
- ACP.init = async function () {
21
- // This should be called automatically by NodeBB when template admin/plugins/discord-onekite is loaded.
22
- // Also safe to call multiple times.
23
- console.log('[discord-onekite] admin init');
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
- const $form = $('.discord-onekite-settings');
26
- if (!$form.length) return;
26
+ // Load saved settings into the form
27
+ settings.load('discord-onekite', $form);
27
28
 
28
- // Load current settings
29
- const saved = await new Promise((resolve) => {
30
- settings.get('discord-onekite', (data) => resolve(data || {}));
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
- settings.load('discord-onekite', $form);
34
- const savedCids = normalizeCids(saved.cids);
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
- // Populate categories select
37
- const $select = $('#cids');
38
- try {
39
- const categories = await fetchCategories();
40
- $select.empty();
41
- categories
42
- .filter(c => c && typeof c.cid !== 'undefined' && c.name)
43
- .forEach(c => {
44
- const cid = String(c.cid);
45
- const $opt = $('<option />').val(cid).text(c.name);
46
- if (savedCids.includes(cid)) $opt.prop('selected', true);
47
- $opt.appendTo($select);
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
- } catch (e) {
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
- // Save
55
- $('#save').off('click.discordOnekite').on('click.discordOnekite', function () {
56
- settings.save('discord-onekite', $form, function () {
57
- if (app && app.alertSuccess) app.alertSuccess('Paramètres enregistrés !');
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
- return ACP;
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
- Envoie une notification dans Discord via webhook, avec filtres par catégories.
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 -->