const fs = require('fs'); const xml2js = require('xml2js'); const { Client, Intents } = require('discord.js-selfbot-v13'); const irc = require('irc'); // Load config.xml let config; const parser = new xml2js.Parser({ explicitArray: false }); try { const xmlData = fs.readFileSync('config.xml', 'utf8'); parser.parseString(xmlData, (err, result) => { if (err) throw err; config = result.BridgeConfig; }); } catch (e) { console.error('Failed to load or parse config.xml:', e); process.exit(1); } // Extract configuration const DISCORD_TOKEN = config.Discord.Token; const DISCORD_CHANNEL_ID = config.Discord.ChannelId; const IRC_SERVER = config.IRC.Server; const IRC_PORT = parseInt(config.IRC.Port, 10); const IRC_CHANNEL = config.IRC.Channel; const IRC_NICK = config.IRC.Nick; // Discord client setup const discordClient = new Client({ checkUpdate: false, intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES] }); // IRC client setup const ircClient = new irc.Client(IRC_SERVER, IRC_NICK, { channels: [IRC_CHANNEL], port: IRC_PORT, autoConnect: false }); // Function to start IRC connection function startIRC() { console.log('Attempting to connect to IRC...'); ircClient.connect(5, () => { console.log(`Connected to IRC server ${IRC_SERVER}`); }); } // Handle IRC connection errors ircClient.addListener('error', (message) => { console.error('IRC error:', message); }); // Handle IRC messages and forward them to Discord ircClient.addListener('message', (from, to, message) => { console.log(`Received IRC message from ${from}: ${message}`); if (from === IRC_NICK) return; const ircMessage = `<${from}> ${message}`; const discordChannel = discordClient.channels.cache.get(DISCORD_CHANNEL_ID); if (discordChannel) { discordChannel.send(ircMessage); } }); // Handle Discord messages and forward them to IRC discordClient.on('messageCreate', message => { if (message.author.bot || message.channel.id !== DISCORD_CHANNEL_ID) return; if (message.author.id === discordClient.user.id) return; const discordMessage = `<${message.author.username}> ${message.content}`; console.log(`Forwarding Discord message to IRC: ${discordMessage}`); ircClient.say(IRC_CHANNEL, discordMessage); }); // Handle Discord ready event discordClient.on('ready', () => { console.log(`Logged in as ${discordClient.user.tag}`); startIRC(); }); // Login to Discord discordClient.login(DISCORD_TOKEN).catch(err => { console.error('Failed to login to Discord:', err); });