Initial commit
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -130,3 +130,4 @@ dist
|
||||
.yarn/install-state.gz
|
||||
.pnp.*
|
||||
|
||||
config.xml
|
||||
17
README.md
17
README.md
@@ -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
86
bot.js
Normal 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
13
example.config.xml
Normal 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
1552
package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
18
package.json
Normal file
18
package.json
Normal 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": ""
|
||||
}
|
||||
Reference in New Issue
Block a user