Skip to content

Commit

Permalink
Reduce cooldown and truncate title/description (#208)
Browse files Browse the repository at this point in the history
* Truncate embed title and description

* Reduce command cooldown to 30 seconds
  • Loading branch information
riccardofano authored May 25, 2024
1 parent b41101d commit 9f090be
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/commands/ask.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { Discord, Slash, SlashChoice, SlashOption } from 'discordx'
const COMMAND_NAME = 'ask'
const COMMAND_DESC = 'Ask a question to Wolfram Alpha'

const COOLDOWN_MILLISECONDS = 3 * 60 * 1000
const COOLDOWN_MILLISECONDS = 30 * 1000

@Discord()
class Ask {
Expand Down Expand Up @@ -56,8 +56,8 @@ class Ask {
const capitalizedAnswer = answer.charAt(0).toUpperCase() + answer.slice(1)
const embed = new EmbedBuilder()
.setColor('#FBAB00') // MasterMind's color
.setTitle(escapeMarkdown(question))
.setDescription(capitalizedAnswer)
.setTitle(truncate(escapeMarkdown(question).trim(), 256))
.setDescription(truncate(capitalizedAnswer.trim(), 4096))

return await interaction.reply({ embeds: [embed] })
} catch (err) {
Expand Down Expand Up @@ -106,3 +106,11 @@ class Ask {
return null
}
}

function truncate(text: string, maxLength: number): string {
if (text.length <= maxLength) {
return text
}

return text.substring(0, maxLength - 3).trim() + '...'
}

0 comments on commit 9f090be

Please sign in to comment.