diff options
-rw-r--r-- | CHANGELOG | 8 | ||||
-rw-r--r-- | handlers.js | 107 | ||||
-rw-r--r-- | index.js | 48 | ||||
-rw-r--r-- | util.js | 31 |
4 files changed, 146 insertions, 48 deletions
@@ -1,4 +1,4 @@ -0.1.0 +0.0.1 ----- - Initial alpha release with basic IRC functionality and commands - Support /join and /part of channels @@ -7,13 +7,13 @@ - Can send /whois and channel /list commands - Interpret join, part, quit, kill, kick, and mode messages - Display topics and user lists in channels -0.1.1 +0.0.2 ----- - Added ability to send PMs with /msg -0.2.0 +0.1.0 ----- - Added basic connection UI at startup (automatically populated from config.json) -0.2.1 +0.1.1 ----- - Create channel tab when names list is received, to support bouncers - Added SSL connection option diff --git a/handlers.js b/handlers.js index 88259c7..b2437bc 100644 --- a/handlers.js +++ b/handlers.js @@ -1,9 +1,30 @@ -module.exports.handleCommands = function(client) { +var linkify = require("linkifyjs"); +var linkifyHtml = require('linkifyjs/html'); +var util = require("./util.js") +var numChans = 1; +var channels; +var buffers = []; +var client; +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("messsagee + " + event.message) + console.log(event); + receiveMsg(event.target, event.nick, event.message) + }) client.on('userlist', function(event) { console.log(event); channel = event.channel.replace("#","") @@ -19,4 +40,86 @@ module.exports.handleCommands = function(client) { } } }); + +} + +function joinChannel(channel, sendJoin) { + console.log("here"); + if (sendJoin) { + var channelObj = client.channel(channel); + buffers.push(channelObj); + channelObj.join(); + channelObj.say("beep"); + } + channel = channel.replace("#",""); + chanId = $(".active.chat").attr("data-id") + + $(".active").removeClass("active"); + + $(".ui.menu").append("<a class='active item' data-id='"+numChans+"' data-tab='chan-"+channel+"'>#"+channel+"</a>"); + $("#chan-container").append("<div class='ui active tab' data-id='"+numChans+"' data-tab='chan-"+channel+"'></div>"); + + var chanTab = $("[data-tab=chan-"+ channel +"].tab"); + + chanTab.append("<div class='ui selection list users' data-id='"+numChans+"' data-tab='chan-"+channel+"'></div>"); + chanTab.append("<div class='ui segment chat' data-id='"+numChans+"' data-tab='chan-"+channel+"'></div>"); + chanTab.append("<div class='ui topic' data-id='"+numChans+"' data-tab='chan-"+channel+"'></div>"); + + $('.menu .item').tab({history:false}); + + channelObj.updateUserList(function() { + channel = event.channel.replace("#","") + console.log(channel); + if($(".ui.tab[data-tab=chan-"+channel+"]").length == 0) { + console.log("there"); + } + for(nick in channelObj.users) { + if($(".ui.users[data-tab=chan-"+channel+"] [data-nick="+nick+"]").length == 0) { + $(".ui.users[data-tab=chan-"+channel+"]").append("<div class=item data-nick="+nick+">"+nick+"</div>") + } + } + }) + numChans++; +} + +function receiveMsg(channel, from, message) { + // message = message.autoLink( { + // callback: function(url) { + // return /\.(gif|png|jpe?g)$/i.test(url) ? '<img src="' + url + '">' : null; + // }, + // 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); + message = linkifyHtml(message); + console.log(from + ' => #'+ channel +': ' + message); + + chatTab.append("<p class='chat-line'><" + from + "> " + message +"</p>"); + var imgMatch = message.match(/[a-z0-9\-]+[\.:]\S+\.(gif|png|jpe?g|bmp)/); + var vidMatch = message.match(/[a-z0-9\-]+[\.:]\S+\.(webm|mp4)/); + 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); + chatTab.append("<p class=chat-line>"+image+"</p>"); + } + if (vidMatch != null && vidMatch.length > 0) { + chatTab.append("<p class=chat-line><video controls><source src="+vidMatch[0]+"></video></p>"); + } + if (audioMatch != null && audioMatch.length > 0) { + chatTab.append("<p class=chat-line><audio controls><source src="+audioMatch[0]+"></audio></p>"); + } + if (youtubeMatch != null && youtubeMatch.length > 0) { + console.log(youtubeMatch) + youtubeParts = youtubeMatch[0].split("/"); + youtubeId = youtubeParts[youtubeParts.length-1]; + youtubeId = youtubeId.replace("watch?v=",""); + chatTab.append("<p class=chat-line><iframe width='480' height='270' src='https://www.youtube.com/embed/"+youtubeId+"' frameborder='0' allowfullscreen></iframe></p>"); + } + + chatTab.scrollTop(chatTab.prop("scrollHeight")); } @@ -1,5 +1,4 @@ -var linkify = require("linkifyjs"); -var linkifyHtml = require('linkifyjs/html'); + var shell = require('electron').shell; var config = require('./config.json') var pjson = require('./package.json'); @@ -49,6 +48,7 @@ console.log($("#channel-input").val()); ssl = ($("#ssl-input:checked").val() == "on"); console.log(ssl); client.use(debugmiddleware.DebugMiddleware()); + console.log(server) client.connect({ host: server, port: port, @@ -57,12 +57,15 @@ console.log($("#channel-input").val()); gecos: myNick, password: password, tls: ssl, - rejectUnauthorized: false + rejectUnauthorized: false, + version: "blachat 0.1.3" }); + handlers.setChannels(channels); handlers.handleCommands(client); + $("#chan-container").show(); $("#message").show(); $("#connect-container").hide(); @@ -200,45 +203,6 @@ function joinChannel(channel, sendJoin) { $('.menu .item').tab({history:false}); - - client.addListener('message#'+channel, function (from, message) { - // message = message.autoLink( { - // callback: function(url) { - // return /\.(gif|png|jpe?g)$/i.test(url) ? '<img src="' + url + '">' : null; - // }, - // target: "_blank" - // }); - // console.log(message.autoLink()); - console.log(from + ' => #'+ channel +': ' + message); - var chatTab = $("[data-tab=chan-"+ channel +"].chat"); - message = linkifyHtml(message); - - chatTab.append("<p class='chat-line'><" + from + "> " + message +"</p>"); - var imgMatch = message.match(/[a-z0-9\-]+[\.:]\S+\.(gif|png|jpe?g|bmp)/); - var vidMatch = message.match(/[a-z0-9\-]+[\.:]\S+\.(webm|mp4)/); - 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 = imagify(imgMatch[0],channel); - chatTab.append("<p class=chat-line>"+image+"</p>"); - } - if (vidMatch != null && vidMatch.length > 0) { - chatTab.append("<p class=chat-line><video controls><source src="+vidMatch[0]+"></video></p>"); - } - if (audioMatch != null && audioMatch.length > 0) { - chatTab.append("<p class=chat-line><audio controls><source src="+audioMatch[0]+"></audio></p>"); - } - if (youtubeMatch != null && youtubeMatch.length > 0) { - console.log(youtubeMatch) - youtubeParts = youtubeMatch[0].split("/"); - youtubeId = youtubeParts[youtubeParts.length-1]; - youtubeId = youtubeId.replace("watch?v=",""); - chatTab.append("<p class=chat-line><iframe width='480' height='270' src='https://www.youtube.com/embed/"+youtubeId+"' frameborder='0' allowfullscreen></iframe></p>"); - } - - chatTab.scrollTop(chatTab.prop("scrollHeight")); - }); - numChans++; } function removeChannel(channel, sendPart) { @@ -0,0 +1,31 @@ + +module.exports.imagify = function(url, channel) { + console.log(url); + $.ajax({ + type: 'HEAD', + url: url, + complete: function(xhr) { + var type = xhr.getResponseHeader('Content-Type') + var size = xhr.getResponseHeader('Content-Length'); + console.log(type); + console.log(size); + if (size < 10000000) { + $("[data-img='"+url+"']").append("("+humanize(size)+")"); + $("[data-img='"+url+"']").append("<p class='chat-line'><img src="+url+" onload=scrollToTop('"+channel+"')></p>"); + $("[data-img='"+url+"']").removeClass("loading"); + + } + + } + }); + + return "<div data-img='"+url+"' class='ui image loading'></div>"; + +} + +humanize = function(size) { + var units = ['bytes', 'kB', 'MB', 'GB', 'TB', 'PB']; + var ord = Math.floor(Math.log(size) / Math.log(1000)); + var s = Math.round((size / Math.pow(1000, ord)) * 100) / 100; + return s + ' ' + units[ord]; +} |