From 40b1c978b00911cf17dc1a7b45c10b82ce57641d Mon Sep 17 00:00:00 2001 From: Joe Robinson Date: Thu, 13 Oct 2016 22:34:21 +0100 Subject: Fix PM sending/receiving, some cleanup for messages --- handlers.js | 58 +++++++++++++++++++++++++++++++--------------------------- 1 file changed, 31 insertions(+), 27 deletions(-) (limited to 'handlers.js') diff --git a/handlers.js b/handlers.js index 938c2e2..e43a250 100644 --- a/handlers.js +++ b/handlers.js @@ -6,29 +6,24 @@ var numChans = 1; var channels; var buffers = []; var client; +var myNick = "" module.exports.setChannels = function(myChannels) { - console.log("setting channels: " + myChannels); channels = myChannels; } module.exports.handleCommands = function(myClient) { client = myClient; client.on('registered', function(event) { - console.log(event); - console.log("channels: " + channels); channels.forEach(function(channelStr) { - console.log(channelStr); joinChannel(channelStr, true); }); }); client.on('message', function(event) { - console.log(event); receiveMsg(event.target, event.nick, event.message) }) client.on('userlist', function(event) { - channel = event.channel.replace("#","") - if($(".ui.tab[data-tab=chan-"+channel+"]").length == 0) { + if($(".ui.tab[data-tab='"+channel+"']").length == 0) { joinChannel(channel, false) } event.users.forEach(function (user) { @@ -37,15 +32,14 @@ module.exports.handleCommands = function(myClient) { user.modes.forEach(function (modeChar) { if (modeChar === "o") { mode = "@" - console.log(mode) } else if (modeChar === "h") { mode = "%" } else if (modeChar === "v") { mode = "+" } }) - if($(".ui.users[data-tab=chan-"+channel+"] [data-nick="+nick+"]").length == 0) { - $(".ui.users[data-tab=chan-"+channel+"]").append("
"+mode+nick+"
") + if($(".ui.users[data-tab='"+channel+"'] [data-nick="+nick+"]").length == 0) { + $(".ui.users[data-tab='"+channel+"']").append("
"+mode+nick+"
") } }) }); @@ -53,7 +47,6 @@ module.exports.handleCommands = function(myClient) { } function joinChannel(channel, sendJoin) { - console.log("here"); var channelObj = client.channel(channel); if (sendJoin) { @@ -61,26 +54,25 @@ function joinChannel(channel, sendJoin) { channelObj.join(); channelObj.say("beep"); } - channel = channel.replace("#",""); chanId = $(".active.chat").attr("data-id") $(".active").removeClass("active"); - $(".ui.menu").append("#"+channel+""); - $("#chan-container").append("
"); + $(".ui.menu").append(""+channel+""); + $("#chan-container").append("
"); - var chanTab = $("[data-tab=chan-"+ channel +"].tab"); + var chanTab = $("[data-tab='"+ channel +"'].tab"); - chanTab.append("
"); - chanTab.append("
"); - chanTab.append("
"); + chanTab.append("
"); + chanTab.append("
"); + chanTab.append("
"); $('.menu .item').tab({history:false}); numChans++; } -function receiveMsg(channel, from, message) { +function receiveMsg(target, from, message) { // message = message.autoLink( { // callback: function(url) { // return /\.(gif|png|jpe?g)$/i.test(url) ? '' : null; @@ -88,13 +80,26 @@ function receiveMsg(channel, from, message) { // target: "_blank" // }); // console.log(message.autoLink()); - channel = channel.replace("#","") - console.log(from + ' => #'+ channel +': ' + message); - console.log($("[data-tab=chan-"+ channel +"].chat")); - var chatTab = $("[data-tab=chan-"+ channel +"].chat"); - console.log(chatTab); + + console.log(from + ' => '+ target +': ' + message); + + if (target === client.user.nick) { + target = from + } + var chatTab = $("[data-tab='"+ target +"'].chat"); + + if (chatTab.length == 0) { + $(".ui.menu").append(""+target+""); + $("#chan-container").append("
"); + chanTab = $("[data-tab="+target+"].tab"); + chanTab.append("
"); + + $('.menu .item').tab({history:false}); + numChans++; + chatTab = $("[data-tab="+ target +"].chat"); + } + message = linkifyHtml(message); - console.log(from + ' => #'+ channel +': ' + message); chatTab.append("

<" + from + "> " + message +"

"); var imgMatch = message.match(/[a-z0-9\-]+[\.:]\S+\.(gif|png|jpe?g|bmp)/); @@ -102,7 +107,7 @@ function receiveMsg(channel, from, message) { var audioMatch = message.match(/[a-z0-9\-]+[\.:]\S+\.(mp3|wav|ogg)/); var youtubeMatch = message.match(/(https?\:\/\/)?(www\.)?(youtube\.com|youtu\.be)\/(watch\?v=)?[a-z0-9A-Z_\-]+/); if (imgMatch != null && imgMatch.length > 0) { - var image = util.imagify(imgMatch[0],channel); + var image = util.imagify(imgMatch[0],target); chatTab.append("

"+image+"

"); } if (vidMatch != null && vidMatch.length > 0) { @@ -112,7 +117,6 @@ function receiveMsg(channel, from, message) { chatTab.append("

"); } if (youtubeMatch != null && youtubeMatch.length > 0) { - console.log(youtubeMatch) youtubeParts = youtubeMatch[0].split("/"); youtubeId = youtubeParts[youtubeParts.length-1]; youtubeId = youtubeId.replace("watch?v=",""); -- cgit v1.2.3