Revamp !help command. Add support for linking to specific commands in zep docs.
This commit is contained in:
parent
f1644709fb
commit
9a04e0fb25
2 changed files with 88 additions and 14 deletions
|
@ -27,21 +27,22 @@
|
||||||
<!-- Usage guide -->
|
<!-- Usage guide -->
|
||||||
<div v-if="data.info.usageGuide">
|
<div v-if="data.info.usageGuide">
|
||||||
<h2 id="usage-guide">Usage guide</h2>
|
<h2 id="usage-guide">Usage guide</h2>
|
||||||
<MarkdownBlock :content="data.info.usageGuide" class="content"></MarkdownBlock>
|
<MarkdownBlock :content="data.info.usageGuide" class="content" />
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- Command list -->
|
<!-- Command list -->
|
||||||
<div v-if="data.commands.length">
|
<div v-if="data.commands.length">
|
||||||
<h2 id="commands">Commands</h2>
|
<h2 id="commands">Commands</h2>
|
||||||
<div v-for="command in data.commands" class="mb-4">
|
<div v-for="command in data.commands"
|
||||||
|
class="command mb-4"
|
||||||
|
v-bind:ref="getCommandSlug(command.trigger)" v-bind:class="{target: targetCommandId === getCommandSlug(command.trigger)}">
|
||||||
<h3 class="text-xl mb-0">
|
<h3 class="text-xl mb-0">
|
||||||
!{{ command.trigger }}
|
!{{ command.trigger }}
|
||||||
<span v-for="alias in command.config.aliases"> <span class="text-gray-600">/</span> !{{ alias }}</span>
|
<span v-for="alias in command.config.aliases"> <span class="text-gray-600">/</span> !{{ alias }}</span>
|
||||||
</h3>
|
</h3>
|
||||||
<MarkdownBlock v-if="command.config.extra.info && command.config.extra.info.description"
|
<MarkdownBlock v-if="command.config.extra.info && command.config.extra.info.description"
|
||||||
:content="command.config.extra.info.description"
|
:content="command.config.extra.info.description"
|
||||||
class="content">
|
class="content" />
|
||||||
</MarkdownBlock>
|
|
||||||
|
|
||||||
<div v-bind:class="{'-mt-2': command.config.extra.info && command.config.extra.info.description}">
|
<div v-bind:class="{'-mt-2': command.config.extra.info && command.config.extra.info.description}">
|
||||||
<div v-if="command.config.extra.info && command.config.extra.info.basicUsage">
|
<div v-if="command.config.extra.info && command.config.extra.info.basicUsage">
|
||||||
|
@ -144,6 +145,17 @@
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
|
<style scoped>
|
||||||
|
.command.target {
|
||||||
|
@apply mt-5 mb-3;
|
||||||
|
@apply pt-2 pb-2 pl-4 pr-4;
|
||||||
|
@apply border;
|
||||||
|
@apply border-gray-400;
|
||||||
|
@apply border-dashed;
|
||||||
|
@apply rounded;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import Vue from "vue";
|
import Vue from "vue";
|
||||||
import {mapState} from "vuex";
|
import {mapState} from "vuex";
|
||||||
|
@ -172,6 +184,18 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
this.loading = false;
|
this.loading = false;
|
||||||
|
|
||||||
|
this.$nextTick(() => {
|
||||||
|
if (this.tab === "usage" && window.location.hash) {
|
||||||
|
this.scrollToCommand(window.location.hash.slice(1));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
this.hashChangeListener = () => this.scrollToCommand(window.location.hash.slice(1));
|
||||||
|
window.addEventListener('hashchange', this.hashChangeListener);
|
||||||
|
},
|
||||||
|
beforeDestroy() {
|
||||||
|
window.removeEventListener('hashchange', this.hashChangeListener);
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
renderConfiguration(options) {
|
renderConfiguration(options) {
|
||||||
|
@ -199,6 +223,20 @@
|
||||||
return `[${str}]`;
|
return `[${str}]`;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
getCommandSlug(str) {
|
||||||
|
return 'command-' + str.trim().toLowerCase().replace(/\s/g, '-');
|
||||||
|
},
|
||||||
|
scrollToCommand(hash) {
|
||||||
|
if (this.$refs[hash]) {
|
||||||
|
this.targetCommandId = hash;
|
||||||
|
(this.$refs[hash][0] as Element).scrollIntoView({
|
||||||
|
behavior: "smooth",
|
||||||
|
block: "center"
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
this.targetCommandId = null;
|
||||||
|
}
|
||||||
|
},
|
||||||
},
|
},
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
|
@ -207,6 +245,8 @@
|
||||||
tab: validTabs.includes(this.$route.params.tab)
|
tab: validTabs.includes(this.$route.params.tab)
|
||||||
? this.$route.params.tab
|
? this.$route.params.tab
|
||||||
: defaultTab,
|
: defaultTab,
|
||||||
|
targetCommandId: null,
|
||||||
|
hashChangeListener: null
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
|
|
|
@ -26,6 +26,7 @@ import {
|
||||||
DAYS,
|
DAYS,
|
||||||
embedPadding,
|
embedPadding,
|
||||||
errorMessage,
|
errorMessage,
|
||||||
|
get,
|
||||||
getInviteCodesInString,
|
getInviteCodesInString,
|
||||||
isSnowflake,
|
isSnowflake,
|
||||||
MINUTES,
|
MINUTES,
|
||||||
|
@ -1110,7 +1111,10 @@ export class UtilityPlugin extends ZeppelinPlugin<TConfigSchema> {
|
||||||
helpCmd(msg: Message, args: { command: string }) {
|
helpCmd(msg: Message, args: { command: string }) {
|
||||||
const searchStr = args.command.toLowerCase();
|
const searchStr = args.command.toLowerCase();
|
||||||
|
|
||||||
const matchingCommands: Array<ICommandDefinition<ICommandContext, ICommandExtraData>> = [];
|
const matchingCommands: Array<{
|
||||||
|
plugin: ZeppelinPlugin;
|
||||||
|
command: ICommandDefinition<ICommandContext, ICommandExtraData>;
|
||||||
|
}> = [];
|
||||||
|
|
||||||
const guildData = this.knub.getGuildData(this.guildId);
|
const guildData = this.knub.getGuildData(this.guildId);
|
||||||
for (const plugin of guildData.loadedPlugins.values()) {
|
for (const plugin of guildData.loadedPlugins.values()) {
|
||||||
|
@ -1118,18 +1122,48 @@ export class UtilityPlugin extends ZeppelinPlugin<TConfigSchema> {
|
||||||
|
|
||||||
const registeredCommands = plugin.getRegisteredCommands();
|
const registeredCommands = plugin.getRegisteredCommands();
|
||||||
for (const registeredCommand of registeredCommands) {
|
for (const registeredCommand of registeredCommands) {
|
||||||
for (const trigger of registeredCommand.command.triggers) {
|
for (const trigger of registeredCommand.command.originalTriggers) {
|
||||||
if (trigger.source.startsWith(searchStr)) {
|
const strTrigger = typeof trigger === "string" ? trigger : trigger.source;
|
||||||
matchingCommands.push(registeredCommand.command);
|
|
||||||
|
if (strTrigger.startsWith(searchStr)) {
|
||||||
|
matchingCommands.push({
|
||||||
|
plugin,
|
||||||
|
command: registeredCommand.command,
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const totalResults = matchingCommands.length;
|
const totalResults = matchingCommands.length;
|
||||||
const limitedResults = matchingCommands.slice(0, 15);
|
const limitedResults = matchingCommands.slice(0, 3);
|
||||||
const signatures = limitedResults.map(command => {
|
const commandSnippets = limitedResults.map(({ plugin, command }) => {
|
||||||
return "`" + getCommandSignature(command) + "`";
|
const prefix: string = command.originalPrefix
|
||||||
|
? typeof command.originalPrefix === "string"
|
||||||
|
? command.originalPrefix
|
||||||
|
: command.originalPrefix.source
|
||||||
|
: "";
|
||||||
|
|
||||||
|
const originalTrigger = command.originalTriggers[0];
|
||||||
|
const trigger: string = originalTrigger
|
||||||
|
? typeof originalTrigger === "string"
|
||||||
|
? originalTrigger
|
||||||
|
: originalTrigger.source
|
||||||
|
: "";
|
||||||
|
|
||||||
|
const description = get(command, "config.extra.info.description");
|
||||||
|
const basicUsage = get(command, "config.extra.info.basicUsage");
|
||||||
|
const commandSlug = trigger
|
||||||
|
.trim()
|
||||||
|
.toLowerCase()
|
||||||
|
.replace(/\s/g, "-");
|
||||||
|
|
||||||
|
let snippet = `**${prefix}${trigger}**`;
|
||||||
|
if (description) snippet += `\n${description}`;
|
||||||
|
if (basicUsage) snippet += `\nBasic usage: \`${basicUsage}\``;
|
||||||
|
snippet += `\n<https://zeppelin.gg/docs/plugins/${plugin.runtimePluginName}/usage#command-${commandSlug}>`;
|
||||||
|
|
||||||
|
return snippet;
|
||||||
});
|
});
|
||||||
|
|
||||||
if (totalResults === 0) {
|
if (totalResults === 0) {
|
||||||
|
@ -1139,10 +1173,10 @@ export class UtilityPlugin extends ZeppelinPlugin<TConfigSchema> {
|
||||||
|
|
||||||
let message =
|
let message =
|
||||||
totalResults !== limitedResults.length
|
totalResults !== limitedResults.length
|
||||||
? `Results (${totalResults} total, showing first ${limitedResults.length}):`
|
? `Results (${totalResults} total, showing first ${limitedResults.length}):\n\n`
|
||||||
: `Results:`;
|
: "";
|
||||||
|
|
||||||
message += `\n\n${signatures.join("\n")}`;
|
message += `${commandSnippets.join("\n\n")}`;
|
||||||
createChunkedMessage(msg.channel, message);
|
createChunkedMessage(msg.channel, message);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue