2015-12-28 23:34:32 +00:00
|
|
|
import createCommandMiddleware from './middleware/command';
|
|
|
|
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';
|
2016-01-27 19:48:47 +00:00
|
|
|
import { sendMessage, addMessage, inform, raw } from './actions/message';
|
2015-12-28 23:34:32 +00:00
|
|
|
|
|
|
|
const help = [
|
|
|
|
'/join <channel> - Join a channel',
|
|
|
|
'/part [channel] - Leave the current or specified channel',
|
|
|
|
'/nick <nick> - Change nick',
|
|
|
|
'/quit - Disconnect from the current server',
|
|
|
|
'/me <message> - Send action message',
|
|
|
|
'/topic - Show topic for the current channel',
|
|
|
|
'/msg <target> <message> - Send message to the specified channel or user',
|
|
|
|
'/say <message> - Send message to the current chat',
|
|
|
|
'/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',
|
2016-01-27 19:48:47 +00:00
|
|
|
'/away [message] - Set or clear away message',
|
|
|
|
'/raw [message] - Send raw IRC message to the current server'
|
2017-04-20 02:16:15 +00:00
|
|
|
];
|
2015-12-28 23:34:32 +00:00
|
|
|
|
|
|
|
export default createCommandMiddleware(COMMAND, {
|
|
|
|
join({ dispatch, server }, channel) {
|
|
|
|
if (channel) {
|
|
|
|
dispatch(join([channel], server));
|
|
|
|
dispatch(select(server, channel));
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
part({ dispatch, server, channel }, partChannel) {
|
|
|
|
if (partChannel) {
|
|
|
|
dispatch(part([partChannel], server));
|
|
|
|
} else {
|
|
|
|
dispatch(part([channel], server));
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
nick({ dispatch, server }, nick) {
|
|
|
|
if (nick) {
|
|
|
|
dispatch(setNick(nick, server));
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
quit({ dispatch, server }) {
|
|
|
|
dispatch(disconnect(server));
|
|
|
|
},
|
|
|
|
|
|
|
|
me({ dispatch, server, channel }, ...params) {
|
|
|
|
if (params.length > 0) {
|
|
|
|
dispatch(sendMessage(`\x01ACTION ${params.join(' ')}\x01`, channel, server));
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
topic({ dispatch, getState, server, channel }) {
|
|
|
|
const topic = getState().channels.getIn([server, channel, 'topic']);
|
|
|
|
if (topic) {
|
|
|
|
dispatch(addMessage({
|
|
|
|
server,
|
|
|
|
to: channel,
|
2017-04-17 20:36:37 +00:00
|
|
|
content: topic
|
2015-12-28 23:34:32 +00:00
|
|
|
}));
|
|
|
|
} else {
|
|
|
|
dispatch(inform('No topic set', server, channel));
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
msg({ dispatch, server }, target, ...message) {
|
|
|
|
if (target && message) {
|
|
|
|
dispatch(sendMessage(message.join(' '), target, server));
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
say({ dispatch, server, channel }, ...message) {
|
|
|
|
if (channel && message) {
|
|
|
|
dispatch(sendMessage(message.join(' '), channel, server));
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
invite({ dispatch, server, channel }, user, inviteChannel) {
|
|
|
|
if (user && inviteChannel) {
|
|
|
|
dispatch(invite(user, inviteChannel, server));
|
|
|
|
} else if (user && channel) {
|
|
|
|
dispatch(invite(user, channel, server));
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
kick({ dispatch, server, channel }, user) {
|
|
|
|
if (user && channel) {
|
|
|
|
dispatch(kick(user, channel, server));
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
whois({ dispatch, server }, user) {
|
|
|
|
if (user) {
|
|
|
|
dispatch(whois(user, server));
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
away({ dispatch, server }, message) {
|
|
|
|
dispatch(away(message, server));
|
|
|
|
},
|
|
|
|
|
2016-01-27 19:48:47 +00:00
|
|
|
raw({ dispatch, server }, ...message) {
|
|
|
|
if (message) {
|
|
|
|
dispatch(raw(message.join(' '), server));
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2015-12-28 23:34:32 +00:00
|
|
|
help({ dispatch, server, channel }) {
|
|
|
|
dispatch(inform(help, server, channel));
|
|
|
|
}
|
|
|
|
});
|