Merge pull request #7 from xPaw/invites

Handle invite event
This commit is contained in:
Alistair McKinlay 2016-02-19 21:58:22 +00:00
commit 761958e3ee
5 changed files with 44 additions and 4 deletions

View File

@ -672,6 +672,13 @@ button, .user {
#chat.hide-quit .quit {
display: none !important;
}
#chat .invite .from:before {
font-family: FontAwesome;
content: "\f003";
color: #2ECC40;
}
#chat .join .from:before {
font-family: FontAwesome;
content: "\f090";

View File

@ -194,8 +194,10 @@ $(function() {
var chan = chat.find(target);
var from = data.msg.from;
var msg;
if ([
"invite",
"join",
"mode",
"kick",
@ -206,6 +208,7 @@ $(function() {
"action",
].indexOf(type) !== -1) {
switch (type) {
case "invite": data.msg.formattedAction = "invited " + data.msg.target + " to"; break;
case "join": data.msg.formattedAction = "has joined the channel"; break;
case "mode": data.msg.formattedAction = "sets mode"; break;
case "kick": data.msg.formattedAction = "has kicked"; break;
@ -216,12 +219,11 @@ $(function() {
default: data.msg.formattedAction = "";
}
var action = $(render("msg_action", data.msg));
return action;
msg = $(render("msg_action", data.msg));
} else {
msg = $(render("msg", data.msg));
}
var msg = $(render("msg", data.msg));
var text = msg.find(".text");
if (text.find("i").size() === 1) {
text = text.find("i");

View File

@ -17,6 +17,7 @@ var id = 0;
var events = [
"ctcp",
"error",
"invite",
"join",
"kick",
"mode",

View File

@ -4,6 +4,7 @@ var moment = require("moment");
Msg.Type = {
ACTION: "action",
ERROR: "error",
INVITE: "invite",
JOIN: "join",
KICK: "kick",
MESSAGE: "message",

View File

@ -0,0 +1,29 @@
var _ = require("lodash");
var Msg = require("../../models/msg");
module.exports = function(irc, network) {
var client = this;
irc.on("invite", function(data) {
var target = data.to;
if (target.toLowerCase() === irc.me.toLowerCase()) {
target = "you";
}
var chan = _.findWhere(network.channels, {name: data.channel});
if (typeof chan === "undefined") {
chan = network.channels[0];
}
var msg = new Msg({
type: Msg.Type.INVITE,
from: data.from,
target: target,
text: data.channel
});
chan.messages.push(msg);
client.emit("msg", {
chan: chan.id,
msg: msg
});
});
};