diff options
author | Joe Robinson <joe@lc8n.com> | 2016-10-16 22:34:58 +0100 |
---|---|---|
committer | Joe Robinson <joe@lc8n.com> | 2016-10-16 22:34:58 +0100 |
commit | ac48b1195c4cd68f716e4119181c720cc9ec8b4f (patch) | |
tree | 0d5555edaca816fe175bbf129838d33f44dfb836 /handlers.js | |
parent | e0840642f1710a5f50d3508d3fe661fdc17d9d56 (diff) |
Handle error and server messages
Diffstat (limited to 'handlers.js')
-rw-r--r-- | handlers.js | 112 |
1 files changed, 106 insertions, 6 deletions
diff --git a/handlers.js b/handlers.js index 24b783c..9142f04 100644 --- a/handlers.js +++ b/handlers.js @@ -18,7 +18,7 @@ module.exports.handleCommands = function(myClient) { }); }); client.on('message', function(event) { - receiveMsg(event.target, event.nick, event.message) + receiveMsg(event.target, event.nick, event.message, event.from_server) }) client.on('userlist', function(event) { @@ -48,17 +48,31 @@ module.exports.handleCommands = function(myClient) { channel = event.channel topic = event.topic //TODO: Handle topicsetby to add the user and time for the topic - nick = "vov" - time = "vov" var chatTab = $("[data-tab='"+ channel +"'].chat"); if($(".ui.tab[data-tab='"+channel+"']").length == 0) { commands.joinChannel(channel, false) } - chatTab.append("<p class='chat-line'>Topic for "+channel+" is "+topic+" - set by "+nick+" at "+time+"</p>") + chatTab.append("<p class='chat-line'>Topic for "+channel+" is "+topic+"</p>") var topicTab = $("[data-tab='"+ channel +"'].topic"); topicTab.html("<p class='topic-line'>"+topic+"</p>") }) + client.on('topicsetby', function(event) { + channel = event.channel + nick = event.nick + timestamp = event.when + + //TODO: Handle topicsetby to add the user and time for the topic + + var chatTab = $("[data-tab='"+ channel +"'].chat"); + if($(".ui.tab[data-tab='"+channel+"']").length == 0) { + commands.joinChannel(channel, false) + } + chatTab.append("<p class='chat-line'>Set by "+nick+" at "+timestamp+"</p>") + var topicLine = $("[data-tab='"+ channel +"'].topic .topic-line"); + topicLine.append(" by " + nick + " at " + timestamp) + }) + client.on('whois', function(event) { var nick = event.nick var chatTab = $(".active .chat"); @@ -160,7 +174,7 @@ module.exports.handleCommands = function(myClient) { modeLine = " removes channel half-operator status from " + argument; } else if (mode == "-q") { modeLine = " removes channel owner status from " + argument; - } else if (argument == myNick) { + } else if (argument == globals.myNick) { modeLine = " sets mode " + mode + " on " + argument; } else if (argument != null) { modeLine = " sets mode " + mode + " " + argument + " on " +channel; @@ -190,9 +204,90 @@ module.exports.handleCommands = function(myClient) { } }) + client.on('motd', function(event) { + serverMsg(event.motd) + }) + + //Server Info + //eg: Your host is irc.lc8n.com, running version Unreal3.2.10.4" + //param 0 is your nick + client.on('002', function(event) { + serverMsg(event.params[1]) + }) + + //Server created + //eg Your host is irc.lc8n.com, running version Unreal3.2.10.4" + //param 0 is your nick + client.on('003', function(event) { + serverMsg(event.params[1]) + }) + + //004: Some unknown server strings + client.on('004', function(event) { + serverMsg(event.params[1] + " " + event.params[2] + " " + event.params[3] + " " + event.params[4]) + }) + //Users online + //eg: There are 7 users and 47 invisible on 4 servers + client.on('251', function(event) { + serverMsg(event.params[1]) + }) + + //Operators online + //eg: "10" "operator(s) online" + client.on('252', function(event) { + serverMsg(event.params[1] + " " +event.params[2]) + }) + + //Channels formed + //eg "49" "channels formed" + client.on('254', function(event) { + serverMsg(event.params[1] + " " +event.params[2]) + }) + + //'Clients' and 'Servers'? + //eg "I have 8 clients and 1 servers" + client.on('255', function(event) { + serverMsg(event.params[1]) + }) + + //User stats + //eg ""Current global users 54, max 63" + //param 0 is your nick, 1 is current users, 2 is max users + client.on('266', function(event) { + serverMsg(event.params[3]) + }) + + client.on('irc error', function(event) { + errorMsg(event.error, event.reason, event.channel) + }); + + //No such channel error + client.on('403', function(event) { + errorMsg("403", event.params[2], event.params[1]) + }); } -function receiveMsg(target, from, message) { + +function errorMsg(error, message, param) { + var chatTab = $(".active .chat"); + + chatTab.append("<p class='chat-line'>Error: "+error+"!</p>"); + if (param.length > 0) { + chatTab.append("<p class='chat-line'>Param: "+param+"</p>"); + } + if (message.length > 0) { + chatTab.append("<p class='chat-line'>Message: "+message+"</p>"); + } + chatTab.scrollTop(chatTab.prop("scrollHeight")); + console.log('error: ', error); +} +function serverMsg(message) { + var statusTab = $("[data-tab=status].chat"); + statusTab.append("<p class='chat-line'>"+message+"</p>") + statusTab.scrollTop(statusTab.prop("scrollHeight")); +} + +function receiveMsg(target, from, message, from_server) { // message = message.autoLink( { // callback: function(url) { // return /\.(gif|png|jpe?g)$/i.test(url) ? '<img src="' + url + '">' : null; @@ -200,6 +295,11 @@ function receiveMsg(target, from, message) { // target: "_blank" // }); // console.log(message.autoLink()); + + if (from_server) { + serverMsg(message) + return false + } numChans = globals.channels.length console.log(from + ' => '+ target +': ' + message); |