Add /raw command

This commit is contained in:
Ken-Håvard Lieng 2016-01-27 20:48:47 +01:00
parent d51b5a35fd
commit b50a4a1068
6 changed files with 46 additions and 11 deletions

File diff suppressed because one or more lines are too long

View File

@ -15,6 +15,7 @@ export const JOIN = 'JOIN';
export const KICK = 'KICK';
export const OPEN_PRIVATE_CHAT = 'OPEN_PRIVATE_CHAT';
export const PART = 'PART';
export const RAW = 'RAW';
export const SEARCH_MESSAGES = 'SEARCH_MESSAGES';
export const SELECT_TAB = 'SELECT_TAB';
export const SEND_MESSAGE = 'SEND_MESSAGE';
@ -34,8 +35,8 @@ export const SOCKET_NICK = 'SOCKET_NICK';
export const SOCKET_PART = 'SOCKET_PART';
export const SOCKET_PM = 'SOCKET_PM';
export const SOCKET_QUIT = 'SOCKET_QUIT';
export const SOCKET_SERVERS = 'SOCKET_SERVERS';
export const SOCKET_SEARCH = 'SOCKET_SEARCH';
export const SOCKET_SERVERS = 'SOCKET_SERVERS';
export const SOCKET_TOPIC = 'SOCKET_TOPIC';
export const SOCKET_USERS = 'SOCKET_USERS';
export const TAB_HISTORY_POP = 'TAB_HISTORY_POP';

View File

@ -75,3 +75,15 @@ export function runCommand(command, channel, server) {
server
};
}
export function raw(message, server) {
return {
type: actions.RAW,
message,
server,
socket: {
type: 'raw',
data: { message, server }
}
};
}

View File

@ -4,7 +4,7 @@ import { COMMAND } from './actions';
import { setNick, disconnect, whois, away } from './actions/server';
import { join, part, invite, kick } from './actions/channel';
import { select } from './actions/tab';
import { sendMessage, addMessage, inform } from './actions/message';
import { sendMessage, addMessage, inform, raw } from './actions/message';
const help = [
'/join <channel> - Join a channel',
@ -18,7 +18,8 @@ const help = [
'/invite <user> [channel] - Invite user to the current or specified channel',
'/kick <user> - Kick user from the current channel',
'/whois <user> - Get information about user',
'/away [message] - Set or clear away message'
'/away [message] - Set or clear away message',
'/raw [message] - Send raw IRC message to the current server'
].map(_.escape);
export default createCommandMiddleware(COMMAND, {
@ -102,6 +103,12 @@ export default createCommandMiddleware(COMMAND, {
dispatch(away(message, server));
},
raw({ dispatch, server }, ...message) {
if (message) {
dispatch(raw(message.join(' '), server));
}
},
help({ dispatch, server, channel }) {
dispatch(inform(help, server, channel));
}

View File

@ -115,6 +115,11 @@ type Away struct {
Message string `json:"message"`
}
type Raw struct {
Server string `json:"server"`
Message string `json:"message"`
}
type SearchRequest struct {
Server string `json:"server"`
Channel string `json:"channel"`

View File

@ -217,6 +217,15 @@ func (h *wsHandler) away(b []byte) {
}
}
func (h *wsHandler) raw(b []byte) {
var data Raw
json.Unmarshal(b, &data)
if i, ok := h.session.getIRC(data.Server); ok {
i.Write(data.Message)
}
}
func (h *wsHandler) search(b []byte) {
go func() {
var data SearchRequest
@ -261,6 +270,7 @@ func (h *wsHandler) initHandlers() {
"kick": h.kick,
"whois": h.whois,
"away": h.away,
"raw": h.raw,
"search": h.search,
"cert": h.cert,
}