diff options
author | Joe Robinson <joe@lc8n.com> | 2016-03-30 14:04:27 +0100 |
---|---|---|
committer | Joe Robinson <joe@lc8n.com> | 2016-03-30 14:04:27 +0100 |
commit | 60b2520abe1f8ed3f334890330c5fe2e2b0bf0a7 (patch) | |
tree | 789625a0a7e5472559350b733573e68b03da34e2 | |
parent | fcaeaa8655bac6a33755de99d14ae979c07d3be7 (diff) |
Server message, topic, kick, quit, kill, whois, channel list support etc
-rw-r--r-- | index.js | 163 | ||||
-rw-r--r-- | style.css | 15 |
2 files changed, 158 insertions, 20 deletions
@@ -1,6 +1,7 @@ var linkify = require("linkifyjs"); var linkifyHtml = require('linkifyjs/html'); var shell = require('electron').shell; +const myNick = "wclient"; $(document).ready(function() { $("#send-message").focus(); @@ -11,6 +12,14 @@ $(document).on('click', 'a[href^="http"]', function(event) { shell.openExternal(this.href); }); +const irc = require('irc'); + +var channels = ["#wtest", "#wtest2"] +const client = new irc.Client('irc.blatech.net', myNick, { + channels: channels, + userName: [myNick] +}); + function imagify(url, channel) { console.log(url); $.ajax({ @@ -51,14 +60,19 @@ $("#send-message").keypress(function(e) { joinChannel(message.substring(6, message.length)); } else if (message.indexOf("/part") == 0) { if (message.length > 6) { - channel = message.substring(6, message.length) + channel = message.substring(6, message.length); } console.log() - partChannel(channel); + removeChannel(channel, true); + } else if (message.indexOf("/whois") == 0) { + console.log("whois "+message.substring(7, message.length)); + client.whois(message.substring(7, message.length)); + } else if (message.indexOf("/list") == 0) { + client.list(); } else { - var tab = $(".tab.active").attr("data-tab") + var tab = $(".tab.active").attr("data-tab"); if (tab.startsWith("chan-")) { - sendMsg(message, channel.replace("#","")) + sendMsg(message, channel.replace("#","")); } else if(tab.startsWith("pm-")){ sendPm(message, tab.substring(3, tab.length)); @@ -96,6 +110,8 @@ function joinChannel(channel) { chanTab.append("<div class='ui selection list users' data-id='"+numChans+"' data-tab='chan-"+channel+"'></div>"); chanTab.append("<div class='ui segment chat' data-id='"+numChans+"' data-tab='chan-"+channel+"'></div>"); + chanTab.append("<div class='ui topic' data-id='"+numChans+"' data-tab='chan-"+channel+"'></div>"); + $('.menu .item').tab({history:false}); @@ -139,25 +155,19 @@ function joinChannel(channel) { numChans++; } -function partChannel(channel) { +function removeChannel(channel, sendPart) { channel = channel.replace("#",""); chanId = $("[data-tab=chan-"+channel+"].chat").attr("data-id"); $("[data-tab=chan-"+channel+"]").remove(); - client.part("#"+channel); + if (sendPart) { + client.part("#"+channel); + } while ($("[data-id="+(chanId-1)+"]").length == 0 && chanId >=0) { chanId--; } $("[data-id="+(chanId-1)+"]").addClass("active"); } -const irc = require('irc'); - -var channels = ["#wtest", "#wtest2"] -const client = new irc.Client('irc.blatech.net', 'wclient', { - channels: channels, - userName: ['wclient'] -}); - client.addListener('error', function(message) { console.log('error: ', message); }); @@ -171,12 +181,16 @@ client.addListener('registered', function() { client.addListener('motd', function(motd) { var statusTab = $("[data-tab=status].chat"); statusTab.append("<p class='chat-line'>"+motd+"</p>") + statusTab.scrollTop(statusTab.prop("scrollHeight")); }); client.addListener('raw', function(message) { var statusTab = $("[data-tab=status].chat"); - statusTab.append("<p class='chat-line'>"+message.command+message.args+"</p>") - statusTab.scrollTop(statusTab.prop("scrollHeight")); + statusCmds = ["NOTICEAUTH", "rpl_welcome, rpl_yourhoust", "rpl_created", "rpl_myinfo", "rpl_isupport", "rpl_luserclient", "rpl_luserop", "rpl_luserme", "rpl_luserchannels", "rpl_localusers", "rpl_globalusers"]; + if (statusCmds.indexOf(message.command) > -1) { + statusTab.append("<p class='chat-line'>"+message.args+"</p>") + statusTab.scrollTop(statusTab.prop("scrollHeight")); + } }); client.addListener('ctcp-version', function(from, to, text, message) { @@ -210,6 +224,7 @@ client.addListener('part', function(channel, nick) { } var chatTab = $("[data-tab=chan-"+ channel +"].chat"); chatTab.append("<p class='chat-line'>"+nick+" left #"+channel+"</p>") + chatTab.scrollTop(chatTab.prop("scrollHeight")); }); client.addListener('quit', function(nick, reason, channels, message) { @@ -220,7 +235,9 @@ client.addListener('quit', function(nick, reason, channels, message) { } var chatTab = $("[data-tab=chan-"+ channel +"].chat"); chatTab.append("<p class='chat-line'>"+nick+" quit ("+reason+")</p>") + chatTab.scrollTop(chatTab.prop("scrollHeight")); }); + }); client.addListener('pm', function(nick, text, message) { @@ -235,8 +252,122 @@ client.addListener('pm', function(nick, text, message) { } 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); + } else { + channel = channel.replace("#",""); + if($(".ui.users[data-tab=chan-"+channel+"] [data-nick="+nick+"]").length > 0) { + $(".ui.users[data-tab=chan-"+channel+"] [data-nick="+nick+"]").remove(); + } + var chatTab = $("[data-tab=chan-"+ channel +"].chat"); + chatTab.append("<p class='chat-line'>"+nick+"was kicked from #"+channel+" by "+by+" ("+reason+")</p>") + chatTab.scrollTop(chatTab.prop("scrollHeight")); + } +}); + +client.addListener('kill', function(nick, reason, channels, message) { + channels.forEach(function(channel) { + channel = channel.replace("#","") + if($(".ui.users[data-tab=chan-"+channel+"] [data-nick="+nick+"]").length > 0) { + $(".ui.users[data-tab=chan-"+channel+"] [data-nick="+nick+"]").remove(); + } + var chatTab = $("[data-tab=chan-"+ channel +"].chat"); + chatTab.append("<p class='chat-line'>"+nick+" was killed by the server ("+reason+")</p>") + chatTab.scrollTop(chatTab.prop("scrollHeight")); + }); +}); + +client.addListener('topic', function(channel, topic, nick, message) { + channel = channel.replace("#",""); + var chatTab = $("[data-tab=chan-"+ channel +"].chat"); + 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) + channel = channel.replace("#","") + var chatTab = $("[data-tab=chan-"+ channel +"].chat"); + var modeLine = mode; + if (mode == "o") { + modeLine = " gives channel operator status to " + argument; + } else if (mode == "v") { + modeLine = " gives voice to " + argument; + } else if (mode == "h") { + modeLine = " gives channel half-operator status to " + argument; + } else if (mode == "q") { + modeLine = " gives channel owner status to " + argument; + } else if (argument == myNick) { + modeLine = " sets mode +" + mode + " on " + argument; + } else if (argument != null) { + modeLine = " sets mode " + mode + " " + argument + " on #" +channel; + } else { + modeLine = " sets mode +"+mode+" on #" +channel + } + var chatTab = $("[data-tab=chan-"+ channel +"].chat"); + chatTab.append("<p class='chat-line'>"+by+modeLine+"</p>"); + chatTab.scrollTop(chatTab.prop("scrollHeight")); +}); + +client.addListener('-mode', function(channel, by, mode, argument, message) { + channel = channel.replace("#","") + var chatTab = $("[data-tab=chan-"+ channel +"].chat"); + var modeLine = mode; + if (mode == "o") { + modeLine = " removes channel operator status from "; + } else if (mode == "v") { + modeLine = " removes voice from "; + } else if (mode == "h") { + modeLine = " removes channel half-operator status from "; + } else if (mode == "q") { + modeLine = " removes channel owner status from "; + } else if (argument == myNick) { + modeLine = " sets mode -"+mode+" on " + argument; + } else if (argument != null) { + modeLine = " sets mode -" + mode + " " + argument + " on #" +channel; + } else { + modeLine = " sets mode -"+mode+" on #" +channel + } + var chatTab = $("[data-tab=chan-"+ channel +"].chat"); + chatTab.append("<p class='chat-line'>"+by+modeLine+"</p>"); + chatTab.scrollTop(chatTab.prop("scrollHeight")); +}); + +client.addListener('channellist', function(channelList) { + var statusTab = $("[data-tab=status].chat"); + statusTab.append("<p class='chat-line'>Channel List:</p>") + for (i in channelList) { + if (channelList[i].topic == null) { + statusTab.append("<p class='chat-line'>"+channelList[i].name+" ("+channelList[i].users+")</p>"); + } else { + statusTab.append("<p class='chat-line'>"+channelList[i].name+" ("+channelList[i].users+") : "+channelList[i].topic+"</p>"); + } + statusTab.scrollTop(statusTab.prop("scrollHeight")); + } +}); // client.addListener('message#wtest', function (from, message) { // console.log(from + ' => #wtest: ' + message); // var chanTab = $("[data-tab=chan-wtest].chat"); @@ -17,19 +17,26 @@ body { } +.ui.topic { + position: absolute; + top: 35px; + height: 30px; + margin-top:5px; + width: 100%; + padding:2px; +} .ui.segment.chat { position: absolute; - top: 35; - padding:10px; + top: 65; bottom:42px; width: 80%; - margin-top:5px; overflow-y: scroll; + margin: 0px; } .ui.users { position: absolute; - top: 35; + top: 65; right:0; padding:10px; margin:0px; |