diff options
author | Joe Robinson <joe@lc8n.com> | 2016-10-16 21:41:00 +0100 |
---|---|---|
committer | Joe Robinson <joe@lc8n.com> | 2016-10-16 21:41:00 +0100 |
commit | e0840642f1710a5f50d3508d3fe661fdc17d9d56 (patch) | |
tree | 327f25dcd00dab2c7c77b169a12234ac0897ff6e | |
parent | bf695e6ad13b0fd0fb2706d6bf9960a66e656696 (diff) |
Add kick handler
-rw-r--r-- | commands.js | 3 | ||||
-rw-r--r-- | globals.js | 2 | ||||
-rw-r--r-- | handlers.js | 17 | ||||
-rw-r--r-- | 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) { @@ -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("<p class='chat-line'>"+kicked+" was kicked from "+channel+" by "+by+" ("+reason+")</p>") + chatTab.scrollTop(chatTab.prop("scrollHeight")); + } + }) + } function receiveMsg(target, from, message) { @@ -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("<p class='chat-line'>"+nick+" quit ("+reason+")</p>") - 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("<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")); -}); - } |