2021-11-18 18:56:42 +01:00
const { MessageEmbed } = require ( "discord.js" ) ;
const moment = require ( "moment" ) ;
2022-01-28 09:00:28 +01:00
const axios = require ( "axios" ) ;
2021-11-18 18:56:42 +01:00
module . exports = {
name : "build" ,
description : "Get gunsmith builds" ,
2022-02-01 15:00:50 +01:00
usage : "[Weapon Name] [Author] [Tag]" ,
2021-11-18 18:56:42 +01:00
type : "CHAT_INPUT" ,
category : "CODM" ,
2022-02-05 02:01:51 +01:00
2021-11-18 18:56:42 +01:00
run : async ( client , interaction , args ) => {
2022-01-28 09:00:28 +01:00
const cwts = args [ 1 ] ;
2021-11-18 18:56:42 +01:00
const cc = args [ 2 ] ;
const tag = args [ 3 ] ;
const data = await axios
. get (
2022-02-04 12:50:08 +01:00
` ${ process . env . api } /api/v1/codm/build?cwts= ${ cwts } &cc= ${ cc } &tag= ${ tag } ` ,
2022-01-28 21:19:50 +01:00
{
2021-11-18 18:56:42 +01:00
headers : {
2022-01-28 21:19:50 +01:00
Authorization : process . env . CODM _API _KEY ,
2021-11-18 18:56:42 +01:00
} ,
}
)
. then ( res => res . data )
2022-01-16 23:39:30 +01:00
. catch ( e => null ) ;
2022-01-28 09:00:28 +01:00
2022-01-30 10:03:03 +01:00
if ( ! data ? . cwts ) {
2021-12-10 19:42:33 +01:00
const embed = new MessageEmbed ( )
. setDescription (
2022-02-04 12:50:08 +01:00
` <:nyx_not_available:897378400031879188> We don't have a ** ${ tag } ** gunsmith build for the gun with **CWTS 🆔 ${ cwts } ** by ** ${ cc } **, Please try another tag or a differnt content creator `
2021-12-10 19:42:33 +01:00
)
. setColor ( client . color ) ;
interaction . followUp ( { embeds : [ embed ] } ) ;
2021-11-18 18:56:42 +01:00
} else {
const arr = [ ] ;
data . attachments . map ( ( e , i ) => {
2021-12-09 20:38:01 +01:00
return arr . push ( ` ** ${ i + 1 } :** ${ e } ` ) ;
2021-11-18 18:56:42 +01:00
} ) ;
const embed = new MessageEmbed ( )
. setTitle (
2022-01-28 21:19:50 +01:00
` ${ all [ tag ] } build for ${ data . weaponName } from ${ data . author } `
2021-11-18 18:56:42 +01:00
)
. setDescription (
2022-02-03 10:13:53 +01:00
` <:nyx_description:897379659665264650> **Description** \` \` \` \n ${ data . notes } \n \` \` \` `
2021-11-18 18:56:42 +01:00
)
. setColor ( 16580400 )
. setImage ( data . imageUrl )
2022-01-30 10:03:03 +01:00
. setFooter ( {
text : ` Builds Aggregated by ${ client . author } ` ,
iconURL : client . user . displayAvatarURL ( ) ,
} )
2021-11-18 18:56:42 +01:00
. setTimestamp ( )
. addFields (
{
name : "<:nyx_author:897379080549314601> Author:" ,
value : ` \` \` \` \n ${ data . author } \n \` \` \` ` ,
inline : true ,
} ,
{
name : "<a:lastupdate:897381474330873887> Last Updated:" ,
value : ` \` \` \` \n ${ moment ( Date . parse ( data . lastUpdate ) ) . format (
"MMMM Do YYYY"
) } \ n \ ` \` \` ` ,
inline : true ,
} ,
{
name : ":id: CWTS:" ,
value : ` \` \` \` \n ${ data . cwts } \n \` \` \` ` ,
inline : true ,
} ,
{
name : ":paperclip: Attachments:" ,
value : arr . join ( "\n" ) ,
} ,
{
name : "<a:tags:897034924140404776> Tags" ,
value : data . tags . join ( ", " ) ,
}
)
. setURL ( client . web ) ;
interaction . followUp ( {
embeds : [ embed ] ,
} ) ;
}
} ,
2022-01-28 21:19:50 +01:00
} ;