summaryrefslogtreecommitdiff
path: root/commands.js
diff options
context:
space:
mode:
Diffstat (limited to 'commands.js')
-rw-r--r--commands.js89
1 files changed, 89 insertions, 0 deletions
diff --git a/commands.js b/commands.js
new file mode 100644
index 0000000..1847b74
--- /dev/null
+++ b/commands.js
@@ -0,0 +1,89 @@
+var client
+var globals = require('./globals.js')
+
+module.exports.init = function(myClient) {
+ client = myClient
+}
+
+module.exports.sendMsg = function(message, channel) {
+ client.say(channel, message);
+ var chanTab = $("[data-tab='"+ channel +"'].chat");
+ chanTab.append("<p class='chat-line'>&lt;" + globals.myNick + "&gt; " + message +"</p>");
+ chanTab.scrollTop(chanTab.prop("scrollHeight"));
+}
+
+module.exports.sendPm = function(message, nick) {
+
+ var chanTab = $("[data-tab="+nick+"].tab");
+ $(".active").removeClass("active");
+ numChans = globals.channels.length
+ if (chanTab.length == 0) {
+ $(".ui.menu").append("<a class='active item' data-id='"+numChans+"' data-tab='"+nick+"'>"+nick+"</a>");
+ $("#chan-container").append("<div class='ui active tab' data-id='"+numChans+"' data-tab='"+nick+"'></div>");
+ chanTab = $("[data-tab="+nick+"].tab");
+ chanTab.append("<div class='ui segment chat' data-id='"+numChans+"' data-tab='"+nick+"'></div>");
+
+ $('.menu .item').tab({history:false});
+ globals.channels.push(nick)
+ numChans++;
+ }
+ $("[data-tab="+nick+"]").addClass("active");
+ var chatTab = $("[data-tab="+nick+"].chat");
+ console.log(nick + ': ' + message);
+ client.say(nick, message);
+ chatTab.append("<p class='chat-line'>&lt;" + globals.myNick + "&gt; " + message +"</p>");
+ chatTab.scrollTop(chanTab.prop("scrollHeight"));
+}
+
+
+module.exports.setTopic = function(channel, topic) {
+ client.raw("TOPIC", channel, topic);
+}
+
+module.exports.joinChannel = function (channel, sendJoin) {
+
+ numChans = globals.channels.length
+ 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});
+ globals.channels.push(channel)
+ numChans++;
+}
+
+module.exports.removeChannel = function(channel, sendPart) {
+
+ chanId = $("[data-tab='"+channel+"'].chat").attr("data-id");
+ $("[data-tab='"+channel+"']").remove();
+ if (sendPart) {
+ var channelObj = client.channel(channel)
+ channelObj.part();
+ }
+ while ($("[data-id="+(chanId-1)+"]").length == 0 && chanId >=0) {
+ chanId--;
+ }
+ $("[data-id="+(chanId-1)+"]").addClass("active");
+}
+
+module.exports.whois = function(nick) {
+ client.whois(nick);
+}
+
+module.exports.list = function() {
+ client.raw("LIST")
+}