diff options
author | Joe Robinson <joe@grabyo.com> | 2016-03-31 14:22:57 +0100 |
---|---|---|
committer | Joe Robinson <joe@grabyo.com> | 2016-03-31 14:22:57 +0100 |
commit | 61a590751e1407cdecf0503433e8c01824a14805 (patch) | |
tree | d594b1fab8eafaf8c47ca144d94fff9938df775c | |
parent | 65a6fc4dfdff2ad58966178029bfd0152d0eab86 (diff) |
Add ability to send PMs with /msg, fixed bug with channel messages
-rw-r--r-- | index.js | 29 |
1 files changed, 25 insertions, 4 deletions
@@ -70,10 +70,16 @@ $("#send-message").keypress(function(e) { client.whois(message.substring(7, message.length)); } else if (message.indexOf("/list") == 0) { client.list(); + } else if (message.indexOf("/msg") == 0) { + nick = message.split(" ")[1]; + message = message.substring(6+nick.length, message.length); + console.log(nick); + console.log(message); + sendPm(message, nick); } else { var tab = $(".tab.active").attr("data-tab"); if (tab.startsWith("chan-")) { - sendMsg(message, channel.replace("#","")); + sendMsg(message, channel); } else if(tab.startsWith("pm-")){ sendPm(message, tab.substring(3, tab.length)); @@ -92,18 +98,33 @@ function sendMsg(message, channel) { } function sendPm(message, nick) { + + var chanTab = $("[data-tab=pm-"+nick+"].tab"); + $(".active").removeClass("active"); + if (chanTab.length == 0) { + $(".ui.menu").append("<a class='active item' data-id='"+numChans+"' data-tab='pm-"+nick+"'>"+nick+"</a>"); + $("#chan-container").append("<div class='ui active tab' data-id='"+numChans+"' data-tab='pm-"+nick+"'></div>"); + chanTab = $("[data-tab=pm-"+nick+"].tab"); + chanTab.append("<div class='ui segment chat' data-id='"+numChans+"' data-tab='pm-"+nick+"'></div>"); + + $('.menu .item').tab({history:false}); + numChans++; + } + $("[data-tab=pm-"+nick+"]").addClass("active"); + var chatTab = $("[data-tab=pm-"+nick+"].chat"); console.log(nick + ': ' + message); client.say(nick, message); - var chanTab = $("[data-tab=pm-"+nick+"].chat"); - chanTab.append("<p class='chat-line'><" + "wclient" + "> " + message +"</p>"); - chanTab.scrollTop(chanTab.prop("scrollHeight")); + chatTab.append("<p class='chat-line'><" + myNick + "> " + message +"</p>"); + chatTab.scrollTop(chanTab.prop("scrollHeight")); } function joinChannel(channel) { client.join(channel); channel = channel.replace("#",""); chanId = $(".active.chat").attr("data-id") + $(".active").removeClass("active"); + $(".ui.menu").append("<a class='active item' data-id='"+numChans+"' data-tab='chan-"+channel+"'>#"+channel+"</a>"); $("#chan-container").append("<div class='ui active tab' data-id='"+numChans+"' data-tab='chan-"+channel+"'></div>"); |