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
|
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
|
||||||
|
|
18
main.js
18
main.js
|
@ -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 (attachmentUrls) {
|
if (includeImages) {
|
||||||
attachmentUrls = ' ' + attachmentUrls;
|
attachmentUrls = message.attachments.map(a => a.url).join(' ');
|
||||||
|
if (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]
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue