effects.js (5292B)
1 const common = require("../../util/functions/common"); 2 const data = require("../../util/Data/data.json"); 3 4 let currGun, currAttachments, interpretion, hasError; 5 const errMsg = "*Generic placeholder error message*"; 6 7 module.exports = { 8 name: "effects", 9 description: "Check gun effects", 10 usage: "(Gun)", 11 category: "CODM", 12 options: [ 13 { 14 type: 7, 15 name: "gun", 16 description: "Gun name", 17 required: true, 18 }, 19 ], 20 run: async (client, interaction, args) => { 21 const repEmb = attachments(args[0].replace("\n", " ")); 22 if (hasError) { 23 interaction.followUp({ embeds: [repEmb] }); 24 } else { 25 interaction.followUp({ embeds: [repEmb] }); 26 } 27 }, 28 }; 29 30 function attachments(inpmsg) { 31 const out = "", 32 at = data.attachmentTypes.map(x => (x.slice(-1) === "s" ? x : x + "s")); 33 if (inpmsg.includes("+") && inpmsg.includes(":")) { 34 hasError = true; 35 return "Bro, can u liek, not do that?"; 36 } 37 if (inpmsg.includes(":")) { 38 const inpAll = inpmsg 39 .split(":") 40 .map(x => x.trim()) 41 .filter(x => x), 42 inpType = inpAll.length === 2 ? inpAll[1] : null; 43 if (!inpType) { 44 hasError = true; 45 return inpAll.length < 2 46 ? "Empty " + (inpAll[0] ? "" : "weapon name and ") + "attachment type" 47 : "Multiple `:`s detected"; 48 } 49 currGun = common.weaponIdentifier(inpAll[0]); 50 if (typeof currGun == "string") { 51 hasError = true; 52 return currGun; 53 } 54 let currAttachmentsType = at.filter(x => simplify(x) == simplify(inpType)); 55 currAttachmentsType = currAttachmentsType.length 56 ? currAttachmentsType 57 : at.filter( 58 x => simplify(x.substring(0, x.length - 1)) == simplify(inpType) 59 ); 60 currAttachmentsType = currAttachmentsType.length 61 ? currAttachmentsType 62 : at.filter(x => simplify(x).includes(simplify(inpType))); 63 if (currAttachmentsType.length === 0) { 64 hasError = true; 65 return "Couldn't identify `" + inpType + "`"; 66 } else if (currAttachmentsType.length === 1) { 67 currAttachmentsType = at.indexOf(currAttachmentsType[0]); 68 } else { 69 hasError = true; 70 return ( 71 "Did you mean `" + 72 currAttachmentsType.reduce((out, x, i) => 73 [out, x].join( 74 i === currAttachmentsType.length - 1 ? "` or `" : "`, `" 75 ) 76 ) + 77 "`" 78 ); 79 } 80 return { 81 title: currGun.gunname, 82 color: 11348938, 83 fields: [ 84 { 85 name: 86 "**" + 87 currGun.gunname + 88 "** has the following " + 89 at[currAttachmentsType], 90 value: 91 "```\n" + 92 currGun.aments 93 .filter(x => x.type - 1 === currAttachmentsType) 94 .map(x => x.name) 95 .join("\n") + 96 "```", 97 }, 98 ], 99 footer: { 100 text: "All the stats courtesy of Project Lighthouse", 101 icon_url: 102 "https://media.discordapp.net/attachments/735590814662656102/806960573753327657/cc.png?width=638&height=638", 103 }, 104 }; 105 function simplify(v) { 106 return v.toLowerCase().replace(/[^0-9a-z]/g, ""); 107 } 108 } 109 currGun = common.weaponIdentifier(inpmsg); 110 if (typeof currGun == "string") { 111 hasError = true; 112 return currGun; 113 } 114 hasAttachments = common.hasAttachments(inpmsg); 115 currAttachments = []; 116 if (hasAttachments) { 117 currAttachments = common.attachmentsIdentifier(inpmsg, currGun); 118 if (typeof currAttachments == "string") { 119 hasError = true; 120 return currAttachments; 121 } 122 return { 123 title: currGun.gunname + common.interpretioner(currAttachments), 124 color: 11348938, 125 fields: common.attachmentHandler( 126 common.totaler(currAttachments), 127 currGun.stats 128 ), 129 footer: { 130 text: "All the stats courtesy of Project Lighthouse", 131 icon_url: 132 "https://media.discordapp.net/attachments/735590814662656102/806960573753327657/cc.png?width=638&height=638", 133 }, 134 }; 135 } else { 136 const availableAttachmentTypes = [ 137 ...new Set(currGun.aments.map(x => x.type)), 138 ]; 139 return { 140 title: currGun.gunname, 141 color: 11348938, 142 fields: [ 143 { 144 name: 145 "**" + currGun.gunname + "** has the following attachment types:", 146 value: 147 "```\n" + 148 availableAttachmentTypes.map(x => at[x - 1]).join(",\n") + 149 "```", 150 }, 151 ], 152 footer: { 153 text: "All the stats courtesy of Project Lighthouse", 154 icon_url: 155 "https://media.discordapp.net/attachments/735590814662656102/806960573753327657/cc.png?width=638&height=638", 156 }, 157 }; 158 } 159 } 160 // console.log(attachments("Peacekeeper:muzzle")); //common.makeError(); 161 /* console.log(attachments(":")); //common.makeError(); 162 console.log(attachments("47:optics")); //common.makeError(); 163 console.log(attachments("47")); //common.makeError(); 164 console.log(attachments("47 + ")); //common.makeError(); 165 console.log(attachments("47 + :")); //common.makeError(); 166 console.log(attachments("47 + red dot")); common.makeError();*/