Added /whois, /invite, /kick, /msg and /say

This commit is contained in:
khlieng 2015-02-10 02:25:28 +01:00
parent 5df364a3a4
commit ed09a97ade
7 changed files with 150 additions and 0 deletions

View File

@ -6,6 +6,8 @@ var socket = require('../socket');
var channelActions = Reflux.createActions([ var channelActions = Reflux.createActions([
'join', 'join',
'part', 'part',
'invite',
'kick',
'addUser', 'addUser',
'removeUser', 'removeUser',
'removeUserAll', 'removeUserAll',
@ -30,4 +32,20 @@ channelActions.part.preEmit = function(channels, server) {
}); });
}; };
channelActions.invite.preEmit = function(user, channel, server) {
socket.send('invite', {
server: server,
channel: channel,
user: user
});
};
channelActions.kick.preEmit = function(user, channel, server) {
socket.send('kick', {
server: server,
channel: channel,
user: user
});
};
module.exports = channelActions; module.exports = channelActions;

View File

@ -5,6 +5,7 @@ var socket = require('../socket');
var serverActions = Reflux.createActions([ var serverActions = Reflux.createActions([
'connect', 'connect',
'disconnect', 'disconnect',
'whois',
'setNick', 'setNick',
'load' 'load'
]); ]);
@ -25,6 +26,13 @@ serverActions.disconnect.preEmit = function(server) {
socket.send('quit', { server: server }); socket.send('quit', { server: server });
}; };
serverActions.whois.preEmit = function(user, server) {
socket.send('whois', {
server: server,
user: user
});
};
serverActions.setNick.preEmit = function(nick, server) { serverActions.setNick.preEmit = function(nick, server) {
socket.send('nick', { socket.send('nick', {
server: server, server: server,

View File

@ -1,4 +1,5 @@
var channelStore = require('./stores/channel'); var channelStore = require('./stores/channel');
var selectedTabStore = require('./stores/selectedTab');
var channelActions = require('./actions/channel'); var channelActions = require('./actions/channel');
var messageActions = require('./actions/message'); var messageActions = require('./actions/message');
var serverActions = require('./actions/server'); var serverActions = require('./actions/server');
@ -46,5 +47,43 @@ messageActions.command.listen(function(line, channel, server) {
messageActions.inform('No topic set', server, channel); messageActions.inform('No topic set', server, channel);
} }
break; break;
case 'invite':
if (params[1] && params[2] && server) {
channelActions.invite(params[1], params[2], server);
} else if (params[1] && channel) {
channelActions.invite(params[1], channel, server);
}
break;
case 'kick':
if (params[1] && channel) {
channelActions.kick(params[1], channel, server);
}
break;
case 'msg':
if (params.length > 2) {
var dest = params[1];
var message = params.slice(2).join(' ');
messageActions.send(message, dest, server);
}
break;
case 'say':
if (params.length > 1) {
var message = params.slice(1).join(' ');
messageActions.send(message, channel, server);
}
break;
case 'whois':
if (params[1]) {
serverActions.whois(params[1], server);
}
break;
} }
}); });

View File

@ -1,6 +1,7 @@
var _ = require('lodash'); var _ = require('lodash');
var socket = require('./socket'); var socket = require('./socket');
var selectedTabStore = require('./stores/selectedTab');
var channelActions = require('./actions/channel'); var channelActions = require('./actions/channel');
var messageActions = require('./actions/message'); var messageActions = require('./actions/message');
var serverActions = require('./actions/server'); var serverActions = require('./actions/server');
@ -55,6 +56,19 @@ socket.on('mode', function(data) {
channelActions.setMode(data); channelActions.setMode(data);
}); });
socket.on('whois', function(data) {
var tab = selectedTabStore.getState();
console.log(data.channels);
messageActions.inform('Nick: ' + data.nick, tab.server, tab.channel);
messageActions.inform('Username: ' + data.username, tab.server, tab.channel);
messageActions.inform('Realname: ' + data.realname, tab.server, tab.channel);
messageActions.inform('Host: ' + data.host, tab.server, tab.channel);
messageActions.inform('Server: ' + data.server, tab.server, tab.channel);
messageActions.inform('Channels: ' + data.channels, tab.server, tab.channel);
});
socket.on('servers', function(data) { socket.on('servers', function(data) {
serverActions.load(data); serverActions.load(data);
}); });

View File

@ -80,6 +80,32 @@ type MOTD struct {
Content []string `json:"content"` Content []string `json:"content"`
} }
type Invite struct {
Server string `json:"server"`
Channel string `json:"channel"`
User string `json:"user"`
}
type Kick struct {
Server string `json:"server"`
Channel string `json:"channel"`
User string `json:"user"`
}
type Whois struct {
Server string `json:"server"`
User string `json:"user"`
}
type WhoisReply struct {
Nick string `json:"nick"`
Username string `json:"username"`
Host string `json:"host"`
Realname string `json:"realname"`
Server string `json:"server"`
Channels []string `json:"channels"`
}
type Error struct { type Error struct {
Server string `json:"server"` Server string `json:"server"`
Message string `json:"message"` Message string `json:"message"`

View File

@ -8,6 +8,7 @@ import (
) )
func handleMessages(irc *IRC, session *Session) { func handleMessages(irc *IRC, session *Session) {
var whois WhoisReply
userBuffers := make(map[string][]string) userBuffers := make(map[string][]string)
var motd MOTD var motd MOTD
@ -112,6 +113,23 @@ func handleMessages(irc *IRC, session *Session) {
Message: strings.Join(msg.Params[1:], " "), Message: strings.Join(msg.Params[1:], " "),
}) })
case RPL_WHOISUSER:
whois.Nick = msg.Params[1]
whois.Username = msg.Params[2]
whois.Host = msg.Params[3]
whois.Realname = msg.Params[5]
case RPL_WHOISSERVER:
whois.Server = msg.Params[2]
case RPL_WHOISCHANNELS:
whois.Channels = append(whois.Channels, strings.Split(strings.TrimRight(msg.Trailing, " "), " ")...)
case RPL_ENDOFWHOIS:
session.sendJSON("whois", whois)
whois = WhoisReply{}
case RPL_TOPIC: case RPL_TOPIC:
session.sendJSON("topic", Topic{ session.sendJSON("topic", Topic{
Server: irc.Host, Server: irc.Host,

View File

@ -148,6 +148,33 @@ func handleWS(ws *websocket.Conn) {
irc.Nick(data.New) irc.Nick(data.New)
session.user.SetNick(data.New, data.Server) session.user.SetNick(data.New, data.Server)
} }
case "invite":
var data Invite
json.Unmarshal(req.Request, &data)
if irc, ok := session.getIRC(data.Server); ok {
irc.Invite(data.User, data.Channel)
}
case "kick":
var data Invite
json.Unmarshal(req.Request, &data)
if irc, ok := session.getIRC(data.Server); ok {
irc.Kick(data.Channel, data.User)
}
case "whois":
var data Whois
json.Unmarshal(req.Request, &data)
if irc, ok := session.getIRC(data.Server); ok {
irc.Whois(data.User)
}
} }
} }
} }