summaryrefslogtreecommitdiff
path: root/index.js
diff options
context:
space:
mode:
Diffstat (limited to 'index.js')
-rw-r--r--index.js416
1 files changed, 60 insertions, 356 deletions
diff --git a/index.js b/index.js
index 96ce9dd..e65d207 100644
--- a/index.js
+++ b/index.js
@@ -1,12 +1,17 @@
-var linkify = require("linkifyjs");
-var linkifyHtml = require('linkifyjs/html');
+
var shell = require('electron').shell;
var config = require('./config.json')
var pjson = require('./package.json');
+var handlers = require('./handlers.js');
+var commands = require('./commands.js');
+var globals = require('./globals.js')
+var debugmiddleware = require('./debugmiddleware.js');
const progName = pjson.name;
const version = pjson.version;
var myNick = config.nick;
-
+var server = config.server;
+var port = config.port;
+var password = config.password;
$(document).ready(function() {
$("#send-message").focus();
});
@@ -16,7 +21,8 @@ $(document).on('click', 'a[href^="http"]', function(event) {
shell.openExternal(this.href);
});
-const irc = require('irc');
+const IRC = require('irc-framework');
+const client = new IRC.Client()
$("#server-input").val(config.server);
$("#port-input").val(config.port);
@@ -31,24 +37,32 @@ config.channels.forEach(function(channel) {
txtChannels = txtChannels.substring(0, txtChannels.length-1)
$("#channel-input").val(txtChannels);
-var client;
$('#connect').on('click', function() {
-console.log($("#channel-input").val());
+ server = $("#server-input").val();
+ port = $("#port-input").val();
channels = $("#channel-input").val().split(" ");
- myNick = $("#nick-input").val()
+ myNick = $("#nick-input").val();
+ password = $("#password-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);
+ client.use(debugmiddleware.DebugMiddleware());
+ client.connect({
+ host: server,
+ port: port,
+ nick: myNick,
+ username: myNick,
+ gecos: myNick,
+ password: password,
+ tls: ssl,
+ rejectUnauthorized: false,
+ version: pjson.name + " " + pjson.version
+ });
+
+ globals.myNick = myNick
+ commands.init(client)
+ handlers.setChannels(channels)
+ handlers.handleCommands(client)
+
$("#chan-container").show();
@@ -57,10 +71,6 @@ console.log($("#channel-input").val());
});
-
-
-
-
function imagify(url, channel) {
console.log(url);
$.ajax({
@@ -92,363 +102,57 @@ function humanize(size) {
return s + ' ' + units[ord];
}
-var numChans = 1;
+var numChans = globals.channels.length
$("#send-message").keypress(function(e) {
if(e.which == 13) {
var message = $("#send-message").val();
- var channel = $(".tab.active").attr("data-tab").replace("chan-", "#")
+ var channel = $(".tab.active").attr("data-tab")
if (message.indexOf("/join") == 0) {
- joinChannel(message.substring(6, message.length), true);
+ commands.joinChannel(message.substring(6, message.length), true);
} else if (message.indexOf("/part") == 0) {
if (message.length > 6) {
channel = message.substring(6, message.length);
}
- console.log()
- removeChannel(channel, true);
+ commands.removeChannel(channel, true);
} else if (message.indexOf("/whois") == 0) {
- console.log("whois "+message.substring(7, message.length));
- client.whois(message.substring(7, message.length));
+ commands.whois(message.substring(7, message.length))
+
} else if (message.indexOf("/list") == 0) {
- client.list();
+ commands.list();
} else if (message.indexOf("/msg") == 0) {
nick = message.split(" ")[1];
message = message.substring(6+nick.length, message.length);
- sendPm(message, nick);
+ commands.sendPm(message, nick);
} else if (message.indexOf("/topic") == 0) {
- var channel = $(".tab.active").attr("data-tab").replace("chan-", "#")
+ var channel = $(".tab.active").attr("data-tab")
topic = message.substring(7, message.length);
- setTopic(channel, topic);
+ 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("chan-")) {
- sendMsg(message, channel);
+ if (tab.startsWith("#")) {
+ commands.sendMsg(message, channel);
- } else if(tab.startsWith("pm-")){
- sendPm(message, tab.substring(3, tab.length));
+ } else {
+ commands.sendPm(message, tab);
}
}
$("#send-message").val('');
}
});
-function sendMsg(message, channel) {
- client.say(channel, message);
- var chanTab = $("[data-tab=chan-"+ channel.replace("#","") +"].chat");
- chanTab.append("<p class='chat-line'>&lt;" + myNick + "&gt; " + message +"</p>");
- chanTab.scrollTop(chanTab.prop("scrollHeight"));
-}
-
-function sendPm(message, nick) {
-
- var chanTab = $("[data-tab=pm-"+nick+"].tab");
- $(".active").removeClass("active");
- if (chanTab.length == 0) {
- $(".ui.menu").append("<a class='active item' data-id='"+numChans+"' data-tab='pm-"+nick+"'>"+nick+"</a>");
- $("#chan-container").append("<div class='ui active tab' data-id='"+numChans+"' data-tab='pm-"+nick+"'></div>");
- chanTab = $("[data-tab=pm-"+nick+"].tab");
- chanTab.append("<div class='ui segment chat' data-id='"+numChans+"' data-tab='pm-"+nick+"'></div>");
-
- $('.menu .item').tab({history:false});
- numChans++;
- }
- $("[data-tab=pm-"+nick+"]").addClass("active");
- var chatTab = $("[data-tab=pm-"+nick+"].chat");
- console.log(nick + ': ' + message);
- client.say(nick, message);
- chatTab.append("<p class='chat-line'>&lt;" + myNick + "&gt; " + message +"</p>");
- chatTab.scrollTop(chanTab.prop("scrollHeight"));
-}
-
-function setTopic(channel, topic) {
- client.send("TOPIC", channel, topic);
-}
-
-function joinChannel(channel, sendJoin) {
- if (sendJoin) {
- client.join(channel);
- }
- channel = channel.replace("#","");
- chanId = $(".active.chat").attr("data-id")
-
- $(".active").removeClass("active");
-
- $(".ui.menu").append("<a class='active item' data-id='"+numChans+"' data-tab='chan-"+channel+"'>#"+channel+"</a>");
- $("#chan-container").append("<div class='ui active tab' data-id='"+numChans+"' data-tab='chan-"+channel+"'></div>");
-
- var chanTab = $("[data-tab=chan-"+ channel +"].tab");
-
- chanTab.append("<div class='ui selection list users' data-id='"+numChans+"' data-tab='chan-"+channel+"'></div>");
- chanTab.append("<div class='ui segment chat' data-id='"+numChans+"' data-tab='chan-"+channel+"'></div>");
- chanTab.append("<div class='ui topic' data-id='"+numChans+"' data-tab='chan-"+channel+"'></div>");
-
- $('.menu .item').tab({history:false});
-
-
- client.addListener('message#'+channel, function (from, message) {
- // message = message.autoLink( {
- // callback: function(url) {
- // return /\.(gif|png|jpe?g)$/i.test(url) ? '<img src="' + url + '">' : null;
- // },
- // target: "_blank"
- // });
- // console.log(message.autoLink());
- console.log(from + ' => #'+ channel +': ' + message);
- var chatTab = $("[data-tab=chan-"+ channel +"].chat");
- message = linkifyHtml(message);
-
- chatTab.append("<p class='chat-line'>&lt;" + from + "&gt; " + message +"</p>");
- var imgMatch = message.match(/[a-z0-9\-]+[\.:]\S+\.(gif|png|jpe?g|bmp)/);
- var vidMatch = message.match(/[a-z0-9\-]+[\.:]\S+\.(webm|mp4)/);
- var audioMatch = message.match(/[a-z0-9\-]+[\.:]\S+\.(mp3|wav|ogg)/);
- var youtubeMatch = message.match(/(https?\:\/\/)?(www\.)?(youtube\.com|youtu\.be)\/(watch\?v=)?[a-z0-9A-Z_\-]+/);
- if (imgMatch != null && imgMatch.length > 0) {
- var image = imagify(imgMatch[0],channel);
- chatTab.append("<p class=chat-line>"+image+"</p>");
- }
- if (vidMatch != null && vidMatch.length > 0) {
- chatTab.append("<p class=chat-line><video controls><source src="+vidMatch[0]+"></video></p>");
- }
- if (audioMatch != null && audioMatch.length > 0) {
- chatTab.append("<p class=chat-line><audio controls><source src="+audioMatch[0]+"></audio></p>");
- }
- if (youtubeMatch != null && youtubeMatch.length > 0) {
- console.log(youtubeMatch)
- youtubeParts = youtubeMatch[0].split("/");
- youtubeId = youtubeParts[youtubeParts.length-1];
- youtubeId = youtubeId.replace("watch?v=","");
- chatTab.append("<p class=chat-line><iframe width='480' height='270' src='https://www.youtube.com/embed/"+youtubeId+"' frameborder='0' allowfullscreen></iframe></p>");
- }
-
- chatTab.scrollTop(chatTab.prop("scrollHeight"));
- });
- numChans++;
-}
-
-function removeChannel(channel, sendPart) {
- channel = channel.replace("#","");
- chanId = $("[data-tab=chan-"+channel+"].chat").attr("data-id");
- $("[data-tab=chan-"+channel+"]").remove();
- if (sendPart) {
- client.part("#"+channel);
- }
- while ($("[data-id="+(chanId-1)+"]").length == 0 && chanId >=0) {
- chanId--;
- }
- $("[data-id="+(chanId-1)+"]").addClass("active");
-}
-
-function createListeners(client) {
-
-
-client.addListener('error', function(message) {
- console.log('error: ', message);
-});
-
-client.addListener('registered', function() {
- channels.forEach(function(channel) {
- joinChannel(channel, false);
- });
-});
-
-client.addListener('motd', function(motd) {
- var statusTab = $("[data-tab=status].chat");
- statusTab.append("<p class='chat-line'>"+motd+"</p>")
- statusTab.scrollTop(statusTab.prop("scrollHeight"));
-});
-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 || message.command.startsWith("rpl_")) {
- statusTab.append("<p class='chat-line'>"+message.command + ": " +message.args+"</p>")
- statusTab.scrollTop(statusTab.prop("scrollHeight"));
- }
-});
-
-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("#","")
- 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('pm', function(nick, text, message) {
-
- if($(".ui.tab[data-tab=pm-"+nick+"]").length == 0) {
- $(".ui.menu").append("<a class='item' data-id='"+numChans+"' data-tab='pm-"+nick+"'>"+nick+"</a>");
- $("#chan-container").append("<div class='ui tab' data-id='"+numChans+"' data-tab='pm-"+nick+"'></div>");
- var chanTab = $("[data-tab=pm-"+ nick +"].tab");
- chanTab.append("<div class='ui segment chat' data-id='"+numChans+"' data-tab='pm-"+nick+"'></div>");
- numChans++;
- $('.menu .item').tab({history:false});
- }
- var chatTab = $("[data-tab=pm-"+ nick +"].chat");
- chatTab.append("<p class='chat-line'>&lt"+nick+"&gt "+text+"</p>")
- chatTab.scrollTop(chatTab.prop("scrollHeight"));
-});
-
-client.addListener('kick', function(channel, nick, by, reason, message) {
- if (myNick == nick) {
- removeChannel(channel, false);
- } else {
- 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+"was kicked from #"+channel+" by "+by+" ("+reason+")</p>")
- chatTab.scrollTop(chatTab.prop("scrollHeight"));
- }
-});
-
-client.addListener('kill', 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+" was killed by the server ("+reason+")</p>")
- chatTab.scrollTop(chatTab.prop("scrollHeight"));
- });
-});
-
-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>")
-});
-
-client.addListener('whois', function(info) {
- console.log(info)
- var chatTab = $(".active .chat");
- chatTab.append("<p class='chat-line'> Nick:"+info.nick+"</p>");
- chatTab.append("<p class='chat-line'> User:"+info.user+"</p>");
- chatTab.append("<p class='chat-line'> Host:"+info.host+"</p>");
- chatTab.append("<p class='chat-line'> Real Name:"+info.realname+"</p>");
- chatTab.append("<p class='chat-line'> Channels:");
- for (channel in info.channels) {
- chatTab.append(" "+info.channels[channel])
- }
- chatTab.append("</p>")
- chatTab.append("<p class='chat-line'> Server:"+info.server+"</p>");
- chatTab.append("<p class='chat-line'> Server Info:"+info.serverinfo+"</p>");
- chatTab.append("<p class='chat-line'>"+info.operator+"</p>");
- chatTab.scrollTop(chatTab.prop("scrollHeight"));
-});
-
-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"));
-});
-
-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"));
- }
-});
-
-}
+// client.addListener('kill', 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+" was killed by the server ("+reason+")</p>")
+// chatTab.scrollTop(chatTab.prop("scrollHeight"));
+// });
+// });