import { Helper, BotManager, Context, User, Message } from "../Core"; import { Bot } from "../Bot"; import { Matcher } from '../Matcher'; const Rx = require("rx").Rx; const typofix = require("typofix"); export class dym { static pluginName: string = "auth"; static description: string = "Authorization and Role Manager"; static apply(bot: Bot) { bot.miss$ .do((msg) => { var commands = bot.respondsTo(); typofix.pushNewWords(commands); var suggestions = []; msg.text.split(' ').forEach(word => { var correction = typofix.suggest(word); if (correction.length > 0) { var newCommand = msg.text.replace(word, correction[0]); var result = Matcher.findMatchFromListOfCommands(commands, msg.user, newCommand, bot._id); if (result.match) { suggestions.push(newCommand); } } }); msg.suggestions = suggestions; }) .where(msg => msg.suggestions.length > 0) .reply(msg => 'did you mean `' + msg.suggestions[0] + '`') .subscribe(); } };