Compare commits

...

7 Commits

Author SHA1 Message Date
59d82f3a0b
1.1.0 2020-11-27 12:23:51 +01:00
46eb0452f5 Merge pull request 'Re-connect XMPP when disconnected' (#2) from feature/1-reconnect_xmpp into master
Reviewed-on: #2
2020-11-27 11:22:32 +00:00
33747dd59d
Add default nickname to run script 2020-11-27 01:56:26 +01:00
82313c72ea
Make XMPP nickname configurable 2020-11-27 01:55:34 +01:00
d653d184f2
XMPP: re-connect when disconnected
closes #1
2020-11-26 18:43:58 +01:00
377040e196
Fix run.sh and only join kosmos-random rooms 2020-11-26 18:42:51 +01:00
aacfc7f83d
Remove prefix from chat messages
As the wormhole user only ever posts messages from the other side of the
wormhole, we don't need to see the protocol name before every single
message.
2019-07-30 09:11:24 +02:00
4 changed files with 33 additions and 15 deletions

2
package-lock.json generated
View File

@ -1,6 +1,6 @@
{
"name": "wormhole",
"version": "1.0.0",
"version": "1.1.0",
"lockfileVersion": 1,
"requires": true,
"dependencies": {

View File

@ -1,6 +1,6 @@
{
"name": "wormhole",
"version": "1.0.0",
"version": "1.1.0",
"private": true,
"author": "Sebastian Kippe <sebastian@kip.pe>",
"description": "A portal between IRC and XMPP MUC",

11
run.sh
View File

@ -1,14 +1,15 @@
#!/bin/bash
HUBOT_LOG_LEVEL="debug" \
HUBOT_IRC_SERVER="irc.freenode.net" \
HUBOT_IRC_ROOMS="#kosmos-random,#kosmos-dev" \
HUBOT_IRC_NICK="wormhole" \
HUBOT_IRC_ROOMS="#kosmos-random" \
HUBOT_IRC_NICK="wormholedev" \
HUBOT_IRC_UNFLOOD="300" \
HUBOT_IRC_NICKSERV_USERNAME="wormhole" \
HUBOT_IRC_NICKSERV_USERNAME="wormholedev" \
HUBOT_IRC_NICKSERV_PASSWORD="" \
HUBOT_WORMHOLE_XMPP_JID="wormhole@kosmos.org" \
HUBOT_WORMHOLE_XMPP_JID="jimmy@kosmos.org" \
HUBOT_WORMHOLE_XMPP_PASSWORD="" \
HUBOT_WORMHOLE_XMPP_NICKNAME="wormhole" \
HUBOT_WORMHOLE_XMPP_HOST="xmpp.kosmos.org" \
HUBOT_WORMHOLE_XMPP_PORT="5222" \
HUBOT_WORMHOLE_XMPP_ROOMS="kosmos-random@chat.kosmos.org,kosmos-dev@chat.kosmos.org" \
HUBOT_WORMHOLE_XMPP_ROOMS="kosmos-random@kosmos.chat" \
bin/hubot -a irc --name wormhole

View File

@ -3,27 +3,44 @@ const xmpp = require('simple-xmpp');
const hubotRooms = process.env.HUBOT_IRC_ROOMS.split(',');
const xmppRooms = process.env.HUBOT_WORMHOLE_XMPP_ROOMS.split(',');
const xmppNickname = process.env.HUBOT_WORMHOLE_XMPP_NICKNAME;
const xmppConfig = {
jid: process.env.HUBOT_WORMHOLE_XMPP_JID,
password: process.env.HUBOT_WORMHOLE_XMPP_PASSWORD,
host: process.env.HUBOT_WORMHOLE_XMPP_HOST,
port: parseInt(process.env.HUBOT_WORMHOLE_XMPP_PORT)
};
module.exports = function (robot) {
xmpp.on('online', function(data) {
robot.logger.info('XMPP connected with JID: ' + data.jid.toString());
xmppRooms.forEach(room => xmpp.join(`${room}/${xmppNickname}`));
});
xmpp.on('close', function() {
robot.logger.info('XMPP connection has been closed. Re-connecting...');
xmpp.connect(xmppConfig);
});
xmpp.on('groupchat', function(conference, from, message, whatevs, meta) {
if (meta || (from === 'wormhole')) return;
if (!xmppRooms.includes(conference)) return;
const room = hubotRooms[xmppRooms.indexOf(conference)];
const msg = `[xmpp] <${from}> ${message}`;
const msg = `<${from}> ${message}`;
robot.messageRoom(room, msg);
});
xmpp.connect({
jid: process.env.HUBOT_WORMHOLE_XMPP_JID,
password: process.env.HUBOT_WORMHOLE_XMPP_PASSWORD,
host: process.env.HUBOT_WORMHOLE_XMPP_HOST,
port: parseInt(process.env.HUBOT_WORMHOLE_XMPP_PORT)
xmpp.on('error', function(err) {
robot.logger.error(err);
});
xmppRooms.forEach(room => xmpp.join(`${room}/wormhole`));
xmpp.connect(xmppConfig);
function messageMUC(res) {
const message = res.message;
@ -34,7 +51,7 @@ module.exports = function (robot) {
if (!hubotRooms.includes(message.user.room)) return;
const room = xmppRooms[hubotRooms.indexOf(message.user.room)];
const msg = `[irc] <${message.user['id']}> ${message.text}`;
const msg = `<${message.user['id']}> ${message.text}`;
xmpp.send(room, msg, true);
}