Add IMAGES enviornment variable for showing links and images
This commit is contained in:
parent
6fc18624e2
commit
6a56a38f51
|
@ -1,3 +1,4 @@
|
|||
SOURCE_CHANNEL_ID_1=111111111111111111
|
||||
TARGET_CHANNEL_ID_1=111111111111111111
|
||||
DISCORD_TOKEN=mASJIUFHKWHG.18295790udqawihKS
|
||||
IMAGES=0
|
||||
|
|
14
main.js
14
main.js
|
@ -10,6 +10,8 @@ const channelMappings = {
|
|||
[process.env.SOURCE_CHANNEL_ID_2]: process.env.TARGET_CHANNEL_ID_2,
|
||||
};
|
||||
|
||||
const includeImages = process.env.IMAGES === '1';
|
||||
|
||||
client.on('ready', () => {
|
||||
console.log(`${client.user.tag} is ready!`);
|
||||
setInterval(processMessageQueue, BATCH_INTERVAL);
|
||||
|
@ -19,14 +21,22 @@ client.on('messageCreate', async message => {
|
|||
if (channelMappings[message.channel.id]) {
|
||||
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();
|
||||
let attachmentUrls = message.attachments.map(a => a.url).join(' ');
|
||||
let attachmentUrls = '';
|
||||
if (includeImages) {
|
||||
attachmentUrls = message.attachments.map(a => a.url).join(' ');
|
||||
if (attachmentUrls) {
|
||||
attachmentUrls = ' ' + attachmentUrls;
|
||||
}
|
||||
}
|
||||
|
||||
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]
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in New Issue