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 --- commands.js | 3 ++- globals.js | 2 ++ handlers.js | 17 ++++++++++++++++ index.js | 68 +------------------------------------------------------------ 4 files changed, 22 insertions(+), 68 deletions(-) diff --git a/commands.js b/commands.js index 59be364..138c55f 100644 --- a/commands.js +++ b/commands.js @@ -67,10 +67,11 @@ module.exports.joinChannel = function (channel, sendJoin) { } module.exports.removeChannel = function(channel, sendPart) { - var channelObj = client.channel(channel) + chanId = $("[data-tab='"+channel+"'].chat").attr("data-id"); $("[data-tab='"+channel+"']").remove(); if (sendPart) { + var channelObj = client.channel(channel) channelObj.part(); } while ($("[data-id="+(chanId-1)+"]").length == 0 && chanId >=0) { diff --git a/globals.js b/globals.js index a0c689b..d96f702 100644 --- a/globals.js +++ b/globals.js @@ -3,3 +3,5 @@ module.exports.channels = ['status'] module.exports.pms = [] module.exports.networks = [] + +module.exports.myNick = "" 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) { 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