2015-12-28 23:34:32 +00:00
|
|
|
import createCommandMiddleware from './middleware/command';
|
2017-05-26 06:20:00 +00:00
|
|
|
import { COMMAND } from './state/actions';
|
|
|
|
import { join, part, invite, kick } from './state/channels';
|
|
|
|
import { sendMessage, addMessage, raw } from './state/messages';
|
|
|
|
import { setNick, disconnect, whois, away } from './state/servers';
|
|
|
|
import { select } from './state/tab';
|
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 {
|
2017-05-22 01:49:37 +00:00
|
|
|
return 'No topic set';
|
2015-12-28 23:34:32 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
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) {
|
2017-05-22 01:49:37 +00:00
|
|
|
const cmd = message.join(' ');
|
|
|
|
dispatch(raw(cmd, server));
|
|
|
|
return `=> ${cmd}`;
|
2016-01-27 19:48:47 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2017-05-22 01:49:37 +00:00
|
|
|
help() {
|
|
|
|
return help;
|
|
|
|
},
|
|
|
|
|
|
|
|
commandNotFound(_, command) {
|
|
|
|
return `The command /${command} was not found`;
|
2015-12-28 23:34:32 +00:00
|
|
|
}
|
|
|
|
});
|