refactor new announcement command to process content for newlines and streamline database insertion
This commit is contained in:
@@ -71,7 +71,7 @@ export default async function (_client: Client) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
const title = interaction.options.getString("title", true);
|
const title = interaction.options.getString("title", true);
|
||||||
const content = interaction.options.getString("content", true);
|
let content = interaction.options.getString("content", true);
|
||||||
const changesRaw = interaction.options.getString(
|
const changesRaw = interaction.options.getString(
|
||||||
"changes",
|
"changes",
|
||||||
false,
|
false,
|
||||||
@@ -86,6 +86,9 @@ export default async function (_client: Client) {
|
|||||||
link = "https://github.com/Space-Banane/shsf";
|
link = "https://github.com/Space-Banane/shsf";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Post Process Content
|
||||||
|
content = content.replace(/\\n/g, "\n"); // allow users to input \n for newlines
|
||||||
|
|
||||||
const fields = [];
|
const fields = [];
|
||||||
|
|
||||||
if (changesRaw && changesRaw.trim() !== "") {
|
if (changesRaw && changesRaw.trim() !== "") {
|
||||||
@@ -172,6 +175,20 @@ export default async function (_client: Client) {
|
|||||||
await message.react("👍");
|
await message.react("👍");
|
||||||
await message.react("🔥");
|
await message.react("🔥");
|
||||||
await message.react("👎");
|
await message.react("👎");
|
||||||
|
|
||||||
|
// Add to database with messageId for future updates
|
||||||
|
await db.collection("announcements").insertOne({
|
||||||
|
messageId: message.id,
|
||||||
|
title,
|
||||||
|
content,
|
||||||
|
changes: changesRaw ?? null,
|
||||||
|
imageUrl: image?.url ?? null,
|
||||||
|
comingWhen: comingWhenRaw ?? null,
|
||||||
|
link,
|
||||||
|
announcedBy: interaction.user.id,
|
||||||
|
announcedByUsername: interaction.user.username,
|
||||||
|
announcedAt: new Date(),
|
||||||
|
});
|
||||||
} else {
|
} else {
|
||||||
console.error(
|
console.error(
|
||||||
"Announcement channel not found or is not text-based.",
|
"Announcement channel not found or is not text-based.",
|
||||||
@@ -183,21 +200,6 @@ export default async function (_client: Client) {
|
|||||||
content: "You do not have permission to use this command.",
|
content: "You do not have permission to use this command.",
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add to database
|
|
||||||
await db.collection("announcements").insertOne({
|
|
||||||
title: interaction.options.getString("title", true),
|
|
||||||
content: interaction.options.getString("content", true),
|
|
||||||
changes: interaction.options.getString("changes", false),
|
|
||||||
imageUrl:
|
|
||||||
interaction.options.getAttachment("image", false)?.url ||
|
|
||||||
null,
|
|
||||||
comingWhen:
|
|
||||||
interaction.options.getString("coming_when", false) || null,
|
|
||||||
link: interaction.options.getString("link", false) || null,
|
|
||||||
announcedBy: interaction.user.id,
|
|
||||||
announcedAt: new Date(),
|
|
||||||
});
|
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user