Browse Source

Hello universe

tags/v1.0.0
raucao 1 year ago
commit
3583d74eff
Signed by: raucao <sebastian@kip.pe> GPG Key ID: BE4634D632D39B67
9 changed files with 1173 additions and 0 deletions
  1. +2
    -0
      .gitignore
  2. +7
    -0
      README.md
  3. +7
    -0
      bin/hubot
  4. +7
    -0
      bin/hubot.cmd
  5. +2
    -0
      external-scripts.json
  6. +1068
    -0
      package-lock.json
  7. +15
    -0
      package.json
  8. +14
    -0
      run.sh
  9. +51
    -0
      scripts/xmpp-muc-bridge.js

+ 2
- 0
.gitignore View File

@@ -0,0 +1,2 @@
node_modules
.hubot_history

+ 7
- 0
README.md View File

@@ -0,0 +1,7 @@
# Wormhole

Wormhole is a portal (sometimes called a bridge) between XMPP MUC and other
chat protocols. It's a very simple script on top of [Hubot][hubot]. In the case
of this particular bot, it is bridging IRC channels with XMPP MUC rooms.

[hubot]: http://hubot.github.com

+ 7
- 0
bin/hubot View File

@@ -0,0 +1,7 @@
#!/bin/sh

set -e

export PATH="node_modules/.bin:node_modules/hubot/node_modules/.bin:$PATH"

exec node_modules/.bin/hubot --name "wormhole" "$@"

+ 7
- 0
bin/hubot.cmd View File

@@ -0,0 +1,7 @@
@echo off

call npm install
SETLOCAL
SET PATH=node_modules\.bin;node_modules\hubot\node_modules\.bin;%PATH%

node_modules\.bin\hubot.cmd --name "wormhole" %*

+ 2
- 0
external-scripts.json View File

@@ -0,0 +1,2 @@
[
]

+ 1068
- 0
package-lock.json
File diff suppressed because it is too large
View File


+ 15
- 0
package.json View File

@@ -0,0 +1,15 @@
{
"name": "wormhole",
"version": "1.0.0",
"private": true,
"author": "Sebastian Kippe <sebastian@kip.pe>",
"description": "A portal between IRC and XMPP MUC",
"dependencies": {
"hubot": "^3.3.2",
"hubot-irc": "github:67P/hubot-irc#dev",
"simple-xmpp": "^1.3.1"
},
"engines": {
"node": "10.x"
}
}

+ 14
- 0
run.sh View File

@@ -0,0 +1,14 @@
#!/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_UNFLOOD="300" \
HUBOT_IRC_NICKSERV_USERNAME="wormhole" \
HUBOT_IRC_NICKSERV_PASSWORD="" \
HUBOT_WORMHOLE_XMPP_JID="wormhole@kosmos.org" \
HUBOT_WORMHOLE_XMPP_PASSWORD="" \
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" \
bin/hubot -a irc --name wormhole

+ 51
- 0
scripts/xmpp-muc-bridge.js View File

@@ -0,0 +1,51 @@
const hubot = require("hubot");
const xmpp = require('simple-xmpp');

const hubotRooms = process.env.HUBOT_IRC_ROOMS.split(',');
const xmppRooms = process.env.HUBOT_WORMHOLE_XMPP_ROOMS.split(',');

module.exports = function (robot) {

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}`;

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)
});

xmppRooms.forEach(room => xmpp.join(`${room}/wormhole`));

function messageMUC(res) {
const message = res.message;

if ((typeof message === 'object' && message.constructor.name === 'TextMessage') ||
message instanceof hubot.TextMessage) {
if (message.user['id'] === 'botka_dev') return;
if (!hubotRooms.includes(message.user.room)) return;

const room = xmppRooms[hubotRooms.indexOf(message.user.room)];
const msg = `[irc] <${message.user['id']}> ${message.text}`;

xmpp.send(room, msg, true);
}
}

const listener = new hubot.Listener(robot, function() {
return true;
}, function(res) {
return messageMUC(res);
});

robot.listeners.push(listener);

};

Loading…
Cancel
Save