├── README.md └── server.js /README.md: -------------------------------------------------------------------------------- 1 | # Shopify-ATC-Generator 2 | Finds shopify variants and generates add to cart links. Also gathers info about the item such as weight and price 3 | 4 | # How to configure: 5 | 6 | Install node.js 7 | 8 | ### Edit the following variables on the top: 9 | Set the token variable to your discord bot token 10 | Set the prefix variable to your desired command prefix (Default is !) 11 | 12 | ## Run the following Commands: 13 | 14 | npm i discord.js node-fetch 15 | 16 | node server.js 17 | 18 | 19 | ## Finished Product!: 20 | ![Screenshot](https://media.discordapp.net/attachments/728300471927963740/745497681044045834/unknown.png?width=383&height=599) 21 | 22 | -------------------------------------------------------------------------------- /server.js: -------------------------------------------------------------------------------- 1 | //user configurable items 2 | let prefix = "!"; 3 | let token = "redacted"; 4 | 5 | //imports 6 | const fetch = require("node-fetch"); 7 | const discord = require("discord.js"); 8 | const client = new discord.Client(); 9 | 10 | client.on("ready", ready => { 11 | console.log("Client Logged In!"); 12 | }); 13 | 14 | client.on("message", message => { 15 | if (!message.content.startsWith(prefix)) return; 16 | const withoutPrefix = message.content.slice(prefix.length); 17 | const split = withoutPrefix.split(/ +/); 18 | const command = split[0]; 19 | const args = split.slice(1); 20 | if (command == "shopify") { 21 | let link = args[0]; 22 | //get product details 23 | grabJSON(link) 24 | .then(async json => { 25 | let productname = json.product.title; 26 | let handle = json.product.handle; 27 | let vendor = json.product.vendor; 28 | let imagesrc = json.product.image.src; 29 | console.log(json.product.variants); 30 | //create our embed 31 | const exampleEmbed = new discord.MessageEmbed() 32 | .setColor("#D20069") 33 | .setTitle(productname) 34 | .setURL(link) 35 | .setDescription( 36 | "Variants of product w/ handle " + handle + " on the site " + vendor 37 | ) 38 | .setThumbnail(imagesrc) 39 | .setTimestamp() 40 | .setFooter( 41 | "Developed by Carcraftz#5445", 42 | "https://cdn.discordapp.com/avatars/605463770998898718/a_f47f7b1dbf415cc7601d65cfc45a323c.gif?size=128" 43 | ); 44 | //add variant links to our embed 45 | json.product.variants.forEach(variant=>{ 46 | let cleanlink = link.split("?")[0] 47 | let partarr = cleanlink.split("/") 48 | cleanlink = partarr.slice(0,3).join("/") 49 | exampleEmbed.addField(variant.title, "[ATC]("+cleanlink +"/cart/"+variant.id+":1)\n$"+variant.price+"\nWeight: "+variant.weight+" "+variant["weight_unit"]+"\nsku: "+variant.sku, true) 50 | 51 | }) 52 | message.channel.send(exampleEmbed) 53 | }) 54 | .catch(e => { 55 | console.log(e); 56 | message.reply("This is not a valid shopify link!"); 57 | }); 58 | } 59 | }); 60 | async function grabJSON(link) { 61 | //remove query strings from our link 62 | let parsedlink = link.split("?")[0]; 63 | let response = await fetch(parsedlink + ".json"); 64 | let json = await response.json(); 65 | return json; 66 | } 67 | client.login(token); 68 | --------------------------------------------------------------------------------