diff options
-rw-r--r-- | commands.js | 8 | ||||
-rw-r--r-- | handlers.js | 112 | ||||
-rw-r--r-- | index.js | 60 |
3 files changed, 121 insertions, 59 deletions
diff --git a/commands.js b/commands.js index 138c55f..1847b74 100644 --- a/commands.js +++ b/commands.js @@ -5,14 +5,14 @@ module.exports.init = function(myClient) { client = myClient } -function sendMsg(message, channel) { +module.exports.sendMsg = function(message, channel) { client.say(channel, message); var chanTab = $("[data-tab='"+ channel +"'].chat"); - chanTab.append("<p class='chat-line'><" + myNick + "> " + message +"</p>"); + chanTab.append("<p class='chat-line'><" + globals.myNick + "> " + message +"</p>"); chanTab.scrollTop(chanTab.prop("scrollHeight")); } -function sendPm(message, nick) { +module.exports.sendPm = function(message, nick) { var chanTab = $("[data-tab="+nick+"].tab"); $(".active").removeClass("active"); @@ -31,7 +31,7 @@ function sendPm(message, nick) { var chatTab = $("[data-tab="+nick+"].chat"); console.log(nick + ': ' + message); client.say(nick, message); - chatTab.append("<p class='chat-line'><" + myNick + "> " + message +"</p>"); + chatTab.append("<p class='chat-line'><" + globals.myNick + "> " + message +"</p>"); chatTab.scrollTop(chanTab.prop("scrollHeight")); } 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); @@ -148,53 +148,15 @@ $("#send-message").keypress(function(e) { } }); -function createListeners(client) { - -client.addListener('error', function(message) { - console.log('error: ', message); -}); - - -client.addListener('motd', function(motd) { - var statusTab = $("[data-tab=status].chat"); - statusTab.append("<p class='chat-line'>"+motd+"</p>") - statusTab.scrollTop(statusTab.prop("scrollHeight")); -}); - -client.addListener('raw', function(message) { - var statusTab = $("[data-tab=status].chat"); - statusCmds = ["NOTICEAUTH", "rpl_welcome, rpl_yourhost", "rpl_created", "rpl_myinfo", "rpl_isupport", "rpl_luserclient", "rpl_luserop", "rpl_luserme", "rpl_luserchannels", "rpl_localusers", "rpl_globalusers"]; - if (statusCmds.indexOf(message.command) > -1 || message.command.startsWith("rpl_")) { - statusTab.append("<p class='chat-line'>"+message.command + ": " +message.args+"</p>") - statusTab.scrollTop(statusTab.prop("scrollHeight")); - } -}); - -client.addListener('kick', function(channel, nick, by, reason, message) { - if (myNick == nick) { - removeChannel(channel, false); - } else { - channel = channel.replace("#",""); - if($(".ui.users[data-tab=chan-"+channel+"] [data-nick="+nick+"]").length > 0) { - $(".ui.users[data-tab=chan-"+channel+"] [data-nick="+nick+"]").remove(); - } - var chatTab = $("[data-tab=chan-"+ channel +"].chat"); - chatTab.append("<p class='chat-line'>"+nick+"was kicked from #"+channel+" by "+by+" ("+reason+")</p>") - chatTab.scrollTop(chatTab.prop("scrollHeight")); - } -}); - -client.addListener('kill', function(nick, reason, channels, message) { - channels.forEach(function(channel) { - channel = channel.replace("#","") - if($(".ui.users[data-tab=chan-"+channel+"] [data-nick="+nick+"]").length > 0) { - $(".ui.users[data-tab=chan-"+channel+"] [data-nick="+nick+"]").remove(); - } - var chatTab = $("[data-tab=chan-"+ channel +"].chat"); - chatTab.append("<p class='chat-line'>"+nick+" was killed by the server ("+reason+")</p>") - chatTab.scrollTop(chatTab.prop("scrollHeight")); - }); -}); - -} +// client.addListener('kill', function(nick, reason, channels, message) { +// channels.forEach(function(channel) { +// channel = channel.replace("#","") +// if($(".ui.users[data-tab=chan-"+channel+"] [data-nick="+nick+"]").length > 0) { +// $(".ui.users[data-tab=chan-"+channel+"] [data-nick="+nick+"]").remove(); +// } +// var chatTab = $("[data-tab=chan-"+ channel +"].chat"); +// chatTab.append("<p class='chat-line'>"+nick+" was killed by the server ("+reason+")</p>") +// chatTab.scrollTop(chatTab.prop("scrollHeight")); +// }); +// }); |