diff options
author | Joe Robinson <joe@lc8n.com> | 2016-10-16 20:38:10 +0100 |
---|---|---|
committer | Joe Robinson <joe@lc8n.com> | 2016-10-16 20:38:10 +0100 |
commit | 63405f05a0406e55daf1fb4bfb00b324f2bf5f7e (patch) | |
tree | 2930a5475b06e4b40462319b955e1d634ee5c5e3 /index.js | |
parent | f88564402afd517c01c4bd1e8bb4d8de8afc7690 (diff) |
Fix channel list function
Diffstat (limited to 'index.js')
-rw-r--r-- | index.js | 104 |
1 files changed, 7 insertions, 97 deletions
@@ -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("<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")); -} - -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("<a class='item' data-id='"+numChans+"' data-tab='pm-"+nick+"'>"+nick+"</a>"); - $("#chan-container").append("<div class='ui tab' data-id='"+numChans+"' data-tab='pm-"+nick+"'></div>"); - var chanTab = $("[data-tab=pm-"+ nick +"].tab"); - chanTab.append("<div class='ui segment chat' data-id='"+numChans+"' data-tab='pm-"+nick+"'></div>"); - numChans++; - $('.menu .item').tab({history:false}); - } - var chatTab = $("[data-tab=pm-"+ nick +"].chat"); - chatTab.append("<p class='chat-line'><"+nick+"> "+text+"</p>") - 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("<p class='chat-line'>Topic for #"+channel+" is "+topic+" - set by "+nick+" at "+message.args[3]+"</p>") - var topicTab = $("[data-tab=chan-"+ channel +"].topic"); - topicTab.html("<p class='topic-line'>"+topic+"</p>") -}); - -client.addListener('whois', function(info) { - console.log(info) - var chatTab = $(".active .chat"); - chatTab.append("<p class='chat-line'> Nick:"+info.nick+"</p>"); - chatTab.append("<p class='chat-line'> User:"+info.user+"</p>"); - chatTab.append("<p class='chat-line'> Host:"+info.host+"</p>"); - chatTab.append("<p class='chat-line'> Real Name:"+info.realname+"</p>"); - chatTab.append("<p class='chat-line'> Channels:"); - for (channel in info.channels) { - chatTab.append(" "+info.channels[channel]) - } - chatTab.append("</p>") - chatTab.append("<p class='chat-line'> Server:"+info.server+"</p>"); - chatTab.append("<p class='chat-line'> Server Info:"+info.serverinfo+"</p>"); - chatTab.append("<p class='chat-line'>"+info.operator+"</p>"); - chatTab.scrollTop(chatTab.prop("scrollHeight")); -}); client.addListener('+mode', function(channel, by, mode, argument, message) { console.log(message) |