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 --- index.js | 104 +++++---------------------------------------------------------- 1 file changed, 7 insertions(+), 97 deletions(-) (limited to 'index.js') 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