@duque.edits/sdk 1.3.4 → 1.3.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -59,14 +59,15 @@ class GuildUserManager extends import_base.BaseManager {
59
59
  }
60
60
  async updateMany(...users) {
61
61
  users = users.map((a) => {
62
+ if (!a.id) return;
62
63
  const user = this.cache.get(a.id);
63
64
  const userWrapped = user.userDailyWrapper(a);
64
- return {
65
- ...user.toJSON(),
65
+ const finalUser = {
66
+ ...a,
66
67
  daily: userWrapped.daily,
67
- consecutive_wins: userWrapped.consecutive_wins,
68
- wins: userWrapped.wins
68
+ consecutive_wins: userWrapped.consecutive_wins
69
69
  };
70
+ return finalUser;
70
71
  });
71
72
  const url = this.base_url;
72
73
  const response = await this.rest.request({
@@ -351,6 +351,8 @@ const _GuildUser = class _GuildUser {
351
351
  if (!data?.type) data.type = "add";
352
352
  const url = import_Routes.Routes.guilds.users.get(this.manager.guild.id, this.id);
353
353
  let payload = {};
354
+ payload["daily"] = this.userDailyWrapper(data).daily;
355
+ payload["consecutive_wins"] = this.userDailyWrapper(data).consecutive_wins;
354
356
  const numericFields = [
355
357
  "wins",
356
358
  "points",
@@ -397,8 +399,6 @@ const _GuildUser = class _GuildUser {
397
399
  }
398
400
  }
399
401
  if ("accessories" in data) payload["accessories"] = data["accessories"];
400
- payload["daily"] = this.userDailyWrapper(data).daily;
401
- payload["consecutive_wins"] = this.userDailyWrapper(data).consecutive_wins;
402
402
  const response = await this.rest.request({
403
403
  method: "patch",
404
404
  url,
@@ -457,7 +457,7 @@ const _GuildUser = class _GuildUser {
457
457
  const prev = this.daily ?? { points: 0, wins: 0, coins: 0, losses: 0, mvps: 0 };
458
458
  const inc = {
459
459
  points: user?.points || 0,
460
- wins: user?.wins || 0,
460
+ wins: user?.wins ?? 0,
461
461
  coins: user?.coins || 0,
462
462
  losses: user?.losses || 0,
463
463
  mvps: user?.mvps || 0
@@ -470,9 +470,15 @@ const _GuildUser = class _GuildUser {
470
470
  mvps: clamp02((sameDay ? prev.mvps : 0) + inc.mvps),
471
471
  date: now
472
472
  };
473
- const gainedWins = inc.wins;
474
- const hasLostToday = user.losses !== 0;
475
- user.consecutive_wins = hasLostToday && !gainedWins ? 0 : (this.consecutive_wins || 0) + 1;
473
+ const hasGainedWins = inc.wins > 0;
474
+ const hasLostToday = inc.losses > 0;
475
+ let consecutive = user.consecutive_wins ?? this.consecutive_wins ?? 0;
476
+ if (hasLostToday) {
477
+ consecutive = 0;
478
+ } else if (hasGainedWins) {
479
+ consecutive += 1;
480
+ }
481
+ user.consecutive_wins = consecutive;
476
482
  return user;
477
483
  }
478
484
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@duque.edits/sdk",
3
- "version": "1.3.4",
3
+ "version": "1.3.5",
4
4
  "main": "./dist/index.js",
5
5
  "module": "./dist/index.mjs",
6
6
  "types": "./dist/index.d.ts",