nodebb-plugin-discord-onekite 1.0.9 → 1.0.10
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 +2 -1
- package/lib/controllers.js +8 -32
- package/library.js +5 -20
- package/package.json +2 -2
- package/plugin.json +1 -1
- package/templates/admin/plugins/discord-onekite.tpl +9 -12
package/README.md
CHANGED
|
@@ -1 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
# nodebb-plugin-discord-onekite v1.0.8
|
|
2
|
+
Clean build (no debug). Server-side ACP + success alert.
|
package/lib/controllers.js
CHANGED
|
@@ -12,28 +12,13 @@ function normalizeCids(v) {
|
|
|
12
12
|
return [];
|
|
13
13
|
}
|
|
14
14
|
|
|
15
|
-
async function
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
if (err) {
|
|
22
|
-
result.error = err.message || String(err);
|
|
23
|
-
return resolve([]);
|
|
24
|
-
}
|
|
25
|
-
if (!Array.isArray(categoriesData)) return resolve([]);
|
|
26
|
-
resolve(categoriesData.filter(Boolean));
|
|
27
|
-
});
|
|
28
|
-
} catch (e) {
|
|
29
|
-
result.error = e.message || String(e);
|
|
30
|
-
resolve([]);
|
|
31
|
-
}
|
|
15
|
+
async function getReadableCategories(uid) {
|
|
16
|
+
return await new Promise((resolve) => {
|
|
17
|
+
categories.getCategoriesByPrivilege('categories:cid', uid || 0, 'read', (err, categoriesData) => {
|
|
18
|
+
if (err || !Array.isArray(categoriesData)) return resolve([]);
|
|
19
|
+
resolve(categoriesData.filter(Boolean));
|
|
20
|
+
});
|
|
32
21
|
});
|
|
33
|
-
|
|
34
|
-
result.count = cats.length;
|
|
35
|
-
result.sample = cats.slice(0, 5).map(c => ({ cid: c.cid, name: c.name }));
|
|
36
|
-
return { cats, result };
|
|
37
22
|
}
|
|
38
23
|
|
|
39
24
|
const controllers = {};
|
|
@@ -42,7 +27,7 @@ controllers.renderAdminPage = async function (req, res) {
|
|
|
42
27
|
const settings = await meta.settings.get(SETTINGS_KEY);
|
|
43
28
|
const savedCids = normalizeCids(settings && settings.cids);
|
|
44
29
|
|
|
45
|
-
const
|
|
30
|
+
const cats = await getReadableCategories(req.uid);
|
|
46
31
|
const categoriesForTpl = (cats || [])
|
|
47
32
|
.filter(c => c && typeof c.cid !== 'undefined' && c.name)
|
|
48
33
|
.map(c => ({
|
|
@@ -52,19 +37,10 @@ controllers.renderAdminPage = async function (req, res) {
|
|
|
52
37
|
}))
|
|
53
38
|
.sort((a, b) => a.name.localeCompare(b.name));
|
|
54
39
|
|
|
55
|
-
const debug = {
|
|
56
|
-
uid: req.uid,
|
|
57
|
-
relative_path: meta.config && meta.config.relative_path,
|
|
58
|
-
url: meta.config && meta.config.url,
|
|
59
|
-
categories: result,
|
|
60
|
-
savedCidsCount: savedCids.length,
|
|
61
|
-
now: new Date().toISOString(),
|
|
62
|
-
};
|
|
63
|
-
|
|
64
40
|
res.render('admin/plugins/discord-onekite', {
|
|
65
41
|
settings: settings || {},
|
|
66
42
|
categories: categoriesForTpl,
|
|
67
|
-
|
|
43
|
+
saved: req.query && (req.query.saved === '1' || req.query.saved === 'true'),
|
|
68
44
|
});
|
|
69
45
|
};
|
|
70
46
|
|
package/library.js
CHANGED
|
@@ -75,8 +75,6 @@ async function buildTopicEmbed({ tid, pid, type }) {
|
|
|
75
75
|
const Plugin = {};
|
|
76
76
|
|
|
77
77
|
Plugin.init = async ({ router }) => {
|
|
78
|
-
console.log('[discord-onekite] init hook fired');
|
|
79
|
-
|
|
80
78
|
routeHelpers.setupAdminPageRoute(
|
|
81
79
|
router,
|
|
82
80
|
'/admin/plugins/discord-onekite',
|
|
@@ -94,26 +92,11 @@ Plugin.init = async ({ router }) => {
|
|
|
94
92
|
cids: req.body.cids || '',
|
|
95
93
|
};
|
|
96
94
|
await meta.settings.set(SETTINGS_KEY, payload);
|
|
97
|
-
console.log('[discord-onekite] settings saved');
|
|
98
95
|
} catch (e) {
|
|
96
|
+
// eslint-disable-next-line no-console
|
|
99
97
|
console.error('[discord-onekite] save failed', e);
|
|
100
98
|
}
|
|
101
|
-
res.redirect('/admin/plugins/discord-onekite');
|
|
102
|
-
}
|
|
103
|
-
);
|
|
104
|
-
|
|
105
|
-
router.get('/admin/plugins/discord-onekite/ping',
|
|
106
|
-
middleware.admin.checkPrivileges,
|
|
107
|
-
(req, res) => {
|
|
108
|
-
res.json({
|
|
109
|
-
ok: true,
|
|
110
|
-
plugin: 'nodebb-plugin-discord-onekite',
|
|
111
|
-
version: '1.0.7',
|
|
112
|
-
uid: req.uid,
|
|
113
|
-
relative_path: meta.config && meta.config.relative_path,
|
|
114
|
-
url: meta.config && meta.config.url,
|
|
115
|
-
time: new Date().toISOString(),
|
|
116
|
-
});
|
|
99
|
+
res.redirect('/admin/plugins/discord-onekite?saved=1');
|
|
117
100
|
}
|
|
118
101
|
);
|
|
119
102
|
};
|
|
@@ -122,7 +105,7 @@ Plugin.addAdminNavigation = (header) => {
|
|
|
122
105
|
header.plugins.push({
|
|
123
106
|
route: '/plugins/discord-onekite',
|
|
124
107
|
icon: 'fa-bell',
|
|
125
|
-
name: 'Discord Onekite
|
|
108
|
+
name: 'Discord Onekite',
|
|
126
109
|
});
|
|
127
110
|
return header;
|
|
128
111
|
};
|
|
@@ -149,6 +132,7 @@ Plugin.onTopicSave = async (data) => {
|
|
|
149
132
|
|
|
150
133
|
await postToDiscord(settings.webhookUrl, { embeds: [built.embed] });
|
|
151
134
|
} catch (err) {
|
|
135
|
+
// eslint-disable-next-line no-console
|
|
152
136
|
console.error(err);
|
|
153
137
|
}
|
|
154
138
|
};
|
|
@@ -174,6 +158,7 @@ Plugin.onPostSave = async (data) => {
|
|
|
174
158
|
|
|
175
159
|
await postToDiscord(settings.webhookUrl, { embeds: [built.embed] });
|
|
176
160
|
} catch (err) {
|
|
161
|
+
// eslint-disable-next-line no-console
|
|
177
162
|
console.error(err);
|
|
178
163
|
}
|
|
179
164
|
};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "nodebb-plugin-discord-onekite",
|
|
3
|
-
"version": "1.0.
|
|
4
|
-
"description": "Discord webhook notifier for Onekite (NodeBB v4.x only)
|
|
3
|
+
"version": "1.0.10",
|
|
4
|
+
"description": "Discord webhook notifier for Onekite (NodeBB v4.x only)",
|
|
5
5
|
"main": "library.js",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"keywords": [
|
package/plugin.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"id": "nodebb-plugin-discord-onekite",
|
|
3
3
|
"name": "Discord Onekite Notifier",
|
|
4
|
-
"description": "Notifie Discord via webhook (v4.x
|
|
4
|
+
"description": "Notifie Discord via webhook pour nouveaux sujets et/ou r\u00e9ponses, filtrable par cat\u00e9gories (NodeBB v4.x uniquement).",
|
|
5
5
|
"library": "./library.js",
|
|
6
6
|
"hooks": [
|
|
7
7
|
{
|
|
@@ -1,9 +1,15 @@
|
|
|
1
1
|
<div class="acp-page-container">
|
|
2
|
-
<h4>Discord Onekite
|
|
2
|
+
<h4>Discord Onekite</h4>
|
|
3
3
|
<p class="text-muted">
|
|
4
|
-
|
|
4
|
+
Notifications Discord via webhook (rendu serveur).
|
|
5
5
|
</p>
|
|
6
6
|
|
|
7
|
+
<!-- IF saved -->
|
|
8
|
+
<div class="alert alert-success" role="alert">
|
|
9
|
+
Paramètres enregistrés !
|
|
10
|
+
</div>
|
|
11
|
+
<!-- ENDIF saved -->
|
|
12
|
+
|
|
7
13
|
<form role="form" method="post" action="/admin/plugins/discord-onekite/save">
|
|
8
14
|
<input type="hidden" name="_csrf" value="{config.csrf_token}" />
|
|
9
15
|
|
|
@@ -15,7 +21,7 @@
|
|
|
15
21
|
<div class="form-check mb-3">
|
|
16
22
|
<input class="form-check-input" type="checkbox" id="notifyReplies" name="notifyReplies" <!-- IF settings.notifyReplies -->checked<!-- ENDIF settings.notifyReplies -->>
|
|
17
23
|
<label class="form-check-label" for="notifyReplies">
|
|
18
|
-
Notifier aussi les réponses
|
|
24
|
+
Notifier aussi les réponses (si décoché : uniquement les nouveaux sujets)
|
|
19
25
|
</label>
|
|
20
26
|
</div>
|
|
21
27
|
|
|
@@ -33,13 +39,4 @@
|
|
|
33
39
|
|
|
34
40
|
<button type="submit" class="btn btn-primary">Enregistrer</button>
|
|
35
41
|
</form>
|
|
36
|
-
|
|
37
|
-
<hr />
|
|
38
|
-
|
|
39
|
-
<h5>Debug</h5>
|
|
40
|
-
<pre style="white-space: pre-wrap;">{debug}</pre>
|
|
41
|
-
<p>
|
|
42
|
-
Endpoint de test (doit répondre JSON) :
|
|
43
|
-
<code>/admin/plugins/discord-onekite/ping</code>
|
|
44
|
-
</p>
|
|
45
42
|
</div>
|