Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
  • 4 commits
  • 4 files changed
  • 0 comments
  • 2 contributors
Oct 01, 2012
Rohan Jain crodjer Support for whois command
Asking for whois info is quite popular. This adds it to the server
and the client side.

Signed-off-by: Rohan Jain <crodjer@gmail.com>
8fe5ae4
Rohan Jain crodjer Command store and better command handler
This doesn't add and functionality right now, but it can be used for
functionalities like autocomplete, help text.

Signed-off-by: Rohan Jain <crodjer@gmail.com>
80c335b
David Petersen thedjpetersen Merge pull request #170 from crodjer/master
Better comand handling, whois command
be164f8
David Petersen thedjpetersen Merge pull request #168 from noraesae/master
make 'keeping connection alive' optional
9505050
181 assets/js/client.js
@@ -150,6 +150,27 @@ $(function() {
150 150 irc.chatWindows.getByName('status').stream.add(message);
151 151 });
152 152
  153 + // Whois data
  154 + irc.socket.on('whois', function(data){
  155 + var key, message;
  156 + var stream = irc.chatWindows.getByName('status').stream;
  157 + if (data.info){
  158 + var info = {
  159 + " ": data.info.nick + ' (' + (data.info.user + '@' + data.info.host) + ')',
  160 + realname: data.info.realname,
  161 + server: data.info.server + ' (' + data.info.serverinfo + ')',
  162 + account: data.info.account
  163 + };
  164 +
  165 + for (key in info){
  166 + if (info.hasOwnProperty(key)){
  167 + message = new Message({sender: key, raw: info[key], type: 'whois'});
  168 + stream.add(message);
  169 + }
  170 + }
  171 + }
  172 + });
  173 +
