import React from 'react'; import AutocompleteProvider from './AutocompleteProvider'; import FuzzyMatcher from './FuzzyMatcher'; import {TextualCompletion} from './Components'; const COMMANDS = [ { command: '/me', args: '', description: 'Displays action', }, { command: '/part', args: '[#alias:domain]', description: 'Leave room', }, { command: '/ban', args: ' [reason]', description: 'Bans user with given id', }, { command: '/unban', args: '', description: 'Unbans user with given id', }, { command: '/deop', args: '', description: 'Deops user with given id', }, { command: '/invite', args: '', description: 'Invites user with given id to current room', }, { 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', }, { command: '/ddg', args: '', description: 'Searches DuckDuckGo for results', }, { command: '/op', args: ' []', description: 'Define the power level of a user', } ]; let COMMAND_RE = /(^\/\w*)/g; let instance = null; export default class CommandProvider extends AutocompleteProvider { constructor() { super(COMMAND_RE); this.matcher = new FuzzyMatcher(COMMANDS, { keys: ['command', 'args', 'description'], }); } async getCompletions(query: string, selection: {start: number, end: number}) { let completions = []; let {command, range} = this.getCurrentCommand(query, selection); if (command) { completions = this.matcher.match(command[0]).map(result => { return { completion: result.command + ' ', component: (), range, }; }); } return completions; } getName() { return '*️⃣ Commands'; } static getInstance(): CommandProvider { if (instance == null) {instance = new CommandProvider();} return instance; } renderCompletions(completions: [React.Component]): ?React.Component { return
{completions}
; } }