Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix autocomplete and search by displayName and internalName #116

Merged
merged 3 commits into from
Apr 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions lib/commands/hubsupport.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ async function fetchManifest () {
return manifestCache
}

function replaceSpaceWithDash (string) {
return string.replace(/\s+/g, '-')
}

export default {
data: new SlashCommandBuilder()
.setName('hubsupport')
Expand All @@ -34,17 +38,14 @@ export default {
.setAutocomplete(true)
),
async execute (interaction) {
let value = interaction.options.getString('name')
const value = interaction.options.getString('name')

if (!value) {
return interaction.followUp('Support for hub plugins should be directed to the author of the plugin.\nYou can find the support link by searching for the plugin in the Plugin Hub panel and clicking the `?` button on the plugin, or by right-clicking the plugin in the plugin panel and clicking the `Support` menu option.')
}

// Replace spaces with dashes to fix an issue with spaces not returning anything
value = value.replace(/\s+/g, '-')

const manifest = await fetchManifest()
const plugin = manifest.display.find(p => p.internalName === value)
const plugin = manifest.display.find(p => p.internalName === replaceSpaceWithDash(value) || p.displayName.toLowerCase() === value.toLowerCase())

if (plugin) {
return interaction.followUp(`Get support for the **${plugin.displayName}** Plugin Hub plugin here: <https://runelite.net/plugin-hub/show/${value}>.\nYou can also find the support link by searching for the plugin in the Plugin Hub panel and clicking the \`?\` button on the plugin, or by right-clicking the plugin in the plugin panel and clicking the \`Support\` menu option.`)
Expand All @@ -56,7 +57,7 @@ export default {
const value = interaction.options.getString('name').toLowerCase()
const manifest = await fetchManifest()
return manifest.display.map(p => ({ name: p.displayName, value: p.internalName }))
.filter(p => (p.name.includes(value)) || p.value.includes(value))
.filter(p => (p.name.includes(value)) || p.value.includes(replaceSpaceWithDash(value)))
.slice(0, 24)
}
}
4 changes: 3 additions & 1 deletion lib/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ export default {
contributorRepos: [
'runelite/runelite',
'runelite/launcher',
'runelite/runelite.net'
'runelite/runelite.net',
'runelite/runelite-discord-bot',
'runelite/api.runelite.net'
],
// GitHub repository to fetch plugin hub contributors from
pluginHubRepo: 'runelite/plugin-hub'
Expand Down
Loading