diff options
author | Joe Robinson <joe@lc8n.com> | 2016-10-16 21:05:57 +0100 |
---|---|---|
committer | Joe Robinson <joe@lc8n.com> | 2016-10-16 21:05:57 +0100 |
commit | f13842bc63f002e456727d1a48239d4e044d0c75 (patch) | |
tree | 8bab949f76193239f274df703bc883b9ddd71e1a | |
parent | 63405f05a0406e55daf1fb4bfb00b324f2bf5f7e (diff) |
Add join, part, and quit handlers
-rw-r--r-- | commands.js | 2 | ||||
-rw-r--r-- | handlers.js | 41 | ||||
-rw-r--r-- | index.js | 54 |
3 files changed, 46 insertions, 51 deletions
diff --git a/commands.js b/commands.js index 5ab1d5e..59be364 100644 --- a/commands.js +++ b/commands.js @@ -62,7 +62,7 @@ module.exports.joinChannel = function (channel, sendJoin) { chanTab.append("<div class='ui topic' data-id='"+numChans+"' data-tab='"+channel+"'></div>"); $('.menu .item').tab({history:false}); - + globals.channels.push(channel) numChans++; } 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("<div class=item data-nick="+nick+">"+nick+"</div>") + } + var chatTab = $("[data-tab='"+ channel +"'].chat"); + chatTab.append("<p class='chat-line'>"+nick+" joined "+channel+"</p>") + }); + + 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("<p class='chat-line'>"+nick+" left "+channel+" ("+message+")</p>") + 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("<p class='chat-line'>"+nick+" quit ("+message+")</p>") + chatTab.scrollTop(chatTab.prop("scrollHeight")); + } + + }); + }) + } function receiveMsg(target, from, message) { @@ -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("<p class='chat-line'>"+message.command + ": " +message.args+"</p>") 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("<div class=item data-nick="+nick+">"+mode+nick+"</div>") - } - } -}); -- -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("<div class=item data-nick="+nick+">"+nick+"</div>") - } - var chatTab = $("[data-tab=chan-"+ channel +"].chat"); - chatTab.append("<p class='chat-line'>"+nick+" joined #"+channel+"</p>") -}); - -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("<p class='chat-line'>"+nick+" left #"+channel+"</p>") - 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("<p class='chat-line'>Channel List:</p>") - for (i in channelList) { - if (channelList[i].topic == null) { - statusTab.append("<p class='chat-line'>"+channelList[i].name+" ("+channelList[i].users+")</p>"); - } else { - statusTab.append("<p class='chat-line'>"+channelList[i].name+" ("+channelList[i].users+") : "+channelList[i].topic+"</p>"); - } - statusTab.scrollTop(statusTab.prop("scrollHeight")); - } -}); - } |