update command search rankings

This commit is contained in:
derpystuff 2023-06-30 23:30:01 +02:00
parent b3989587bb
commit 40c6b6d7e7

View file

@ -113,16 +113,27 @@ module.exports = {
permissionsClient: [Permissions.EMBED_LINKS, Permissions.SEND_MESSAGES, Permissions.USE_EXTERNAL_EMOJIS],
run: async (context, args) => {
if(args.command){
await context.triggerTyping()
// Detailed command view
let results = []
let resultScores = {}
let resultMappings = {}
for(const c of context.commandClient.commands){
if(c.name.includes(args.command.toLowerCase()) || c.aliases.filter((f)=>{return f.includes(args.command.toLowerCase())}).length >= 1){
if(c.metadata.explicit && !context.channel.nsfw) continue;
results.push(c)
resultScores[c.name] = 1
resultMappings[c.name] = c
}
// Boost exact matches to rank higher in the result list
if(c.name == args.command.toLowerCase()) resultScores[c.name] += 1
if(c.aliases.filter((f)=>{return f == args.command.toLowerCase()}).length >= 1) resultScores[c.name] += 1
}
let results = [];
resultScores = Object.fromEntries(Object.entries(resultScores).sort(([,a],[,b]) => b-a));
for(const k of Object.keys(resultScores)) results.push(resultMappings[k])
let pages = []
let prefix = DEFAULT_BOT_PREFIX
try{