-
-
Save ChristopherKing42/71e37c1a0f1812b5e4448ba800d781eb to your computer and use it in GitHub Desktop.
Node.JS - Quick & Dirty Poloniex Trollbox IRC Relay. Debian/Ubuntu: apt-get install libicu-dev / NPM Modules: npm install autobahn ent irc irc-colors
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var autobahn = require('autobahn'); | |
var ent = require('ent'); | |
var irc = require('irc'); | |
var c = require('irc-colors'); | |
var channelName = '##trollboxtest'; | |
var captureDuration = 60 * 1000; // 60 seconds in milis | |
var wsuri = "wss://api.poloniex.com"; | |
var connection = new autobahn.Connection({ | |
url: wsuri, | |
realm: "realm1" | |
}); | |
var client = new irc.Client('irc.freenode.net', 'Trollbox', { | |
userName: 'Trollbox', | |
realName: 'Poloniex Trollbox IRC Relay', | |
port: 6667, | |
debug: false, | |
autoRejoin: true, | |
channels: [channelName], | |
}); | |
var captures = []; | |
client.addListener('error', function(message) { | |
console.log('error: ', message); | |
}); | |
connection.onopen = function (session) { | |
function trollboxEvent (args,kwargs) { | |
var nick = args[2]; | |
var msg = ent.decode(args[3]); | |
if (msg.toLowerCase().indexOf("monero") != -1 || | |
msg.toLowerCase().indexOf("xmr") != -1) | |
{ | |
say(nick, msg); | |
if (captures.indexOf(nick.toLowerCase()) == -1) { | |
captures.push(nick.toLowerCase()); | |
console.log('Added', nick, 'to capture list.', captures.length); | |
setTimeout(function() { | |
captures.splice(captures.indexOf(nick.toLowerCase()), 1); | |
console.log("Removed", nick, 'from capture list.', captures.length); | |
}, captureDuration); | |
} | |
} | |
captures.forEach(function(capture) { | |
if(msg.toLowerCase().indexOf(capture.toLowerCase()) != -1 || nick == capture) { | |
if(msg.toLowerCase().indexOf("monero") == -1 && msg.toLowerCase().indexOf("xmr") == -1) { | |
say(nick, msg); | |
} | |
} | |
}); | |
} | |
session.subscribe('trollbox', trollboxEvent); | |
} | |
connection.onclose = function () { | |
console.log("Websocket connection closed"); | |
} | |
connection.open(); | |
function say(nick, msg) { | |
client.say(channelName, '-> ' + c.bold(nick) + ': ' + msg); | |
console.log('Relay', nick, '-> ', msg); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment