2021-04-11 09:11:21 +00:00
import { NamedCommand , RestCommand } from "../../core" ;
2021-03-31 01:40:29 +00:00
import { MessageEmbed } from "discord.js" ;
2021-04-08 11:37:49 +00:00
import urban from "relevant-urban" ;
2021-03-31 01:40:29 +00:00
2021-04-05 12:21:27 +00:00
export default new NamedCommand ( {
2021-03-31 01:40:29 +00:00
description : "Gives you a definition of the inputted word." ,
2021-04-08 11:37:49 +00:00
run : "Please input a word." ,
2021-04-10 17:07:55 +00:00
any : new RestCommand ( {
2021-04-11 09:11:21 +00:00
async run ( { send , combined } ) {
2021-04-08 11:37:49 +00:00
// [Bug Fix]: Use encodeURIComponent() when emojis are used: "TypeError [ERR_UNESCAPED_CHARACTERS]: Request path contains unescaped characters"
2021-04-10 17:07:55 +00:00
urban ( encodeURIComponent ( combined ) )
2021-04-08 11:37:49 +00:00
. then ( ( res ) = > {
const embed = new MessageEmbed ( )
. setColor ( 0x1d2439 )
. setTitle ( res . word )
. setURL ( res . urbanURL )
. setDescription ( ` **Definition:** \ n* ${ res . definition } * \ n \ n**Example:** \ n* ${ res . example } * ` )
// [Bug Fix] When an embed field is empty (if the author field is missing, like the top entry for "british"): "RangeError [EMBED_FIELD_VALUE]: MessageEmbed field values may not be empty."
. addField ( "Author" , res . author || "N/A" , true )
. addField ( "Rating" , ` ** \` Upvotes: ${ res . thumbsUp } | Downvotes: ${ res . thumbsDown } \` ** ` ) ;
if ( res . tags && res . tags . length > 0 && res . tags . join ( " " ) . length < 1024 )
embed . addField ( "Tags" , res . tags . join ( ", " ) , true ) ;
2021-04-10 13:34:55 +00:00
send ( embed ) ;
2021-04-08 11:37:49 +00:00
} )
. catch ( ( ) = > {
2021-04-10 13:34:55 +00:00
send ( "Sorry, that word was not found." ) ;
2021-04-08 11:37:49 +00:00
} ) ;
2021-03-31 01:40:29 +00:00
}
2021-04-08 11:37:49 +00:00
} )
2021-03-31 01:40:29 +00:00
} ) ;