diff options
author | lassulus <lassulus@googlemail.com> | 2013-11-11 18:05:25 +0100 |
---|---|---|
committer | lassulus <lassulus@googlemail.com> | 2013-11-11 18:05:25 +0100 |
commit | bc0a0e1ec282bcfc7aa2ef9eb444b2403d0c7199 (patch) | |
tree | 5702abe66d226370e58f721679b2253760fd7737 /webchat | |
parent | d577b700aa39c6dba270cbc9c11f3777866d4a69 (diff) |
webchat: refactor into serverCommands.js
Diffstat (limited to 'webchat')
-rw-r--r-- | webchat/index.js | 24 | ||||
-rw-r--r-- | webchat/serverCommands.js | 26 |
2 files changed, 27 insertions, 23 deletions
diff --git a/webchat/index.js b/webchat/index.js index cf045912..8a669d84 100644 --- a/webchat/index.js +++ b/webchat/index.js @@ -4,6 +4,7 @@ var http = require('https'); var sockjs = require('sockjs'); var connect = require('connect'); var irc = require('irc'); +var serverCommands = require('./serverCommands.js'); var serverstate = { connected = false, @@ -24,29 +25,6 @@ clients.notifyAll = function (method, params) { } -var serverCommands = {}; - -serverCommands.say = function (settings, params) { - var nick = settings.nick - var message = params.msg - params.nick = nick - irc_client.say("#krebs", nick + ' → ' + message); - return clients.notifyAll('message', params) -// return clients.broadcast({ method: 'message', params: params }) - -} - -serverCommands.nick = function (settings, params) { - var oldnick = settings.nick || settings.conn.remoteAddress - var newnick = params.nick - settings.nick = newnick - return clients.notifyAll('nickchange', { nick: oldnick, newnick: newnick }); -// return clients.broadcast({ method: 'nickchange', params: { nick: oldnick, newnick: newnick }}) -} - -serverCommands.badcommand = function (settings, params) { - settings.conn.write(JSON.stringify({ method: 'usererror', params: { message: 'bad command' }})) -} var irc_reconnect = function() { //reconnt to irc console.log("reconnecting due to pingtimeout"); diff --git a/webchat/serverCommands.js b/webchat/serverCommands.js new file mode 100644 index 00000000..05c9ea0e --- /dev/null +++ b/webchat/serverCommands.js @@ -0,0 +1,26 @@ + + +var serverCommands = {}; +serverCommands.say = function (settings, params) { + var nick = settings.nick + var message = params.msg + params.nick = nick + irc_client.say("#krebs", nick + ' → ' + message); + return clients.notifyAll('message', params) +// return clients.broadcast({ method: 'message', params: params }) + +} + +serverCommands.nick = function (settings, params) { + var oldnick = settings.nick || settings.conn.remoteAddress + var newnick = params.nick + settings.nick = newnick + return clients.notifyAll('nickchange', { nick: oldnick, newnick: newnick }); +// return clients.broadcast({ method: 'nickchange', params: { nick: oldnick, newnick: newnick }}) +} + +serverCommands.badcommand = function (settings, params) { + settings.conn.write(JSON.stringify({ method: 'usererror', params: { message: 'bad command' }})) +} + +module.exports = serverCommands |