From 60b2520abe1f8ed3f334890330c5fe2e2b0bf0a7 Mon Sep 17 00:00:00 2001 From: Joe Robinson Date: Wed, 30 Mar 2016 14:04:27 +0100 Subject: Server message, topic, kick, quit, kill, whois, channel list support etc --- index.js | 163 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++------ style.css | 15 ++++-- 2 files changed, 158 insertions(+), 20 deletions(-) diff --git a/index.js b/index.js index 70eb620..f4fc162 100644 --- a/index.js +++ b/index.js @@ -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("
"); chanTab.append("
"); + chanTab.append("
"); + $('.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("

"+motd+"

") + statusTab.scrollTop(statusTab.prop("scrollHeight")); }); client.addListener('raw', function(message) { var statusTab = $("[data-tab=status].chat"); - statusTab.append("

"+message.command+message.args+"

") - 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("

"+message.args+"

") + 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("

"+nick+" left #"+channel+"

") + 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("

"+nick+" quit ("+reason+")

") + 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("

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

") + 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("

"+nick+"was kicked from #"+channel+" by "+by+" ("+reason+")

") + 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("

"+nick+" was killed by the server ("+reason+")

") + 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("

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) + 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("

"+by+modeLine+"

"); + 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("

"+by+modeLine+"

"); + chatTab.scrollTop(chatTab.prop("scrollHeight")); +}); + +client.addListener('channellist', function(channelList) { + var statusTab = $("[data-tab=status].chat"); + statusTab.append("

Channel List:

") + for (i in channelList) { + if (channelList[i].topic == null) { + statusTab.append("

"+channelList[i].name+" ("+channelList[i].users+")

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

"+channelList[i].name+" ("+channelList[i].users+") : "+channelList[i].topic+"

"); + } + statusTab.scrollTop(statusTab.prop("scrollHeight")); + } +}); // client.addListener('message#wtest', function (from, message) { // console.log(from + ' => #wtest: ' + message); // var chanTab = $("[data-tab=chan-wtest].chat"); diff --git a/style.css b/style.css index cd7e10a..d196b54 100644 --- a/style.css +++ b/style.css @@ -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; -- cgit v1.2.3