153 174 irc.socket.on('message', function(data) {
154 175 var chatWindow = irc.chatWindows.getByName(data.to.toLowerCase());
155 176 var type = 'message';
@@ -329,61 +350,119 @@ $(function() {
329 350 }
330 351 });
331 352
332   - irc.handleCommand = function(commandText) {
333   - switch (commandText[0]) {
334   - case '/join':
335   - irc.socket.emit('join', commandText[1]);
336   - break;
337   - case '/wc':
338   - case '/close':
339   - case '/part':
340   - if (commandText[1]) {
341   - irc.socket.emit('part', commandText[1]);
342   - irc.appView.channelList.channelTabs[0].setActive();
343   - } else {
344   - irc.socket.emit('part', irc.chatWindows.getActive().get('name'));
345   - irc.appView.channelList.channelTabs[0].setActive();
  353 + irc.commands = (function(){
  354 + var commandStore = {
  355 + 'default': function(args, command){
  356 + // Do nothing, override it;
  357 + },
  358 + };
  359 +
  360 + that = {
  361 + add: function(name, handler, helpText){
  362 + commandStore[name] = {
  363 + handler: handler,
  364 + help: helpText
  365 + };
  366 + },
  367 +
  368 + alias: function(name, toName){
  369 + commandStore[name] = commandStore[toName];
  370 + },
  371 +
  372 + lookup: function(string){
  373 + var command, results = [];
  374 + string = string.toLowerCase();
  375 +
  376 + for (command in commandStore) {
  377 + if (commandStore.hasOwnProperty(command)){
  378 + if (command.toLowerCase().indexOf(string) === 0 && string.replace(/\s+/g, '')) {
  379 + results.push(command);
  380 + }
  381 + }
346 382 }
347   - break;
  383 + return results.sort();
  384 + },
348 385
349   - case '/nick':
350   - if (commandText[1]) {
351   - irc.socket.emit('nick', {nick : commandText[1]});
352   - }
353   - break;
354   - case '/topic':
355   - if (commandText[2]) {
356   - irc.socket.emit('topic', {name: commandText[1], topic: commandText[2]});
357   - } else {
358   - irc.socket.emit('topic', {name: irc.chatWindows.getActive().get('name'),
359   - topic: commandText[1]});
360   - }
361   - break;
362   - case '/me':
363   - irc.socket.emit('action', {
364   - target: irc.chatWindows.getActive().get('name'),
365   - message: commandText.splice(1).join(" ")
366   - });
367   - break;
368   - case '/query':
369   - case '/privmsg':
370   - case '/msg':
371   - var target = commandText[1].toLowerCase();
372   - var myNick = irc.me.get('nick');
373   - if (typeof irc.chatWindows.getByName(target) === 'undefined') {
374   - irc.chatWindows.add({name: target, type: 'pm'});
  386 + handle: function(args){
  387 + var command = args[0];
  388 + var handler = commandStore[command] && commandStore[command].handler;
  389 +
  390 + args.splice(0, 1);
  391 +
  392 + if (typeof(handler) === 'function'){
  393 + handler(args, command);
375 394 }
376   - irc.socket.emit('getOldMessages',{channelName: target, skip:0, amount: 50});
377   - irc.socket.emit('say', {
378   - target: target,
379   - message: commandText.splice(2).join(" ")
380   - });
381   - break;
382   - default:
383   - commandText[0] = commandText[0].substr(1).toUpperCase();
384   - irc.socket.emit('command', commandText);
  395 + }
  396 + };
  397 +
  398 + return that;
  399 +
  400 + }());
  401 +
  402 + irc.commands.add('join', function(args){
  403 + irc.socket.emit('join', args[0]);
  404 + });
  405 +
  406 + irc.commands.add('part', function(args){
  407 + if (args[0]) {
  408 + irc.socket.emit('part', args[0]);
  409 + irc.appView.channelList.channelTabs[0].setActive();
  410 + } else {
  411 + irc.socket.emit('part', irc.chatWindows.getActive().get('name'));
  412 + irc.appView.channelList.channelTabs[0].setActive();
  413 + }
  414 + });
  415 + irc.commands.alias('wc', 'part');
  416 + irc.commands.alias('close', 'part');
  417 +
  418 + irc.commands.add('nick', function(args){
  419 + if (args[0]) {
  420 + irc.socket.emit('nick', {nick : args[0]});
  421 + }
  422 + });
  423 +
  424 + irc.commands.add('topic', function(args){
  425 + if (args[1]) {
  426 + irc.socket.emit('topic', {name: args[0], topic: args[1]});
  427 + } else {
  428 + irc.socket.emit('topic', {name: irc.chatWindows.getActive().get('name'),
  429 + topic: args[0]});
385 430 }
386   - };
  431 + });
  432 +
  433 + irc.commands.add('whois', function(args){
  434 + if (args[0]){
  435 + irc.socket.emit('whois', {nick: args[0]});
  436 + }
  437 + });
  438 +
  439 + irc.commands.add('me', function(args){
  440 + irc.socket.emit('action', {
  441 + target: irc.chatWindows.getActive().get('name'),
  442 + message: args.join(" ")
  443 + });
  444 + });
  445 +
  446 + irc.commands.add('query', function(args){
  447 + var target = args[0].toLowerCase();
  448 + var myNick = irc.me.get('nick');
  449 + if (typeof irc.chatWindows.getByName(target) === 'undefined') {
  450 + irc.chatWindows.add({name: target, type: 'pm'});
  451 + }
  452 + irc.socket.emit('getOldMessages',{channelName: target, skip:0, amount: 50});
  453 + irc.socket.emit('say', {
  454 + target: target,
  455 + message: args.splice(1).join(" ")
  456 + });
  457 + });
  458 + irc.commands.alias('msg', 'query');
  459 + irc.commands.alias('privmsg', 'query');
  460 +
  461 + irc.commands.add('default', function(args, command){
  462 + command = command.substr(1).toUpperCase();
  463 + args.unshift(command);
  464 + irc.socket.emit('command', args);
  465 + });
387 466
388 467 });
389 468
8 assets/js/views/chat.js
@@ -39,8 +39,8 @@ var ChatView = Backbone.View.extend({
39 39 $('#chat-button').click( function(){
40 40 var message = $('#chat-input').val();
41 41 if (message.substr(0, 1) === '/') {
42   - var commandText = message.split(' ');
43   - irc.handleCommand(commandText);
  42 + var commandText = message.substr(1).split(' ');
  43 + irc.commands.handle(commandText);
44 44 } else {
45 45 irc.socket.emit('say', {target: irc.chatWindows.getActive().get('name'), message:message});
46 46 }
@@ -75,8 +75,8 @@ var ChatView = Backbone.View.extend({
75 75 var message = $(this).val();
76 76 // Handle IRC commands
77 77 if (message.substr(0, 1) === '/') {
78   - var commandText = message.split(' ');
79   - irc.handleCommand(commandText);
  78 + var commandText = message.substr(1).split(' ');
  79 + irc.commands.handle(commandText);
80 80 } else {
81 81 // Send the message
82 82 console.log(irc.chatWindows.getActive().get('name'));
1  lib/irclink.js
@@ -60,6 +60,7 @@ var IRCLink = function(hostname, port, ssl, selfSigned, nick, realName, password
5 lib/socket.js
@@ -140,6 +140,11 @@ module.exports = function(socket, connections) {
140 140 );
141 141 });
142 142
  143 + socket.removeAllListeners('whois');
  144 + socket.on('whois', function(data) {
  145 + connection.client.whois(data.nick);
  146 + });
  147 +
143 148 socket.removeAllListeners('topic');
144 149 socket.on('topic', function(data){
145 150 connection.client.send('TOPIC ', data.name, data.topic);

No commit comments for this range

Something went wrong with that request. Please try again.