From 777808182320e0584a38e2ae9fdfb6e8e7d99973 Mon Sep 17 00:00:00 2001 From: Joe Robinson Date: Sat, 15 Oct 2016 20:59:27 +0100 Subject: Move set topic and join channel functions to commands.js --- commands.js | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 commands.js (limited to 'commands.js') diff --git a/commands.js b/commands.js new file mode 100644 index 0000000..b8f53f5 --- /dev/null +++ b/commands.js @@ -0,0 +1,34 @@ +var client + +module.exports.init = function(myClient) { + client = myClient +} + +module.exports.setTopic = function(channel, topic) { + client.raw("TOPIC", channel, topic); +} + +module.exports.joinChannel = function (channel, sendJoin) { + + var channelObj = client.channel(channel); + if (sendJoin) { + channelObj.join(); + channelObj.say("beep"); + } + chanId = $(".active.chat").attr("data-id") + + $(".active").removeClass("active"); + + $(".ui.menu").append(""+channel+""); + $("#chan-container").append("
"); + + var chanTab = $("[data-tab='"+ channel +"'].tab"); + + chanTab.append("
"); + chanTab.append("
"); + chanTab.append("
"); + + $('.menu .item').tab({history:false}); + + numChans++; +} -- cgit v1.2.3 From 1dd55949f2d53bf48ca016ab2d4acff172c443b4 Mon Sep 17 00:00:00 2001 From: Joe Robinson Date: Sun, 16 Oct 2016 19:53:23 +0100 Subject: Fix part command, refactoring --- commands.js | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) (limited to 'commands.js') 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("

<" + myNick + "> " + message +"

"); + 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(""+nick+""); + $("#chan-container").append("
"); + chanTab = $("[data-tab="+nick+"].tab"); + chanTab.append("
"); + + $('.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("

<" + myNick + "> " + message +"

"); + 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"); +} -- cgit v1.2.3 From 63405f05a0406e55daf1fb4bfb00b324f2bf5f7e Mon Sep 17 00:00:00 2001 From: Joe Robinson Date: Sun, 16 Oct 2016 20:38:10 +0100 Subject: Fix channel list function --- commands.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'commands.js') diff --git a/commands.js b/commands.js index 6bffb76..5ab1d5e 100644 --- a/commands.js +++ b/commands.js @@ -66,7 +66,7 @@ module.exports.joinChannel = function (channel, sendJoin) { numChans++; } -function removeChannel(channel, sendPart) { +module.exports.removeChannel = function(channel, sendPart) { var channelObj = client.channel(channel) chanId = $("[data-tab='"+channel+"'].chat").attr("data-id"); $("[data-tab='"+channel+"']").remove(); @@ -78,3 +78,11 @@ function removeChannel(channel, sendPart) { } $("[data-id="+(chanId-1)+"]").addClass("active"); } + +module.exports.whois = function(nick) { + client.whois(nick); +} + +module.exports.list = function() { + client.raw("LIST") +} -- cgit v1.2.3 From f13842bc63f002e456727d1a48239d4e044d0c75 Mon Sep 17 00:00:00 2001 From: Joe Robinson Date: Sun, 16 Oct 2016 21:05:57 +0100 Subject: Add join, part, and quit handlers --- commands.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'commands.js') diff --git a/commands.js b/commands.js index 5ab1d5e..59be364 100644 --- a/commands.js +++ b/commands.js @@ -62,7 +62,7 @@ module.exports.joinChannel = function (channel, sendJoin) { chanTab.append("
"); $('.menu .item').tab({history:false}); - + globals.channels.push(channel) numChans++; } -- cgit v1.2.3 From e0840642f1710a5f50d3508d3fe661fdc17d9d56 Mon Sep 17 00:00:00 2001 From: Joe Robinson Date: Sun, 16 Oct 2016 21:41:00 +0100 Subject: Add kick handler --- commands.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'commands.js') diff --git a/commands.js b/commands.js index 59be364..138c55f 100644 --- a/commands.js +++ b/commands.js @@ -67,10 +67,11 @@ module.exports.joinChannel = function (channel, sendJoin) { } module.exports.removeChannel = function(channel, sendPart) { - var channelObj = client.channel(channel) + chanId = $("[data-tab='"+channel+"'].chat").attr("data-id"); $("[data-tab='"+channel+"']").remove(); if (sendPart) { + var channelObj = client.channel(channel) channelObj.part(); } while ($("[data-id="+(chanId-1)+"]").length == 0 && chanId >=0) { -- cgit v1.2.3 From ac48b1195c4cd68f716e4119181c720cc9ec8b4f Mon Sep 17 00:00:00 2001 From: Joe Robinson Date: Sun, 16 Oct 2016 22:34:58 +0100 Subject: Handle error and server messages --- commands.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'commands.js') 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("

<" + myNick + "> " + message +"

"); + chanTab.append("

<" + globals.myNick + "> " + message +"

"); 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("

<" + myNick + "> " + message +"

"); + chatTab.append("

<" + globals.myNick + "> " + message +"

"); chatTab.scrollTop(chanTab.prop("scrollHeight")); } -- cgit v1.2.3