Added replies to the bridge.

This commit is contained in:
2025-05-05 23:28:03 +02:00
parent 9586cbf978
commit 00fcac9a5a

23
bot.js
View File

@@ -86,17 +86,30 @@ discordClient.once('ready', () => {
} }
}); });
// Forward Discord messages to corresponding IRC channel // Forward Discord messages to corresponding IRC channel, handling replies as quotes
discordClient.on('messageCreate', (message) => { discordClient.on('messageCreate', async (message) => {
if (message.author.bot) return; if (message.author.bot) return;
// Find the IRC client(s) that correspond to this Discord channel
for (const [ircClient, info] of ircClients.entries()) { for (const [ircClient, info] of ircClients.entries()) {
if (message.channel.id === info.discordChannelId) { if (message.channel.id === info.discordChannelId) {
// Avoid echoing messages sent by the bot itself
if (message.author.id === discordClient.user.id) return; if (message.author.id === discordClient.user.id) return;
const discordMessage = `<${message.author.username}> ${message.content}`; let quote = '';
if (message.reference && message.reference.messageId) {
try {
const referencedMessage = await message.channel.messages.fetch(message.reference.messageId);
if (referencedMessage) {
const refAuthor = referencedMessage.author.username;
const refContent = referencedMessage.content || '[Embed/Attachment]';
const quotedLines = refContent.split('\n').map(line => `> ${line}`).join('\n');
quote = `> ${refAuthor} said:\n${quotedLines}\n`;
}
} catch (err) {
console.warn('Failed to fetch referenced message:', err);
}
}
const discordMessage = `${quote}<${message.author.username}> ${message.content}`;
console.log(`Forwarding Discord message to IRC [${info.server} ${info.channel}]: ${discordMessage}`); console.log(`Forwarding Discord message to IRC [${info.server} ${info.channel}]: ${discordMessage}`);
ircClient.say(info.channel, discordMessage); ircClient.say(info.channel, discordMessage);
} }