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 --- handlers.js | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 handlers.js (limited to 'handlers.js') diff --git a/handlers.js b/handlers.js new file mode 100644 index 0000000..88259c7 --- /dev/null +++ b/handlers.js @@ -0,0 +1,22 @@ +module.exports.handleCommands = function(client) { + + client.on('registered', function(event) { + console.log(event); + }); + + client.on('userlist', function(event) { + console.log(event); + channel = event.channel.replace("#","") + console.log(channel); + if($(".ui.tab[data-tab=chan-"+channel+"]").length == 0) { + console.log("there"); + joinChannel(channel, false) + } + for(nick in event.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+"
") + } + } + }); +} -- 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 --- handlers.js | 107 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 105 insertions(+), 2 deletions(-) (limited to 'handlers.js') diff --git a/handlers.js b/handlers.js index 88259c7..b2437bc 100644 --- a/handlers.js +++ b/handlers.js @@ -1,9 +1,30 @@ -module.exports.handleCommands = function(client) { +var linkify = require("linkifyjs"); +var linkifyHtml = require('linkifyjs/html'); +var util = require("./util.js") +var numChans = 1; +var channels; +var buffers = []; +var client; +module.exports.setChannels = function(myChannels) { + console.log("setting channels: " + myChannels); + channels = myChannels; +} +module.exports.handleCommands = function(myClient) { + client = myClient; client.on('registered', function(event) { console.log(event); + console.log("channels: " + channels); + channels.forEach(function(channelStr) { + console.log(channelStr); + joinChannel(channelStr, true); + }); }); - + client.on('message', function(event) { + console.log("messsagee + " + event.message) + console.log(event); + receiveMsg(event.target, event.nick, event.message) + }) client.on('userlist', function(event) { console.log(event); channel = event.channel.replace("#","") @@ -19,4 +40,86 @@ module.exports.handleCommands = function(client) { } } }); + +} + +function joinChannel(channel, sendJoin) { + console.log("here"); + if (sendJoin) { + var channelObj = client.channel(channel); + buffers.push(channelObj); + channelObj.join(); + channelObj.say("beep"); + } + channel = channel.replace("#",""); + chanId = $(".active.chat").attr("data-id") + + $(".active").removeClass("active"); + + $(".ui.menu").append("#"+channel+""); + $("#chan-container").append("
"); + + var chanTab = $("[data-tab=chan-"+ channel +"].tab"); + + chanTab.append("
"); + chanTab.append("
"); + chanTab.append("
"); + + $('.menu .item').tab({history:false}); + + channelObj.updateUserList(function() { + channel = event.channel.replace("#","") + console.log(channel); + if($(".ui.tab[data-tab=chan-"+channel+"]").length == 0) { + console.log("there"); + } + for(nick in channelObj.users) { + if($(".ui.users[data-tab=chan-"+channel+"] [data-nick="+nick+"]").length == 0) { + $(".ui.users[data-tab=chan-"+channel+"]").append("
"+nick+"
") + } + } + }) + numChans++; +} + +function receiveMsg(channel, from, message) { + // message = message.autoLink( { + // callback: function(url) { + // return /\.(gif|png|jpe?g)$/i.test(url) ? '' : null; + // }, + // target: "_blank" + // }); + // console.log(message.autoLink()); + channel = channel.replace("#","") + console.log(from + ' => #'+ channel +': ' + message); + console.log($("[data-tab=chan-"+ channel +"].chat")); + var chatTab = $("[data-tab=chan-"+ channel +"].chat"); + console.log(chatTab); + message = linkifyHtml(message); + console.log(from + ' => #'+ channel +': ' + 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 = util.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")); } -- cgit v1.2.3 From 97fa9bf68f5e3aa50f094fa7e7bb4c427f2702aa Mon Sep 17 00:00:00 2001 From: Joe Robinson Date: Thu, 13 Oct 2016 14:26:31 +0100 Subject: Create user list on channel join, remove some debug lines --- handlers.js | 38 ++++++++++++++++++-------------------- 1 file changed, 18 insertions(+), 20 deletions(-) (limited to 'handlers.js') diff --git a/handlers.js b/handlers.js index b2437bc..938c2e2 100644 --- a/handlers.js +++ b/handlers.js @@ -21,32 +21,42 @@ module.exports.handleCommands = function(myClient) { }); }); client.on('message', function(event) { - console.log("messsagee + " + event.message) console.log(event); receiveMsg(event.target, event.nick, event.message) }) + client.on('userlist', function(event) { - console.log(event); channel = event.channel.replace("#","") - console.log(channel); + if($(".ui.tab[data-tab=chan-"+channel+"]").length == 0) { - console.log("there"); joinChannel(channel, false) } - for(nick in event.nicks) { - var mode = nicks[nick]; + event.users.forEach(function (user) { + var nick = user.nick + var mode = "" + user.modes.forEach(function (modeChar) { + if (modeChar === "o") { + mode = "@" + console.log(mode) + } else if (modeChar === "h") { + mode = "%" + } else if (modeChar === "v") { + mode = "+" + } + }) if($(".ui.users[data-tab=chan-"+channel+"] [data-nick="+nick+"]").length == 0) { $(".ui.users[data-tab=chan-"+channel+"]").append("
"+mode+nick+"
") } - } + }) }); } function joinChannel(channel, sendJoin) { console.log("here"); - if (sendJoin) { + var channelObj = client.channel(channel); + if (sendJoin) { buffers.push(channelObj); channelObj.join(); channelObj.say("beep"); @@ -67,18 +77,6 @@ function joinChannel(channel, sendJoin) { $('.menu .item').tab({history:false}); - channelObj.updateUserList(function() { - channel = event.channel.replace("#","") - console.log(channel); - if($(".ui.tab[data-tab=chan-"+channel+"]").length == 0) { - console.log("there"); - } - for(nick in channelObj.users) { - if($(".ui.users[data-tab=chan-"+channel+"] [data-nick="+nick+"]").length == 0) { - $(".ui.users[data-tab=chan-"+channel+"]").append("
"+nick+"
") - } - } - }) numChans++; } -- 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 --- handlers.js | 58 +++++++++++++++++++++++++++++++--------------------------- 1 file changed, 31 insertions(+), 27 deletions(-) (limited to 'handlers.js') diff --git a/handlers.js b/handlers.js index 938c2e2..e43a250 100644 --- a/handlers.js +++ b/handlers.js @@ -6,29 +6,24 @@ var numChans = 1; var channels; var buffers = []; var client; +var myNick = "" module.exports.setChannels = function(myChannels) { - console.log("setting channels: " + myChannels); channels = myChannels; } module.exports.handleCommands = function(myClient) { client = myClient; client.on('registered', function(event) { - console.log(event); - console.log("channels: " + channels); channels.forEach(function(channelStr) { - console.log(channelStr); joinChannel(channelStr, true); }); }); client.on('message', function(event) { - console.log(event); receiveMsg(event.target, event.nick, event.message) }) client.on('userlist', function(event) { - channel = event.channel.replace("#","") - if($(".ui.tab[data-tab=chan-"+channel+"]").length == 0) { + if($(".ui.tab[data-tab='"+channel+"']").length == 0) { joinChannel(channel, false) } event.users.forEach(function (user) { @@ -37,15 +32,14 @@ module.exports.handleCommands = function(myClient) { user.modes.forEach(function (modeChar) { if (modeChar === "o") { mode = "@" - console.log(mode) } else if (modeChar === "h") { mode = "%" } else if (modeChar === "v") { mode = "+" } }) - if($(".ui.users[data-tab=chan-"+channel+"] [data-nick="+nick+"]").length == 0) { - $(".ui.users[data-tab=chan-"+channel+"]").append("
"+mode+nick+"
") + if($(".ui.users[data-tab='"+channel+"'] [data-nick="+nick+"]").length == 0) { + $(".ui.users[data-tab='"+channel+"']").append("
"+mode+nick+"
") } }) }); @@ -53,7 +47,6 @@ module.exports.handleCommands = function(myClient) { } function joinChannel(channel, sendJoin) { - console.log("here"); var channelObj = client.channel(channel); if (sendJoin) { @@ -61,26 +54,25 @@ function joinChannel(channel, sendJoin) { channelObj.join(); channelObj.say("beep"); } - 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}); numChans++; } -function receiveMsg(channel, from, message) { +function receiveMsg(target, from, message) { // message = message.autoLink( { // callback: function(url) { // return /\.(gif|png|jpe?g)$/i.test(url) ? '' : null; @@ -88,13 +80,26 @@ function receiveMsg(channel, from, message) { // target: "_blank" // }); // console.log(message.autoLink()); - channel = channel.replace("#","") - console.log(from + ' => #'+ channel +': ' + message); - console.log($("[data-tab=chan-"+ channel +"].chat")); - var chatTab = $("[data-tab=chan-"+ channel +"].chat"); - console.log(chatTab); + + console.log(from + ' => '+ target +': ' + message); + + if (target === client.user.nick) { + target = from + } + var chatTab = $("[data-tab='"+ target +"'].chat"); + + if (chatTab.length == 0) { + $(".ui.menu").append(""+target+""); + $("#chan-container").append("
"); + chanTab = $("[data-tab="+target+"].tab"); + chanTab.append("
"); + + $('.menu .item').tab({history:false}); + numChans++; + chatTab = $("[data-tab="+ target +"].chat"); + } + message = linkifyHtml(message); - console.log(from + ' => #'+ channel +': ' + message); chatTab.append("

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

"); var imgMatch = message.match(/[a-z0-9\-]+[\.:]\S+\.(gif|png|jpe?g|bmp)/); @@ -102,7 +107,7 @@ function receiveMsg(channel, from, message) { 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 = util.imagify(imgMatch[0],channel); + var image = util.imagify(imgMatch[0],target); chatTab.append("

"+image+"

"); } if (vidMatch != null && vidMatch.length > 0) { @@ -112,7 +117,6 @@ function receiveMsg(channel, from, message) { 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=",""); -- 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 --- handlers.js | 2 -- 1 file changed, 2 deletions(-) (limited to 'handlers.js') diff --git a/handlers.js b/handlers.js index e43a250..6769b53 100644 --- a/handlers.js +++ b/handlers.js @@ -4,7 +4,6 @@ var util = require("./util.js") var numChans = 1; var channels; -var buffers = []; var client; var myNick = "" module.exports.setChannels = function(myChannels) { @@ -50,7 +49,6 @@ function joinChannel(channel, sendJoin) { var channelObj = client.channel(channel); if (sendJoin) { - buffers.push(channelObj); channelObj.join(); channelObj.say("beep"); } -- cgit v1.2.3 From c797f12928e65722beea1265d0383fb10db010f3 Mon Sep 17 00:00:00 2001 From: Joe Robinson Date: Fri, 14 Oct 2016 16:04:27 +0100 Subject: Fix user list --- handlers.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'handlers.js') diff --git a/handlers.js b/handlers.js index 6769b53..0e26d7f 100644 --- a/handlers.js +++ b/handlers.js @@ -21,7 +21,7 @@ module.exports.handleCommands = function(myClient) { }) client.on('userlist', function(event) { - + channel = event.channel if($(".ui.tab[data-tab='"+channel+"']").length == 0) { joinChannel(channel, false) } -- 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 --- handlers.js | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) (limited to 'handlers.js') diff --git a/handlers.js b/handlers.js index 0e26d7f..0e27c25 100644 --- a/handlers.js +++ b/handlers.js @@ -41,7 +41,22 @@ module.exports.handleCommands = function(myClient) { $(".ui.users[data-tab='"+channel+"']").append("
"+mode+nick+"
") } }) - }); + }) + + client.on('topic', function(event) { + channel = event.channel + topic = event.topic + //TODO: Handle topicsetby to add the user and time for the topic + nick = "vov" + time = "vov" + var chatTab = $("[data-tab='"+ channel +"'].chat"); + if($(".ui.tab[data-tab='"+channel+"']").length == 0) { + joinChannel(channel, false) + } + chatTab.append("

Topic for "+channel+" is "+topic+" - set by "+nick+" at "+time+"

") + var topicTab = $("[data-tab='"+ channel +"'].topic"); + topicTab.html("

"+topic+"

") + }) } -- 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 --- handlers.js | 32 ++++---------------------------- 1 file changed, 4 insertions(+), 28 deletions(-) (limited to 'handlers.js') diff --git a/handlers.js b/handlers.js index 0e27c25..9b956c3 100644 --- a/handlers.js +++ b/handlers.js @@ -1,6 +1,7 @@ var linkify = require("linkifyjs"); var linkifyHtml = require('linkifyjs/html'); var util = require("./util.js") +var commands = require("./commands.js") var numChans = 1; var channels; @@ -13,7 +14,7 @@ module.exports.handleCommands = function(myClient) { client = myClient; client.on('registered', function(event) { channels.forEach(function(channelStr) { - joinChannel(channelStr, true); + commands.joinChannel(channelStr, true); }); }); client.on('message', function(event) { @@ -23,7 +24,7 @@ module.exports.handleCommands = function(myClient) { client.on('userlist', function(event) { channel = event.channel if($(".ui.tab[data-tab='"+channel+"']").length == 0) { - joinChannel(channel, false) + commands.joinChannel(channel, false) } event.users.forEach(function (user) { var nick = user.nick @@ -51,7 +52,7 @@ module.exports.handleCommands = function(myClient) { time = "vov" var chatTab = $("[data-tab='"+ channel +"'].chat"); if($(".ui.tab[data-tab='"+channel+"']").length == 0) { - joinChannel(channel, false) + commands.joinChannel(channel, false) } chatTab.append("

Topic for "+channel+" is "+topic+" - set by "+nick+" at "+time+"

") var topicTab = $("[data-tab='"+ channel +"'].topic"); @@ -60,31 +61,6 @@ module.exports.handleCommands = function(myClient) { } -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 receiveMsg(target, from, message) { // message = message.autoLink( { // callback: function(url) { -- 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 --- handlers.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'handlers.js') diff --git a/handlers.js b/handlers.js index 9b956c3..ffbb4f4 100644 --- a/handlers.js +++ b/handlers.js @@ -2,8 +2,8 @@ var linkify = require("linkifyjs"); var linkifyHtml = require('linkifyjs/html'); var util = require("./util.js") var commands = require("./commands.js") - -var numChans = 1; +var globals = require("./globals.js") +var numChans = globals.channels.length + globals.pms.length; var channels; var client; var myNick = "" @@ -69,7 +69,7 @@ function receiveMsg(target, from, message) { // target: "_blank" // }); // console.log(message.autoLink()); - + numChans = globals.channels.length console.log(from + ' => '+ target +': ' + message); if (target === client.user.nick) { @@ -84,6 +84,7 @@ function receiveMsg(target, from, message) { chanTab.append("
"); $('.menu .item').tab({history:false}); + global.channels.push(target) numChans++; chatTab = $("[data-tab="+ target +"].chat"); } -- cgit v1.2.3 From f88564402afd517c01c4bd1e8bb4d8de8afc7690 Mon Sep 17 00:00:00 2001 From: Joe Robinson Date: Sun, 16 Oct 2016 20:22:07 +0100 Subject: Fix whois function --- handlers.js | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'handlers.js') diff --git a/handlers.js b/handlers.js index ffbb4f4..0abb297 100644 --- a/handlers.js +++ b/handlers.js @@ -59,6 +59,29 @@ module.exports.handleCommands = function(myClient) { topicTab.html("

"+topic+"

") }) + client.on('whois', function(event) { + var nick = event.nick + var chatTab = $(".active .chat"); + chatTab.append("

"+event.nick+": "+event.user+"@"+event.host+"

"); + chatTab.append("

Real Name: "+event.real_name+"

"); + chatTab.append("

Channels: " + event.channels+"

"); + chatTab.append("

Server: "+event.server+" "+event.server_info+"

"); + if (event.operator.length > 0) { + chatTab.append("

"+event.operator+"

"); + } + if (event.registered_nick.length > 0) { + chatTab.append("

"+event.registered_nick+"

"); + } + if (event.away.length > 0) { + chatTab.append("

"+event.away+"

"); + } + if (event.secure) { + chatTab.append("

is using a secure connection

"); + } + chatTab.scrollTop(chatTab.prop("scrollHeight")); + + }) + } function receiveMsg(target, from, message) { -- 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 --- handlers.js | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'handlers.js') diff --git a/handlers.js b/handlers.js index 0abb297..c4adbd7 100644 --- a/handlers.js +++ b/handlers.js @@ -82,6 +82,19 @@ module.exports.handleCommands = function(myClient) { }) + client.on('channel list', function(event) { + var statusTab = $("[data-tab='status'].chat"); + statusTab.append("

Channel List:

") + event.forEach( function(channel) { + if (channel.topic.length == 0) { + statusTab.append("

"+channel.channel+" ("+channel.num_users+")

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

"+channel.channel+" ("+channel.num_users+") : "+channel.topic+"

"); + } + statusTab.scrollTop(statusTab.prop("scrollHeight")); + }) + }) + } function receiveMsg(target, from, 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 --- handlers.js | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) (limited to 'handlers.js') diff --git a/handlers.js b/handlers.js index c4adbd7..e68a14d 100644 --- a/handlers.js +++ b/handlers.js @@ -95,6 +95,47 @@ module.exports.handleCommands = function(myClient) { }) }) + + client.on('join', function(event) { + var channel = event.channel + var nick = event.nick + if($(".ui.users[data-tab='"+channel+"'] [data-nick="+nick+"]").length == 0) { + $(".ui.users[data-tab='"+channel+"']").append("
"+nick+"
") + } + var chatTab = $("[data-tab='"+ channel +"'].chat"); + chatTab.append("

"+nick+" joined "+channel+"

") + }); + + client.on('part', function(event) { + var channel = event.channel + var nick = event.nick + var message = event.message + + if($(".ui.users[data-tab='"+channel+"'] [data-nick="+nick+"]").length > 0) { + $(".ui.users[data-tab='"+channel+"'] [data-nick="+nick+"]").remove(); + } + var chatTab = $("[data-tab='"+ channel +"'].chat"); + + chatTab.append("

"+nick+" left "+channel+" ("+message+")

") + chatTab.scrollTop(chatTab.prop("scrollHeight")); + }); + + client.on('quit', function(event) { + var nick = event.nick + var message = event.message + + + globals.channels.forEach(function(channel) { + if($(".ui.users[data-tab='"+channel+"'] [data-nick="+nick+"]").length > 0) { + $(".ui.users[data-tab='"+channel+"'] [data-nick="+nick+"]").remove(); + var chatTab = $("[data-tab='"+ channel +"'].chat"); + chatTab.append("

"+nick+" quit ("+message+")

") + chatTab.scrollTop(chatTab.prop("scrollHeight")); + } + + }); + }) + } function receiveMsg(target, from, message) { -- cgit v1.2.3 From bf695e6ad13b0fd0fb2706d6bf9960a66e656696 Mon Sep 17 00:00:00 2001 From: Joe Robinson Date: Sun, 16 Oct 2016 21:22:31 +0100 Subject: Add mode handler --- handlers.js | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) (limited to 'handlers.js') diff --git a/handlers.js b/handlers.js index e68a14d..c6d86de 100644 --- a/handlers.js +++ b/handlers.js @@ -136,6 +136,43 @@ module.exports.handleCommands = function(myClient) { }); }) + client.on('mode', function(event) { + var chatTab = $("[data-tab='"+ channel +"'].chat"); + var by = event.nick + var channel = event.target + event.modes.forEach(function (modeObj) { + + var mode = modeObj.mode + var argument = modeObj.param + 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 (mode == "-o") { + modeLine = " removes channel operator status from " + argument; + } else if (mode == "-v") { + modeLine = " removes voice from "; + } else if (mode == "-h") { + modeLine = " removes channel half-operator status from " + argument; + } else if (mode == "-q") { + modeLine = " removes channel owner status from " + 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='"+ channel +"'].chat"); + chatTab.append("

"+by+modeLine+"

"); + }) + chatTab.scrollTop(chatTab.prop("scrollHeight")); + }) + } function receiveMsg(target, from, message) { -- 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 --- handlers.js | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'handlers.js') diff --git a/handlers.js b/handlers.js index c6d86de..24b783c 100644 --- a/handlers.js +++ b/handlers.js @@ -173,6 +173,23 @@ module.exports.handleCommands = function(myClient) { chatTab.scrollTop(chatTab.prop("scrollHeight")); }) + client.on('kick', function(event) { + var kicked = event.kicked + var by = event.nick + var channel = event.channel + var reason = event.message + if (globals.myNick == kicked) { + commands.removeChannel(channel, false); + } else { + if($(".ui.users[data-tab='"+channel+"'] [data-nick="+kicked+"]").length > 0) { + $(".ui.users[data-tab='"+channel+"'] [data-nick="+kicked+"]").remove(); + } + var chatTab = $("[data-tab='"+ channel +"'].chat"); + chatTab.append("

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

") + chatTab.scrollTop(chatTab.prop("scrollHeight")); + } + }) + } function receiveMsg(target, from, message) { -- 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 --- handlers.js | 112 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 106 insertions(+), 6 deletions(-) (limited to 'handlers.js') diff --git a/handlers.js b/handlers.js index 24b783c..9142f04 100644 --- a/handlers.js +++ b/handlers.js @@ -18,7 +18,7 @@ module.exports.handleCommands = function(myClient) { }); }); client.on('message', function(event) { - receiveMsg(event.target, event.nick, event.message) + receiveMsg(event.target, event.nick, event.message, event.from_server) }) client.on('userlist', function(event) { @@ -48,17 +48,31 @@ module.exports.handleCommands = function(myClient) { channel = event.channel topic = event.topic //TODO: Handle topicsetby to add the user and time for the topic - nick = "vov" - time = "vov" var chatTab = $("[data-tab='"+ channel +"'].chat"); if($(".ui.tab[data-tab='"+channel+"']").length == 0) { commands.joinChannel(channel, false) } - chatTab.append("

Topic for "+channel+" is "+topic+" - set by "+nick+" at "+time+"

") + chatTab.append("

Topic for "+channel+" is "+topic+"

") var topicTab = $("[data-tab='"+ channel +"'].topic"); topicTab.html("

"+topic+"

") }) + client.on('topicsetby', function(event) { + channel = event.channel + nick = event.nick + timestamp = event.when + + //TODO: Handle topicsetby to add the user and time for the topic + + var chatTab = $("[data-tab='"+ channel +"'].chat"); + if($(".ui.tab[data-tab='"+channel+"']").length == 0) { + commands.joinChannel(channel, false) + } + chatTab.append("

Set by "+nick+" at "+timestamp+"

") + var topicLine = $("[data-tab='"+ channel +"'].topic .topic-line"); + topicLine.append(" by " + nick + " at " + timestamp) + }) + client.on('whois', function(event) { var nick = event.nick var chatTab = $(".active .chat"); @@ -160,7 +174,7 @@ module.exports.handleCommands = function(myClient) { modeLine = " removes channel half-operator status from " + argument; } else if (mode == "-q") { modeLine = " removes channel owner status from " + argument; - } else if (argument == myNick) { + } else if (argument == globals.myNick) { modeLine = " sets mode " + mode + " on " + argument; } else if (argument != null) { modeLine = " sets mode " + mode + " " + argument + " on " +channel; @@ -190,9 +204,90 @@ module.exports.handleCommands = function(myClient) { } }) + client.on('motd', function(event) { + serverMsg(event.motd) + }) + + //Server Info + //eg: Your host is irc.lc8n.com, running version Unreal3.2.10.4" + //param 0 is your nick + client.on('002', function(event) { + serverMsg(event.params[1]) + }) + + //Server created + //eg Your host is irc.lc8n.com, running version Unreal3.2.10.4" + //param 0 is your nick + client.on('003', function(event) { + serverMsg(event.params[1]) + }) + + //004: Some unknown server strings + client.on('004', function(event) { + serverMsg(event.params[1] + " " + event.params[2] + " " + event.params[3] + " " + event.params[4]) + }) + //Users online + //eg: There are 7 users and 47 invisible on 4 servers + client.on('251', function(event) { + serverMsg(event.params[1]) + }) + + //Operators online + //eg: "10" "operator(s) online" + client.on('252', function(event) { + serverMsg(event.params[1] + " " +event.params[2]) + }) + + //Channels formed + //eg "49" "channels formed" + client.on('254', function(event) { + serverMsg(event.params[1] + " " +event.params[2]) + }) + + //'Clients' and 'Servers'? + //eg "I have 8 clients and 1 servers" + client.on('255', function(event) { + serverMsg(event.params[1]) + }) + + //User stats + //eg ""Current global users 54, max 63" + //param 0 is your nick, 1 is current users, 2 is max users + client.on('266', function(event) { + serverMsg(event.params[3]) + }) + + client.on('irc error', function(event) { + errorMsg(event.error, event.reason, event.channel) + }); + + //No such channel error + client.on('403', function(event) { + errorMsg("403", event.params[2], event.params[1]) + }); } -function receiveMsg(target, from, message) { + +function errorMsg(error, message, param) { + var chatTab = $(".active .chat"); + + chatTab.append("

Error: "+error+"!

"); + if (param.length > 0) { + chatTab.append("

Param: "+param+"

"); + } + if (message.length > 0) { + chatTab.append("

Message: "+message+"

"); + } + chatTab.scrollTop(chatTab.prop("scrollHeight")); + console.log('error: ', error); +} +function serverMsg(message) { + var statusTab = $("[data-tab=status].chat"); + statusTab.append("

"+message+"

") + statusTab.scrollTop(statusTab.prop("scrollHeight")); +} + +function receiveMsg(target, from, message, from_server) { // message = message.autoLink( { // callback: function(url) { // return /\.(gif|png|jpe?g)$/i.test(url) ? '' : null; @@ -200,6 +295,11 @@ function receiveMsg(target, from, message) { // target: "_blank" // }); // console.log(message.autoLink()); + + if (from_server) { + serverMsg(message) + return false + } numChans = globals.channels.length console.log(from + ' => '+ target +': ' + message); -- cgit v1.2.3