How to bridge discord to game?

Post Reply
BlueR23
Member
Posts: 26
Joined: Thu Jul 23, 2020 15:34
GitHub: DiamondPlane
Location: Behind you

How to bridge discord to game?

by BlueR23 » Post

Hello, can someone help me with one question? I want to bridge discord to Minetest server how can I do it?

User avatar
GreenXenith
Member
Posts: 1356
Joined: Wed Oct 28, 2015 01:26
GitHub: GreenXenith
Location: UTC-8:00
Contact:

Re: How to bridge discord to game?

by GreenXenith » Post

Discord to Minetest (Python) https://github.com/archfan7411/discordmt/
Discord to IRC to Minetest (NodeJS) https://github.com/GreenXenith/skynet (This will be the easiest to set up and use soon, without depending on IRC)
Discord to Minetest (Go) https://github.com/Jordach/discorduroy
Minetest to chatsocket (NodeJS) https://gitlab.com/sztest/szutilpack/-/ ... chatsocket
Discord NodeJS portion for chatsocket:
Spoiler

Code: Select all

const process = require('process');
const net = require('net');
const readline = require('readline');
const discord = require('discord.js');

setTimeout(process.exit, 2 * 3600 * 1000);

const sockpath = process.env.HOME + '/.chatsocket';
const token = 'REDACTIFICATED';
const chname = 'ingame'.toLowerCase();
const activity = 'NodeCore';

const sock = new net.Socket();
sock.on('close', () => { throw 'minetest connection lost'; });
sock.connect(sockpath);

const client = new discord.Client();
client.on('error', () => { throw 'discord connection lost'; });
client.on('ready', () => client.user.setActivity(activity));
client.on('message', msg => {
        if(!msg || !msg.channel
                || msg.channel.deleted
                || msg.channel.type !== 'text'
                || msg.channel.name.toLowerCase() !== chname
                || !msg.author
                || !msg.author.username
                || !msg.content
                || msg.author.id === client.user.id)
                return;
        var msg = '<@' + msg.author.username + '> ' + msg.content;
        console.log('D2G: ' + msg);
        sock.write(msg + '\n');
});
client.login(token);

function rxesc(s) { return s.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); }

readline.createInterface({input: sock}).on('line', l => {
        console.log('G2D: ' + l);
        client.users.forEach(u =>
                l = l.replace(new RegExp('@' + rxesc(u.username), 'gi'),
                '<@' + u.id + '>'));
        client.channels
                .filter(c => !c.deleted
                        && c.type === 'text'
                        && c.name.toLowerCase() === chname)
                .forEach(c => c.send(l));
});
YouTube | Mods | Patreon | Minetest Discord @greenxenith

You should not be able to read this message.

BlueR23
Member
Posts: 26
Joined: Thu Jul 23, 2020 15:34
GitHub: DiamondPlane
Location: Behind you

Re: How to bridge discord to game?

by BlueR23 » Post

GreenXenith wrote:
Wed Oct 28, 2020 20:57
Discord to Minetest (Python) https://github.com/archfan7411/discordmt/
Discord to IRC to Minetest (NodeJS) https://github.com/GreenXenith/skynet (This will be the easiest to set up and use soon, without depending on IRC)
Discord to Minetest (Go) https://github.com/Jordach/discorduroy
Minetest to chatsocket (NodeJS) https://gitlab.com/sztest/szutilpack/-/ ... chatsocket
Discord NodeJS portion for chatsocket:
Spoiler

Code: Select all

const process = require('process');
const net = require('net');
const readline = require('readline');
const discord = require('discord.js');

setTimeout(process.exit, 2 * 3600 * 1000);

const sockpath = process.env.HOME + '/.chatsocket';
const token = 'REDACTIFICATED';
const chname = 'ingame'.toLowerCase();
const activity = 'NodeCore';

const sock = new net.Socket();
sock.on('close', () => { throw 'minetest connection lost'; });
sock.connect(sockpath);

const client = new discord.Client();
client.on('error', () => { throw 'discord connection lost'; });
client.on('ready', () => client.user.setActivity(activity));
client.on('message', msg => {
        if(!msg || !msg.channel
                || msg.channel.deleted
                || msg.channel.type !== 'text'
                || msg.channel.name.toLowerCase() !== chname
                || !msg.author
                || !msg.author.username
                || !msg.content
                || msg.author.id === client.user.id)
                return;
        var msg = '<@' + msg.author.username + '> ' + msg.content;
        console.log('D2G: ' + msg);
        sock.write(msg + '\n');
});
client.login(token);

function rxesc(s) { return s.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); }

readline.createInterface({input: sock}).on('line', l => {
        console.log('G2D: ' + l);
        client.users.forEach(u =>
                l = l.replace(new RegExp('@' + rxesc(u.username), 'gi'),
                '<@' + u.id + '>'));
        client.channels
                .filter(c => !c.deleted
                        && c.type === 'text'
                        && c.name.toLowerCase() === chname)
                .forEach(c => c.send(l));
});
Thanks

Post Reply

Who is online

Users browsing this forum: No registered users and 13 guests