Initial commit

This commit is contained in:
2025-04-29 20:47:12 +02:00
parent adc85ce6b6
commit d12a0c20d5
6 changed files with 1686 additions and 1 deletions

1
.gitignore vendored
View File

@@ -130,3 +130,4 @@ dist
.yarn/install-state.gz
.pnp.*
config.xml

View File

@@ -1,3 +1,18 @@
# Discord-userbot-to-irc
A crappy group chat to a IRC room bridge written in node </3
A crappy Discord userbot bridge to bridge a discord group chat with a IRC room.
# What you need to run this:
```
Dependecies:
xml2js
discord.js-selfbot-v13
irc
```
### You also need a discord user token.
Before you run it edit the example.config.xml file with all the correct informatiion and rename it to config.xml
## To run it just run:
```
node bot.js
```

86
bot.js Normal file
View File

@@ -0,0 +1,86 @@
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);
});

13
example.config.xml Normal file
View File

@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<BridgeConfig>
<Discord>
<Token>YOUR_DISCORD_TOKEN_HERE</Token>
<ChannelId>YOUR_DISCORD_CHANNEL_ID_HERE</ChannelId>
</Discord>
<IRC>
<Server>IRC_SERVER_HERE</Server>
<Port>IRC_PORT_HERE</Port>
<Channel>IRC_CHANNEL_HERE</Channel>
<Nick>Bridge nick over on the IRC side</Nick>
</IRC>
</BridgeConfig>

1552
package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

18
package.json Normal file
View File

@@ -0,0 +1,18 @@
{
"dependencies": {
"discord.js-selfbot-v13": "^3.4.5",
"irc": "^0.5.2",
"irc-framework": "^4.14.0",
"xml2js": "^0.6.2"
},
"name": "bridge",
"version": "1.0.0",
"main": "bot.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"description": ""
}