Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function bestCat(label, showRating = false, log = false) {
const lbl = label.toLowerCase()
if (lbl in SIM_EXCEPTIONS) {
const target = SIM_EXCEPTIONS[lbl]
return showRating ? {target, rating: 1} : target
}
const match = {...strSim.findBestMatch(lbl, CATEGORIES).bestMatch, ref: 'M'}
const seMatch = {...strSim.findBestMatch(lbl, SE).bestMatch, ref: 'SE'}
const nclMatch = {
...strSim.findBestMatch(lbl, NON_CATEGORY_LABELS).bestMatch,
ref: 'NC',
}
const clMatch = {...strSim.findBestMatch(lbl, CL).bestMatch, ref: 'CL'}
const scores = [match, seMatch, clMatch, nclMatch].sort(
(a, b) => b.rating - a.rating,
)
if (log) {
//eslint-disable-next-line no-console
console.log('scores=', scores)
}
let idx = 0
while (scores[idx++].rating < MATCH_THRESHOLD && idx < scores.length) {
/* */
}
const related = this.isDefined(option, 'options');
if (related) {
const details = this.readOption(related);
Object.assign(options, details);
}
if (!related && !definedSubcommand) {
// Unknown Option
const availableOptions = [];
this.details.options.forEach((opt) => {
availableOptions.push(...opt.usage);
});
const suggestOption = stringSimilarity.findBestMatch(
option,
availableOptions,
);
console.log(`The option "${option}" is unknown.`); // eslint-disable-line
if (suggestOption.bestMatch.rating >= 0.5) {
console.log(' Did you mean the following one?\n'); // eslint-disable-line
const suggestion = this.details.options.filter((item) => {
for (const flag of item.usage) {
if (flag === suggestOption.bestMatch.target) {
return true;
}
}
const getClosest = (value, list) => {
const matches = stringSimilarity.findBestMatch(value, list);
// only return the best match if its greater than .5 in similarity
return matches.bestMatch.rating >= 0.5 ? matches.bestMatch.target : '';
};
function bestCat(label, showRating = false, log = false) {
const lbl = label.toLowerCase()
if (lbl in SIM_EXCEPTIONS) {
const target = SIM_EXCEPTIONS[lbl]
return showRating ? {target, rating: 1} : target
}
const match = {...strSim.findBestMatch(lbl, CATEGORIES).bestMatch, ref: 'M'}
const seMatch = {...strSim.findBestMatch(lbl, SE).bestMatch, ref: 'SE'}
const nclMatch = {
...strSim.findBestMatch(lbl, NON_CATEGORY_LABELS).bestMatch,
ref: 'NC',
}
const clMatch = {...strSim.findBestMatch(lbl, CL).bestMatch, ref: 'CL'}
const scores = [match, seMatch, clMatch, nclMatch].sort(
(a, b) => b.rating - a.rating,
)
if (log) {
//eslint-disable-next-line no-console
console.log('scores=', scores)
}
let idx = 0
while (scores[idx++].rating < MATCH_THRESHOLD && idx < scores.length) {
module.exports.run = async (bot, message, args) => {
if(message.author.bot) return;
if(message.channel.type !== "text") return;
let members = [];
let indexes = [];
message.guild.members.forEach(function(member){
members.push(member.user.username);
indexes.push(member.id);
})
let match = sm.findBestMatch(args.join(' '), members);
let username = match.bestMatch.target;
let member = message.guild.members.get(indexes[members.indexOf(username)])
let definedUser = "";
let definedUser2 = "";
if(!args[0]) {
definedUser = message.author
definedUser2 = message.member
} else {
let mention = message.mentions.users.first()
definedUser = mention || member.user
definedUser2 = message.mentions.members.first() || message.guild.members.get(args[0]) || member
}
message.channel.send({embed: new Discord.RichEmbed()
export const getIntendedInput = (commands, command, terms = []) => {
const VALID_COMMANDS = keys(commands);
const {bestMatch: {target: intendedCommand}} = findBestMatch(command, VALID_COMMANDS);
const VALID_TERMS = keys(commands[intendedCommand]);
const intendedTerms = terms.map(term => findBestMatch(term, VALID_TERMS).bestMatch.target);
return {intendedCommand, intendedTerms};
};
/**
function guessQuestion(message) {
const match = findBestMatch(message, Object.values(QUESTIONS));
if (match.bestMatch.rating > 0.5) {
return Object.keys(QUESTIONS)[match.bestMatchIndex];
}
}
.map(flag => {
if (!argNames.includes(flag)) {
const match = stringSimilarity.findBestMatch(flag, argNames).bestMatch
throw new FlagNotFoundError(
chalk.red(`Error: Flag ${chalk.red.underline(flag)} not found\n`) +
(match.rating > 0.4
? chalk.yellow(
`Did you mean: ${chalk.yellow.underline(match.target)} ?`,
)
: '') +
'\n' +
functionHelpText(fn),
)
}
})