Skip to content
This repository was archived by the owner on Dec 9, 2024. It is now read-only.

Commit 6e0681a

Browse files
committed
formatTitle & Channel Submit Edit
1 parent 7b9a177 commit 6e0681a

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

events/interactionCreate.js

-3
Original file line numberDiff line numberDiff line change
@@ -320,9 +320,6 @@ module.exports = {
320320
while (message) {
321321
await channel.messages
322322
.fetch({ limit: 100, before: message.id })
323-
.then((messagePage) =>
324-
messagePage.filter((m) => !excludedUsers.includes(m.author.id))
325-
)
326323
.then((messagePage) => {
327324
messagePage.forEach((msg) => {
328325
// this has issues (i believe) with starter messages that have been edited

functions/discourse.js

+16-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,18 @@ const { hostname, apiKey, apiUsername } = require("../config.json");
88
// Etc. /admin/groups; /t/{id}; /latest
99
const path = "/posts";
1010

11+
12+
function formatTitle(title) {
13+
if (title.length > 255) {
14+
title.substring(0, 255);
15+
}
16+
if (title.length < 20) {
17+
title.padEnd(20, "_")
18+
}
19+
20+
return title.replace(/-/g, "").replace(//g, "'")
21+
}
22+
1123
// Data will be request object? sent from function
1224
function discoursePost(message) {
1325
// Basic Nodejs http post implementation: https://nodejs.dev/learn/making-http-requests-with-nodejs
@@ -20,7 +32,7 @@ function discoursePost(message) {
2032
// Next leg of dev will be refactoring and writing in Redwood on API side;
2133
// Then will pick up here
2234
var data = {
23-
title: message.title,
35+
title: formatTitle(message.title),
2436
raw: message.raw,
2537
category: 22
2638
};
@@ -47,15 +59,18 @@ function discoursePost(message) {
4759
res.on('data', d => {
4860
process.stdout.write(d);
4961
});
62+
return res;
5063
});
5164

5265
req.on('error', error => {
5366
console.error(error);
67+
return error;
5468
});
5569

5670
req.write(data);
5771
req.end();
5872

73+
5974
}
6075

6176
module.exports = { discoursePost };

0 commit comments

Comments
 (0)