diff options
author | Joe Robinson <joe@lc8n.com> | 2016-10-16 19:53:23 +0100 |
---|---|---|
committer | Joe Robinson <joe@lc8n.com> | 2016-10-16 19:53:23 +0100 |
commit | 1dd55949f2d53bf48ca016ab2d4acff172c443b4 (patch) | |
tree | 629c5f9db7dae755a59a536b4acc04e897ef7fdc | |
parent | 777808182320e0584a38e2ae9fdfb6e8e7d99973 (diff) |
Fix part command, refactoring
-rw-r--r-- | commands.js | 46 | ||||
-rw-r--r-- | globals.js | 5 | ||||
-rw-r--r-- | handlers.js | 7 | ||||
-rw-r--r-- | index.js | 5 |
4 files changed, 59 insertions, 4 deletions
diff --git a/commands.js b/commands.js index b8f53f5..6bffb76 100644 --- a/commands.js +++ b/commands.js @@ -1,15 +1,48 @@ var client +var globals = require('./globals.js') module.exports.init = function(myClient) { client = myClient } +function sendMsg(message, channel) { + client.say(channel, message); + var chanTab = $("[data-tab='"+ channel +"'].chat"); + chanTab.append("<p class='chat-line'><" + myNick + "> " + message +"</p>"); + chanTab.scrollTop(chanTab.prop("scrollHeight")); +} + +function sendPm(message, nick) { + + var chanTab = $("[data-tab="+nick+"].tab"); + $(".active").removeClass("active"); + numChans = globals.channels.length + if (chanTab.length == 0) { + $(".ui.menu").append("<a class='active item' data-id='"+numChans+"' data-tab='"+nick+"'>"+nick+"</a>"); + $("#chan-container").append("<div class='ui active tab' data-id='"+numChans+"' data-tab='"+nick+"'></div>"); + chanTab = $("[data-tab="+nick+"].tab"); + chanTab.append("<div class='ui segment chat' data-id='"+numChans+"' data-tab='"+nick+"'></div>"); + + $('.menu .item').tab({history:false}); + globals.channels.push(nick) + numChans++; + } + $("[data-tab="+nick+"]").addClass("active"); + var chatTab = $("[data-tab="+nick+"].chat"); + console.log(nick + ': ' + message); + client.say(nick, message); + chatTab.append("<p class='chat-line'><" + myNick + "> " + message +"</p>"); + chatTab.scrollTop(chanTab.prop("scrollHeight")); +} + + module.exports.setTopic = function(channel, topic) { client.raw("TOPIC", channel, topic); } module.exports.joinChannel = function (channel, sendJoin) { + numChans = globals.channels.length var channelObj = client.channel(channel); if (sendJoin) { channelObj.join(); @@ -32,3 +65,16 @@ module.exports.joinChannel = function (channel, sendJoin) { numChans++; } + +function removeChannel(channel, sendPart) { + var channelObj = client.channel(channel) + chanId = $("[data-tab='"+channel+"'].chat").attr("data-id"); + $("[data-tab='"+channel+"']").remove(); + if (sendPart) { + channelObj.part(); + } + while ($("[data-id="+(chanId-1)+"]").length == 0 && chanId >=0) { + chanId--; + } + $("[data-id="+(chanId-1)+"]").addClass("active"); +} diff --git a/globals.js b/globals.js new file mode 100644 index 0000000..a0c689b --- /dev/null +++ b/globals.js @@ -0,0 +1,5 @@ +module.exports.channels = ['status'] + +module.exports.pms = [] + +module.exports.networks = [] diff --git a/handlers.js b/handlers.js index 9b956c3..ffbb4f4 100644 --- a/handlers.js +++ b/handlers.js @@ -2,8 +2,8 @@ var linkify = require("linkifyjs"); var linkifyHtml = require('linkifyjs/html'); var util = require("./util.js") var commands = require("./commands.js") - -var numChans = 1; +var globals = require("./globals.js") +var numChans = globals.channels.length + globals.pms.length; var channels; var client; var myNick = "" @@ -69,7 +69,7 @@ function receiveMsg(target, from, message) { // target: "_blank" // }); // console.log(message.autoLink()); - + numChans = globals.channels.length console.log(from + ' => '+ target +': ' + message); if (target === client.user.nick) { @@ -84,6 +84,7 @@ function receiveMsg(target, from, message) { chanTab.append("<div class='ui segment chat' data-id='"+numChans+"' data-tab='"+target+"'></div>"); $('.menu .item').tab({history:false}); + global.channels.push(target) numChans++; chatTab = $("[data-tab="+ target +"].chat"); } @@ -4,6 +4,7 @@ var config = require('./config.json') var pjson = require('./package.json'); var handlers = require('./handlers.js'); var commands = require('./commands.js'); +var globals = require('./globals.js') var debugmiddleware = require('./debugmiddleware.js'); const progName = pjson.name; const version = pjson.version; @@ -104,7 +105,7 @@ function humanize(size) { return s + ' ' + units[ord]; } -var numChans = 1; +var numChans = globals.channels.length $("#send-message").keypress(function(e) { if(e.which == 13) { var message = $("#send-message").val(); @@ -157,6 +158,7 @@ function sendPm(message, nick) { var chanTab = $("[data-tab="+nick+"].tab"); $(".active").removeClass("active"); + numChans = globals.channels.length if (chanTab.length == 0) { $(".ui.menu").append("<a class='active item' data-id='"+numChans+"' data-tab='"+nick+"'>"+nick+"</a>"); $("#chan-container").append("<div class='ui active tab' data-id='"+numChans+"' data-tab='"+nick+"'></div>"); @@ -164,6 +166,7 @@ function sendPm(message, nick) { chanTab.append("<div class='ui segment chat' data-id='"+numChans+"' data-tab='"+nick+"'></div>"); $('.menu .item').tab({history:false}); + globals.channels.push(nick) numChans++; } $("[data-tab="+nick+"]").addClass("active"); |