Last active
March 18, 2019 02:57
-
-
Save rgajrawala/53c75ab35b980c7f2d97424edcfcdc38 to your computer and use it in GitHub Desktop.
IRC Javascript Runner
This file contains hidden or 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 config = { | |
server: 'irc.freenode.net', /**< Server address */ | |
userName: 'jsrunner', /**< Display name */ | |
realName: 'Javascript/Typescript/Coffeescript Runner', /**< Real name */ | |
password: undefined, /**< Password (plaintext string) */ | |
port: 6667, /**< Server port */ | |
debug: false, | |
showErrors: false, | |
autoRejoin: false, | |
autoConnect: false, | |
channels: ['####c++'], /**< Channels */ | |
secure: false, | |
selfSigned: false, | |
certExpired: false, | |
floodProtection: false, | |
floodProtectionDelay: 1000, | |
sasl: false, | |
stripColors: false, | |
channelPrefixes: "&#", | |
messageSplit: 512 | |
}; | |
module.exports = config; |
This file contains hidden or 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
{ | |
"name": "jsrunner", | |
"main": "runner.js", | |
"scripts": { | |
"start": "node runner.js" | |
}, | |
"author": "Usandfriends <[email protected]>", | |
"dependencies": { | |
"coffee-script": "^1.10.0", | |
"irc": "^0.5.0", | |
"sandbox": "^0.8.6", | |
"typescript": "^1.8.9" | |
} | |
} |
This file contains hidden or 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 inspect = require('util').inspect; | |
var ts = require('typescript'); | |
var cs = require('coffee-script'); | |
var Sandbox = require('sandbox'); | |
var IRClient = require('irc').Client; | |
var clientConfig = require('./config'); | |
var sandbox = new Sandbox(); | |
var client = new IRClient(clientConfig.server, clientConfig.userName, clientConfig); | |
client.addListener('message', function(nick, to, text) { | |
var match = text.match(/^(j|t|c)s>(.*)$/); | |
if (!match) { | |
return; | |
} | |
try { | |
switch (match[1]) { | |
case 't': match[2] = ts.transpile(match[2]); break; | |
case 'c': match[2] = cs.compile(match[2]); break; | |
} | |
} catch (e) { | |
client.say(to, '=> TranspileError: ' + e.message); | |
return; | |
} | |
sandbox.run(match[2], function(output) { | |
if (output.console.length > 0) { | |
var isTrunc = false; | |
if (output.console.length > 3) { | |
isTrunc = true; | |
} | |
output.console.slice(0, 3).forEach(function(output) { | |
if (typeof output === 'object' || typeof output === 'function') { | |
try { | |
output = inspect(output); | |
} catch (e) {} | |
} | |
output = output.toString().replace(/\s+/g, ' '); | |
var truncText = output.length > 280 ? ' ...' : ''; | |
client.say(to, 'console: ' + output.substring(0, 280) + truncText); | |
}); | |
if (isTrunc) { | |
client.say(to, 'console: [' + (output.console.length - 3) + ' line(s) truncated]'); | |
} | |
} | |
var result = output.result.replace(/\s+/g, ' '); | |
var truncText = result.length > 280 ? ' ...' : ''; | |
client.say(to, '=> ' + result.substring(0, 280) + truncText); | |
}); | |
}); | |
console.info('Connecting...'); | |
client.connect(0, function() { | |
console.info('Connected to "%s".', clientConfig.server); | |
clientConfig.channels.forEach(function(chan) { | |
client.join(chan, function() { | |
console.info('Connected to "%s".', chan); | |
}); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment