partially working discord

This commit is contained in:
Thomas Rudin 2020-01-20 18:13:05 +01:00
parent 8098f6dc39
commit 8b86c2bd27
6 changed files with 158 additions and 114 deletions

View File

@ -1,9 +1,10 @@
{
"debug": true,
"remotes": [{
"name": "freenode",
"type": "irc",
"debug": true,
"host": "chat.freenode.net",
"username": "pandorabot_test",
"password": "abcxyz",
@ -13,8 +14,10 @@
},{
"name": "discord",
"type": "discord",
"debug": true,
"token": "NjY4ODUyOTExOTYyNTg3MTU2.XiXUCg.7fp0uO1hw3E8QHsI8EBeB2pgdZ4",
"channels": {
"main": "myToken"
"main": "test"
}
}]
}

186
package-lock.json generated
View File

@ -9,7 +9,7 @@
"resolved": "https://registry.npmjs.org/accepts/-/accepts-1.3.7.tgz",
"integrity": "sha512-Il80Qs2WjYlJIBNzNkK6KYqlVMTbZLXgHx2oT0pU/fjRHyEp+PEfEPY0R3WCwAGVOtauxh1hOxNgIf5bv7dQpA==",
"requires": {
"mime-types": "~2.1.24",
"mime-types": "2.1.24",
"negotiator": "0.6.2"
}
},
@ -35,15 +35,15 @@
"integrity": "sha512-dhEPs72UPbDnAQJ9ZKMNTP6ptJaionhP5cBb541nXPlW60Jepo9RV/a4fX4XWW9CuFNK22krhrj1+rgzifNCsw==",
"requires": {
"bytes": "3.1.0",
"content-type": "~1.0.4",
"content-type": "1.0.4",
"debug": "2.6.9",
"depd": "~1.1.2",
"depd": "1.1.2",
"http-errors": "1.7.2",
"iconv-lite": "0.4.24",
"on-finished": "~2.3.0",
"on-finished": "2.3.0",
"qs": "6.7.0",
"raw-body": "2.4.0",
"type-is": "~1.6.17"
"type-is": "1.6.18"
}
},
"brace-expansion": {
@ -52,7 +52,7 @@
"integrity": "sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA==",
"dev": true,
"requires": {
"balanced-match": "^1.0.0",
"balanced-match": "1.0.0",
"concat-map": "0.0.1"
}
},
@ -68,7 +68,7 @@
"dev": true,
"requires": {
"exit": "0.1.2",
"glob": "^7.1.1"
"glob": "7.1.6"
}
},
"concat-map": {
@ -83,7 +83,7 @@
"integrity": "sha1-8CQcRXMKn8YyOyBtvzjtx0HQuxA=",
"dev": true,
"requires": {
"date-now": "^0.1.4"
"date-now": "0.1.4"
}
},
"content-disposition": {
@ -149,11 +149,11 @@
"resolved": "https://registry.npmjs.org/discord.js/-/discord.js-11.5.1.tgz",
"integrity": "sha512-tGhV5xaZXE3Z+4uXJb3hYM6gQ1NmnSxp9PClcsSAYFVRzH6AJH74040mO3afPDMWEAlj8XsoPXXTJHTxesqcGw==",
"requires": {
"long": "^4.0.0",
"prism-media": "^0.0.3",
"snekfetch": "^3.6.4",
"tweetnacl": "^1.0.0",
"ws": "^6.0.0"
"long": "4.0.0",
"prism-media": "0.0.3",
"snekfetch": "3.6.4",
"tweetnacl": "1.0.2",
"ws": "6.2.1"
}
},
"dom-serializer": {
@ -162,8 +162,8 @@
"integrity": "sha512-2/xPb3ORsQ42nHYiSunXkDjPLBaEj/xTwUO4B7XCZQTRk7EBtTOPaygh10YAAh2OI1Qrp6NWfpAhzswj0ydt9g==",
"dev": true,
"requires": {
"domelementtype": "^2.0.1",
"entities": "^2.0.0"
"domelementtype": "2.0.1",
"entities": "2.0.0"
},
"dependencies": {
"domelementtype": {
@ -192,7 +192,7 @@
"integrity": "sha1-LeWaCCLVAn+r/28DLCsloqir5zg=",
"dev": true,
"requires": {
"domelementtype": "1"
"domelementtype": "1.3.1"
}
},
"domutils": {
@ -201,8 +201,8 @@
"integrity": "sha1-3NhIiib1Y9YQeeSMn3t+Mjc2gs8=",
"dev": true,
"requires": {
"dom-serializer": "0",
"domelementtype": "1"
"dom-serializer": "0.2.2",
"domelementtype": "1.3.1"
}
},
"ee-first": {
@ -247,36 +247,36 @@
"resolved": "https://registry.npmjs.org/express/-/express-4.17.1.tgz",
"integrity": "sha512-mHJ9O79RqluphRrcw2X/GTh3k9tVv8YcoyY4Kkh4WDMUYKRZUq0h1o0w2rrrxBqM7VoeUVqgb27xlEMXTnYt4g==",
"requires": {
"accepts": "~1.3.7",
"accepts": "1.3.7",
"array-flatten": "1.1.1",
"body-parser": "1.19.0",
"content-disposition": "0.5.3",
"content-type": "~1.0.4",
"content-type": "1.0.4",
"cookie": "0.4.0",
"cookie-signature": "1.0.6",
"debug": "2.6.9",
"depd": "~1.1.2",
"encodeurl": "~1.0.2",
"escape-html": "~1.0.3",
"etag": "~1.8.1",
"finalhandler": "~1.1.2",
"depd": "1.1.2",
"encodeurl": "1.0.2",
"escape-html": "1.0.3",
"etag": "1.8.1",
"finalhandler": "1.1.2",
"fresh": "0.5.2",
"merge-descriptors": "1.0.1",
"methods": "~1.1.2",
"on-finished": "~2.3.0",
"parseurl": "~1.3.3",
"methods": "1.1.2",
"on-finished": "2.3.0",
"parseurl": "1.3.3",
"path-to-regexp": "0.1.7",
"proxy-addr": "~2.0.5",
"proxy-addr": "2.0.5",
"qs": "6.7.0",
"range-parser": "~1.2.1",
"range-parser": "1.2.1",
"safe-buffer": "5.1.2",
"send": "0.17.1",
"serve-static": "1.14.1",
"setprototypeof": "1.1.1",
"statuses": "~1.5.0",
"type-is": "~1.6.18",
"statuses": "1.5.0",
"type-is": "1.6.18",
"utils-merge": "1.0.1",
"vary": "~1.1.2"
"vary": "1.1.2"
}
},
"fast-text-encoding": {
@ -290,12 +290,12 @@
"integrity": "sha512-aAWcW57uxVNrQZqFXjITpW3sIUQmHGG3qSb9mUah9MgMC4NeWhNOlNjXEYq3HjRAvL6arUviZGGJsBg6z0zsWA==",
"requires": {
"debug": "2.6.9",
"encodeurl": "~1.0.2",
"escape-html": "~1.0.3",
"on-finished": "~2.3.0",
"parseurl": "~1.3.3",
"statuses": "~1.5.0",
"unpipe": "~1.0.0"
"encodeurl": "1.0.2",
"escape-html": "1.0.3",
"on-finished": "2.3.0",
"parseurl": "1.3.3",
"statuses": "1.5.0",
"unpipe": "1.0.0"
}
},
"forwarded": {
@ -320,12 +320,12 @@
"integrity": "sha512-LwaxwyZ72Lk7vZINtNNrywX0ZuLyStrdDtabefZKAY5ZGJhVtgdznluResxNmPitE0SAO+O26sWTHeKSI2wMBA==",
"dev": true,
"requires": {
"fs.realpath": "^1.0.0",
"inflight": "^1.0.4",
"inherits": "2",
"minimatch": "^3.0.4",
"once": "^1.3.0",
"path-is-absolute": "^1.0.0"
"fs.realpath": "1.0.0",
"inflight": "1.0.6",
"inherits": "2.0.3",
"minimatch": "3.0.4",
"once": "1.4.0",
"path-is-absolute": "1.0.1"
}
},
"grapheme-splitter": {
@ -339,11 +339,11 @@
"integrity": "sha1-mWwosZFRaovoZQGn15dX5ccMEGg=",
"dev": true,
"requires": {
"domelementtype": "1",
"domhandler": "2.3",
"domutils": "1.5",
"entities": "1.0",
"readable-stream": "1.1"
"domelementtype": "1.3.1",
"domhandler": "2.3.0",
"domutils": "1.5.1",
"entities": "1.0.0",
"readable-stream": "1.1.14"
}
},
"http-errors": {
@ -351,10 +351,10 @@
"resolved": "https://registry.npmjs.org/http-errors/-/http-errors-1.7.2.tgz",
"integrity": "sha512-uUQBt3H/cSIVfch6i1EuPNy/YsRSOUBXTVfZ+yR7Zjez3qjBz6i9+i4zjNaoqcoFVI4lQJ5plg63TvGfRSDCRg==",
"requires": {
"depd": "~1.1.2",
"depd": "1.1.2",
"inherits": "2.0.3",
"setprototypeof": "1.1.1",
"statuses": ">= 1.5.0 < 2",
"statuses": "1.5.0",
"toidentifier": "1.0.0"
}
},
@ -363,7 +363,7 @@
"resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.4.24.tgz",
"integrity": "sha512-v3MXnZAcvnywkTUEZomIActle7RXXeedOR31wwl7VlyoXO4Qi9arvSenNQWne1TcRwhCL1HwLI21bEqdpj8/rA==",
"requires": {
"safer-buffer": ">= 2.1.2 < 3"
"safer-buffer": "2.1.2"
}
},
"inflight": {
@ -372,8 +372,8 @@
"integrity": "sha1-Sb1jMdfQLQwJvJEKEHW6gWW1bfk=",
"dev": true,
"requires": {
"once": "^1.3.0",
"wrappy": "1"
"once": "1.4.0",
"wrappy": "1.0.2"
}
},
"inherits": {
@ -391,15 +391,15 @@
"resolved": "https://registry.npmjs.org/irc-framework/-/irc-framework-4.4.0.tgz",
"integrity": "sha512-81ZjeFg0J+OdwGO4S90f8/GpwNwIcP9KaCt0lvRqt1GueT7cKPX2v1yiRML3cJXofkz/MsVZqJCnAEThYYaTUQ==",
"requires": {
"core-js": "^3.0.1",
"eventemitter3": "^2.0.2",
"grapheme-splitter": "^1.0.4",
"iconv-lite": "^0.4.24",
"isomorphic-textencoder": "^1.0.1",
"lodash": "^4.17.11",
"middleware-handler": "^0.2.0",
"regenerator-runtime": "^0.13.2",
"socksjs": "^0.5.0"
"core-js": "3.2.0",
"eventemitter3": "2.0.3",
"grapheme-splitter": "1.0.4",
"iconv-lite": "0.4.24",
"isomorphic-textencoder": "1.0.1",
"lodash": "4.17.15",
"middleware-handler": "0.2.0",
"regenerator-runtime": "0.13.3",
"socksjs": "0.5.0"
}
},
"isarray": {
@ -413,7 +413,7 @@
"resolved": "https://registry.npmjs.org/isomorphic-textencoder/-/isomorphic-textencoder-1.0.1.tgz",
"integrity": "sha512-676hESgHullDdHDsj469hr+7t3i/neBKU9J7q1T4RHaWwLAsaQnywC0D1dIUId0YZ+JtVrShzuBk1soo0+GVcQ==",
"requires": {
"fast-text-encoding": "^1.0.0"
"fast-text-encoding": "1.0.0"
}
},
"jshint": {
@ -422,14 +422,14 @@
"integrity": "sha512-d8AoXcNNYzmm7cdmulQ3dQApbrPYArtVBO6n4xOICe4QsXGNHCAKDcFORzqP52LhK61KX0VhY39yYzCsNq+bxQ==",
"dev": true,
"requires": {
"cli": "~1.0.0",
"console-browserify": "1.1.x",
"exit": "0.1.x",
"htmlparser2": "3.8.x",
"lodash": "~4.17.11",
"minimatch": "~3.0.2",
"shelljs": "0.3.x",
"strip-json-comments": "1.0.x"
"cli": "1.0.1",
"console-browserify": "1.1.0",
"exit": "0.1.2",
"htmlparser2": "3.8.3",
"lodash": "4.17.15",
"minimatch": "3.0.4",
"shelljs": "0.3.0",
"strip-json-comments": "1.0.4"
}
},
"lodash": {
@ -486,7 +486,7 @@
"integrity": "sha512-yJHVQEhyqPLUTgt9B83PXu6W3rx4MvvHvSUvToogpwoGDOUQ+yDrR0HRot+yOCdCO7u4hX3pWft6kWBBcqh0UA==",
"dev": true,
"requires": {
"brace-expansion": "^1.1.7"
"brace-expansion": "1.1.11"
}
},
"ms": {
@ -513,7 +513,7 @@
"integrity": "sha1-WDsap3WWHUsROsF9nFC6753Xa9E=",
"dev": true,
"requires": {
"wrappy": "1"
"wrappy": "1.0.2"
}
},
"parseurl": {
@ -542,7 +542,7 @@
"resolved": "https://registry.npmjs.org/proxy-addr/-/proxy-addr-2.0.5.tgz",
"integrity": "sha512-t/7RxHXPH6cJtP0pRG6smSr9QJidhB+3kXu0KgXnbGYMgzEnUxRQ4/LDdfOwZEMyIh3/xHb8PX3t+lfL9z+YVQ==",
"requires": {
"forwarded": "~0.1.2",
"forwarded": "0.1.2",
"ipaddr.js": "1.9.0"
}
},
@ -573,10 +573,10 @@
"integrity": "sha1-fPTFTvZI44EwhMY23SB54WbAgdk=",
"dev": true,
"requires": {
"core-util-is": "~1.0.0",
"inherits": "~2.0.1",
"core-util-is": "1.0.2",
"inherits": "2.0.3",
"isarray": "0.0.1",
"string_decoder": "~0.10.x"
"string_decoder": "0.10.31"
}
},
"regenerator-runtime": {
@ -600,18 +600,18 @@
"integrity": "sha512-BsVKsiGcQMFwT8UxypobUKyv7irCNRHk1T0G680vk88yf6LBByGcZJOTJCrTP2xVN6yI+XjPJcNuE3V4fT9sAg==",
"requires": {
"debug": "2.6.9",
"depd": "~1.1.2",
"destroy": "~1.0.4",
"encodeurl": "~1.0.2",
"escape-html": "~1.0.3",
"etag": "~1.8.1",
"depd": "1.1.2",
"destroy": "1.0.4",
"encodeurl": "1.0.2",
"escape-html": "1.0.3",
"etag": "1.8.1",
"fresh": "0.5.2",
"http-errors": "~1.7.2",
"http-errors": "1.7.2",
"mime": "1.6.0",
"ms": "2.1.1",
"on-finished": "~2.3.0",
"range-parser": "~1.2.1",
"statuses": "~1.5.0"
"on-finished": "2.3.0",
"range-parser": "1.2.1",
"statuses": "1.5.0"
},
"dependencies": {
"ms": {
@ -626,9 +626,9 @@
"resolved": "https://registry.npmjs.org/serve-static/-/serve-static-1.14.1.tgz",
"integrity": "sha512-JMrvUwE54emCYWlTI+hGrGv5I8dEwmco/00EvkzIIsR7MqrHonbD9pO2MOfFnpFntl7ecpZs+3mW+XbQZu9QCg==",
"requires": {
"encodeurl": "~1.0.2",
"escape-html": "~1.0.3",
"parseurl": "~1.3.3",
"encodeurl": "1.0.2",
"escape-html": "1.0.3",
"parseurl": "1.3.3",
"send": "0.17.1"
}
},
@ -696,7 +696,7 @@
"integrity": "sha512-TkRKr9sUTxEH8MdfuCSP7VizJyzRNMjj2J2do2Jr3Kym598JVdEksuzPQCnlFPW4ky9Q+iA+ma9BGm06XQBy8g==",
"requires": {
"media-typer": "0.3.0",
"mime-types": "~2.1.24"
"mime-types": "2.1.24"
}
},
"unpipe": {
@ -725,7 +725,7 @@
"resolved": "https://registry.npmjs.org/ws/-/ws-6.2.1.tgz",
"integrity": "sha512-GIyAXC2cB7LjvpgMt9EKS2ldqr0MTrORaleiOno6TweZ6r3TKtoFQWay/2PceJ3RuBasOHzXNn5Lrw1X0bEjqA==",
"requires": {
"async-limiter": "~1.0.0"
"async-limiter": "1.0.1"
}
}
}

View File

@ -1,20 +1,56 @@
const Discord = require('discord.js');
module.exports = function(remote){
Object.keys(remote.channels).forEach(ingame_channel => {
const token = remote.channels[ingame_channel];
const client = new Discord.Client();
module.exports = function(remote, events){
const client = new Discord.Client();
client.on('ready', () => {
console.log(`Logged in as ${client.user.tag}!`);
});
client.on('ready', () => {
console.log(`Logged in as ${client.user.tag}!`);
client.on('message', msg => {
if (msg.content === 'ping') {
msg.reply('Pong!');
}
});
events.on("message-out", function(event){
if (event.name != remote.name)
//not meant for this remote, ignore
return;
client.login(token);
});
if (remote.debug) {
console.log("Discord-message-out", event);
}
const discord_channel_name = remote.channels[event.channel];
if (!discord_channel_name){
console.warn("discord, not mapped channel found", event.channel);
return;
}
const channel = client.channels.find(ch => ch.name == discord_channel_name);
if (channel) {
channel.send(`<${event.username}${event.type == "minetest" ? "" : "@" + event.name}> ${event.message}`);
} else {
console.warn("discord, no channel found", discord_channel_name);
}
});
});
client.on('message', msg => {
console.log("discord-bot", msg.channel.type, msg.channel.name, msg.content, msg.author.username);
var ingame_channel = "";
Object.keys(remote.channels).forEach(mapped_channel => {
if (remote.channels[mapped_channel] == msg.channel.name)
ingame_channel = mapped_channel;
});
// "dm" == direct
if (msg.channel.type == "text"){
events.emit("message-in", {
type: "discord",
name: remote.name,
username: msg.author.username,
channel: ingame_channel,
message: msg.content
});
}
});
client.login(remote.token);
};

View File

@ -40,7 +40,7 @@ module.exports = function(remote, events){
var channel = "";
Object.keys(remote.channels).forEach(ingame_channel => {
const irc_channel = remote.channels[ingame_channel];
if (irc_channel == event.target){
if (irc_channel == event.target.substr(1)){
channel = ingame_channel;
}
});
@ -65,7 +65,7 @@ module.exports = function(remote, events){
const channel = channels[event.channel];
if (channel) {
channel.say(`<${event.username}${event.type == "minetest" ? "" : event.type}> ${event.message}`);
channel.say(`<${event.username}${event.type == "minetest" ? "" : "@" + event.name}> ${event.message}`);
}
});
};

View File

@ -21,6 +21,6 @@ cfg.remotes.forEach(remote => {
});
console.log("Starting message router");
router(cfg.remotes, events);
router(cfg, events);
app.listen(8080, () => console.log('Listening on http://127.0.0.1:8080'));

View File

@ -1,8 +1,13 @@
module.exports = function(remotes, events){
module.exports = function(cfg, events){
const remotes = cfg.remotes;
events.on("message-in", function(event){
// dispatch to other systems as message-out event with their names
if (cfg.debug){
console.log("message-in", event);
}
remotes.forEach(remote => {
if (event.name == remote.name){
//skip self
@ -12,7 +17,7 @@ module.exports = function(remotes, events){
// dispatch to remotes
events.emit("message-out", {
type: event.type,
name: remote.name,
name: event.name,
username: event.username,
channel: event.channel,
message: event.message