brawlstats
Version:
A simple API Wrapper for Brawl Stars
1,152 lines (1,134 loc) • 32.5 kB
JavaScript
"use strict";
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from2, except, desc) => {
if (from2 && typeof from2 === "object" || typeof from2 === "function") {
for (let key of __getOwnPropNames(from2))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from2[key], enumerable: !(desc = __getOwnPropDesc(from2, key)) || desc.enumerable });
}
return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, mod));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var __publicField = (obj, key, value) => {
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
return value;
};
var __accessCheck = (obj, member, msg) => {
if (!member.has(obj))
throw TypeError("Cannot " + msg);
};
var __privateGet = (obj, member, getter) => {
__accessCheck(obj, member, "read from private field");
return getter ? getter.call(obj) : member.get(obj);
};
var __privateAdd = (obj, member, value) => {
if (member.has(obj))
throw TypeError("Cannot add the same private member more than once");
member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
};
var __privateSet = (obj, member, value, setter) => {
__accessCheck(obj, member, "write to private field");
setter ? setter.call(obj, value) : member.set(obj, value);
return value;
};
// src/index.ts
var src_exports = {};
__export(src_exports, {
BattlelogManager: () => BattlelogManager,
Brawlers: () => Brawlers,
Client: () => Client,
ClubManager: () => ClubManager,
Events: () => Events,
LeaderboardManager: () => LeaderboardManager,
PlayerManager: () => PlayerManager,
RotationManager: () => RotationManager,
dateFromBrawlStars: () => dateFromBrawlStars,
hours: () => hours,
minutes: () => minutes
});
module.exports = __toCommonJS(src_exports);
// src/internal/container.ts
var container = {};
// src/lib/makeBrawlersMap.ts
var import_collection = __toESM(require("@discordjs/collection"));
function makeBrawlersMap() {
const collection = new import_collection.default();
collection.set("SHELLY", {
id: 16e6,
name: "SHELLY",
starPowers: [
{ id: 23000076, name: "SHELL SHOCK" },
{ id: 23000135, name: "BAND-AID" }
],
gadgets: [
{ id: 23000255, name: "FAST FORWARD" },
{ id: 23000288, name: "CLAY PIGEONS" }
]
});
collection.set("COLT", {
id: 16000001,
name: "COLT",
starPowers: [
{ id: 23000077, name: "SLICK BOOTS" },
{ id: 23000138, name: "MAGNUM SPECIAL" }
],
gadgets: [
{ id: 23000273, name: "SPEEDLOADER" },
{ id: 23000319, name: "SILVER BULLET" }
]
});
collection.set("BULL", {
id: 16000002,
name: "BULL",
starPowers: [
{ id: 23000078, name: "BERSERKER" },
{ id: 23000137, name: "TOUGH GUY" }
],
gadgets: [
{ id: 23000272, name: "T-BONE INJECTOR" },
{ id: 23000310, name: "STOMPER" }
]
});
collection.set("BROCK", {
id: 16000003,
name: "BROCK",
starPowers: [
{ id: 23000079, name: "MORE ROCKETS!" },
{ id: 23000150, name: "ROCKET NO. 4" }
],
gadgets: [
{ id: 23000245, name: "ROCKET LACES" },
{ id: 23000316, name: "ROCKET FUEL" }
]
});
collection.set("RICO", {
id: 16000004,
name: "RICO",
starPowers: [
{ id: 23000080, name: "SUPER BOUNCY" },
{ id: 23000156, name: "ROBO RETREAT" }
],
gadgets: [
{ id: 23000246, name: "MULTIBALL LAUNCHER" },
{ id: 23000409, name: "BOUNCY CASTLE" }
]
});
collection.set("SPIKE", {
id: 16000005,
name: "SPIKE",
starPowers: [
{ id: 23000081, name: "FERTILIZE" },
{ id: 23000151, name: "CURVEBALL" }
],
gadgets: [
{ id: 23000247, name: "POPPING PINCUSHION" },
{ id: 23000406, name: "LIFE PLANT" }
]
});
collection.set("BARLEY", {
id: 16000006,
name: "BARLEY",
starPowers: [
{ id: 23000082, name: "MEDICAL USE" },
{ id: 23000158, name: "EXTRA NOXIOUS" }
],
gadgets: [
{ id: 23000250, name: "STICKY SYRUP MIXER" },
{ id: 23000293, name: "HERBAL TONIC" }
]
});
collection.set("JESSIE", {
id: 16000007,
name: "JESSIE",
starPowers: [
{ id: 23000083, name: "ENERGIZE" },
{ id: 23000149, name: "SHOCKY" }
],
gadgets: [
{ id: 23000251, name: "SPARK PLUG" },
{ id: 23000295, name: "RECOIL SPRING" }
]
});
collection.set("NITA", {
id: 16000008,
name: "NITA",
starPowers: [
{ id: 23000084, name: "BEAR WITH ME" },
{ id: 23000136, name: "HYPER BEAR" }
],
gadgets: [
{ id: 23000249, name: "BEAR PAWS" },
{ id: 23000314, name: "FAUX FUR" }
]
});
collection.set("DYNAMIKE", {
id: 16000009,
name: "DYNAMIKE",
starPowers: [
{ id: 23000085, name: "DYNA-JUMP" },
{ id: 23000155, name: "DEMOLITION" }
],
gadgets: [
{ id: 23000258, name: "FIDGET SPINNER" },
{ id: 23000294, name: "SATCHEL CHARGE" }
]
});
collection.set("EL PRIMO", {
id: 16000010,
name: "EL PRIMO",
starPowers: [
{ id: 23000086, name: "EL FUEGO" },
{ id: 23000140, name: "METEOR RUSH" }
],
gadgets: [
{ id: 23000264, name: "SUPLEX SUPPLEMENT" },
{ id: 23000292, name: "ASTEROID BELT" }
]
});
collection.set("MORTIS", {
id: 16000011,
name: "MORTIS",
starPowers: [
{ id: 23000087, name: "CREEPY HARVEST" },
{ id: 23000154, name: "COILED SNAKE" }
],
gadgets: [
{ id: 23000265, name: "COMBO SPINNER" },
{ id: 23000290, name: "SURVIVAL SHOVEL" }
]
});
collection.set("CROW", {
id: 16000012,
name: "CROW",
starPowers: [
{ id: 23000088, name: "EXTRA TOXIC" },
{ id: 23000143, name: "CARRION CROW" }
],
gadgets: [
{ id: 23000243, name: "DEFENSE BOOSTER" },
{ id: 23000286, name: "SLOWING TOXIN" }
]
});
collection.set("POCO", {
id: 16000013,
name: "POCO",
starPowers: [
{ id: 23000089, name: "DA CAPO!" },
{ id: 23000144, name: "SCREECHING SOLO" }
],
gadgets: [
{ id: 23000267, name: "TUNING FORK" },
{ id: 23000350, name: "PROTECTIVE TUNES" }
]
});
collection.set("BO", {
id: 16000014,
name: "BO",
starPowers: [
{ id: 23000090, name: "CIRCLING EAGLE" },
{ id: 23000148, name: "SNARE A BEAR" }
],
gadgets: [
{ id: 23000263, name: "SUPER TOTEM" },
{ id: 23000289, name: "TRIPWIRE" }
]
});
collection.set("PIPER", {
id: 16000015,
name: "PIPER",
starPowers: [
{ id: 23000091, name: "AMBUSH" },
{ id: 23000152, name: "SNAPPY SNIPING" }
],
gadgets: [
{ id: 23000268, name: "AUTO AIMER" },
{ id: 23000291, name: "HOMEMADE RECIPE" }
]
});
collection.set("PAM", {
id: 16000016,
name: "PAM",
starPowers: [
{ id: 23000092, name: "MAMA'S HUG" },
{ id: 23000139, name: "MAMA'S SQUEEZE" }
],
gadgets: [
{ id: 23000257, name: "PULSE MODULATOR" },
{ id: 23000404, name: "SCRAPSUCKER" }
]
});
collection.set("TARA", {
id: 16000017,
name: "TARA",
starPowers: [
{ id: 23000093, name: "BLACK PORTAL" },
{ id: 23000160, name: "HEALING SHADE" }
],
gadgets: [
{ id: 23000266, name: "PSYCHIC ENHANCER" },
{ id: 23000356, name: "SUPPORT FROM BEYOND" }
]
});
collection.set("DARRYL", {
id: 16000018,
name: "DARRYL",
starPowers: [
{ id: 23000094, name: "STEEL HOOPS" },
{ id: 23000157, name: "ROLLING RELOAD" }
],
gadgets: [
{ id: 23000260, name: "RECOILING ROTATOR" },
{ id: 23000313, name: "TAR BARREL" }
]
});
collection.set("PENNY", {
id: 16000019,
name: "PENNY",
starPowers: [
{ id: 23000099, name: "LAST BLAST" },
{ id: 23000142, name: "BALLS OF FIRE" }
],
gadgets: [
{ id: 23000248, name: "POCKET DETONATOR" },
{ id: 23000287, name: "CAPTAIN'S COMPASS" }
]
});
collection.set("FRANK", {
id: 16000020,
name: "FRANK",
starPowers: [
{ id: 23000104, name: "POWER GRAB" },
{ id: 23000153, name: "SPONGE" }
],
gadgets: [
{ id: 23000261, name: "ACTIVE NOISE CANCELING" },
{ id: 23000351, name: "IRRESISTIBLE ATTRACTION" }
]
});
collection.set("GENE", {
id: 16000021,
name: "GENE",
starPowers: [
{ id: 23000109, name: "MAGIC PUFFS" },
{ id: 23000159, name: "SPIRIT SLAP" }
],
gadgets: [
{ id: 23000252, name: "LAMP BLOWOUT" },
{ id: 23000352, name: "VENGEFUL SPIRITS" }
]
});
collection.set("TICK", {
id: 16000022,
name: "TICK",
starPowers: [
{ id: 23000114, name: "WELL OILED" },
{ id: 23000161, name: "AUTOMA-TICK RELOAD" }
],
gadgets: [
{ id: 23000253, name: "MINE MANIA" },
{ id: 23000355, name: "LAST HURRAH" }
]
});
collection.set("LEON", {
id: 16000023,
name: "LEON",
starPowers: [
{ id: 23000119, name: "SMOKE TRAILS" },
{ id: 23000141, name: "INVISIHEAL" }
],
gadgets: [
{ id: 23000276, name: "CLONE PROJECTOR" },
{ id: 23000408, name: "LOLLIPOP DROP" }
]
});
collection.set("ROSA", {
id: 16000024,
name: "ROSA",
starPowers: [
{ id: 23000124, name: "PLANT LIFE" },
{ id: 23000147, name: "THORNY GLOVES" }
],
gadgets: [
{ id: 23000242, name: "GROW LIGHT" },
{ id: 23000348, name: "UNFRIENDLY BUSHES" }
]
});
collection.set("CARL", {
id: 16000025,
name: "CARL",
starPowers: [
{ id: 23000129, name: "POWER THROW" },
{ id: 23000145, name: "PROTECTIVE PIROUETTE" }
],
gadgets: [
{ id: 23000262, name: "HEAT EJECTOR" },
{ id: 23000317, name: "FLYING HOOK" }
]
});
collection.set("BIBI", {
id: 16000026,
name: "BIBI",
starPowers: [
{ id: 23000134, name: "HOME RUN" },
{ id: 23000146, name: "BATTING STANCE" }
],
gadgets: [
{ id: 23000275, name: "VITAMIN BOOSTER" },
{ id: 23000458, name: "EXTRA STICKY" }
]
});
collection.set("8-BIT", {
id: 16000027,
name: "8-BIT",
starPowers: [
{ id: 23000168, name: "BOOSTED BOOSTER" },
{ id: 23000181, name: "PLUGGED IN" }
],
gadgets: [
{ id: 23000259, name: "CHEAT CARTRIDGE" },
{ id: 23000318, name: "EXTRA CREDITS" }
]
});
collection.set("SANDY", {
id: 16000028,
name: "SANDY",
starPowers: [
{ id: 23000186, name: "RUDE SANDS" },
{ id: 23000187, name: "HEALING WINDS" }
],
gadgets: [
{ id: 23000270, name: "SLEEP STIMULATOR" },
{ id: 23000405, name: "SWEET DREAMS" }
]
});
collection.set("BEA", {
id: 16000029,
name: "BEA",
starPowers: [
{ id: 23000192, name: "INSTA BEALOAD" },
{ id: 23000193, name: "HONEYCOMB" }
],
gadgets: [
{ id: 23000271, name: "HONEY MOLASSES" },
{ id: 23000312, name: "RATTLED HIVE" }
]
});
collection.set("EMZ", {
id: 16000030,
name: "EMZ",
starPowers: [
{ id: 23000198, name: "BAD KARMA" },
{ id: 23000199, name: "HYPE" }
],
gadgets: [
{ id: 23000274, name: "FRIENDZONER" },
{ id: 23000459, name: "ACID SPRAY" }
]
});
collection.set("MR. P", {
id: 16000031,
name: "MR. P",
starPowers: [
{ id: 23000204, name: "HANDLE WITH CARE" },
{ id: 23000205, name: "REVOLVING DOOR" }
],
gadgets: [
{ id: 23000269, name: "SERVICE BELL" },
{ id: 23000349, name: "PORTER REINFORCEMENTS" }
]
});
collection.set("MAX", {
id: 16000032,
name: "MAX",
starPowers: [
{ id: 23000210, name: "SUPER CHARGED" },
{ id: 23000211, name: "RUN N GUN" }
],
gadgets: [
{ id: 23000254, name: "PHASE SHIFTER" },
{ id: 23000311, name: "SNEAKY SNEAKERS" }
]
});
collection.set("JACKY", {
id: 16000034,
name: "JACKY",
starPowers: [
{ id: 23000222, name: "COUNTER CRUSH" },
{ id: 23000223, name: "HARDY HARD HAT" }
],
gadgets: [{ id: 23000256, name: "PNEUMATIC BOOSTER" }]
});
collection.set("GALE", {
id: 16000035,
name: "GALE",
starPowers: [
{ id: 23000228, name: "BLUSTERY BLOW" },
{ id: 23000229, name: "FREEZING SNOW" }
],
gadgets: [
{ id: 23000277, name: "SPRING EJECTOR" },
{ id: 23000407, name: "TWISTER" }
]
});
collection.set("NANI", {
id: 16000036,
name: "NANI",
starPowers: [
{ id: 23000234, name: "AUTOFOCUS" },
{ id: 23000235, name: "TEMPERED STEEL" }
],
gadgets: [
{ id: 23000278, name: "WARP BLAST" },
{ id: 23000353, name: "RETURN TO SENDER" }
]
});
collection.set("SPROUT", {
id: 16000037,
name: "SPROUT",
starPowers: [
{ id: 23000240, name: "OVERGROWTH" },
{ id: 23000241, name: "PHOTOSYNTHESIS" }
],
gadgets: [
{ id: 23000244, name: "GARDEN MULCHER" },
{ id: 23000315, name: "TRANSPLANT" }
]
});
collection.set("SURGE", {
id: 16000038,
name: "SURGE",
starPowers: [
{ id: 23000283, name: "TO THE MAX!" },
{ id: 23000284, name: "SERVE ICE COLD" }
],
gadgets: [{ id: 23000285, name: "POWER SURGE" }]
});
collection.set("COLETTE", {
id: 16000039,
name: "COLETTE",
starPowers: [
{ id: 23000300, name: "PUSH IT" },
{ id: 23000301, name: "MASS TAX" }
],
gadgets: [
{ id: 23000302, name: "NA-AH!" },
{ id: 23000457, name: "GOTCHA!" }
]
});
collection.set("AMBER", {
id: 16000040,
name: "AMBER",
starPowers: [
{ id: 23000307, name: "WILD FLAMES" },
{ id: 23000308, name: "SCORCHIN' SIPHON" }
],
gadgets: [{ id: 23000309, name: "FIRE STARTERS" }]
});
collection.set("LOU", {
id: 16000041,
name: "LOU",
starPowers: [
{ id: 23000324, name: "SUPERCOOL" },
{ id: 23000325, name: "HYPOTHERMIA" }
],
gadgets: [
{ id: 23000326, name: "ICE BLOCK" },
{ id: 23000400, name: "CRYO SYRUP" }
]
});
collection.set("BYRON", {
id: 16000042,
name: "BYRON",
starPowers: [
{ id: 23000331, name: "MALAISE" },
{ id: 23000332, name: "INJECTION" }
],
gadgets: [
{ id: 23000333, name: "SHOT IN THE ARM" },
{ id: 23000461, name: "BOOSTER SHOTS" }
]
});
collection.set("EDGAR", {
id: 16000043,
name: "EDGAR",
starPowers: [
{ id: 23000338, name: "HARD LANDING" },
{ id: 23000339, name: "FISTICUFFS" }
],
gadgets: [
{ id: 23000340, name: "LET'S FLY" },
{ id: 23000403, name: "HARDCORE" }
]
});
collection.set("COLONEL RUFFS", {
id: 16000044,
name: "COLONEL RUFFS",
starPowers: [
{ id: 23000345, name: "AIR SUPERIORITY" },
{ id: 23000346, name: "FIELD PROMOTION" }
],
gadgets: [
{ id: 23000347, name: "TAKE COVER" },
{ id: 23000402, name: "AIR SUPPORT" }
]
});
collection.set("STU", {
id: 16000045,
name: "STU",
starPowers: [
{ id: 23000362, name: "ZERO DRAG" },
{ id: 23000363, name: "GASO-HEAL" }
],
gadgets: [
{ id: 23000364, name: "SPEED ZONE" },
{ id: 23000401, name: "BREAKTHROUGH" }
]
});
collection.set("BELLE", {
id: 16000046,
name: "BELLE",
starPowers: [
{ id: 23000369, name: "POSITIVE FEEDBACK" },
{ id: 23000370, name: "GROUNDED" }
],
gadgets: [
{ id: 23000371, name: "NEST EGG" },
{ id: 23000463, name: "REVERSE POLARITY" }
]
});
collection.set("SQUEAK", {
id: 16000047,
name: "SQUEAK",
starPowers: [
{ id: 23000376, name: "CHAIN REACTION" },
{ id: 23000377, name: "SUPER STICKY" }
],
gadgets: [
{ id: 23000378, name: "WINDUP" },
{ id: 23000462, name: "RESIDUE" }
]
});
collection.set("GROM", {
id: 16000048,
name: "GROM",
starPowers: [
{ id: 23000383, name: "FOOT PATROL" },
{ id: 23000384, name: "X-FACTOR" }
],
gadgets: [
{ id: 23000385, name: "WATCHTOWER" },
{ id: 23000460, name: "RADIO CHECK" }
]
});
collection.set("BUZZ", {
id: 16000049,
name: "BUZZ",
starPowers: [
{ id: 23000390, name: "TOUGHER TORPEDO" },
{ id: 23000391, name: "EYES SHARP" }
],
gadgets: [{ id: 23000392, name: "RESERVE BUOY" }]
});
collection.set("GRIFF", {
id: 16000050,
name: "GRIFF",
starPowers: [
{ id: 23000397, name: "KEEP THE CHANGE" },
{ id: 23000398, name: "BUSINESS RESILIENCE" }
],
gadgets: [{ id: 23000399, name: "PIGGY BANK" }]
});
collection.set("ASH", {
id: 16000051,
name: "ASH",
starPowers: [
{ id: 23000414, name: "FIRST BASH" },
{ id: 23000415, name: "MAD AS HECK" }
],
gadgets: [
{ id: 23000416, name: "CHILL PILL" },
{ id: 23000465, name: "ROTTEN BANANA" }
]
});
collection.set("MEG", {
id: 16000052,
name: "MEG",
starPowers: [
{ id: 23000421, name: "FORCE FIELD" },
{ id: 23000422, name: "HEAVY METAL" }
],
gadgets: [{ id: 23000423, name: "JOLTING VOLTS" }]
});
collection.set("LOLA", {
id: 16000053,
name: "LOLA",
starPowers: [
{ id: 23000431, name: "IMPROVISE" },
{ id: 23000432, name: "SEALED WITH A KISS" }
],
gadgets: [
{ id: 23000433, name: "FREEZE FRAME" },
{ id: 23000456, name: "STUNT DOUBLE" }
]
});
collection.set("FANG", {
id: 16000054,
name: "FANG",
starPowers: [
{ id: 23000438, name: "FRESH KICKS" },
{ id: 23000439, name: "DIVINE SOLES" }
],
gadgets: [
{ id: 23000440, name: "CORN-FU" },
{ id: 23000464, name: "ROUNDHOUSE KICK" }
]
});
collection.set("EVE", {
id: 16000056,
name: "EVE",
starPowers: [{ id: 23000452, name: "UNNATURAL ORDER" }],
gadgets: [{ id: 23000454, name: "GOTTA GO!" }]
});
return collection;
}
__name(makeBrawlersMap, "makeBrawlersMap");
// src/lib/helpers.ts
function parseTag(tag) {
if (tag.startsWith("%23"))
return tag;
if (tag.startsWith("#"))
return tag.replaceAll("#", "%23");
return `%23${tag}`;
}
__name(parseTag, "parseTag");
// src/lib/structures/Structure.ts
var import_fetch = require("@sapphire/fetch");
var _url, _endpoint;
var Structure = class {
constructor(endpoint) {
__privateAdd(this, _url, "https://bsproxy.royaleapi.dev/v1");
__privateAdd(this, _endpoint, void 0);
__privateSet(this, _endpoint, endpoint);
}
async request(endpoint = __privateGet(this, _endpoint), token = process.env.BRAWLSTARS_TOKEN) {
if (__privateGet(this, _endpoint) !== endpoint)
endpoint = `${__privateGet(this, _endpoint)}/${endpoint}`;
return (0, import_fetch.fetch)(`${__privateGet(this, _url)}/${endpoint}`, {
headers: {
Authorization: `Bearer ${token}`
}
});
}
};
__name(Structure, "Structure");
_url = new WeakMap();
_endpoint = new WeakMap();
// src/lib/errors/BrawlAPIError.ts
var BrawlAPIError = class extends Error {
constructor(options) {
switch (options.reason) {
case "accessDenied":
options.message = "Invalid API key provided";
break;
case "accessDenied.invalidIp":
options.message = `API key does not allow access from IP ${options.message.split("IP ")[1]}`;
break;
}
super(options.message);
__publicField(this, "reason");
__publicField(this, "code");
this.reason = options.reason;
this.code = options.code;
}
get name() {
return "BrawlAPIError";
}
};
__name(BrawlAPIError, "BrawlAPIError");
// src/lib/utils.ts
async function from(promiseOrCb) {
try {
return await (isFunction(promiseOrCb) ? promiseOrCb() : promiseOrCb);
} catch (e) {
const error = e;
throw new BrawlAPIError({
code: error.code,
message: error.toJSON().message,
reason: error.toJSON().reason
});
}
}
__name(from, "from");
function dateFromBrawlStars(value, timeZone) {
return new Date(Number(value.substring(0, 4)), Number(value.substring(4, 6)) - 1, Number(value.substring(6, 8)), Number(value.substring(9, 11)), Number(value.substring(11, 13))).toLocaleString("en-US", {
timeZone
});
}
__name(dateFromBrawlStars, "dateFromBrawlStars");
function minutes(value) {
return value * 60;
}
__name(minutes, "minutes");
function hours(value) {
return value * minutes(60);
}
__name(hours, "hours");
function isFunction(input) {
return typeof input === "function";
}
__name(isFunction, "isFunction");
// src/lib/managers/BattlelogManager.ts
var _token;
var BattlelogManager = class {
constructor(token) {
__privateAdd(this, _token, void 0);
__privateSet(this, _token, token);
}
fetch(tag) {
const structure = new Structure("players");
tag = parseTag(tag);
return from(async () => {
const data = await structure.request(`${tag}/battlelog`, __privateGet(this, _token));
return data.items;
});
}
async fetchMany(...tags) {
const battlelogs = [];
for (const rawTag of tags) {
const tag = parseTag(rawTag);
const battlelog = await this.fetch(tag);
battlelogs.push(battlelog);
}
return battlelogs;
}
};
__name(BattlelogManager, "BattlelogManager");
_token = new WeakMap();
// src/lib/structures/Club.ts
var Club = class extends Structure {
constructor(data) {
super("clubs");
__publicField(this, "tag");
__publicField(this, "name");
__publicField(this, "description");
__publicField(this, "type");
__publicField(this, "badgeId");
__publicField(this, "requiredTrophies");
__publicField(this, "trophies");
__publicField(this, "members");
Object.assign(this, data);
}
};
__name(Club, "Club");
// src/lib/managers/ClubManager.ts
var import_node_cache = __toESM(require("node-cache"));
var _token2, _cache;
var ClubManager = class {
constructor(token) {
__privateAdd(this, _token2, void 0);
__privateAdd(this, _cache, new import_node_cache.default());
__privateSet(this, _token2, token);
}
fetch(tag) {
if (__privateGet(this, _cache).has(tag)) {
return __privateGet(this, _cache).get(tag);
}
const structure = new Structure("clubs");
tag = parseTag(tag);
return from(async () => {
const data = await structure.request(`${tag}`, __privateGet(this, _token2));
const club = new Club(data);
__privateGet(this, _cache).set(club.tag, club, container.options?.cache?.club?.timeout ?? minutes(10));
return club;
});
}
async fetchMany(...tags) {
const clubs = [];
for (const rawTag of tags) {
const tag = parseTag(rawTag);
const club = await this.fetch(tag);
clubs.push(club);
}
return clubs;
}
};
__name(ClubManager, "ClubManager");
_token2 = new WeakMap();
_cache = new WeakMap();
// src/lib/managers/LeaderboardManager.ts
var import_collection2 = __toESM(require("@discordjs/collection"));
// src/lib/structures/Leaderboard.ts
var Leaderboard = class extends Structure {
constructor(options) {
super("players");
__publicField(this, "tag");
__publicField(this, "name");
__publicField(this, "nameColor");
__publicField(this, "icon");
__publicField(this, "trophies");
__publicField(this, "rank");
__publicField(this, "club");
Object.assign(this, options);
}
};
__name(Leaderboard, "Leaderboard");
// src/lib/managers/LeaderboardManager.ts
var _token3;
var LeaderboardManager = class {
constructor(token) {
__privateAdd(this, _token3, void 0);
__privateSet(this, _token3, token);
}
fetch(options) {
const structure = new Structure("rankings");
let { mode, region, name } = options;
return from(async () => {
name = name ?? "SHELLY";
region ??= "global";
const endpoint = mode === "brawlers" ? `${region}/brawlers/${makeBrawlersMap().get(name)?.id}` : `${region}/${mode}`;
const data = await structure.request(endpoint, __privateGet(this, _token3));
switch (mode) {
case "players": {
const players = new import_collection2.default();
for (const player of data.items) {
const leaderboard = new Leaderboard(player);
players.set(leaderboard.tag, leaderboard);
}
return players;
}
case "brawlers": {
const brawlers = new import_collection2.default();
for (const player of data.items) {
const leaderboard = new Leaderboard(player);
brawlers.set(leaderboard.tag, leaderboard);
}
return brawlers;
}
case "clubs": {
const clubs = new import_collection2.default();
for (const club of data.items) {
const leaderboard = new Leaderboard(club);
clubs.set(leaderboard.tag, leaderboard);
}
return clubs;
}
}
});
}
};
__name(LeaderboardManager, "LeaderboardManager");
_token3 = new WeakMap();
// src/lib/structures/Player.ts
var Player = class extends Structure {
constructor(options) {
super("players");
__publicField(this, "tag");
__publicField(this, "name");
__publicField(this, "nameColor");
__publicField(this, "icon");
__publicField(this, "trophies");
__publicField(this, "highestTrophies");
__publicField(this, "highestPowerPlayPoints");
__publicField(this, "expLevel");
__publicField(this, "expPoints");
__publicField(this, "isQualifiedFromChampionshipChallenge");
__publicField(this, "trioVictories");
__publicField(this, "soloVictories");
__publicField(this, "duoVictories");
__publicField(this, "bestRoboRumbleTime");
__publicField(this, "bestTimeAsBigBrawler");
__publicField(this, "club");
__publicField(this, "brawlers");
Object.assign(this, options);
}
getBattleLog() {
return from(async () => {
const tag = this.tag.replace("#", "%23");
const res = await super.request(`${tag}/battlelog`);
return res.items;
});
}
};
__name(Player, "Player");
// src/lib/managers/PlayerManager.ts
var import_node_cache2 = __toESM(require("node-cache"));
var _token4, _cache2;
var PlayerManager = class {
constructor(token) {
__privateAdd(this, _token4, void 0);
__privateAdd(this, _cache2, new import_node_cache2.default());
__privateSet(this, _token4, token);
}
fetch(tag) {
if (__privateGet(this, _cache2).has(tag)) {
return __privateGet(this, _cache2).get(tag);
}
const structure = new Structure("players");
tag = parseTag(tag);
return from(async () => {
const data = await structure.request(`${tag}`, __privateGet(this, _token4));
const player = new Player(data);
__privateGet(this, _cache2).set(player.tag, player, container.options?.cache?.player?.timeout ?? minutes(10));
return player;
});
}
async fetchMany(...tags) {
const players = [];
for (const rawTag of tags) {
const tag = parseTag(rawTag);
const player = await this.fetch(tag);
players.push(player);
}
return players;
}
};
__name(PlayerManager, "PlayerManager");
_token4 = new WeakMap();
_cache2 = new WeakMap();
// src/lib/managers/RotationManager.ts
var _token5;
var RotationManager = class {
constructor(token) {
__privateAdd(this, _token5, void 0);
__privateSet(this, _token5, token);
}
get(options) {
const structure = new Structure("events/rotation");
return from(async () => {
const data = await structure.request("", __privateGet(this, _token5));
const timezone = options?.timezone ?? "Etc/UTC";
const mapped = data.map((event) => {
event.startTime = dateFromBrawlStars(event.startTime, timezone);
event.endTime = dateFromBrawlStars(event.endTime, timezone);
event.event.mode = event.event.mode.charAt(0).toUpperCase() + event.event.mode.slice(1);
return event;
});
return mapped;
});
}
};
__name(RotationManager, "RotationManager");
_token5 = new WeakMap();
// src/lib/Client.ts
var _token6;
var Client = class {
constructor(options) {
__privateAdd(this, _token6, void 0);
__publicField(this, "options");
__publicField(this, "brawlers", makeBrawlersMap());
__publicField(this, "players");
__publicField(this, "clubs");
__publicField(this, "rotation");
__publicField(this, "leaderboards");
__publicField(this, "battlelogs");
this.options = options;
container.options = this.options;
__privateSet(this, _token6, options?.token ?? process.env.BRAWLSTARS_TOKEN);
this.players = new PlayerManager(__privateGet(this, _token6));
this.clubs = new ClubManager(__privateGet(this, _token6));
this.rotation = new RotationManager(__privateGet(this, _token6));
this.leaderboards = new LeaderboardManager(__privateGet(this, _token6));
this.battlelogs = new BattlelogManager(__privateGet(this, _token6));
}
};
__name(Client, "Client");
_token6 = new WeakMap();
// src/lib/types/enums.ts
var Brawlers = /* @__PURE__ */ ((Brawlers2) => {
Brawlers2["SHELLY"] = "SHELLY";
Brawlers2["COLT"] = "COLT";
Brawlers2["BULL"] = "BULL";
Brawlers2["BROCK"] = "BROCK";
Brawlers2["RICO"] = "RICO";
Brawlers2["SPIKE"] = "SPIKE";
Brawlers2["BARLEY"] = "BARLEY";
Brawlers2["JESSIE"] = "JESSIE";
Brawlers2["NITA"] = "NITA";
Brawlers2["DYNAMIKE"] = "DYNAMIKE";
Brawlers2["EL_PRIMO"] = "EL PRIMO";
Brawlers2["MORTIS"] = "MORTIS";
Brawlers2["CROW"] = "CROW";
Brawlers2["POCO"] = "POCO";
Brawlers2["BO"] = "BO";
Brawlers2["PIPER"] = "PIPER";
Brawlers2["PAM"] = "PAM";
Brawlers2["TARA"] = "TARA";
Brawlers2["DARRYL"] = "DARRYL";
Brawlers2["PENNY"] = "PENNY";
Brawlers2["FRANK"] = "FRANK";
Brawlers2["GENE"] = "GENE";
Brawlers2["TICK"] = "TICK";
Brawlers2["LEON"] = "LEON";
Brawlers2["ROSA"] = "ROSA";
Brawlers2["CARL"] = "CARL";
Brawlers2["BIBI"] = "BIBI";
Brawlers2["BIT8"] = "8-BIT";
Brawlers2["SANDY"] = "SANDY";
Brawlers2["BEA"] = "BEA";
Brawlers2["EMZ"] = "EMZ";
Brawlers2["MR_P"] = "MR. P";
Brawlers2["MAX"] = "MAX";
Brawlers2["JACKY"] = "JACKY";
Brawlers2["GALE"] = "GALE";
Brawlers2["NANI"] = "NANI";
Brawlers2["SPROUT"] = "SPROUT";
Brawlers2["SURGE"] = "SURGE";
Brawlers2["COLETTE"] = "COLETTE";
Brawlers2["AMBER"] = "AMBER";
Brawlers2["LOU"] = "LOU";
Brawlers2["BYRON"] = "BYRON";
Brawlers2["EDGAR"] = "EDGAR";
Brawlers2["COLONEL_RUFFS"] = "COLONEL RUFFS";
Brawlers2["STU"] = "STU";
Brawlers2["BELLE"] = "BELLE";
Brawlers2["SQUEAK"] = "SQUEAK";
Brawlers2["GROM"] = "GROM";
Brawlers2["BUZZ"] = "BUZZ";
Brawlers2["GRIFF"] = "GRIFF";
Brawlers2["ASH"] = "ASH";
Brawlers2["MEG"] = "MEG";
Brawlers2["LOLA"] = "LOLA";
Brawlers2["FANG"] = "FANG";
Brawlers2["EVE"] = "EVE";
return Brawlers2;
})(Brawlers || {});
var Events = /* @__PURE__ */ ((Events2) => {
Events2["GemGrab"] = "GemGrab";
Events2["SoloShowdown"] = "SoloShowdown";
Events2["BrawlBall"] = "BrawlBall";
Events2["HotZone"] = "HotZone";
Events2["DuoShowdown"] = "DuoShowdown";
Events2["Knockout"] = "Knockout";
Events2["BigGame"] = "BigGame";
Events2["Duels"] = "Duels";
Events2["Wipeout"] = "Wipeout";
Events2["Payload"] = "Payload";
return Events2;
})(Events || {});
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
BattlelogManager,
Brawlers,
Client,
ClubManager,
Events,
LeaderboardManager,
PlayerManager,
RotationManager,
dateFromBrawlStars,
hours,
minutes
});
//# sourceMappingURL=index.js.map