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 +++++- handlers.js | 13 ++++++++ index.js | 104 ++++-------------------------------------------------------- 3 files changed, 29 insertions(+), 98 deletions(-) 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") +} diff --git a/handlers.js b/handlers.js index 0abb297..c4adbd7 100644 --- a/handlers.js +++ b/handlers.js @@ -82,6 +82,19 @@ module.exports.handleCommands = function(myClient) { }) + client.on('channel list', function(event) { + var statusTab = $("[data-tab='status'].chat"); + statusTab.append("

Channel List:

") + event.forEach( function(channel) { + if (channel.topic.length == 0) { + statusTab.append("

"+channel.channel+" ("+channel.num_users+")

"); + } else { + statusTab.append("

"+channel.channel+" ("+channel.num_users+") : "+channel.topic+"

"); + } + statusTab.scrollTop(statusTab.prop("scrollHeight")); + }) + }) + } function receiveMsg(target, from, message) { diff --git a/index.js b/index.js index 46eeb26..e9a6f7c 100644 --- a/index.js +++ b/index.js @@ -116,16 +116,16 @@ $("#send-message").keypress(function(e) { if (message.length > 6) { channel = message.substring(6, message.length); } - removeChannel(channel, true); + commands.removeChannel(channel, true); } else if (message.indexOf("/whois") == 0) { - console.log("whois "+message.substring(7, message.length)); - client.whois(message.substring(7, message.length)); + commands.whois(message.substring(7, message.length)) + } else if (message.indexOf("/list") == 0) { - client.list(); + commands.list(); } else if (message.indexOf("/msg") == 0) { nick = message.split(" ")[1]; message = message.substring(6+nick.length, message.length); - sendPm(message, nick); + commands.sendPm(message, nick); } else if (message.indexOf("/topic") == 0) { var channel = $(".tab.active").attr("data-tab") topic = message.substring(7, message.length); @@ -137,58 +137,16 @@ $("#send-message").keypress(function(e) { } else { var tab = $(".tab.active").attr("data-tab"); if (tab.startsWith("#")) { - sendMsg(message, channel); + commands.sendMsg(message, channel); } else { - sendPm(message, tab); + commands.sendPm(message, tab); } } $("#send-message").val(''); } }); -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")); -} - -function removeChannel(channel, sendPart) { - chanId = $("[data-tab='"+channel+"'].chat").attr("data-id"); - $("[data-tab='"+channel+"']").remove(); - if (sendPart) { - client.part(channel); - } - while ($("[data-id="+(chanId-1)+"]").length == 0 && chanId >=0) { - chanId--; - } - $("[data-id="+(chanId-1)+"]").addClass("active"); -} - function createListeners(client) { @@ -196,11 +154,6 @@ client.addListener('error', function(message) { console.log('error: ', message); }); -client.addListener('registered', function() { - channels.forEach(function(channel) { - joinChannel(channel, false); - }); -}); client.addListener('motd', function(motd) { var statusTab = $("[data-tab=status].chat"); @@ -267,21 +220,6 @@ client.addListener('quit', function(nick, reason, channels, message) { }); -client.addListener('pm', function(nick, text, message) { - - if($(".ui.tab[data-tab=pm-"+nick+"]").length == 0) { - $(".ui.menu").append(""+nick+""); - $("#chan-container").append("
"); - var chanTab = $("[data-tab=pm-"+ nick +"].tab"); - chanTab.append("
"); - numChans++; - $('.menu .item').tab({history:false}); - } - var chatTab = $("[data-tab=pm-"+ nick +"].chat"); - chatTab.append("

<"+nick+"> "+text+"

") - chatTab.scrollTop(chatTab.prop("scrollHeight")); -}); - client.addListener('kick', function(channel, nick, by, reason, message) { if (myNick == nick) { removeChannel(channel, false); @@ -308,34 +246,6 @@ client.addListener('kill', function(nick, reason, channels, message) { }); }); -client.addListener('topic', function(channel, topic, nick, message) { - channel = channel.replace("#",""); - var chatTab = $("[data-tab=chan-"+ channel +"].chat"); - if($(".ui.tab[data-tab=chan-"+channel+"]").length == 0) { - joinChannel(channel, false) - } - chatTab.append("

Topic for #"+channel+" is "+topic+" - set by "+nick+" at "+message.args[3]+"

") - var topicTab = $("[data-tab=chan-"+ channel +"].topic"); - topicTab.html("

"+topic+"

") -}); - -client.addListener('whois', function(info) { - console.log(info) - var chatTab = $(".active .chat"); - chatTab.append("

Nick:"+info.nick+"

"); - chatTab.append("

User:"+info.user+"

"); - chatTab.append("

Host:"+info.host+"

"); - chatTab.append("

Real Name:"+info.realname+"

"); - chatTab.append("

Channels:"); - for (channel in info.channels) { - chatTab.append(" "+info.channels[channel]) - } - chatTab.append("

") - chatTab.append("

Server:"+info.server+"

"); - chatTab.append("

Server Info:"+info.serverinfo+"

"); - chatTab.append("

"+info.operator+"

"); - chatTab.scrollTop(chatTab.prop("scrollHeight")); -}); client.addListener('+mode', function(channel, by, mode, argument, message) { console.log(message) -- cgit v1.2.3