summaryrefslogtreecommitdiff
path: root/index.js
diff options
context:
space:
mode:
Diffstat (limited to 'index.js')
-rw-r--r--index.js61
1 files changed, 43 insertions, 18 deletions
diff --git a/index.js b/index.js
index a6e8ebf..7effc5b 100644
--- a/index.js
+++ b/index.js
@@ -5,7 +5,7 @@ var config = require('./config.json')
var pjson = require('./package.json');
const progName = pjson.name;
const version = pjson.version;
-const myNick = config.nick;
+var myNick = config.nick;
$(document).ready(function() {
$("#send-message").focus();
@@ -21,31 +21,43 @@ const irc = require('irc');
$("#server-input").val(config.server);
$("#port-input").val(config.port);
$("#nick-input").val(config.nick);
+$("#password-input").val(config.password);
var channels = config.channels
var txtChannels = "";
config.channels.forEach(function(channel) {
- txtChannels += channel + ", "
+ txtChannels += channel + " "
});
-txtChannels = txtChannels.substring(0, txtChannels.length-2)
+txtChannels = txtChannels.substring(0, txtChannels.length-1)
$("#channel-input").val(txtChannels);
-const client = new irc.Client();
+var client;
$('#connect').on('click', function() {
- client.server = $("#server-input").val();
- client.nick = $("#nick-input").val(config.nick);
+console.log($("#channel-input").val());
+ channels = $("#channel-input").val().split(" ");
+ myNick = $("#nick-input").val()
+ ssl = ($("#ssl-input:checked").val() == "on");
+ console.log(ssl);
+ client = new irc.Client($("#server-input").val(), myNick, {
+ channels: channels,
+ userName: myNick,
+ password: $("#password-input").val(),
+ port: $("#port-input").val(),
+ secure: ssl,
+ selfSigned: true,
+ certExpired: true
+});
+ createListeners(client);
+
+
$("#chan-container").show();
$("#message").show();
$("#connect-container").hide();
- client.connect();
});
-// const client = new irc.Client(config.server, myNick, {
-// channels: config.channels,
-// userName: [myNick]
-// });
+
@@ -102,7 +114,7 @@ $("#send-message").keypress(function(e) {
nick = message.split(" ")[1];
message = message.substring(6+nick.length, message.length);
sendPm(message, nick);
- } else if (message.indexOf("/" == 0)) {
+ } else if (message.indexOf("/") == 0) {
command = message.split(" ")[0].replace("/","");
commandArgs = message.replace(command + " ", "");
client.send("kick", ["#wtest", "wjoe__", "test"]);
@@ -122,7 +134,7 @@ $("#send-message").keypress(function(e) {
function sendMsg(message, channel) {
client.say(channel, message);
var chanTab = $("[data-tab=chan-"+ channel.replace("#","") +"].chat");
- chanTab.append("<p class='chat-line'>&lt;" + "wclient" + "&gt; " + message +"</p>");
+ chanTab.append("<p class='chat-line'>&lt;" + myNick + "&gt; " + message +"</p>");
chanTab.scrollTop(chanTab.prop("scrollHeight"));
}
@@ -147,8 +159,10 @@ function sendPm(message, nick) {
chatTab.scrollTop(chanTab.prop("scrollHeight"));
}
-function joinChannel(channel) {
- client.join(channel);
+function joinChannel(channel, sendJoin) {
+ if (sendJoin) {
+ client.join(channel);
+ }
channel = channel.replace("#","");
chanId = $(".active.chat").attr("data-id")
@@ -219,6 +233,9 @@ function removeChannel(channel, sendPart) {
$("[data-id="+(chanId-1)+"]").addClass("active");
}
+function createListeners(client) {
+
+
client.addListener('error', function(message) {
console.log('error: ', message);
});
@@ -238,8 +255,8 @@ 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"];
- if (statusCmds.indexOf(message.command) > -1) {
- statusTab.append("<p class='chat-line'>"+message.args+"</p>")
+ 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"));
}
});
@@ -250,9 +267,12 @@ client.addListener('ctcp-version', function(from, to, text, message) {
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];
- 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+">"+mode+nick+"</div>")
}
@@ -335,6 +355,9 @@ client.addListener('kill', function(nick, reason, channels, message) {
client.addListener('topic', function(channel, topic, nick, message) {
channel = channel.replace("#","");
var chatTab = $("[data-tab=chan-"+ channel +"].chat");
+ if($(".ui.tab[data-tab=chan-"+channel+"]").length == 0) {
+ joinChannel(channel, false)
+ }
chatTab.append("<p class='chat-line'>Topic for #"+channel+" is "+topic+" - set by "+nick+" at "+message.args[3]+"</p>")
var topicTab = $("[data-tab=chan-"+ channel +"].topic");
topicTab.html("<p class='topic-line'>"+topic+"</p>")
@@ -419,3 +442,5 @@ client.addListener('channellist', function(channelList) {
statusTab.scrollTop(statusTab.prop("scrollHeight"));
}
});
+
+}