summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--commands.js34
-rw-r--r--handlers.js32
-rw-r--r--index.js40
3 files changed, 44 insertions, 62 deletions
diff --git a/commands.js b/commands.js
new file mode 100644
index 0000000..b8f53f5
--- /dev/null
+++ b/commands.js
@@ -0,0 +1,34 @@
+var client
+
+module.exports.init = function(myClient) {
+ client = myClient
+}
+
+module.exports.setTopic = function(channel, topic) {
+ client.raw("TOPIC", channel, topic);
+}
+
+module.exports.joinChannel = function (channel, sendJoin) {
+
+ var channelObj = client.channel(channel);
+ if (sendJoin) {
+ channelObj.join();
+ channelObj.say("beep");
+ }
+ chanId = $(".active.chat").attr("data-id")
+
+ $(".active").removeClass("active");
+
+ $(".ui.menu").append("<a class='active item' data-id='"+numChans+"' data-tab='"+channel+"'>"+channel+"</a>");
+ $("#chan-container").append("<div class='ui active tab' data-id='"+numChans+"' data-tab='"+channel+"'></div>");
+
+ var chanTab = $("[data-tab='"+ channel +"'].tab");
+
+ chanTab.append("<div class='ui selection list users' data-id='"+numChans+"' data-tab='"+channel+"'></div>");
+ chanTab.append("<div class='ui segment chat' data-id='"+numChans+"' data-tab='"+channel+"'></div>");
+ chanTab.append("<div class='ui topic' data-id='"+numChans+"' data-tab='"+channel+"'></div>");
+
+ $('.menu .item').tab({history:false});
+
+ numChans++;
+}
diff --git a/handlers.js b/handlers.js
index 0e27c25..9b956c3 100644
--- a/handlers.js
+++ b/handlers.js
@@ -1,6 +1,7 @@
var linkify = require("linkifyjs");
var linkifyHtml = require('linkifyjs/html');
var util = require("./util.js")
+var commands = require("./commands.js")
var numChans = 1;
var channels;
@@ -13,7 +14,7 @@ module.exports.handleCommands = function(myClient) {
client = myClient;
client.on('registered', function(event) {
channels.forEach(function(channelStr) {
- joinChannel(channelStr, true);
+ commands.joinChannel(channelStr, true);
});
});
client.on('message', function(event) {
@@ -23,7 +24,7 @@ module.exports.handleCommands = function(myClient) {
client.on('userlist', function(event) {
channel = event.channel
if($(".ui.tab[data-tab='"+channel+"']").length == 0) {
- joinChannel(channel, false)
+ commands.joinChannel(channel, false)
}
event.users.forEach(function (user) {
var nick = user.nick
@@ -51,7 +52,7 @@ module.exports.handleCommands = function(myClient) {
time = "vov"
var chatTab = $("[data-tab='"+ channel +"'].chat");
if($(".ui.tab[data-tab='"+channel+"']").length == 0) {
- joinChannel(channel, false)
+ commands.joinChannel(channel, false)
}
chatTab.append("<p class='chat-line'>Topic for "+channel+" is "+topic+" - set by "+nick+" at "+time+"</p>")
var topicTab = $("[data-tab='"+ channel +"'].topic");
@@ -60,31 +61,6 @@ module.exports.handleCommands = function(myClient) {
}
-function joinChannel(channel, sendJoin) {
-
- var channelObj = client.channel(channel);
- if (sendJoin) {
- channelObj.join();
- channelObj.say("beep");
- }
- chanId = $(".active.chat").attr("data-id")
-
- $(".active").removeClass("active");
-
- $(".ui.menu").append("<a class='active item' data-id='"+numChans+"' data-tab='"+channel+"'>"+channel+"</a>");
- $("#chan-container").append("<div class='ui active tab' data-id='"+numChans+"' data-tab='"+channel+"'></div>");
-
- var chanTab = $("[data-tab='"+ channel +"'].tab");
-
- chanTab.append("<div class='ui selection list users' data-id='"+numChans+"' data-tab='"+channel+"'></div>");
- chanTab.append("<div class='ui segment chat' data-id='"+numChans+"' data-tab='"+channel+"'></div>");
- chanTab.append("<div class='ui topic' data-id='"+numChans+"' data-tab='"+channel+"'></div>");
-
- $('.menu .item').tab({history:false});
-
- numChans++;
-}
-
function receiveMsg(target, from, message) {
// message = message.autoLink( {
// callback: function(url) {
diff --git a/index.js b/index.js
index 7b11a23..d6d0a62 100644
--- a/index.js
+++ b/index.js
@@ -3,7 +3,7 @@ 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 debugmiddleware = require('./debugmiddleware.js');
const progName = pjson.name;
const version = pjson.version;
@@ -61,8 +61,9 @@ console.log($("#channel-input").val());
version: "blachat 0.1.3"
});
- handlers.setChannels(channels);
- handlers.handleCommands(client);
+ commands.init(client)
+ handlers.setChannels(channels)
+ handlers.handleCommands(client)
@@ -109,7 +110,7 @@ $("#send-message").keypress(function(e) {
var message = $("#send-message").val();
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);
@@ -127,7 +128,7 @@ $("#send-message").keypress(function(e) {
} else if (message.indexOf("/topic") == 0) {
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 + " ", "");
@@ -173,35 +174,6 @@ function sendPm(message, nick) {
chatTab.scrollTop(chanTab.prop("scrollHeight"));
}
-function setTopic(channel, topic) {
- client.raw("TOPIC", channel, topic);
-}
-
-function joinChannel(channel, sendJoin) {
-
- var channelObj = client.channel(channel);
- if (sendJoin) {
- channelObj.join();
- channelObj.say("beep");
- }
- chanId = $(".active.chat").attr("data-id")
-
- $(".active").removeClass("active");
-
- $(".ui.menu").append("<a class='active item' data-id='"+numChans+"' data-tab='"+channel+"'>"+channel+"</a>");
- $("#chan-container").append("<div class='ui active tab' data-id='"+numChans+"' data-tab='"+channel+"'></div>");
-
- var chanTab = $("[data-tab='"+ channel +"'].tab");
-
- chanTab.append("<div class='ui selection list users' data-id='"+numChans+"' data-tab='"+channel+"'></div>");
- chanTab.append("<div class='ui segment chat' data-id='"+numChans+"' data-tab='"+channel+"'></div>");
- chanTab.append("<div class='ui topic' data-id='"+numChans+"' data-tab='"+channel+"'></div>");
-
- $('.menu .item').tab({history:false});
-
- numChans++;
-}
-
function removeChannel(channel, sendPart) {
chanId = $("[data-tab='"+channel+"'].chat").attr("data-id");
$("[data-tab='"+channel+"']").remove();