mirror of
https://gitlab.com/bignutty/labscore.git
synced 2025-06-08 22:23:03 -04:00
update help command to use pills
This commit is contained in:
parent
1b8b2514c4
commit
15526dcc15
1 changed files with 39 additions and 17 deletions
|
@ -6,28 +6,45 @@ const { DISCORD_INVITES } = require('../../../labscore/constants')
|
||||||
const { paginator } = require('../../../labscore/client');
|
const { paginator } = require('../../../labscore/client');
|
||||||
const { editOrReply } = require('../../../labscore/utils/message');
|
const { editOrReply } = require('../../../labscore/utils/message');
|
||||||
|
|
||||||
function createHelpPage(context, title, contents){
|
function createHelpPage(context, title, contents, descriptions){
|
||||||
return {
|
return {
|
||||||
"embeds": [
|
"embeds": [
|
||||||
createEmbed("default", context, {
|
createEmbed("default", context, {
|
||||||
description: `${title}\n` +
|
description: `${title}\n\n` +
|
||||||
codeblock("ansi", contents) +
|
renderCommandList(contents, descriptions) +
|
||||||
`\n${icon("question")} Use ${highlight(`${context.commandClient.prefixes.custom.first()}help <command>`)} to view more information about a command.`
|
`\n\n${icon("question")} Use ${highlight(`${context.commandClient.prefixes.custom.first()}help <command>`)} to view more information about a command.`
|
||||||
})
|
})
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function renderCommandList(commands, descriptions, limit){
|
||||||
|
let len = Math.max(...(commands.map(el => el.length))) + 3;
|
||||||
|
let render = []
|
||||||
|
let i = 0;
|
||||||
|
for(const c of commands){
|
||||||
|
let pad = len - c.length;
|
||||||
|
|
||||||
|
let desc = descriptions[i]
|
||||||
|
if(desc.includes('\n')) desc = desc.split('\n')[0]
|
||||||
|
if(desc.length >= 41) desc = desc.substr(0, 40) + '...'
|
||||||
|
|
||||||
|
render.push(` \` ${c}${' '.repeat(pad)}\` ${desc}`)
|
||||||
|
i++
|
||||||
|
}
|
||||||
|
|
||||||
|
if(limit && render.length > limit) render.splice(limit, 999)
|
||||||
|
|
||||||
|
return render.join('\n')
|
||||||
|
}
|
||||||
|
|
||||||
function createCommandPage(context, prefix, command){
|
function createCommandPage(context, prefix, command){
|
||||||
|
alias = ''
|
||||||
|
if(command.aliases.length >= 1) alias = ' ` ' + command.aliases.join(' ` ` ') + ' `\n'
|
||||||
let page = createEmbed("default", context, {
|
let page = createEmbed("default", context, {
|
||||||
description: `**${prefix}${command.name}**\n${command.metadata.description}`,
|
description: `${icon("command")} \` ${command.name} \`\n${alias}\n${command.metadata.description}`,
|
||||||
fields: []
|
fields: []
|
||||||
})
|
})
|
||||||
if(command.aliases.length >= 1) page.fields.push({
|
|
||||||
name: `${icon("activity")} Aliases`,
|
|
||||||
value: command.aliases.join(', '),
|
|
||||||
inline: true
|
|
||||||
})
|
|
||||||
|
|
||||||
// TODO: maybe try building a little parser that highlights things via ansi
|
// TODO: maybe try building a little parser that highlights things via ansi
|
||||||
if(command.metadata.usage) page.fields.push({
|
if(command.metadata.usage) page.fields.push({
|
||||||
|
@ -41,7 +58,7 @@ function createCommandPage(context, prefix, command){
|
||||||
for(const e of command.metadata.examples) ex.push(prefix + e)
|
for(const e of command.metadata.examples) ex.push(prefix + e)
|
||||||
page.fields.push({
|
page.fields.push({
|
||||||
name: `${icon("info")} Examples`,
|
name: `${icon("info")} Examples`,
|
||||||
value: codeblock("ansi", ex),
|
value: '```' + ex.join('``````') + '```',
|
||||||
inline: false
|
inline: false
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -54,13 +71,12 @@ function createCommandPage(context, prefix, command){
|
||||||
const categories = {
|
const categories = {
|
||||||
"core": `${icon("house")} Core Commands`,
|
"core": `${icon("house")} Core Commands`,
|
||||||
"info": `${icon("info")} Information Commands`,
|
"info": `${icon("info")} Information Commands`,
|
||||||
|
"search": `${icon("search")} Search Commands`,
|
||||||
"utils": `${icon("utils")} Utility Commands`,
|
"utils": `${icon("utils")} Utility Commands`,
|
||||||
"image": `${icon("image")} Image Commands`,
|
"image": `${icon("image")} Image Commands`,
|
||||||
"mod": `${icon("moderation")} Moderation Commands`,
|
"mod": `${icon("moderation")} Moderation Commands`
|
||||||
"search": `${icon("search")} Search Commands`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
name: 'help',
|
name: 'help',
|
||||||
label: 'command',
|
label: 'command',
|
||||||
|
@ -87,9 +103,12 @@ module.exports = {
|
||||||
|
|
||||||
if(results.length > 1) {
|
if(results.length > 1) {
|
||||||
// Command overview
|
// Command overview
|
||||||
|
|
||||||
|
let cmds = results.map((m)=>{return m.name})
|
||||||
|
let dscs = results.map((m)=>{return m.metadata.description})
|
||||||
pages.push({embeds:[
|
pages.push({embeds:[
|
||||||
createEmbed("default", context, {
|
createEmbed("default", context, {
|
||||||
description: `Check pages for detailed command descriptions.\n` + codeblock("ansi", [(prefix + results.map((m)=>{return m.name}).splice(0, 10).join('\n' + prefix))]) + `\n${icon("question")} Need help with something else? Contact us via our ${link(DISCORD_INVITES.support, "Support Server")}.`
|
description: `Check pages for detailed command descriptions.\n\n` + renderCommandList(cmds, dscs, 15) + `\n\n${icon("question")} Need help with something else? Contact us via our ${link(DISCORD_INVITES.support, "Support Server")}.`
|
||||||
})
|
})
|
||||||
]})
|
]})
|
||||||
|
|
||||||
|
@ -113,17 +132,20 @@ module.exports = {
|
||||||
} else {
|
} else {
|
||||||
// Full command list
|
// Full command list
|
||||||
let commands = {}
|
let commands = {}
|
||||||
|
let descriptions = {}
|
||||||
|
|
||||||
let prefix = context.commandClient.prefixes.custom.first()
|
let prefix = context.commandClient.prefixes.custom.first()
|
||||||
for(const c of context.commandClient.commands){
|
for(const c of context.commandClient.commands){
|
||||||
if(!categories[c.metadata.category]) continue;
|
if(!categories[c.metadata.category]) continue;
|
||||||
if(!commands[c.metadata.category]) commands[c.metadata.category] = []
|
if(!commands[c.metadata.category]) commands[c.metadata.category] = []
|
||||||
commands[c.metadata.category].push(`${prefix}${c.name}`)
|
if(!descriptions[c.metadata.category]) descriptions[c.metadata.category] = []
|
||||||
|
commands[c.metadata.category].push(`${c.name}`);
|
||||||
|
descriptions[c.metadata.category].push(`${c.metadata.description}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
let pages = []
|
let pages = []
|
||||||
for(const cat of Object.keys(categories)){
|
for(const cat of Object.keys(categories)){
|
||||||
pages.push(createHelpPage(context, categories[cat], commands[cat]))
|
pages.push(createHelpPage(context, categories[cat], commands[cat], descriptions[cat]))
|
||||||
}
|
}
|
||||||
|
|
||||||
pages = formatPaginationEmbeds(pages)
|
pages = formatPaginationEmbeds(pages)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue