import AutocompleteProvider from './AutocompleteProvider'; import Q from 'q'; import Fuse from 'fuse.js'; const COMMANDS = [ { command: '/me', args: '', description: 'Displays action' }, { command: '/ban', args: ' [reason]', description: 'Bans user with given id' }, { command: '/deop' }, { command: '/encrypt' }, { command: '/invite' }, { command: '/join', args: '', description: 'Joins room with given alias' }, { command: '/kick', args: ' [reason]', description: 'Kicks user with given id' }, { command: '/nick', args: '', description: 'Changes your display nickname' } ]; let instance = null; export default class CommandProvider extends AutocompleteProvider { constructor() { super(); this.fuse = new Fuse(COMMANDS, { keys: ['command', 'args', 'description'] }); } getCompletions(query: String) { let completions = []; const matches = query.match(/(^\/\w*)/); 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); } getName() { return 'Commands'; } static getInstance(): CommandProvider { if(instance == null) instance = new CommandProvider(); return instance; } }