summaryrefslogtreecommitdiff
path: root/Repl.js
diff options
context:
space:
mode:
authorTrygve Laugstøl <trygvis@inamo.no>2012-06-16 14:24:33 +0200
committerTrygve Laugstøl <trygvis@inamo.no>2012-06-16 14:24:33 +0200
commit2870c4da1aedf41926972dd60227c3d62cdaa123 (patch)
treebab887acdac4969c8a4cc3fcaf827ebb81726f6c /Repl.js
parente971ae61c99c8a602a1d60c95e9f8f908d4cf053 (diff)
downloaddynobot-irc-2870c4da1aedf41926972dd60227c3d62cdaa123.tar.gz
dynobot-irc-2870c4da1aedf41926972dd60227c3d62cdaa123.tar.bz2
dynobot-irc-2870c4da1aedf41926972dd60227c3d62cdaa123.tar.xz
dynobot-irc-2870c4da1aedf41926972dd60227c3d62cdaa123.zip
o Polishing the dynobot a bit.
Diffstat (limited to 'Repl.js')
-rw-r--r--Repl.js82
1 files changed, 82 insertions, 0 deletions
diff --git a/Repl.js b/Repl.js
new file mode 100644
index 0000000..cce93d0
--- /dev/null
+++ b/Repl.js
@@ -0,0 +1,82 @@
+var rl = require('readline');
+
+function quit() {
+ i.close();
+ process.stdin.destroy();
+ process.exit(0);
+}
+
+var i;
+
+module.exports.init = function() {
+ process.stdin.resume();
+ i = rl.createInterface(process.stdin, process.stdout, null);
+}
+
+module.exports.setupRepl = function() {
+}
+
+module.exports.setupSimulatorRepl = function(config) {
+ var from = 'alice!~alice@example.com';
+ var channel = config.channel;
+
+ function updatePrompt() {
+ var prefix = 'from=' + from;
+ prefix += channel ? ', channel=' + channel : '';
+ prefix += '> ';
+ i.setPrompt(prefix, prefix.length);
+ i.prompt();
+ }
+
+ i.on('line', function (cmd) {
+ cmd = cmd.trim();
+ if(cmd.length == 0) {
+ i.prompt();
+ return;
+ }
+ var parts = cmd.split(' ');
+ switch(parts[0]) {
+ case '/quit':
+ case '/q':
+ quit();
+ break;
+ case '/raw':
+ case '/r':
+ parts.shift();
+ stdinPipe.send(parts.join(' '));
+ updatePrompt();
+ break;
+ case '/join':
+ case '/j':
+ channel = parts[1];
+ updatePrompt();
+ break;
+ case '/from':
+ case '/f':
+ from = parts[1];
+ updatePrompt();
+ break;
+ case '/notice':
+ case '/n':
+ if(channel) {
+ parts.shift();
+ stdinPipe.send(':' + from + ' NOTICE ' + channel + ' :' + parts.join(' '));
+ }
+ else {
+ info('You have to /j a channel first');
+ }
+ break;
+ default:
+ stdinPipe.send(':' + from + ' PRIVMSG ' + channel + ' :' + parts.join(' '));
+ updatePrompt();
+ break;
+ }
+ }).on('close', function() {
+ quit();
+ });
+ updatePrompt();
+
+ setTimeout(function() {
+ stdinPipe.send(':irc.foo.bar 001 this :Welcome to Some Internet Relay Chat Network this');
+ }, 1000);
+}