Add IMAGES enviornment variable for showing links and images

This commit is contained in:
Wizzard 2024-02-06 15:13:02 -05:00
parent 6fc18624e2
commit 6a56a38f51
2 changed files with 16 additions and 5 deletions

View File

@ -1,3 +1,4 @@
SOURCE_CHANNEL_ID_1=111111111111111111 SOURCE_CHANNEL_ID_1=111111111111111111
TARGET_CHANNEL_ID_1=111111111111111111 TARGET_CHANNEL_ID_1=111111111111111111
DISCORD_TOKEN=mASJIUFHKWHG.18295790udqawihKS DISCORD_TOKEN=mASJIUFHKWHG.18295790udqawihKS
IMAGES=0

14
main.js
View File

@ -10,6 +10,8 @@ const channelMappings = {
[process.env.SOURCE_CHANNEL_ID_2]: process.env.TARGET_CHANNEL_ID_2, [process.env.SOURCE_CHANNEL_ID_2]: process.env.TARGET_CHANNEL_ID_2,
}; };
const includeImages = process.env.IMAGES === '1';
client.on('ready', () => { client.on('ready', () => {
console.log(`${client.user.tag} is ready!`); console.log(`${client.user.tag} is ready!`);
setInterval(processMessageQueue, BATCH_INTERVAL); setInterval(processMessageQueue, BATCH_INTERVAL);
@ -19,14 +21,22 @@ client.on('messageCreate', async message => {
if (channelMappings[message.channel.id]) { if (channelMappings[message.channel.id]) {
if (message.author.id === client.user.id) return; if (message.author.id === client.user.id) return;
let content = message.content;
if (!includeImages) {
content = content.replace(/https?:\/\/\S+/g, '[Link removed]');
}
const timestamp = new Date(message.createdTimestamp).toISOString(); const timestamp = new Date(message.createdTimestamp).toISOString();
let attachmentUrls = message.attachments.map(a => a.url).join(' '); let attachmentUrls = '';
if (includeImages) {
attachmentUrls = message.attachments.map(a => a.url).join(' ');
if (attachmentUrls) { if (attachmentUrls) {
attachmentUrls = ' ' + attachmentUrls; attachmentUrls = ' ' + attachmentUrls;
} }
}
const formattedMessage = { const formattedMessage = {
content: `<@${message.author.id}> / **${message.author.tag}**: ${message.content}${attachmentUrls} \`${timestamp}\``, content: `<@${message.author.id}> / **${message.author.tag}**: ${content}${attachmentUrls} \`${timestamp}\``,
target: channelMappings[message.channel.id] target: channelMappings[message.channel.id]
}; };