2016-06-01 11:24:21 +00:00
|
|
|
import AutocompleteProvider from './AutocompleteProvider';
|
|
|
|
import Q from 'q';
|
|
|
|
import Fuse from 'fuse.js';
|
|
|
|
|
|
|
|
const COMMANDS = [
|
|
|
|
{
|
|
|
|
command: '/me',
|
|
|
|
args: '<message>',
|
|
|
|
description: 'Displays action'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
command: '/ban',
|
|
|
|
args: '<user-id> [reason]',
|
|
|
|
description: 'Bans user with given id'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
command: '/deop'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
command: '/encrypt'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
command: '/invite'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
command: '/join',
|
|
|
|
args: '<room-alias>',
|
|
|
|
description: 'Joins room with given alias'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
command: '/kick',
|
|
|
|
args: '<user-id> [reason]',
|
|
|
|
description: 'Kicks user with given id'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
command: '/nick',
|
|
|
|
args: '<display-name>',
|
|
|
|
description: 'Changes your display nickname'
|
|
|
|
}
|
|
|
|
];
|
|
|
|
|
2016-06-20 08:22:55 +00:00
|
|
|
let instance = null;
|
|
|
|
|
2016-06-01 11:24:21 +00:00
|
|
|
export default class CommandProvider extends AutocompleteProvider {
|
|
|
|
constructor() {
|
|
|
|
super();
|
|
|
|
this.fuse = new Fuse(COMMANDS, {
|
|
|
|
keys: ['command', 'args', 'description']
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
getCompletions(query: String) {
|
|
|
|
let completions = [];
|
2016-06-20 08:22:55 +00:00
|
|
|
const matches = query.match(/(^\/\w*)/);
|
2016-06-01 11:24:21 +00:00
|
|
|
if(!!matches) {
|
|
|
|
const command = matches[0];
|
|
|
|
completions = this.fuse.search(command).map(result => {
|
|
|
|
return {
|
|
|
|
title: result.command,
|
|
|
|
subtitle: result.args,
|
|
|
|
description: result.description
|
|
|
|
};
|
|
|
|
});
|
|
|
|
}
|
|
|
|
return Q.when(completions);
|
|
|
|
}
|
2016-06-12 11:32:46 +00:00
|
|
|
|
|
|
|
getName() {
|
|
|
|
return 'Commands';
|
|
|
|
}
|
2016-06-20 08:22:55 +00:00
|
|
|
|
|
|
|
static getInstance(): CommandProvider {
|
|
|
|
if(instance == null)
|
|
|
|
instance = new CommandProvider();
|
|
|
|
|
|
|
|
return instance;
|
|
|
|
}
|
2016-06-01 11:24:21 +00:00
|
|
|
}
|