From 6ddb0b77812cf7d3cf92044d985f6889fbb7108b Mon Sep 17 00:00:00 2001 From: night0721 Date: Thu, 27 Jan 2022 08:33:56 +0800 Subject: [PATCH] scorestreak command --- client/CODMClient.js | 2 +- command/CODM/build.js | 2 +- command/CODM/perk.js | 3 +- scorestreak.js => command/CODM/scorestreak.js | 30 +-- command/Owner/scorestreak.js | 177 ------------------ package.json | 2 +- util/functions/common.js | 3 + 7 files changed, 16 insertions(+), 203 deletions(-) rename scorestreak.js => command/CODM/scorestreak.js (85%) delete mode 100644 command/Owner/scorestreak.js diff --git a/client/CODMClient.js b/client/CODMClient.js index 12a4052..7230050 100644 --- a/client/CODMClient.js +++ b/client/CODMClient.js @@ -1,2 +1,2 @@ const { CODMClient } = require("cath"); -module.exports = new CODMClient("Gae"); +module.exports = new CODMClient(process.env.CODM_API_KEY); diff --git a/command/CODM/build.js b/command/CODM/build.js index 13c9349..c6fedb6 100644 --- a/command/CODM/build.js +++ b/command/CODM/build.js @@ -764,7 +764,7 @@ module.exports = { `${process.env.api}/api/v1/codm/builds?name=${gun}&cc=${cc}&tag=${tag}`, { headers: { - Authorization: "Gae", + Authorization: process.env.CODM_API_KEY, }, } ) diff --git a/command/CODM/perk.js b/command/CODM/perk.js index 572dd30..97b5d1a 100644 --- a/command/CODM/perk.js +++ b/command/CODM/perk.js @@ -1,6 +1,5 @@ const { MessageEmbed } = require("discord.js"); -const { CODMClient } = require("cath"); -const c = new CODMClient("Gae"); +const c = require("../../client/CODMClient"); module.exports = { name: "perk", description: "Get perk stats", diff --git a/scorestreak.js b/command/CODM/scorestreak.js similarity index 85% rename from scorestreak.js rename to command/CODM/scorestreak.js index 89c550a..f5c1448 100644 --- a/scorestreak.js +++ b/command/CODM/scorestreak.js @@ -1,6 +1,5 @@ const { MessageEmbed } = require("discord.js"); -const { CODMClient } = require("cath"); -const c = new CODMClient("Gae"); +const c = require("../../client/CODMClient"); module.exports = { name: "scorestreak", description: "Get Scorestreak stats", @@ -59,10 +58,6 @@ module.exports = { name: "Cluster Strike", value: "clusterstrike", }, - { - name: "XS1 Goliath", - value: "xs1goliath", - }, { name: "Stealth Chopper", value: "stealthchopper", @@ -131,7 +126,7 @@ module.exports = { const val = args[1]; const d = await c.getscorestreak(val); const embed = new MessageEmbed() - .setTitle(d.scorestreak) + .setTitle(d.name) .setURL(d.preview_video) .setDescription(`\`\`\`${d.description}\`\`\``) .addFields( @@ -140,21 +135,11 @@ module.exports = { value: `\`\`\`${d.cost}\`\`\``, inline: true, }, - { - name: "Lethal", - value: ` - ${ - d.lethal == true - ? " Yes" - : " No" - }`, - inline: true, - }, { name: "AI-Assisted", value: ` ${ - d.manual == false + d.manual ? " Yes" : " No" }`, @@ -162,16 +147,19 @@ module.exports = { }, { name: "More Info", - value: `\`\`\`${d.special}\`\`\``, + value: `\`\`\`${d.special ? d.special : "** **"}\`\`\``, inline: false, } ) .setThumbnail(d.preview) - .setFooter(`Made by ${client.author}`, client.user.displayAvatarURL()) + .setFooter({ + text: `Made by ${client.author}`, + iconURL: client.user.displayAvatarURL(), + }) .setColor( d.type == "lethal" ? "FF2222" - : d.type == "support" + : d.type == "assist" ? "22FF4A" : client.color ) diff --git a/command/Owner/scorestreak.js b/command/Owner/scorestreak.js deleted file mode 100644 index 104d064..0000000 --- a/command/Owner/scorestreak.js +++ /dev/null @@ -1,177 +0,0 @@ -const { MessageEmbed } = require("discord.js"); -const { CODMClient } = require("cath"); -const c = new CODMClient("Gae"); -module.exports = { - name: "scorestreak", - description: "Get Scorestreak stats", - type: "CHAT_INPUT", - usage: "{Scorestreak}", - category: "CODM", - options: [ - { - type: "SUB_COMMAND", - name: "lethal", - description: "Lethal Scorestreak", - options: [ - { - type: 3, - name: "scorestreak", - description: "Select a lethal scorestreak", - required: true, - choices: [ - { - name: "Shield Turret", - value: "shieldturret", - }, - { - name: "Hunter Killer Drone", - value: "hunterkillerdrone", - }, - { - name: "MQ-27 Dragonfire", - value: "mq27dragonfire", - }, - { - name: "Predator Missile", - value: "predatormissile", - }, - { - name: "Hawk X3", - value: "hawkx3", - }, - { - name: "Sentry Gun", - value: "sentrygun", - }, - { - name: "Lightning Strike", - value: "lightningstrike", - }, - { - name: "Orbital Laser", - value: "orbitallaser", - }, - { - name: "XS1 Goliath", - value: "xs1goliath", - }, - { - name: "Cluster Strike", - value: "clusterstrike", - }, - { - name: "XS1 Goliath", - value: "xs1goliath", - }, - { - name: "Stealth Chopper", - value: "stealthchopper", - }, - { - name: "Swarm", - value: "swarm", - }, - { - name: "Napalm", - value: "napalm", - }, - { - name: "VTOL", - value: "vtol", - }, - ], - }, - ], - }, - { - type: "SUB_COMMAND", - name: "support", - description: "Support Scorestreak", - options: [ - { - type: 3, - name: "scorestreak", - description: "Select a Support Scorestreak", - required: true, - choices: [ - { - name: "UAV", - value: "uav", - }, - { - name: "Shock RC", - value: "shockrc", - }, - { - name: "Care Package", - value: "carepackage", - }, - { - name: "Counter UAV", - value: "cuav", - }, - { - name: "SAM Turret", - value: "samturret", - }, - { - name: "Advance UAV", - value: "auav", - }, - { - name: "EMP Systems", - value: "empsystems", - }, - ], - }, - ], - }, - ], - run: async (client, interaction, args) => { - const val = args[1]; - const d = await c.getscorestreak(val); - const embed = new MessageEmbed() - .setTitle(d.scorestreak) - .setURL(d.preview_video) - .setDescription(`\`\`\`${d.description}\`\`\``) - .addFields( - { - name: "Cost", - value: `\`\`\`${d.cost}\`\`\``, - inline: true - }, - { - name: "Lethal", - value: ` - ${d.lethal == true - ? " Yes" - : " No"}`, - inline: true - }, - { - name: "AI-Assisted", - value: ` - ${d.manual == false - ? " Yes" - : " No"}`, - inline: true - }, - { - name: "More Info", - value: `\`\`\`${d.special}\`\`\``, - inline: false - } - ) - .setThumbnail(`${d.preview}`) - .setFooter(`Made by ${client.author}`, client.user.displayAvatarURL()) - .setColor( - d.type == "lethal" - ? "FF2222" - : d.type == "support" - ? "22FF4A" - : client.color - ) - .setTimestamp(); - interaction.followUp({ embeds: [embed] }); - }, -}; diff --git a/package.json b/package.json index 0d62be0..5fa6450 100644 --- a/package.json +++ b/package.json @@ -41,7 +41,7 @@ }, "dependencies": { "axios": "^0.25.0", - "cath": "^1.4.6", + "cath": "^1.4.7", "discord.js": "^13.6.0", "dotenv": "^14.2.0", "erela.js": "^2.3.3", diff --git a/util/functions/common.js b/util/functions/common.js index e83b5b3..47958e2 100644 --- a/util/functions/common.js +++ b/util/functions/common.js @@ -5,6 +5,7 @@ const weaponActualName = nmDt.weaponActualName; const weaponAlliasName = nmDt.weaponAlliasName; Object.defineProperty(String.prototype, "Simplify", { // Function to remove all characters except 0-9 and a-z + // Eg "AK-47" -> "ak47" value: function Simplify() { return this.toLowerCase().replace(/[^0-9a-z]/g, ""); }, @@ -112,6 +113,8 @@ function weaponIdentifier(inpmsg) { : "There isn't any weapon name."; } let probableWeapons = []; + // Loop through all the weapons to find the probable weapons + // Eg: "ak" for (let i = 0; i < data.cguns.length; i++) { if (inpWeaponName.Simplify() == data.cguns[i].gunname.Simplify()) { return JSON.parse(JSON.stringify(data.cguns[i]));