diff options
Diffstat (limited to 'index.js')
-rw-r--r-- | index.js | 75 |
1 files changed, 64 insertions, 11 deletions
@@ -1,22 +1,75 @@ +$(document).ready(function(){ +}); -$("#submitb").click(function() { - sendMsg(); +$("#send-message").keypress(function(e) { + if(e.which == 13) { + var channel = $(".tab.chat.active").attr("data-tab").replace("chan-", "#") + sendMsg($("#send-message").val(), channel) + $("#send-message").val(''); + } }); +function sendMsg(message, channel) { + console.log(channel + ': ' + message); + client.say(channel, message); + var chanTab = $("[data-tab=chan-"+ channel.replace("#","") +"].chat"); + chanTab.append("<p class='chat-line'><" + "wclient" + "> " + message +"</p>"); + chanTab.scrollTop(chanTab.prop("scrollHeight")); +} + +function joinChannel(channel) { + client.join(channel); + channel = channel.replace("#",""); + + $(".active").removeClass("active"); + $(".ui.menu").append("<a class='active item' data-tab='chan-"+channel+"'>#"+channel+"</a>"); + + + $("#chan-container").append("<div class='ui active tab segment chat active' id='chan-"+channel+"' data-tab='chan-"+channel+"'></div>") + $('.menu .item').tab({history:false}); + var chanTab = $("[data-tab=chan-"+ channel +"].chat"); + client.addListener('message#'+channel, function (from, message) { + console.log(from + ' => #'+ channel +': ' + message); + console.log(chanTab); + chanTab.append("<p class='chat-line'><" + from + "> " + message +"</p>"); + chanTab.scrollTop(chanTab.prop("scrollHeight")); + }); +} + + const irc = require('irc'); +var channels = ["#wtest", "#wtest2"] const client = new irc.Client('irc.blatech.net', 'wclient', { - channels: ['#wtest'], + channels: channels, userName: ['wclient'] }); -function sendMsg() { - console.log('#wtest: ' + $("#send-message").val()); - client.say("#wtest", $("#send-message").val()); -} - +client.addListener('error', function(message) { + console.log('error: ', message); +}); -client.addListener('message#wtest', function (from, message) { - console.log(from + ' => #wtest: ' + message); - $("#chat").append(from + ' : ' + message + "<br>"); +client.addListener('registered', function() { + channels.forEach(function(channel) { + joinChannel(channel); + }); }); + + + +// client.addListener('message#wtest', function (from, message) { +// console.log(from + ' => #wtest: ' + message); +// var chanTab = $("[data-tab=chan-wtest].chat"); +// chanTab.append("<p class='chat-line'><" + from + "> " + message +"</p>"); +// chanTab.scrollTop(chanTab.prop("scrollHeight")); +// }); +// +// client.addListener('message#jerseyesports', function (from, message) { +// console.log(from + ' => #jerseyesports: ' + message); +// $("[data-tab=chan-jerseyesports].chat").append("<p class='chat-line'><" + from + "> " + message +"</p>"); +// }); + +// client.addListener('message#theblueroom', function (from, message) { +// console.log(from + ' => #jerseyesports: ' + message); +// $("[data-tab=chan-theblueroom].chat").append("<p class='chat-line'><" + from + "> " + message +"</p>"); +// }); |