nyx

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

new-stats.js (19733B)


      1 const { EmbedBuilder } = require("discord.js");
      2 const axios = require("axios");
      3 module.exports = {
      4   name: "stats",
      5   description: "Check Stats of a Weapon by SOD",
      6   usage: "[Weapon Name]",
      7   category: "CODM",
      8   options: [
      9     {
     10       type: 1,
     11       name: "assault_rifle",
     12       description: "Get a Stats for Assault Rifle",
     13       options: [
     14         {
     15           type: 3,
     16           name: "Weapon",
     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     },
    108     {
    109       type: 1,
    110       name: "sub_machine_gun",
    111       description: "Get a Stats for Sub Machine Gun",
    112       options: [
    113         {
    114           type: 3,
    115           name: "Weapon",
    116           description: "Name of the Gun",
    117           required: true,
    118           choices: [
    119             {
    120               name: "RUS-79u",
    121               value: "D01",
    122             },
    123             {
    124               name: "Chicom",
    125               value: "D02",
    126             },
    127             {
    128               name: "PDW-57",
    129               value: "D03",
    130             },
    131             {
    132               name: "Razorback",
    133               value: "D04",
    134             },
    135             {
    136               name: "MSMC",
    137               value: "D05",
    138             },
    139             {
    140               name: "HG40",
    141               value: "D06",
    142             },
    143             {
    144               name: "Pharo",
    145               value: "D07",
    146             },
    147             {
    148               name: "GKS",
    149               value: "D08",
    150             },
    151             {
    152               name: "Cordite",
    153               value: "D09",
    154             },
    155             {
    156               name: "QQ9",
    157               value: "D10",
    158             },
    159             {
    160               name: "Fennec",
    161               value: "D11",
    162             },
    163             {
    164               name: "AGR 556",
    165               value: "D12",
    166             },
    167             {
    168               name: "QXR",
    169               value: "D13",
    170             },
    171             {
    172               name: "PP19 Bizon",
    173               value: "D14",
    174             },
    175             {
    176               name: "MX9",
    177               value: "D15",
    178             },
    179             {
    180               name: "CBR4",
    181               value: "D16",
    182             },
    183             {
    184               name: "PPSh 41",
    185               value: "D17",
    186             },
    187           ],
    188         },
    189       ],
    190     },
    191     {
    192       type: 1,
    193       name: "sniper_rifle",
    194       description: "Get a Stats for Sniper Rifle",
    195       options: [
    196         {
    197           type: 3,
    198           name: "Weapon",
    199           description: "Name of the Gun",
    200           required: true,
    201           choices: [
    202             // {
    203             //   name: "XPR-50",
    204             //   value: "B01",
    205             // },
    206             {
    207               name: "Arctic .50",
    208               value: "B02",
    209             },
    210             {
    211               name: "M21 EBR",
    212               value: "B03",
    213             },
    214             {
    215               name: "DL Q33",
    216               value: "B04",
    217             },
    218             {
    219               name: "Locus",
    220               value: "B05",
    221             },
    222             // {
    223             //   name: "NA-45",
    224             //   value: "B06",
    225             // },
    226             {
    227               name: "Outlaw",
    228               value: "B07",
    229             },
    230             {
    231               name: "Rytec AMR",
    232               value: "B08",
    233             },
    234             {
    235               name: "SVD",
    236               value: "B09",
    237             },
    238           ],
    239         },
    240       ],
    241     },
    242     {
    243       type: 1,
    244       name: "light_machine_gun",
    245       description: "Get a Stats for Light Machine Gun",
    246       options: [
    247         {
    248           type: 3,
    249           name: "Weapon",
    250           description: "Name of the Gun",
    251           required: true,
    252           choices: [
    253             {
    254               name: "S36",
    255               value: "C01",
    256             },
    257             {
    258               name: "UL736",
    259               value: "C02",
    260             },
    261             {
    262               name: "RPD",
    263               value: "C03",
    264             },
    265             {
    266               name: "M4 LMG",
    267               value: "C04",
    268             },
    269             {
    270               name: "Chopper",
    271               value: "C05",
    272             },
    273             {
    274               name: "Holger 26",
    275               value: "C06",
    276             },
    277             {
    278               name: "Hades",
    279               value: "C07",
    280             },
    281             {
    282               name: "PKM",
    283               value: "C08",
    284             },
    285           ],
    286         },
    287       ],
    288     },
    289     {
    290       type: 1,
    291       name: "shotgun",
    292       description: "Get a Stats for Shotgun",
    293       options: [
    294         {
    295           type: 3,
    296           name: "Weapon",
    297           description: "Name of the Gun",
    298           required: true,
    299           choices: [
    300             {
    301               name: "HS2126",
    302               value: "E01",
    303             },
    304             {
    305               name: "BY15",
    306               value: "E02",
    307             },
    308             {
    309               name: "HS0405",
    310               value: "E03",
    311             },
    312             {
    313               name: "Striker",
    314               value: "E04",
    315             },
    316             {
    317               name: "KRM_262",
    318               value: "E05",
    319             },
    320             {
    321               name: "Echo",
    322               value: "E06",
    323             },
    324             {
    325               name: "R9-0",
    326               value: "E07",
    327             },
    328             {
    329               name: "JAK-12",
    330               value: "E08",
    331             },
    332           ],
    333         },
    334       ],
    335     },
    336     {
    337       type: 1,
    338       name: "marksman_rifle",
    339       description: "Get a Stats for Marksman Rifle",
    340       options: [
    341         {
    342           type: 3,
    343           name: "Weapon",
    344           description: "Name of the Gun",
    345           required: true,
    346           choices: [
    347             {
    348               name: "Kilo Bolt-Action",
    349               value: "F01",
    350             },
    351             {
    352               name: "SKS",
    353               value: "F02",
    354             },
    355             {
    356               name: "SP-R 208",
    357               value: "F03",
    358             },
    359             {
    360               name: "MK2",
    361               value: "F04",
    362             },
    363           ],
    364         },
    365       ],
    366     },
    367     {
    368       type: 1,
    369       name: "pistol",
    370       description: "Get a Stats for Pistol",
    371       options: [
    372         {
    373           type: 3,
    374           name: "Weapon",
    375           description: "Name of the Gun",
    376           required: true,
    377           choices: [
    378             {
    379               name: "J358",
    380               value: "G01",
    381             },
    382             {
    383               name: "MW11",
    384               value: "G02",
    385             },
    386             {
    387               name: ".50 GS",
    388               value: "G03",
    389             },
    390             {
    391               name: "Renetti",
    392               value: "G04",
    393             },
    394             {
    395               name: "Shorty",
    396               value: "G05",
    397             },
    398             {
    399               name: "Crossbow",
    400               value: "G06",
    401             },
    402           ],
    403         },
    404       ],
    405     },
    406   ],
    407   // It's not complete, Still work in progress.
    408   run: async (client, interaction, args, utils) => {
    409     const cwts = args[1];
    410     const data = await axios
    411       .get(`${process.env.api}/api/v1/codm/builds?cwts=${cwts}`, {
    412         headers: {
    413           Authorization: process.env.CODM_API_KEY,
    414         },
    415       })
    416       .then(res => res.data)
    417       .catch(e => null);
    418 
    419     if (!data?.ID) {
    420       const embed = new EmbedBuilder()
    421         .setDescription(
    422           `<:nyx_not_available:897378400031879188> Sorry, We currently don't have Stats for this Weapon`
    423         )
    424         .setColor(client.color);
    425       interaction.followUp({ embeds: [embed] });
    426     } else {
    427       const embed = new EmbedBuilder()
    428         .setTitle(`${data.author} Statistical Breakdown`)
    429         .setColor(16580400)
    430         .setImage(data.imageUrl)
    431         .setFooter({ text: `Stats Curtosy of Round Table` })
    432         // .setFooter(
    433         //   `Stats Curtosy of Stats on Duty`,
    434         // )
    435         .setDescription(
    436           `<:nyx_description:897379659665264650> **Description** \n${data.description}`
    437         )
    438         .addFields(
    439           {
    440             name: ":id: CWTS:",
    441             value: `\`\`\`\n${data.cwts}\n\`\`\``,
    442             inline: true,
    443           },
    444           {
    445             name: "<a:lastupdate:897381474330873887> Last Updated:",
    446             value: `\`\`\`\n${utils.parseShortDate(
    447               new Date(data.lastUpdate)
    448             )}\n\`\`\``,
    449             inline: true,
    450           },
    451           {
    452             name: "Basic Stats",
    453             value: `\`\`\`\n
    454             BSA Score: ${data.bsa_score}
    455             Hipfire Score: ${data.hipfire_score}
    456             Rate of Fire\t\t\t\t: ${data.rof}
    457             Penetration Level\t\t: ${data.penetration}
    458             Firing Mode\t\t\t\t\t: Full Auto
    459 
    460             \n\`\`\``,
    461             inline: false,
    462           },
    463           {
    464             name: "Handling & Mobility",
    465             value: `\`\`\`\n
    466             Drop Time               :  416.6 ms
    467             Raise Time              :  650 ms
    468             Sprinting Speed         :  6.09 m/s
    469             Walking Speed           :  4.51 m/s
    470             Sprint-to-Fire Time     :  165 ms
    471             \n\`\`\``,
    472             inline: false,
    473           },
    474           {
    475             name: "Ammunation Stats",
    476             value: `\`\`\`\n
    477             Magazine                :  30
    478             Reserve                 :  120
    479             Reload Type             :  Magazine
    480             Cancel Reload Time      :  1.9 s
    481             Reload Time             :  2.3 s
    482             Full Reload Time        :  3.2 s
    483             \n\`\`\``,
    484             inline: false,
    485           },
    486           {
    487             name: ":paperclip: Attachments:",
    488             value: arr.join("\n"),
    489           },
    490           {
    491             name: "<a:tags:897034924140404776> Tags",
    492             value: data.tags.join(", "),
    493           }
    494         )
    495         .setURL(client.web);
    496       interaction.followUp({ embeds: [embed] });
    497     }
    498   },
    499 };
    500 
    501 // @night0721 Damage profile will be avalable by different command
    502 
    503 //     recoilAvailable = false;
    504 //     hasError = false;
    505 //     console.log(args);
    506 //     const repEmb = statsHandler(args.join(" ").replace("\n", " "));
    507 //     if (hasError) {
    508 //       interaction.followUp({ embeds: [repEmb] });
    509 //     }
    510 //     if (recoilAvailable) {
    511 //       repEmb.fields.push({
    512 //         name: "**Recoil Graph**",
    513 //         value:
    514 //           "```\nThe Recoil graph below is dynamic (change based on attachment equipped)```",
    515 //       });
    516 //       const recoilImageLink = await chart.getShortUrl();
    517 //       repEmb.image = { url: recoilImageLink };
    518 //     }
    519 //     interaction.followUp({ embeds: [repEmb] });
    520 //   },
    521 // }
    522 
    523 // run: async (client, interaction, args) => {
    524 //   recoilAvailable = false;
    525 //   hasError = false;
    526 //   console.log(args);
    527 //   const repEmb = statsHandler(args.join(" ").replace("\n", " "));
    528 //   if (hasError) {
    529 //     interaction.followUp({ embeds: [repEmb] });
    530 //   }
    531 //   if (recoilAvailable) {
    532 //     repEmb.fields.push({
    533 //       name: "**Recoil Graph**",
    534 //       value:
    535 //         "```\nThe Recoil graph below is dynamic (change based on attachment equipped)```",
    536 //     });
    537 //     const recoilImageLink = await chart.getShortUrl();
    538 //     repEmb.image = { url: recoilImageLink };
    539 //   }
    540 //   interaction.followUp({ embeds: [repEmb] });
    541 // },
    542 // };
    543 
    544 // function inpHandler(inpmsg) {
    545 // statsHandler(inpmsg.split("+")[0]);
    546 // }
    547 
    548 // function statsHandler(inpmsg) {
    549 // let statsNames = [
    550 //     "Pellets",
    551 //     "Detonation Range",
    552 //     "Explosion Radius",
    553 //     "Explosion Damage",
    554 //     "Firing Mode",
    555 //     "Rate of Fire",
    556 //     "Bullet in Burst",
    557 //     "Time Between Burst",
    558 //     "Bullet Speed",
    559 //     "Penetration Level",
    560 //     "Bullet Spread",
    561 //     "Idle Sway",
    562 //     "Hipfire Pellet Spread",
    563 //     "ADS Pellet Spread",
    564 //     "ADS Time",
    565 //     "Sprint-to-Fire Time",
    566 //     "ADS Zoom",
    567 //     "Magazine",
    568 //     "Reserve",
    569 //     "Reload Type",
    570 //     "Cancel Reload Time",
    571 //     "Reload Time",
    572 //     "Full Reload Time",
    573 //     "Drop Time",
    574 //     "Raise Time",
    575 //     "Sprinting Speed",
    576 //     "Walking Speed",
    577 //     "Straifing Speed",
    578 //     "Damage per Tick",
    579 //     "Number of Ticks",
    580 //     "Time Between Ticks",
    581 //     "Breath Hold Time",
    582 //     "shouldNeverHappen0",
    583 //     "shouldNeverHappen1",
    584 //     "shouldNeverHappen2",
    585 //     "shouldNeverHappen3",
    586 //     "shouldNeverHappen4",
    587 //   ],
    588 //   out = [];
    589 
    590 // currGun = common.weaponIdentifier(inpmsg);
    591 // if (typeof currGun == "string") {
    592 //   hasError = true;
    593 //   return currGun;
    594 // }
    595 // currStats = currGun.stats;
    596 // currDRM = currGun.drm[0];
    597 // currAttachments = [];
    598 // currAttachments = common.attachmentsIdentifier(
    599 //   inpmsg,
    600 //   currGun.aments,
    601 //   currStats
    602 // );
    603 // if (typeof currAttachments == "string") {
    604 //   hasError = true;
    605 //   return currAttachments;
    606 // }
    607 // currRecoilArr = [1, 1, currGun.stats[17]];
    608 // if (currAttachments.length != 0) {
    609 //   const totalEffects = common.totaler(currAttachments);
    610 
    611 //   currStats = common.updateStatswithEffects(totalEffects, currStats);
    612 //   currRecoilArr = [totalEffects[2], totalEffects[3], currGun.stats[17]]; // must happen after currStats update
    613 //   currDRM = currGun.drm[totalEffects[37]];
    614 //   currDRM.range = currDRM.range.map(x =>
    615 //     Math.round(x * (1 + totalEffects[13] / 100))
    616 //   );
    617 //   out = common.attachmentHandler(totalEffects, currStats);
    618 // }
    619 // function statsWorker() {
    620 //   if (currStats[19] === 2) {
    621 //     currStats[21] =
    622 //       currStats[20] + currStats[21] * currStats[17] + currStats[22];
    623 //     currStats[20] = 0;
    624 //     currStats[22] = 0;
    625 //   }
    626 //   currStats[25] = (currStats[25] * currStats[26]) / 100;
    627 
    628 //   const outReady = currStats.map((x, i) =>
    629 //     x ? statsNames[i].padEnd(24) + ":".padEnd(3) + beautifier(i) : ""
    630 //   );
    631 //   out = [
    632 //     ...[
    633 //       "Basic Stats",
    634 //       "ADS Stats",
    635 //       "Bullet Stats",
    636 //       "Magazine",
    637 //       "Handling Stats",
    638 //       "Mobility Stats",
    639 //       "Miscellaneous Stats",
    640 //     ].map((x, i) =>
    641 //       fieldMaker(
    642 //         x,
    643 //         [
    644 //           [04, 05, 09],
    645 //           [14, 16, 11, 31],
    646 //           [00, 06, 07, 08, 10, 12, 13],
    647 //           [17, 18, 19, 20, 21, 22],
    648 //           [23, 24],
    649 //           [25, 26, 27, 15],
    650 //           [28, 29, 30, 01, 02, 03],
    651 //         ][i]
    652 //       )
    653 //     ),
    654 //     ...out,
    655 //   ];
    656 //   function fieldMaker(inpName, inpIndx) {
    657 //     inpIndx = inpIndx.filter(x => outReady[x]);
    658 //     return inpIndx.length
    659 //       ? {
    660 //           name: "**" + inpName + "**",
    661 //           value: "```\n" + inpIndx.map(x => outReady[x]).join("\n") + "```",
    662 //         }
    663 //       : "";
    664 //   }
    665 // }
    666 // statsWorker();
    667 
    668 // function beautifier(j) {
    669 //   switch (j) {
    670 //     case 04:
    671 //       return data.firingModes[currStats[j] - 1];
    672 //     case 09:
    673 //       return data.penetrationLevels[currStats[j] - 1];
    674 //     case 19:
    675 //       return data.reloadTypes[currStats[j] - 1];
    676 //     case 08:
    677 //       if (currStats[j] == -1) {
    678 //         return "Infinity";
    679 //       } else {
    680 //         return parseFloat(currStats[j].toFixed(2)).toString() + " m/s";
    681 //       }
    682 //     case 03:
    683 //       return parseFloat(currStats[j].toFixed(2))
    684 //         .toString()
    685 //         .replace(".", " ~ ");
    686 //     default:
    687 //       return parseFloat(currStats[j].toFixed(2)).toString() + addUnit(j);
    688 //   }
    689 
    690 //   function addUnit(j) {
    691 //     switch (j) {
    692 //       case 07:
    693 //       case 14:
    694 //       case 15:
    695 //       case 23:
    696 //       case 24:
    697 //       case 31:
    698 //         return " ms";
    699 //       case 27:
    700 //       case 28:
    701 //       case 25:
    702 //       case 26:
    703 //         return " m/s";
    704 //       case 20:
    705 //       case 21:
    706 //       case 22:
    707 //         return " s";
    708 //       case 16:
    709 //         return "%";
    710 //       case 06:
    711 //         return " Rounds";
    712 //       case 05:
    713 //         return " RPM";
    714 //       default:
    715 //         return "";
    716 //     }
    717 //   }
    718 // }
    719 // interpretion = currGun.gunname + common.interpretioner(currAttachments);
    720 // if (currGun.recoil.hr.length > 2) {
    721 //   chart = common.recoilHandler(
    722 //     currGun.recoil.hr,
    723 //     currGun.recoil.vr,
    724 //     currRecoilArr[0],
    725 //     currRecoilArr[1],
    726 //     currRecoilArr[2]
    727 //   );
    728 //   recoilAvailable = true;
    729 // } else {
    730 //   recoilAvailable = false;
    731 // }
    732 // if (chart == "none") {
    733 //   recoilAvailable = false;
    734 // }
    735 // if (chart == "err" || currAttachments == "err") {
    736 //   hasError = true;
    737 //   return "Cocaineeee";
    738 // }
    739 // const dmg =
    740 //   common.damageHandler(
    741 //     currDRM.damage,
    742 //     currDRM.range,
    743 //     1,
    744 //     100,
    745 //     60000 / currStats[5],
    746 //     currStats[7],
    747 //     currStats[6],
    748 //     currStats[0]
    749 //   ) || "```This should never happen```";
    750 // out = [
    751 //   currGun.description
    752 //     ? {
    753 //         name: "**Description:**",
    754 //         value: "```\n" + currGun.description + "```",
    755 //       }
    756 //     : {},
    757 //   { name: "**Damage Profile:**", value: dmg },
    758 //   ...out,
    759 // ];
    760 // out = out.filter(x => x.value);
    761 // return {
    762 //   title: interpretion,
    763 //   color: 5814783,
    764 //   fields: out,
    765 //   footer: {
    766 //     text: "[OUTDATED] All data courtesy of Project Lighthouse 2.0 and CoDM Research Crew",
    767 //     icon_url:
    768 //       "https://media.discordapp.net/attachments/735590814662656102/806960573753327657/cc.png",
    769 //   },
    770 // };