Added replies to the bridge.
This commit is contained in:
27
bot.js
27
bot.js
@@ -20,8 +20,8 @@ try {
|
||||
|
||||
const DISCORD_TOKEN = config.Discord.Token;
|
||||
const bridges = Array.isArray(config.Bridges.Bridge)
|
||||
? config.Bridges.Bridge
|
||||
: [config.Bridges.Bridge];
|
||||
? config.Bridges.Bridge
|
||||
: [config.Bridges.Bridge];
|
||||
|
||||
// Create Discord client
|
||||
const discordClient = new Client({
|
||||
@@ -86,17 +86,30 @@ discordClient.once('ready', () => {
|
||||
}
|
||||
});
|
||||
|
||||
// Forward Discord messages to corresponding IRC channel
|
||||
discordClient.on('messageCreate', (message) => {
|
||||
// Forward Discord messages to corresponding IRC channel, handling replies as quotes
|
||||
discordClient.on('messageCreate', async (message) => {
|
||||
if (message.author.bot) return;
|
||||
|
||||
// Find the IRC client(s) that correspond to this Discord channel
|
||||
for (const [ircClient, info] of ircClients.entries()) {
|
||||
if (message.channel.id === info.discordChannelId) {
|
||||
// Avoid echoing messages sent by the bot itself
|
||||
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}`);
|
||||
ircClient.say(info.channel, discordMessage);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user