From f3d0c81c7b004218665ab1123fb6c8915b190ce0 Mon Sep 17 00:00:00 2001 From: Joe Robinson Date: Wed, 8 Jun 2016 00:13:12 +0100 Subject: WIP adding irc-framework, debugging --- index.js | 39 ++++++++++++++++++++++++++------------- 1 file changed, 26 insertions(+), 13 deletions(-) (limited to 'index.js') diff --git a/index.js b/index.js index 96ce9dd..a21b00e 100644 --- a/index.js +++ b/index.js @@ -3,10 +3,15 @@ var linkifyHtml = require('linkifyjs/html'); var shell = require('electron').shell; var config = require('./config.json') var pjson = require('./package.json'); +var handlers = require('./handlers.js'); + +var debugmiddleware = require('./debugmiddleware.js'); const progName = pjson.name; const version = pjson.version; var myNick = config.nick; - +var server = config.server; +var port = config.port; +var password = config.password; $(document).ready(function() { $("#send-message").focus(); }); @@ -17,6 +22,8 @@ $(document).on('click', 'a[href^="http"]', function(event) { }); const irc = require('irc'); +const IRC = require('irc-framework'); +const client = new IRC.Client() $("#server-input").val(config.server); $("#port-input").val(config.port); @@ -31,24 +38,29 @@ config.channels.forEach(function(channel) { txtChannels = txtChannels.substring(0, txtChannels.length-1) $("#channel-input").val(txtChannels); -var client; $('#connect').on('click', function() { console.log($("#channel-input").val()); + server = $("#server-input").val(); + port = $("#port-input").val(); channels = $("#channel-input").val().split(" "); - myNick = $("#nick-input").val() + myNick = $("#nick-input").val(); + password = $("#password-input").val(); ssl = ($("#ssl-input:checked").val() == "on"); console.log(ssl); - client = new irc.Client($("#server-input").val(), myNick, { - channels: channels, - userName: myNick, - password: $("#password-input").val(), - port: $("#port-input").val(), - secure: ssl, - selfSigned: true, - certExpired: true -}); - createListeners(client); + client.use(debugmiddleware.DebugMiddleware()); + client.connect({ + host: server, + port: port, + nick: myNick, + username: myNick, + gecos: myNick, + password: password, + tls: ssl, + rejectUnauthorized: false + }); + + handlers.handleCommands(client); $("#chan-container").show(); @@ -168,6 +180,7 @@ function setTopic(channel, topic) { } function joinChannel(channel, sendJoin) { + console.log("here"); if (sendJoin) { client.join(channel); } -- cgit v1.2.3 From 90533882ae77f811f01cc842fce9cab68df877ba Mon Sep 17 00:00:00 2001 From: Joe Robinson Date: Wed, 17 Aug 2016 15:13:29 +0100 Subject: Fixed receiving messages --- index.js | 48 ++++++------------------------------------------ 1 file changed, 6 insertions(+), 42 deletions(-) (limited to 'index.js') diff --git a/index.js b/index.js index a21b00e..66c9b41 100644 --- a/index.js +++ b/index.js @@ -1,5 +1,4 @@ -var linkify = require("linkifyjs"); -var linkifyHtml = require('linkifyjs/html'); + var shell = require('electron').shell; var config = require('./config.json') var pjson = require('./package.json'); @@ -49,6 +48,7 @@ console.log($("#channel-input").val()); ssl = ($("#ssl-input:checked").val() == "on"); console.log(ssl); client.use(debugmiddleware.DebugMiddleware()); + console.log(server) client.connect({ host: server, port: port, @@ -57,12 +57,15 @@ console.log($("#channel-input").val()); gecos: myNick, password: password, tls: ssl, - rejectUnauthorized: false + rejectUnauthorized: false, + version: "blachat 0.1.3" }); + handlers.setChannels(channels); handlers.handleCommands(client); + $("#chan-container").show(); $("#message").show(); $("#connect-container").hide(); @@ -200,45 +203,6 @@ function joinChannel(channel, sendJoin) { $('.menu .item').tab({history:false}); - - client.addListener('message#'+channel, function (from, message) { - // message = message.autoLink( { - // callback: function(url) { - // return /\.(gif|png|jpe?g)$/i.test(url) ? '' : null; - // }, - // target: "_blank" - // }); - // console.log(message.autoLink()); - console.log(from + ' => #'+ channel +': ' + message); - var chatTab = $("[data-tab=chan-"+ channel +"].chat"); - message = linkifyHtml(message); - - chatTab.append("

<" + from + "> " + message +"

"); - var imgMatch = message.match(/[a-z0-9\-]+[\.:]\S+\.(gif|png|jpe?g|bmp)/); - var vidMatch = message.match(/[a-z0-9\-]+[\.:]\S+\.(webm|mp4)/); - var audioMatch = message.match(/[a-z0-9\-]+[\.:]\S+\.(mp3|wav|ogg)/); - var youtubeMatch = message.match(/(https?\:\/\/)?(www\.)?(youtube\.com|youtu\.be)\/(watch\?v=)?[a-z0-9A-Z_\-]+/); - if (imgMatch != null && imgMatch.length > 0) { - var image = imagify(imgMatch[0],channel); - chatTab.append("

"+image+"

"); - } - if (vidMatch != null && vidMatch.length > 0) { - chatTab.append("

"); - } - if (audioMatch != null && audioMatch.length > 0) { - chatTab.append("

"); - } - if (youtubeMatch != null && youtubeMatch.length > 0) { - console.log(youtubeMatch) - youtubeParts = youtubeMatch[0].split("/"); - youtubeId = youtubeParts[youtubeParts.length-1]; - youtubeId = youtubeId.replace("watch?v=",""); - chatTab.append("

"); - } - - chatTab.scrollTop(chatTab.prop("scrollHeight")); - }); - numChans++; } function removeChannel(channel, sendPart) { -- cgit v1.2.3 From 40b1c978b00911cf17dc1a7b45c10b82ce57641d Mon Sep 17 00:00:00 2001 From: Joe Robinson Date: Thu, 13 Oct 2016 22:34:21 +0100 Subject: Fix PM sending/receiving, some cleanup for messages --- index.js | 51 ++++++++++++++++++++++----------------------------- 1 file changed, 22 insertions(+), 29 deletions(-) (limited to 'index.js') diff --git a/index.js b/index.js index 66c9b41..1142213 100644 --- a/index.js +++ b/index.js @@ -72,10 +72,6 @@ console.log($("#channel-input").val()); }); - - - - function imagify(url, channel) { console.log(url); $.ajax({ @@ -111,7 +107,7 @@ var numChans = 1; $("#send-message").keypress(function(e) { if(e.which == 13) { var message = $("#send-message").val(); - var channel = $(".tab.active").attr("data-tab").replace("chan-", "#") + var channel = $(".tab.active").attr("data-tab") if (message.indexOf("/join") == 0) { joinChannel(message.substring(6, message.length), true); } else if (message.indexOf("/part") == 0) { @@ -130,7 +126,7 @@ $("#send-message").keypress(function(e) { message = message.substring(6+nick.length, message.length); sendPm(message, nick); } else if (message.indexOf("/topic") == 0) { - var channel = $(".tab.active").attr("data-tab").replace("chan-", "#") + var channel = $(".tab.active").attr("data-tab") topic = message.substring(7, message.length); setTopic(channel, topic); } else if (message.indexOf("/") == 0) { @@ -139,11 +135,11 @@ $("#send-message").keypress(function(e) { client.send("kick", ["#wtest", "wjoe__", "test"]); } else { var tab = $(".tab.active").attr("data-tab"); - if (tab.startsWith("chan-")) { + if (tab.startsWith("#")) { sendMsg(message, channel); - } else if(tab.startsWith("pm-")){ - sendPm(message, tab.substring(3, tab.length)); + } else { + sendPm(message, tab); } } $("#send-message").val(''); @@ -152,26 +148,26 @@ $("#send-message").keypress(function(e) { function sendMsg(message, channel) { client.say(channel, message); - var chanTab = $("[data-tab=chan-"+ channel.replace("#","") +"].chat"); + var chanTab = $("[data-tab='"+ channel +"'].chat"); chanTab.append("

<" + myNick + "> " + message +"

"); chanTab.scrollTop(chanTab.prop("scrollHeight")); } function sendPm(message, nick) { - var chanTab = $("[data-tab=pm-"+nick+"].tab"); + var chanTab = $("[data-tab="+nick+"].tab"); $(".active").removeClass("active"); if (chanTab.length == 0) { - $(".ui.menu").append(""+nick+""); - $("#chan-container").append("
"); - chanTab = $("[data-tab=pm-"+nick+"].tab"); - chanTab.append("
"); + $(".ui.menu").append(""+nick+""); + $("#chan-container").append("
"); + chanTab = $("[data-tab="+nick+"].tab"); + chanTab.append("
"); $('.menu .item').tab({history:false}); numChans++; } - $("[data-tab=pm-"+nick+"]").addClass("active"); - var chatTab = $("[data-tab=pm-"+nick+"].chat"); + $("[data-tab="+nick+"]").addClass("active"); + var chatTab = $("[data-tab="+nick+"].chat"); console.log(nick + ': ' + message); client.say(nick, message); chatTab.append("

<" + myNick + "> " + message +"

"); @@ -183,34 +179,31 @@ function setTopic(channel, topic) { } function joinChannel(channel, sendJoin) { - console.log("here"); if (sendJoin) { client.join(channel); } - channel = channel.replace("#",""); chanId = $(".active.chat").attr("data-id") $(".active").removeClass("active"); - $(".ui.menu").append("#"+channel+""); - $("#chan-container").append("
"); + $(".ui.menu").append(""+channel+""); + $("#chan-container").append("
"); - var chanTab = $("[data-tab=chan-"+ channel +"].tab"); + var chanTab = $("[data-tab="+ channel +"].tab"); - chanTab.append("
"); - chanTab.append("
"); - chanTab.append("
"); + chanTab.append("
"); + chanTab.append("
"); + chanTab.append("
"); $('.menu .item').tab({history:false}); } function removeChannel(channel, sendPart) { - channel = channel.replace("#",""); - chanId = $("[data-tab=chan-"+channel+"].chat").attr("data-id"); - $("[data-tab=chan-"+channel+"]").remove(); + chanId = $("[data-tab="+channel+"].chat").attr("data-id"); + $("[data-tab="+channel+"]").remove(); if (sendPart) { - client.part("#"+channel); + client.part(channel); } while ($("[data-id="+(chanId-1)+"]").length == 0 && chanId >=0) { chanId--; -- cgit v1.2.3 From eaa8650c9be413664ef52c56b504e9b7fdaafc38 Mon Sep 17 00:00:00 2001 From: Joe Robinson Date: Thu, 13 Oct 2016 23:26:13 +0100 Subject: Temp fix, duplicate channel joining code --- index.js | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'index.js') diff --git a/index.js b/index.js index 1142213..ca6857d 100644 --- a/index.js +++ b/index.js @@ -114,7 +114,6 @@ $("#send-message").keypress(function(e) { if (message.length > 6) { channel = message.substring(6, message.length); } - console.log() removeChannel(channel, true); } else if (message.indexOf("/whois") == 0) { console.log("whois "+message.substring(7, message.length)); @@ -179,8 +178,11 @@ function setTopic(channel, topic) { } function joinChannel(channel, sendJoin) { + + var channelObj = client.channel(channel); if (sendJoin) { - client.join(channel); + channelObj.join(); + channelObj.say("beep"); } chanId = $(".active.chat").attr("data-id") @@ -189,7 +191,7 @@ function joinChannel(channel, sendJoin) { $(".ui.menu").append(""+channel+""); $("#chan-container").append("
"); - var chanTab = $("[data-tab="+ channel +"].tab"); + var chanTab = $("[data-tab='"+ channel +"'].tab"); chanTab.append("
"); chanTab.append("
"); @@ -197,11 +199,12 @@ function joinChannel(channel, sendJoin) { $('.menu .item').tab({history:false}); + numChans++; } function removeChannel(channel, sendPart) { - chanId = $("[data-tab="+channel+"].chat").attr("data-id"); - $("[data-tab="+channel+"]").remove(); + chanId = $("[data-tab='"+channel+"'].chat").attr("data-id"); + $("[data-tab='"+channel+"']").remove(); if (sendPart) { client.part(channel); } -- cgit v1.2.3 From 855db48bbba753508d68b7d91ec858855e003c9c Mon Sep 17 00:00:00 2001 From: Joe Robinson Date: Fri, 14 Oct 2016 18:17:34 +0100 Subject: Implement topic function --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'index.js') diff --git a/index.js b/index.js index ca6857d..7b11a23 100644 --- a/index.js +++ b/index.js @@ -174,7 +174,7 @@ function sendPm(message, nick) { } function setTopic(channel, topic) { - client.send("TOPIC", channel, topic); + client.raw("TOPIC", channel, topic); } function joinChannel(channel, sendJoin) { -- cgit v1.2.3 From 777808182320e0584a38e2ae9fdfb6e8e7d99973 Mon Sep 17 00:00:00 2001 From: Joe Robinson Date: Sat, 15 Oct 2016 20:59:27 +0100 Subject: Move set topic and join channel functions to commands.js --- index.js | 40 ++++++---------------------------------- 1 file changed, 6 insertions(+), 34 deletions(-) (limited to 'index.js') diff --git a/index.js b/index.js index 7b11a23..d6d0a62 100644 --- a/index.js +++ b/index.js @@ -3,7 +3,7 @@ var shell = require('electron').shell; var config = require('./config.json') var pjson = require('./package.json'); var handlers = require('./handlers.js'); - +var commands = require('./commands.js'); var debugmiddleware = require('./debugmiddleware.js'); const progName = pjson.name; const version = pjson.version; @@ -61,8 +61,9 @@ console.log($("#channel-input").val()); version: "blachat 0.1.3" }); - handlers.setChannels(channels); - handlers.handleCommands(client); + commands.init(client) + handlers.setChannels(channels) + handlers.handleCommands(client) @@ -109,7 +110,7 @@ $("#send-message").keypress(function(e) { var message = $("#send-message").val(); var channel = $(".tab.active").attr("data-tab") if (message.indexOf("/join") == 0) { - joinChannel(message.substring(6, message.length), true); + commands.joinChannel(message.substring(6, message.length), true); } else if (message.indexOf("/part") == 0) { if (message.length > 6) { channel = message.substring(6, message.length); @@ -127,7 +128,7 @@ $("#send-message").keypress(function(e) { } else if (message.indexOf("/topic") == 0) { var channel = $(".tab.active").attr("data-tab") topic = message.substring(7, message.length); - setTopic(channel, topic); + commands.setTopic(channel, topic); } else if (message.indexOf("/") == 0) { command = message.split(" ")[0].replace("/",""); commandArgs = message.replace(command + " ", ""); @@ -173,35 +174,6 @@ function sendPm(message, nick) { chatTab.scrollTop(chanTab.prop("scrollHeight")); } -function setTopic(channel, topic) { - client.raw("TOPIC", channel, topic); -} - -function joinChannel(channel, sendJoin) { - - var channelObj = client.channel(channel); - if (sendJoin) { - channelObj.join(); - channelObj.say("beep"); - } - chanId = $(".active.chat").attr("data-id") - - $(".active").removeClass("active"); - - $(".ui.menu").append(""+channel+""); - $("#chan-container").append("
"); - - var chanTab = $("[data-tab='"+ channel +"'].tab"); - - chanTab.append("
"); - chanTab.append("
"); - chanTab.append("
"); - - $('.menu .item').tab({history:false}); - - numChans++; -} - function removeChannel(channel, sendPart) { chanId = $("[data-tab='"+channel+"'].chat").attr("data-id"); $("[data-tab='"+channel+"']").remove(); -- cgit v1.2.3 From 1dd55949f2d53bf48ca016ab2d4acff172c443b4 Mon Sep 17 00:00:00 2001 From: Joe Robinson Date: Sun, 16 Oct 2016 19:53:23 +0100 Subject: Fix part command, refactoring --- index.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'index.js') diff --git a/index.js b/index.js index d6d0a62..46eeb26 100644 --- a/index.js +++ b/index.js @@ -4,6 +4,7 @@ var config = require('./config.json') var pjson = require('./package.json'); var handlers = require('./handlers.js'); var commands = require('./commands.js'); +var globals = require('./globals.js') var debugmiddleware = require('./debugmiddleware.js'); const progName = pjson.name; const version = pjson.version; @@ -104,7 +105,7 @@ function humanize(size) { return s + ' ' + units[ord]; } -var numChans = 1; +var numChans = globals.channels.length $("#send-message").keypress(function(e) { if(e.which == 13) { var message = $("#send-message").val(); @@ -157,6 +158,7 @@ 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("
"); @@ -164,6 +166,7 @@ function sendPm(message, nick) { chanTab.append("
"); $('.menu .item').tab({history:false}); + globals.channels.push(nick) numChans++; } $("[data-tab="+nick+"]").addClass("active"); -- cgit v1.2.3 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 From f13842bc63f002e456727d1a48239d4e044d0c75 Mon Sep 17 00:00:00 2001 From: Joe Robinson Date: Sun, 16 Oct 2016 21:05:57 +0100 Subject: Add join, part, and quit handlers --- index.js | 54 ++++-------------------------------------------------- 1 file changed, 4 insertions(+), 50 deletions(-) (limited to 'index.js') diff --git a/index.js b/index.js index e9a6f7c..b4333e5 100644 --- a/index.js +++ b/index.js @@ -131,9 +131,9 @@ $("#send-message").keypress(function(e) { topic = message.substring(7, message.length); commands.setTopic(channel, topic); } else if (message.indexOf("/") == 0) { - command = message.split(" ")[0].replace("/",""); - commandArgs = message.replace(command + " ", ""); - client.send("kick", ["#wtest", "wjoe__", "test"]); + // command = message.split(" ")[0].replace("/",""); + // commandArgs = message.replace(command + " ", ""); + // client.send("kick", ["#wtest", "wjoe__", "test"]); } else { var tab = $(".tab.active").attr("data-tab"); if (tab.startsWith("#")) { @@ -163,7 +163,7 @@ client.addListener('motd', function(motd) { client.addListener('raw', function(message) { var statusTab = $("[data-tab=status].chat"); - statusCmds = ["NOTICEAUTH", "rpl_welcome, rpl_yourhoust", "rpl_created", "rpl_myinfo", "rpl_isupport", "rpl_luserclient", "rpl_luserop", "rpl_luserme", "rpl_luserchannels", "rpl_localusers", "rpl_globalusers"]; + statusCmds = ["NOTICEAUTH", "rpl_welcome, rpl_yourhost", "rpl_created", "rpl_myinfo", "rpl_isupport", "rpl_luserclient", "rpl_luserop", "rpl_luserme", "rpl_luserchannels", "rpl_localusers", "rpl_globalusers"]; if (statusCmds.indexOf(message.command) > -1 || message.command.startsWith("rpl_")) { statusTab.append("

"+message.command + ": " +message.args+"

") statusTab.scrollTop(statusTab.prop("scrollHeight")); @@ -174,39 +174,6 @@ client.addListener('ctcp-version', function(from, to, text, message) { client.ctcp(from, "VERSION", "VERSION "+progName + " v"+ version) }); - -client.addListener('names', function(channel, nicks) { - channel = channel.replace("#","") - if($(".ui.tab[data-tab=chan-"+channel+"]").length == 0) { - joinChannel(channel, false) - } - for(nick in nicks) { - var mode = nicks[nick]; - if($(".ui.users[data-tab=chan-"+channel+"] [data-nick="+nick+"]").length == 0) { - $(".ui.users[data-tab=chan-"+channel+"]").append("
"+mode+nick+"
") - } - } -}); -- -client.addListener('join', function(channel, nick) { - channel = channel.replace("#","") - if($(".ui.users[data-tab=chan-"+channel+"] [data-nick="+nick+"]").length == 0) { - $(".ui.users[data-tab=chan-"+channel+"]").append("
"+nick+"
") - } - var chatTab = $("[data-tab=chan-"+ channel +"].chat"); - chatTab.append("

"+nick+" joined #"+channel+"

") -}); - -client.addListener('part', function(channel, nick) { - 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+" left #"+channel+"

") - chatTab.scrollTop(chatTab.prop("scrollHeight")); -}); - client.addListener('quit', function(nick, reason, channels, message) { channels.forEach(function(channel) { channel = channel.replace("#","") @@ -296,17 +263,4 @@ client.addListener('-mode', function(channel, by, mode, argument, message) { 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")); - } -}); - } -- cgit v1.2.3 From e0840642f1710a5f50d3508d3fe661fdc17d9d56 Mon Sep 17 00:00:00 2001 From: Joe Robinson Date: Sun, 16 Oct 2016 21:41:00 +0100 Subject: Add kick handler --- index.js | 68 +--------------------------------------------------------------- 1 file changed, 1 insertion(+), 67 deletions(-) (limited to 'index.js') diff --git a/index.js b/index.js index b4333e5..48f55a0 100644 --- a/index.js +++ b/index.js @@ -62,6 +62,7 @@ console.log($("#channel-input").val()); version: "blachat 0.1.3" }); + globals.myNick = myNick commands.init(client) handlers.setChannels(channels) handlers.handleCommands(client) @@ -170,23 +171,6 @@ client.addListener('raw', function(message) { } }); -client.addListener('ctcp-version', function(from, to, text, message) { - client.ctcp(from, "VERSION", "VERSION "+progName + " v"+ version) -}); - -client.addListener('quit', 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+" quit ("+reason+")

") - chatTab.scrollTop(chatTab.prop("scrollHeight")); - }); - -}); - client.addListener('kick', function(channel, nick, by, reason, message) { if (myNick == nick) { removeChannel(channel, false); @@ -213,54 +197,4 @@ client.addListener('kill', function(nick, reason, channels, message) { }); }); - -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")); -}); - } -- cgit v1.2.3 From ac48b1195c4cd68f716e4119181c720cc9ec8b4f Mon Sep 17 00:00:00 2001 From: Joe Robinson Date: Sun, 16 Oct 2016 22:34:58 +0100 Subject: Handle error and server messages --- index.js | 60 +++++++++++------------------------------------------------- 1 file changed, 11 insertions(+), 49 deletions(-) (limited to 'index.js') diff --git a/index.js b/index.js index 48f55a0..1975bc0 100644 --- a/index.js +++ b/index.js @@ -148,53 +148,15 @@ $("#send-message").keypress(function(e) { } }); -function createListeners(client) { - -client.addListener('error', function(message) { - console.log('error: ', message); -}); - - -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"); - statusCmds = ["NOTICEAUTH", "rpl_welcome, rpl_yourhost", "rpl_created", "rpl_myinfo", "rpl_isupport", "rpl_luserclient", "rpl_luserop", "rpl_luserme", "rpl_luserchannels", "rpl_localusers", "rpl_globalusers"]; - if (statusCmds.indexOf(message.command) > -1 || message.command.startsWith("rpl_")) { - statusTab.append("

"+message.command + ": " +message.args+"

") - statusTab.scrollTop(statusTab.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('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")); +// }); +// }); -- cgit v1.2.3 From 6463d5922886af839627c539feb9706b5fd9c529 Mon Sep 17 00:00:00 2001 From: Joe Robinson Date: Sun, 16 Oct 2016 22:41:28 +0100 Subject: Remove irc.js dependency, bump version --- index.js | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) (limited to 'index.js') diff --git a/index.js b/index.js index 1975bc0..e65d207 100644 --- a/index.js +++ b/index.js @@ -21,7 +21,6 @@ $(document).on('click', 'a[href^="http"]', function(event) { shell.openExternal(this.href); }); -const irc = require('irc'); const IRC = require('irc-framework'); const client = new IRC.Client() @@ -40,16 +39,13 @@ txtChannels = txtChannels.substring(0, txtChannels.length-1) $("#channel-input").val(txtChannels); $('#connect').on('click', function() { -console.log($("#channel-input").val()); server = $("#server-input").val(); port = $("#port-input").val(); channels = $("#channel-input").val().split(" "); myNick = $("#nick-input").val(); password = $("#password-input").val(); ssl = ($("#ssl-input:checked").val() == "on"); - console.log(ssl); client.use(debugmiddleware.DebugMiddleware()); - console.log(server) client.connect({ host: server, port: port, @@ -59,7 +55,7 @@ console.log($("#channel-input").val()); password: password, tls: ssl, rejectUnauthorized: false, - version: "blachat 0.1.3" + version: pjson.name + " " + pjson.version }); globals.myNick = myNick -- cgit v1.2.3