nyx

The first CODM discrod bot -- cath.exe Template
git clone https://codeberg.org/night0721/nyx
Log | Files | Refs | LICENSE

build.js (18133B)


      1 const { Client, CommandInteraction, EmbedBuilder } = require("discord.js");
      2 const axios = require("axios");
      3 module.exports = {
      4   name: "build",
      5   description: "Get gunsmith builds",
      6   usage: "[Weapon Name] [Author] [Tag]",
      7   category: "CODM",
      8   options: [
      9     {
     10       type: 1,
     11       name: "assault_rifle",
     12       description: "Get a gunsmith build for a Assault Rifle",
     13       options: [
     14         {
     15           type: 3,
     16           name: "name",
     17           description: "Name of the Gun",
     18           required: true,
     19           choices: [
     20             {
     21               name: "Type 25",
     22               value: "A01",
     23             },
     24             {
     25               name: "M16",
     26               value: "A02",
     27             },
     28             {
     29               name: "AK117",
     30               value: "A03",
     31             },
     32             {
     33               name: "AK-47",
     34               value: "A04",
     35             },
     36             {
     37               name: "ASM10",
     38               value: "A05",
     39             },
     40             {
     41               name: "M4",
     42               value: "A06",
     43             },
     44             {
     45               name: "BK57",
     46               value: "A07",
     47             },
     48             {
     49               name: "LK24",
     50               value: "A08",
     51             },
     52             {
     53               name: "ICR-1",
     54               value: "A09",
     55             },
     56             {
     57               name: "Man-o-War",
     58               value: "A10",
     59             },
     60             {
     61               name: "KN-44",
     62               value: "A11",
     63             },
     64             {
     65               name: "HBRa3",
     66               value: "A12",
     67             },
     68             {
     69               name: "HVK-30",
     70               value: "A13",
     71             },
     72             {
     73               name: "DR-H",
     74               value: "A14",
     75             },
     76             {
     77               name: "Peacekeeper MK2",
     78               value: "A15",
     79             },
     80             {
     81               name: "FR .556",
     82               value: "A16",
     83             },
     84             {
     85               name: "AS VAL",
     86               value: "A17",
     87             },
     88             {
     89               name: "CR-56 AMAX",
     90               value: "A18",
     91             },
     92             {
     93               name: "M13",
     94               value: "A19",
     95             },
     96             {
     97               name: "Swordfish",
     98               value: "A20",
     99             },
    100             {
    101               name: "Kilo 141",
    102               value: "A21",
    103             },
    104           ],
    105         },
    106         {
    107           type: 3,
    108           name: "author",
    109           description: "Select a Content Creator",
    110           required: true,
    111           choices: [
    112             {
    113               name: "path.exe",
    114               value: "path.exe",
    115             },
    116             {
    117               name: "Jokesta",
    118               value: "Jokesta",
    119             },
    120             // {
    121             //   name: "Stats On Duty",
    122             //   value: "Stats On Duty",
    123             // },
    124           ],
    125         },
    126         {
    127           type: 3,
    128           name: "tag",
    129           description: "Playstyle/game mode of the build",
    130           required: true,
    131           choices: [
    132             {
    133               name: "Aggressive",
    134               value: "Aggressive",
    135             },
    136             {
    137               name: "Passive",
    138               value: "Passive",
    139             },
    140             {
    141               name: "Search And Destroy",
    142               value: "Search And Destroy",
    143             },
    144             {
    145               name: "Respawn",
    146               value: "Respawn",
    147             },
    148           ],
    149         },
    150       ],
    151     },
    152     {
    153       type: 1,
    154       name: "sub_machine_gun",
    155       description: "Get a gunsmith build for a Sub Machine Gun",
    156       options: [
    157         {
    158           type: 3,
    159           name: "name",
    160           description: "Name of the Gun",
    161           required: true,
    162           choices: [
    163             {
    164               name: "RUS-79U",
    165               value: "D01",
    166             },
    167             {
    168               name: "Chicom",
    169               value: "D02",
    170             },
    171             {
    172               name: "PDW-57",
    173               value: "D03",
    174             },
    175             {
    176               name: "Razorback",
    177               value: "D04",
    178             },
    179             {
    180               name: "MSMC",
    181               value: "D05",
    182             },
    183             {
    184               name: "HG40",
    185               value: "D06",
    186             },
    187             {
    188               name: "Pharo",
    189               value: "D07",
    190             },
    191             {
    192               name: "GKS",
    193               value: "D08",
    194             },
    195             {
    196               name: "Cordite",
    197               value: "D09",
    198             },
    199             {
    200               name: "QQ9",
    201               value: "D10",
    202             },
    203             {
    204               name: "Fennec",
    205               value: "D11",
    206             },
    207             {
    208               name: "AGR 556",
    209               value: "D12",
    210             },
    211             {
    212               name: "QXR",
    213               value: "D13",
    214             },
    215             {
    216               name: "PP19 Bizon",
    217               value: "D14",
    218             },
    219             {
    220               name: "MX9",
    221               value: "D15",
    222             },
    223             {
    224               name: "CBR4",
    225               value: "D16",
    226             },
    227             {
    228               name: "PPSh 41",
    229               value: "D17",
    230             },
    231           ],
    232         },
    233         {
    234           type: 3,
    235           name: "author",
    236           description: "Select a Content Creator",
    237           required: true,
    238           choices: [
    239             {
    240               name: "path.exe",
    241               value: "path.exe",
    242             },
    243             {
    244               name: "Jokesta",
    245               value: "Jokesta",
    246             },
    247           ],
    248         },
    249         {
    250           type: 3,
    251           name: "tag",
    252           description: "Playstyle/game mode of the build",
    253           required: true,
    254           choices: [
    255             {
    256               name: "Aggressive",
    257               value: "Aggressive",
    258             },
    259             {
    260               name: "Passive",
    261               value: "Passive",
    262             },
    263             {
    264               name: "Search And Destroy",
    265               value: "Search And Destroy",
    266             },
    267             {
    268               name: "Respawn",
    269               value: "Respawn",
    270             },
    271           ],
    272         },
    273       ],
    274     },
    275     {
    276       type: 1,
    277       name: "sniper_rifle",
    278       description: "Get a gunsmith build for a Sniper Rifle",
    279       options: [
    280         {
    281           type: 3,
    282           name: "name",
    283           description: "Name of the Gun",
    284           required: true,
    285           choices: [
    286             // {
    287             //   name: "XPR-50",
    288             //   value: "B01",
    289             // },
    290             {
    291               name: "Arctic .50",
    292               value: "B02",
    293             },
    294             {
    295               name: "M21 EBR",
    296               value: "B03",
    297             },
    298             {
    299               name: "DL Q33",
    300               value: "B04",
    301             },
    302             {
    303               name: "Locus",
    304               value: "B05",
    305             },
    306             // {
    307             //   name: "NA-45",
    308             //   value: "B06",
    309             // },
    310             {
    311               name: "Outlaw",
    312               value: "B07",
    313             },
    314             {
    315               name: "Rytec AMR",
    316               value: "B08",
    317             },
    318             {
    319               name: "SVD",
    320               value: "B09",
    321             },
    322           ],
    323         },
    324         {
    325           type: 3,
    326           name: "author",
    327           description: "Select a Content Creator",
    328           required: true,
    329           choices: [
    330             {
    331               name: "path.exe",
    332               value: "path.exe",
    333             },
    334           ],
    335         },
    336         {
    337           type: 3,
    338           name: "tag",
    339           description: "Playstyle/game mode of the build",
    340           required: true,
    341           choices: [
    342             {
    343               name: "Aggressive",
    344               value: "Aggressive",
    345             },
    346             {
    347               name: "Passive",
    348               value: "Passive",
    349             },
    350             {
    351               name: "Search And Destroy",
    352               value: "Search And Destroy",
    353             },
    354             {
    355               name: "Respawn",
    356               value: "Respawn",
    357             },
    358           ],
    359         },
    360       ],
    361     },
    362     {
    363       type: 1,
    364       name: "light_machine_gun",
    365       description: "Get a gunsmith build for a Light Machine Gun",
    366       options: [
    367         {
    368           type: 3,
    369           name: "name",
    370           description: "Name of the Gun",
    371           required: true,
    372           choices: [
    373             {
    374               name: "S36",
    375               value: "C01",
    376             },
    377             {
    378               name: "UL736",
    379               value: "C02",
    380             },
    381             {
    382               name: "RPD",
    383               value: "C03",
    384             },
    385             {
    386               name: "M4 LMG",
    387               value: "C04",
    388             },
    389             {
    390               name: "Chopper",
    391               value: "C05",
    392             },
    393             {
    394               name: "Holger 26",
    395               value: "C06",
    396             },
    397             {
    398               name: "Hades",
    399               value: "C07",
    400             },
    401             {
    402               name: "PKM",
    403               value: "C08",
    404             },
    405           ],
    406         },
    407         {
    408           type: 3,
    409           name: "author",
    410           description: "Select a Content Creator",
    411           required: true,
    412           choices: [
    413             {
    414               name: "path.exe",
    415               value: "path.exe",
    416             },
    417           ],
    418         },
    419         {
    420           type: 3,
    421           name: "tag",
    422           description: "Playstyle/game mode of the build",
    423           required: true,
    424           choices: [
    425             {
    426               name: "Aggressive",
    427               value: "Aggressive",
    428             },
    429             {
    430               name: "Passive",
    431               value: "Passive",
    432             },
    433             {
    434               name: "Search And Destroy",
    435               value: "Search And Destroy",
    436             },
    437             {
    438               name: "Respawn",
    439               value: "Respawn",
    440             },
    441           ],
    442         },
    443       ],
    444     },
    445     {
    446       type: 1,
    447       name: "shotgun",
    448       description: "Get a gunsmith build for a Shotgun",
    449       options: [
    450         {
    451           type: 3,
    452           name: "name",
    453           description: "Name of the Gun",
    454           required: true,
    455           choices: [
    456             {
    457               name: "HS2126",
    458               value: "E01",
    459             },
    460             {
    461               name: "BY15",
    462               value: "E02",
    463             },
    464             {
    465               name: "HS0405",
    466               value: "E03",
    467             },
    468             {
    469               name: "Striker",
    470               value: "E04",
    471             },
    472             {
    473               name: "KRM 262",
    474               value: "E05",
    475             },
    476             {
    477               name: "Echo",
    478               value: "E06",
    479             },
    480             {
    481               name: "R9-0",
    482               value: "E07",
    483             },
    484             {
    485               name: "JAK-12",
    486               value: "E08",
    487             },
    488           ],
    489         },
    490         {
    491           type: 3,
    492           name: "author",
    493           description: "Select a Content Creator",
    494           required: true,
    495           choices: [
    496             {
    497               name: "path.exe",
    498               value: "path.exe",
    499             },
    500             {
    501               name: "dHitman",
    502               value: "dhitman",
    503             },
    504           ],
    505         },
    506         {
    507           type: 3,
    508           name: "tag",
    509           description: "Playstyle/game mode of the build",
    510           required: true,
    511           choices: [
    512             {
    513               name: "ADS",
    514               value: "ADS",
    515             },
    516             {
    517               name: "Hipfire",
    518               value: "Hipfire",
    519             },
    520           ],
    521         },
    522       ],
    523     },
    524     {
    525       type: 1,
    526       name: "marksman_rifle",
    527       description: "Get a gunsmith build for a Marksman Rifle",
    528       options: [
    529         {
    530           type: 3,
    531           name: "name",
    532           description: "Name of the Gun",
    533           required: true,
    534           choices: [
    535             {
    536               name: "Kilo Bolt-Action",
    537               value: "F01",
    538             },
    539             {
    540               name: "SKS",
    541               value: "F02",
    542             },
    543             {
    544               name: "SP-R 208",
    545               value: "F03",
    546             },
    547             {
    548               name: "MK2",
    549               value: "F04",
    550             },
    551           ],
    552         },
    553         {
    554           type: 3,
    555           name: "author",
    556           description: "Select a Content Creator",
    557           required: true,
    558           choices: [
    559             {
    560               name: "path.exe",
    561               value: "path.exe",
    562             },
    563             {
    564               name: "Stats On Duty",
    565               value: "Stats On Duty",
    566             },
    567           ],
    568         },
    569         {
    570           type: 3,
    571           name: "tag",
    572           description: "Playstyle/game mode of the build",
    573           required: true,
    574           choices: [
    575             {
    576               name: "Aggressive",
    577               value: "Aggressive",
    578             },
    579             {
    580               name: "Passive",
    581               value: "Passive",
    582             },
    583             {
    584               name: "Respawn",
    585               value: "Respawn",
    586             },
    587           ],
    588         },
    589       ],
    590     },
    591     {
    592       type: 1,
    593       name: "pistol",
    594       description: "Get a gunsmith build for a Pistol",
    595       options: [
    596         {
    597           type: 3,
    598           name: "name",
    599           description: "Name of the Gun",
    600           required: true,
    601           choices: [
    602             {
    603               name: "J358",
    604               value: "G01",
    605             },
    606             {
    607               name: "MW11",
    608               value: "G02",
    609             },
    610             {
    611               name: ".50 GS",
    612               value: "G03",
    613             },
    614             {
    615               name: "Renetti",
    616               value: "G04",
    617             },
    618             {
    619               name: "Shorty",
    620               value: "G05",
    621             },
    622             {
    623               name: "Crossbow",
    624               value: "G06",
    625             },
    626           ],
    627         },
    628         {
    629           type: 3,
    630           name: "author",
    631           description: "Select a Content Creator",
    632           required: true,
    633           choices: [
    634             {
    635               name: "path.exe",
    636               value: "path.exe",
    637             },
    638             // {
    639             //   name: "Stats On Duty",
    640             //   value: "Stats On Duty",
    641             // },
    642           ],
    643         },
    644         {
    645           type: 3,
    646           name: "tag",
    647           description: "Playstyle/game mode of the build",
    648           required: true,
    649           choices: [
    650             {
    651               name: "Respawn",
    652               value: "Respawn",
    653             },
    654           ],
    655         },
    656       ],
    657     },
    658   ],
    659   /**
    660    *
    661    * @param {Client} client
    662    * @param {CommandInteraction} interaction
    663    * @param {String[]} args
    664    */
    665   run: async (client, interaction, args, utils) => {
    666     const cwts = args[1];
    667     const cc = args[2];
    668     const tag = args[3];
    669     const data = await axios
    670       .get(
    671         `${process.env.api}/api/v1/codm/build?cwts=${cwts}&cc=${cc}&tag=${tag}`,
    672         {
    673           headers: {
    674             Authorization: process.env.CODM_API_KEY,
    675           },
    676         }
    677       )
    678       .then(res => res.data)
    679       .catch(e => null);
    680     console.log(data);
    681     if (!data?.cwts) {
    682       const embed = new EmbedBuilder()
    683         .setDescription(
    684           `<: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`
    685         )
    686         .setColor(client.color);
    687       try {
    688         interaction.followUp({ embeds: [embed] });
    689       } catch (e) {
    690         interaction.editReply({ embeds: [embed] });
    691       }
    692     } else {
    693       const arr = [];
    694       data.attachments.map((e, i) => {
    695         return arr.push(`**${i + 1}:** ${e}`);
    696       });
    697       const embed = new EmbedBuilder()
    698         .setTitle(`${tag} build for ${data.weaponName} from ${data.author}`)
    699         .setDescription(
    700           `<:nyx_description:897379659665264650> **Description** \`\`\`\n${data.notes}\n \`\`\``
    701         )
    702         .setColor(16580400)
    703         .setImage(data.imageUrl ? data.imageUrl : null)
    704         .setFooter({
    705           text: `Builds Aggregated by ${client.author}`,
    706           iconURL: client.user.displayAvatarURL({ dynamic: true }),
    707         })
    708         .setTimestamp()
    709         .addFields(
    710           {
    711             name: "<:nyx_author:897379080549314601> Author:",
    712             value: `\`\`\`\n${data.author}\n\`\`\``,
    713             inline: true,
    714           },
    715           {
    716             name: "<a:lastupdate:897381474330873887> Last Updated:",
    717             value: `\`\`\`\n${utils.parseShortDate(
    718               new Date(data.lastUpdate)
    719             )}\n\`\`\``,
    720             inline: true,
    721           },
    722           {
    723             name: ":id: CWTS:",
    724             value: `\`\`\`\n${data.cwts}\n\`\`\``,
    725             inline: true,
    726           },
    727           {
    728             name: ":paperclip: Attachments:",
    729             value: arr.join("\n"),
    730           },
    731           {
    732             name: "<a:tags:897034924140404776> Tags",
    733             value: data.tags.join(", "),
    734           }
    735         )
    736         .setURL(client.web);
    737       try {
    738         interaction.followUp({
    739           embeds: [embed],
    740         });
    741       } catch (e) {
    742         interaction.editReply({ embeds: [embed] });
    743       }
    744     }
    745   },
    746 };