nodebb-plugin-discord-onekite 1.0.1 → 1.0.2
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 -4
- package/library.js +3 -1
- package/package.json +1 -1
- package/plugin.json +2 -1
- package/static/lib/admin.js +67 -0
- package/static/templates/admin/plugins/discord-onekite.tpl +0 -57
package/README.md
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
# nodebb-plugin-discord-onekite (NodeBB v4.x) — v1.0.
|
|
1
|
+
# nodebb-plugin-discord-onekite (NodeBB v4.x) — v1.0.1
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
-
|
|
3
|
+
Fix: template build errors by removing inline <script> from the .tpl and using acpScripts properly.
|
|
4
|
+
|
|
5
|
+
- Categories list loads in ACP
|
|
6
|
+
- Settings save works
|
|
7
|
+
- No categories selected => notify all
|
package/library.js
CHANGED
|
@@ -31,7 +31,7 @@ async function getSettings() {
|
|
|
31
31
|
}
|
|
32
32
|
|
|
33
33
|
function cidAllowed(topicCid, allowedCids) {
|
|
34
|
-
//
|
|
34
|
+
// none selected => ALL
|
|
35
35
|
if (!allowedCids || allowedCids.length === 0) return true;
|
|
36
36
|
return allowedCids.includes(String(topicCid));
|
|
37
37
|
}
|
|
@@ -118,6 +118,7 @@ Plugin.onTopicSave = async (data) => {
|
|
|
118
118
|
|
|
119
119
|
await postToDiscord(settings.webhookUrl, { embeds: [built.embed] });
|
|
120
120
|
} catch (err) {
|
|
121
|
+
// eslint-disable-next-line no-console
|
|
121
122
|
console.error(err);
|
|
122
123
|
}
|
|
123
124
|
};
|
|
@@ -143,6 +144,7 @@ Plugin.onPostSave = async (data) => {
|
|
|
143
144
|
|
|
144
145
|
await postToDiscord(settings.webhookUrl, { embeds: [built.embed] });
|
|
145
146
|
} catch (err) {
|
|
147
|
+
// eslint-disable-next-line no-console
|
|
146
148
|
console.error(err);
|
|
147
149
|
}
|
|
148
150
|
};
|
package/package.json
CHANGED
package/plugin.json
CHANGED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
/* global $, app */
|
|
3
|
+
|
|
4
|
+
define('admin/plugins/discord-onekite', ['settings', 'api'], function (settings, api) {
|
|
5
|
+
const ACP = {};
|
|
6
|
+
|
|
7
|
+
function normalizeCids(v) {
|
|
8
|
+
if (!v) return [];
|
|
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
|
+
}
|
|
13
|
+
return [];
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
ACP.init = async function () {
|
|
17
|
+
const $form = $('.discord-onekite-settings');
|
|
18
|
+
const $select = $('#cids');
|
|
19
|
+
|
|
20
|
+
// Load current saved settings (including cids) BEFORE fetching categories,
|
|
21
|
+
// so we can apply selection after options are created.
|
|
22
|
+
let saved = {};
|
|
23
|
+
try {
|
|
24
|
+
saved = await new Promise((resolve) => {
|
|
25
|
+
settings.get('discord-onekite', (data) => resolve(data || {}));
|
|
26
|
+
});
|
|
27
|
+
} catch (e) {
|
|
28
|
+
saved = {};
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
// Populate simple fields (webhookUrl, notifyReplies, etc.)
|
|
32
|
+
settings.load('discord-onekite', $form);
|
|
33
|
+
|
|
34
|
+
const savedCids = normalizeCids(saved.cids);
|
|
35
|
+
|
|
36
|
+
// Fetch categories list and populate select
|
|
37
|
+
try {
|
|
38
|
+
const res = await api.get('/categories');
|
|
39
|
+
const categories = (res && res.categories) ? res.categories : [];
|
|
40
|
+
|
|
41
|
+
$select.empty();
|
|
42
|
+
categories
|
|
43
|
+
.filter(c => c && typeof c.cid !== 'undefined' && c.name)
|
|
44
|
+
.forEach(c => {
|
|
45
|
+
const cid = String(c.cid);
|
|
46
|
+
const $opt = $('<option />').val(cid).text(c.name);
|
|
47
|
+
if (savedCids.includes(cid)) {
|
|
48
|
+
$opt.prop('selected', true);
|
|
49
|
+
}
|
|
50
|
+
$opt.appendTo($select);
|
|
51
|
+
});
|
|
52
|
+
} catch (e) {
|
|
53
|
+
// eslint-disable-next-line no-console
|
|
54
|
+
console.error('[discord-onekite] Could not load categories', e);
|
|
55
|
+
app.alertError('Impossible de charger la liste des catégories.');
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
// Save button
|
|
59
|
+
$('#save').off('click.discordOnekite').on('click.discordOnekite', function () {
|
|
60
|
+
settings.save('discord-onekite', $form, function () {
|
|
61
|
+
app.alertSuccess('Paramètres enregistrés !');
|
|
62
|
+
});
|
|
63
|
+
});
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
return ACP;
|
|
67
|
+
});
|
|
@@ -31,60 +31,3 @@
|
|
|
31
31
|
<!-- IMPORT admin/partials/save_button.tpl -->
|
|
32
32
|
</form>
|
|
33
33
|
</div>
|
|
34
|
-
|
|
35
|
-
<script>
|
|
36
|
-
require(['settings', 'api'], function (settings, api) {
|
|
37
|
-
var $form = $('.discord-onekite-settings');
|
|
38
|
-
var $select = $('#cids');
|
|
39
|
-
|
|
40
|
-
function normalizeCids(v) {
|
|
41
|
-
if (!v) { return []; }
|
|
42
|
-
if (Array.isArray(v)) { return v.map(String); }
|
|
43
|
-
if (typeof v === 'string') {
|
|
44
|
-
return v.split(',').map(function (s) { return s.trim(); }).filter(Boolean);
|
|
45
|
-
}
|
|
46
|
-
return [];
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
// 1) Load saved settings (fills webhookUrl + checkbox; we also keep cids for later)
|
|
50
|
-
settings.get('discord-onekite', function (saved) {
|
|
51
|
-
saved = saved || {};
|
|
52
|
-
// Populate simple fields now
|
|
53
|
-
settings.load('discord-onekite', $form);
|
|
54
|
-
|
|
55
|
-
var savedCids = normalizeCids(saved.cids);
|
|
56
|
-
|
|
57
|
-
// 2) Load categories, then build options, then apply saved selection
|
|
58
|
-
api.get('/categories', {}).then(function (res) {
|
|
59
|
-
var categories = (res && res.categories) ? res.categories : [];
|
|
60
|
-
$select.empty();
|
|
61
|
-
|
|
62
|
-
categories
|
|
63
|
-
.filter(function (c) { return c && typeof c.cid !== 'undefined' && c.name; })
|
|
64
|
-
.forEach(function (c) {
|
|
65
|
-
var opt = $('<option />').val(String(c.cid)).text(c.name);
|
|
66
|
-
if (savedCids.includes(String(c.cid))) {
|
|
67
|
-
opt.prop('selected', true);
|
|
68
|
-
}
|
|
69
|
-
opt.appendTo($select);
|
|
70
|
-
});
|
|
71
|
-
}).catch(function (e) {
|
|
72
|
-
console.error('[discord-onekite] Could not load categories', e);
|
|
73
|
-
if (window.app && app.alertError) {
|
|
74
|
-
app.alertError('Impossible de charger la liste des catégories.');
|
|
75
|
-
} else {
|
|
76
|
-
alert('Impossible de charger la liste des catégories.');
|
|
77
|
-
}
|
|
78
|
-
});
|
|
79
|
-
|
|
80
|
-
// 3) Save handler
|
|
81
|
-
$('#save').off('click.discordOnekite').on('click.discordOnekite', function () {
|
|
82
|
-
settings.save('discord-onekite', $form, function () {
|
|
83
|
-
if (window.app && app.alertSuccess) {
|
|
84
|
-
app.alertSuccess('Paramètres enregistrés !');
|
|
85
|
-
}
|
|
86
|
-
});
|
|
87
|
-
});
|
|
88
|
-
});
|
|
89
|
-
});
|
|
90
|
-
</script>
|