nodebb-plugin-discord-onekite 1.0.2 → 1.0.4
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 +6 -5
- package/library.js +2 -9
- package/package.json +1 -1
- package/plugin.json +4 -2
- package/static/lib/admin.js +32 -29
- package/static/templates/admin/plugins/discord-onekite.tpl +3 -3
package/README.md
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
# nodebb-plugin-discord-onekite (NodeBB v4.x) — v1.0.
|
|
1
|
+
# nodebb-plugin-discord-onekite (NodeBB v4.x) — v1.0.3
|
|
2
2
|
|
|
3
|
-
|
|
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
|
|
4
7
|
|
|
5
|
-
|
|
6
|
-
- Settings save works
|
|
7
|
-
- No categories selected => notify all
|
|
8
|
+
If you still don't see that log, NodeBB isn't loading the module, so we can narrow it down quickly.
|
package/library.js
CHANGED
|
@@ -15,9 +15,7 @@ const SETTINGS_KEY = 'discord-onekite';
|
|
|
15
15
|
function normalizeCids(value) {
|
|
16
16
|
if (!value) return [];
|
|
17
17
|
if (Array.isArray(value)) return value.map(v => String(v)).filter(Boolean);
|
|
18
|
-
if (typeof value === 'string')
|
|
19
|
-
return value.split(',').map(s => s.trim()).filter(Boolean);
|
|
20
|
-
}
|
|
18
|
+
if (typeof value === 'string') return value.split(',').map(s => s.trim()).filter(Boolean);
|
|
21
19
|
return [];
|
|
22
20
|
}
|
|
23
21
|
|
|
@@ -31,7 +29,6 @@ async function getSettings() {
|
|
|
31
29
|
}
|
|
32
30
|
|
|
33
31
|
function cidAllowed(topicCid, allowedCids) {
|
|
34
|
-
// none selected => ALL
|
|
35
32
|
if (!allowedCids || allowedCids.length === 0) return true;
|
|
36
33
|
return allowedCids.includes(String(topicCid));
|
|
37
34
|
}
|
|
@@ -69,9 +66,7 @@ async function buildTopicEmbed({ tid, pid, type }) {
|
|
|
69
66
|
footer: { text: 'NodeBB → Discord (Onekite)' },
|
|
70
67
|
};
|
|
71
68
|
|
|
72
|
-
if (isReply)
|
|
73
|
-
embed.description = 'Nouvelle réponse dans un sujet.';
|
|
74
|
-
}
|
|
69
|
+
if (isReply) embed.description = 'Nouvelle réponse dans un sujet.';
|
|
75
70
|
|
|
76
71
|
return { topicData, embed };
|
|
77
72
|
}
|
|
@@ -118,7 +113,6 @@ Plugin.onTopicSave = async (data) => {
|
|
|
118
113
|
|
|
119
114
|
await postToDiscord(settings.webhookUrl, { embeds: [built.embed] });
|
|
120
115
|
} catch (err) {
|
|
121
|
-
// eslint-disable-next-line no-console
|
|
122
116
|
console.error(err);
|
|
123
117
|
}
|
|
124
118
|
};
|
|
@@ -144,7 +138,6 @@ Plugin.onPostSave = async (data) => {
|
|
|
144
138
|
|
|
145
139
|
await postToDiscord(settings.webhookUrl, { embeds: [built.embed] });
|
|
146
140
|
} catch (err) {
|
|
147
|
-
// eslint-disable-next-line no-console
|
|
148
141
|
console.error(err);
|
|
149
142
|
}
|
|
150
143
|
};
|
package/package.json
CHANGED
package/plugin.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
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": "
|
|
5
|
+
"library": "library.js",
|
|
6
6
|
"hooks": [
|
|
7
7
|
{ "hook": "static:app.load", "method": "init" },
|
|
8
8
|
{ "hook": "filter:admin.header.build", "method": "addAdminNavigation" },
|
|
@@ -10,5 +10,7 @@
|
|
|
10
10
|
{ "hook": "action:post.save", "method": "onPostSave" }
|
|
11
11
|
],
|
|
12
12
|
"templates": "static/templates",
|
|
13
|
-
"
|
|
13
|
+
"modules": {
|
|
14
|
+
"../admin/plugins/discord-onekite.js": "static/lib/admin.js"
|
|
15
|
+
}
|
|
14
16
|
}
|
package/static/lib/admin.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
'use strict';
|
|
2
|
-
/* global $, app */
|
|
2
|
+
/* global $, app, ajaxify */
|
|
3
3
|
|
|
4
4
|
define('admin/plugins/discord-onekite', ['settings', 'api'], function (settings, api) {
|
|
5
5
|
const ACP = {};
|
|
@@ -7,61 +7,64 @@ define('admin/plugins/discord-onekite', ['settings', 'api'], function (settings,
|
|
|
7
7
|
function normalizeCids(v) {
|
|
8
8
|
if (!v) return [];
|
|
9
9
|
if (Array.isArray(v)) return v.map(String).filter(Boolean);
|
|
10
|
-
if (typeof v === 'string')
|
|
11
|
-
return v.split(',').map(s => s.trim()).filter(Boolean);
|
|
12
|
-
}
|
|
10
|
+
if (typeof v === 'string') return v.split(',').map(s => s.trim()).filter(Boolean);
|
|
13
11
|
return [];
|
|
14
12
|
}
|
|
15
13
|
|
|
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
|
+
}
|
|
19
|
+
|
|
16
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');
|
|
24
|
+
|
|
17
25
|
const $form = $('.discord-onekite-settings');
|
|
18
|
-
|
|
26
|
+
if (!$form.length) return;
|
|
19
27
|
|
|
20
|
-
// Load current
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
saved = await new Promise((resolve) => {
|
|
25
|
-
settings.get('discord-onekite', (data) => resolve(data || {}));
|
|
26
|
-
});
|
|
27
|
-
} catch (e) {
|
|
28
|
-
saved = {};
|
|
29
|
-
}
|
|
28
|
+
// Load current settings
|
|
29
|
+
const saved = await new Promise((resolve) => {
|
|
30
|
+
settings.get('discord-onekite', (data) => resolve(data || {}));
|
|
31
|
+
});
|
|
30
32
|
|
|
31
|
-
// Populate simple fields (webhookUrl, notifyReplies, etc.)
|
|
32
33
|
settings.load('discord-onekite', $form);
|
|
33
|
-
|
|
34
34
|
const savedCids = normalizeCids(saved.cids);
|
|
35
35
|
|
|
36
|
-
//
|
|
36
|
+
// Populate categories select
|
|
37
|
+
const $select = $('#cids');
|
|
37
38
|
try {
|
|
38
|
-
const
|
|
39
|
-
const categories = (res && res.categories) ? res.categories : [];
|
|
40
|
-
|
|
39
|
+
const categories = await fetchCategories();
|
|
41
40
|
$select.empty();
|
|
42
41
|
categories
|
|
43
42
|
.filter(c => c && typeof c.cid !== 'undefined' && c.name)
|
|
44
43
|
.forEach(c => {
|
|
45
44
|
const cid = String(c.cid);
|
|
46
45
|
const $opt = $('<option />').val(cid).text(c.name);
|
|
47
|
-
if (savedCids.includes(cid))
|
|
48
|
-
$opt.prop('selected', true);
|
|
49
|
-
}
|
|
46
|
+
if (savedCids.includes(cid)) $opt.prop('selected', true);
|
|
50
47
|
$opt.appendTo($select);
|
|
51
48
|
});
|
|
52
49
|
} catch (e) {
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
app.alertError('Impossible de charger la liste des catégories.');
|
|
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).');
|
|
56
52
|
}
|
|
57
53
|
|
|
58
|
-
// Save
|
|
54
|
+
// Save
|
|
59
55
|
$('#save').off('click.discordOnekite').on('click.discordOnekite', function () {
|
|
60
56
|
settings.save('discord-onekite', $form, function () {
|
|
61
|
-
app.alertSuccess('Paramètres enregistrés !');
|
|
57
|
+
if (app && app.alertSuccess) app.alertSuccess('Paramètres enregistrés !');
|
|
62
58
|
});
|
|
63
59
|
});
|
|
64
60
|
};
|
|
65
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
|
+
});
|
|
68
|
+
|
|
66
69
|
return ACP;
|
|
67
70
|
});
|
|
@@ -8,9 +8,6 @@
|
|
|
8
8
|
<div class="mb-3">
|
|
9
9
|
<label class="form-label" for="webhookUrl">Discord Webhook URL</label>
|
|
10
10
|
<input type="text" class="form-control" id="webhookUrl" name="webhookUrl" placeholder="https://discord.com/api/webhooks/..." />
|
|
11
|
-
<p class="form-text text-muted">
|
|
12
|
-
Discord → Salon #notifications → Intégrations → Webhooks → Copier l’URL.
|
|
13
|
-
</p>
|
|
14
11
|
</div>
|
|
15
12
|
|
|
16
13
|
<div class="form-check mb-3">
|
|
@@ -26,6 +23,9 @@
|
|
|
26
23
|
<p class="form-text text-muted">
|
|
27
24
|
Si aucune catégorie n’est sélectionnée : <strong>toutes les catégories</strong> seront notifiées.
|
|
28
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
29
|
</div>
|
|
30
30
|
|
|
31
31
|
<!-- IMPORT admin/partials/save_button.tpl -->
|