summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--debugmiddleware.js11
-rw-r--r--handlers.js22
-rw-r--r--index.js39
-rw-r--r--package.json1
4 files changed, 60 insertions, 13 deletions
diff --git a/debugmiddleware.js b/debugmiddleware.js
new file mode 100644
index 0000000..9db3aeb
--- /dev/null
+++ b/debugmiddleware.js
@@ -0,0 +1,11 @@
+module.exports.DebugMiddleware = function() {
+ return function(client, raw_events, parsed_events) {
+ parsed_events.use(theMiddleware);
+ }
+
+ function theMiddleware(command, event, client, next) {
+ // console.log(command);
+ // console.log(event);
+ next();
+ }
+}
diff --git a/handlers.js b/handlers.js
new file mode 100644
index 0000000..88259c7
--- /dev/null
+++ b/handlers.js
@@ -0,0 +1,22 @@
+module.exports.handleCommands = function(client) {
+
+ client.on('registered', function(event) {
+ console.log(event);
+ });
+
+ client.on('userlist', function(event) {
+ console.log(event);
+ channel = event.channel.replace("#","")
+ console.log(channel);
+ if($(".ui.tab[data-tab=chan-"+channel+"]").length == 0) {
+ console.log("there");
+ joinChannel(channel, false)
+ }
+ for(nick in event.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>")
+ }
+ }
+ });
+}
diff --git a/index.js b/index.js
index 96ce9dd..a21b00e 100644
--- a/index.js
+++ b/index.js
@@ -3,10 +3,15 @@ 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 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();
});
@@ -17,6 +22,8 @@ $(document).on('click', 'a[href^="http"]', function(event) {
});
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 +38,29 @@ 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
+ });
+
+ handlers.handleCommands(client);
$("#chan-container").show();
@@ -168,6 +180,7 @@ function setTopic(channel, topic) {
}
function joinChannel(channel, sendJoin) {
+ console.log("here");
if (sendJoin) {
client.join(channel);
}
diff --git a/package.json b/package.json
index d635fce..de2854e 100644
--- a/package.json
+++ b/package.json
@@ -9,5 +9,6 @@
"semantic-ui": "^2.1.8",
"linkifyjs": "2.0.0-beta.9",
"irc": "0.5.0",
+ "irc-framework": "2.0.0",
"electron-prebuilt": "0.37.3" }
}