gambling-bot-shared 0.1.53 → 1.0.0

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.
Files changed (134) hide show
  1. package/README.MD +4 -0
  2. package/dist/{mongoose/atmRequest.schema.js → atm/atmRequest.mongoose.js} +4 -1
  3. package/dist/{types → atm}/index.js +5 -10
  4. package/dist/atm/schemas/atm.forms.js +11 -0
  5. package/dist/blackjack/index.js +21 -0
  6. package/dist/bonus/index.js +23 -0
  7. package/dist/bonus/schemas/bonus.forms.js +39 -0
  8. package/dist/{utils → bonus/utils}/bonusStreak.js +10 -1
  9. package/dist/{utils → bonus/utils}/calculateBonusReward.js +4 -3
  10. package/dist/casino/constants/casinoGames.js +5 -0
  11. package/dist/{constants → casino/constants}/index.js +4 -8
  12. package/dist/{constants → casino/constants}/plinkoConfig.js +1 -1
  13. package/dist/casino/index.js +30 -0
  14. package/dist/casino/schemas/casino.forms.js +80 -0
  15. package/dist/casino/services/casinoBet.service.js +146 -0
  16. package/dist/{utils → casino/utils}/calculateRTP.js +7 -4
  17. package/dist/{utils → common}/formatters.js +9 -2
  18. package/dist/{server.js → common/index.js} +4 -1
  19. package/dist/common/zod.js +16 -0
  20. package/dist/{mongoose/guildConfiguration.schema.js → guild/guildConfiguration.mongoose.js} +6 -5
  21. package/dist/guild/index.js +26 -0
  22. package/dist/guild/schemas/guild.forms.js +43 -0
  23. package/dist/guild/utils/normalizeGlobalSettings.js +46 -0
  24. package/dist/mongoose/index.js +17 -22
  25. package/dist/predictions/index.js +29 -0
  26. package/dist/{mongoose/prediction.schema.js → predictions/prediction.mongoose.js} +3 -2
  27. package/dist/predictions/schemas/prediction.forms.js +24 -0
  28. package/dist/predictions/services/normalizePredictionInput.js +53 -0
  29. package/dist/predictions/services/parsePredictionAutolock.js +20 -0
  30. package/dist/predictions/services/parsePredictionChoices.js +26 -0
  31. package/dist/predictions/services/prediction.db.js +72 -0
  32. package/dist/predictions/services/predictionLifecycle.service.js +133 -0
  33. package/dist/predictions/services/predictionSummary.js +58 -0
  34. package/dist/raffle/index.js +24 -0
  35. package/dist/raffle/schemas/raffle.forms.js +17 -0
  36. package/dist/raffle/services/raffle.db.js +153 -0
  37. package/dist/raffle/services/raffleLifecycle.service.js +34 -0
  38. package/dist/{schemas → transactions/constants}/index.js +2 -1
  39. package/dist/{index.js → transactions/index.js} +3 -2
  40. package/dist/transactions/types/transaction.js +2 -0
  41. package/dist/user/index.js +20 -0
  42. package/dist/user/types/user.js +2 -0
  43. package/dist/vip/index.js +21 -0
  44. package/dist/vip/schemas/vip.forms.js +16 -0
  45. package/dist/vip/types/vipRoom.js +2 -0
  46. package/package.json +67 -27
  47. package/dist/constants/blackjack.d.ts +0 -41
  48. package/dist/constants/bonusLimits.d.ts +0 -4
  49. package/dist/constants/commonTimezones.d.ts +0 -4
  50. package/dist/constants/defaultConfig.d.ts +0 -108
  51. package/dist/constants/defaultGlobalSettings.d.ts +0 -20
  52. package/dist/constants/gameRecordFields.d.ts +0 -8
  53. package/dist/constants/index.d.ts +0 -11
  54. package/dist/constants/lotteryConfig.d.ts +0 -2
  55. package/dist/constants/maxSimulations.d.ts +0 -5
  56. package/dist/constants/plinkoConfig.d.ts +0 -15
  57. package/dist/constants/rouletteConfig.d.ts +0 -1
  58. package/dist/constants/transaction.d.ts +0 -2
  59. package/dist/index.d.ts +0 -3
  60. package/dist/mongoose/atmRequest.schema.d.ts +0 -139
  61. package/dist/mongoose/blackjackGame.schema.d.ts +0 -139
  62. package/dist/mongoose/guildConfiguration.schema.d.ts +0 -237
  63. package/dist/mongoose/index.d.ts +0 -8
  64. package/dist/mongoose/prediction.schema.d.ts +0 -112
  65. package/dist/mongoose/raffle.schema.d.ts +0 -151
  66. package/dist/mongoose/transaction.schema.d.ts +0 -103
  67. package/dist/mongoose/user.schema.d.ts +0 -103
  68. package/dist/mongoose/vipRoom.schema.d.ts +0 -85
  69. package/dist/schemas/forms.d.ts +0 -183
  70. package/dist/schemas/forms.js +0 -173
  71. package/dist/schemas/index.d.ts +0 -1
  72. package/dist/server.d.ts +0 -1
  73. package/dist/types/atmRequest.d.ts +0 -15
  74. package/dist/types/blackjackGame.d.ts +0 -30
  75. package/dist/types/bonus.d.ts +0 -13
  76. package/dist/types/guildConfiguration.d.ts +0 -35
  77. package/dist/types/index.d.ts +0 -11
  78. package/dist/types/prediction.d.ts +0 -20
  79. package/dist/types/raffle.d.ts +0 -19
  80. package/dist/types/transaction.d.ts +0 -11
  81. package/dist/types/user.d.ts +0 -11
  82. package/dist/types/vipRoom.d.ts +0 -9
  83. package/dist/utils/bonusStreak.d.ts +0 -6
  84. package/dist/utils/calculateBonusReward.d.ts +0 -13
  85. package/dist/utils/calculateRTP.d.ts +0 -2
  86. package/dist/utils/formatters.d.ts +0 -13
  87. package/dist/utils/generateBonusPreview.d.ts +0 -11
  88. package/dist/utils/generateId.d.ts +0 -1
  89. package/dist/utils/globalSettings.d.ts +0 -6
  90. package/dist/utils/guildTimezone.d.ts +0 -6
  91. package/dist/utils/index.d.ts +0 -15
  92. package/dist/utils/index.js +0 -31
  93. package/dist/utils/normalizeBonusSettings.d.ts +0 -6
  94. package/dist/utils/normalizeCasinoSettings.d.ts +0 -2
  95. package/dist/utils/normalizeGlobalSettings.d.ts +0 -2
  96. package/dist/utils/normalizeGlobalSettings.js +0 -45
  97. package/dist/utils/parseTimeToSeconds.d.ts +0 -1
  98. package/dist/utils/validateBetAmount.d.ts +0 -8
  99. package/dist/utils/validatePredictionBet.d.ts +0 -13
  100. package/dist/utils/winAnnouncements.d.ts +0 -4
  101. /package/dist/{types → atm/types}/atmRequest.js +0 -0
  102. /package/dist/{constants → bonus/constants}/bonusLimits.js +0 -0
  103. /package/dist/{types → bonus/types}/bonus.js +0 -0
  104. /package/dist/{utils → bonus/utils}/generateBonusPreview.js +0 -0
  105. /package/dist/{utils → bonus/utils}/normalizeBonusSettings.js +0 -0
  106. /package/dist/{mongoose/blackjackGame.schema.js → casino/blackjackGame.mongoose.js} +0 -0
  107. /package/dist/{constants → casino/constants}/blackjack.js +0 -0
  108. /package/dist/{constants → casino/constants}/defaultConfig.js +0 -0
  109. /package/dist/{constants → casino/constants}/lotteryConfig.js +0 -0
  110. /package/dist/{constants → casino/constants}/maxSimulations.js +0 -0
  111. /package/dist/{constants → casino/constants}/rouletteConfig.js +0 -0
  112. /package/dist/{types → casino/types}/blackjackGame.js +0 -0
  113. /package/dist/{types/guildConfiguration.js → casino/types/casinoSettings.js} +0 -0
  114. /package/dist/{utils → casino/utils}/normalizeCasinoSettings.js +0 -0
  115. /package/dist/{utils → casino/utils}/validateBetAmount.js +0 -0
  116. /package/dist/{utils → casino/utils}/winAnnouncements.js +0 -0
  117. /package/dist/{utils → common}/generateId.js +0 -0
  118. /package/dist/{utils → common}/parseTimeToSeconds.js +0 -0
  119. /package/dist/{constants → guild/constants}/commonTimezones.js +0 -0
  120. /package/dist/{constants → guild/constants}/defaultGlobalSettings.js +0 -0
  121. /package/dist/{types/prediction.js → guild/types/guildConfiguration.js} +0 -0
  122. /package/dist/{utils → guild/utils}/globalSettings.js +0 -0
  123. /package/dist/{utils → guild/utils}/guildTimezone.js +0 -0
  124. /package/dist/{types/raffle.js → predictions/services/types.js} +0 -0
  125. /package/dist/{types/transaction.js → predictions/types/prediction.js} +0 -0
  126. /package/dist/{utils → predictions/utils}/validatePredictionBet.js +0 -0
  127. /package/dist/{mongoose/raffle.schema.js → raffle/raffle.mongoose.js} +0 -0
  128. /package/dist/{types/user.js → raffle/services/types.js} +0 -0
  129. /package/dist/{types/vipRoom.js → raffle/types/raffle.js} +0 -0
  130. /package/dist/{constants → transactions/constants}/gameRecordFields.js +0 -0
  131. /package/dist/{constants → transactions/constants}/transaction.js +0 -0
  132. /package/dist/{mongoose/transaction.schema.js → transactions/transaction.mongoose.js} +0 -0
  133. /package/dist/{mongoose/user.schema.js → user/user.mongoose.js} +0 -0
  134. /package/dist/{mongoose/vipRoom.schema.js → vip/vipRoom.mongoose.js} +0 -0
package/README.MD CHANGED
@@ -42,6 +42,10 @@ curl -fsSL https://raw.githubusercontent.com/krouskystepan/gambling-bot-shared/m
42
42
 
43
43
  See [docs/LOCAL_DEVELOPMENT.md](./docs/LOCAL_DEVELOPMENT.md) for the local linking workflow, debugging commands, and CI release process.
44
44
 
45
+ ## Package imports
46
+
47
+ Domain subpath exports only — see [docs/ARCHITECTURE.md](./docs/ARCHITECTURE.md) for the domain map.
48
+
45
49
  ## GitHub / CI
46
50
 
47
51
  See [docs/GITHUB_SETUP.md](./docs/GITHUB_SETUP.md) for CI workflows and branch protection on `main`.
@@ -18,6 +18,9 @@ exports.AtmRequestSchema = new mongoose_1.Schema({
18
18
  },
19
19
  handledBy: { type: String },
20
20
  handledAt: { type: Date },
21
+ notes: { type: String },
21
22
  logChannelId: { type: String },
22
- logMessageId: { type: String }
23
+ logMessageId: { type: String },
24
+ meta: { type: mongoose_1.Schema.Types.Mixed }
23
25
  }, { timestamps: true });
26
+ exports.AtmRequestSchema.index({ guildId: 1, status: 1, createdAt: -1 });
@@ -14,13 +14,8 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./user"), exports);
18
- __exportStar(require("./vipRoom"), exports);
19
- __exportStar(require("./prediction"), exports);
20
- __exportStar(require("./transaction"), exports);
21
- __exportStar(require("./guildConfiguration"), exports);
22
- __exportStar(require("./atmRequest"), exports);
23
- __exportStar(require("./raffle"), exports);
24
- __exportStar(require("./blackjackGame"), exports);
25
- // No db
26
- __exportStar(require("./bonus"), exports);
17
+ exports.AtmRequestSchema = void 0;
18
+ __exportStar(require("./types/atmRequest"), exports);
19
+ var atmRequest_mongoose_1 = require("./atmRequest.mongoose");
20
+ Object.defineProperty(exports, "AtmRequestSchema", { enumerable: true, get: function () { return atmRequest_mongoose_1.AtmRequestSchema; } });
21
+ __exportStar(require("./schemas/atm.forms"), exports);
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.atmChannelsFormSchema = void 0;
7
+ const zod_1 = __importDefault(require("zod"));
8
+ exports.atmChannelsFormSchema = zod_1.default.object({
9
+ actions: zod_1.default.string(),
10
+ logs: zod_1.default.string()
11
+ });
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ exports.BlackjackGameSchema = void 0;
18
+ __exportStar(require("../casino/constants/blackjack"), exports);
19
+ __exportStar(require("../casino/types/blackjackGame"), exports);
20
+ var blackjackGame_mongoose_1 = require("../casino/blackjackGame.mongoose");
21
+ Object.defineProperty(exports, "BlackjackGameSchema", { enumerable: true, get: function () { return blackjackGame_mongoose_1.BlackjackGameSchema; } });
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./constants/bonusLimits"), exports);
18
+ __exportStar(require("./types/bonus"), exports);
19
+ __exportStar(require("./utils/bonusStreak"), exports);
20
+ __exportStar(require("./utils/calculateBonusReward"), exports);
21
+ __exportStar(require("./utils/generateBonusPreview"), exports);
22
+ __exportStar(require("./utils/normalizeBonusSettings"), exports);
23
+ __exportStar(require("./schemas/bonus.forms"), exports);
@@ -0,0 +1,39 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.bonusFormSchema = void 0;
7
+ const zod_1 = __importDefault(require("zod"));
8
+ const bonusLimits_1 = require("../constants/bonusLimits");
9
+ const bonusAmountSchema = zod_1.default
10
+ .number()
11
+ .min(0, 'Must be ≥ 0')
12
+ .max(bonusLimits_1.BONUS_MAX_AMOUNT, `Must be ≤ ${bonusLimits_1.BONUS_MAX_AMOUNT.toLocaleString()}`);
13
+ const bonusMultiplierSchema = zod_1.default
14
+ .number()
15
+ .min(0, 'Must be ≥ 0')
16
+ .max(bonusLimits_1.BONUS_MAX_STREAK_MULTIPLIER, `Must be ≤ ${bonusLimits_1.BONUS_MAX_STREAK_MULTIPLIER}`)
17
+ .optional();
18
+ const bonusMultiplierInputSchema = zod_1.default
19
+ .union([zod_1.default.number(), zod_1.default.string()])
20
+ .optional()
21
+ .transform((val) => {
22
+ if (val === '' || val === undefined || val === null)
23
+ return undefined;
24
+ const num = typeof val === 'string' ? Number(val) : val;
25
+ return Number.isNaN(num) ? undefined : num;
26
+ })
27
+ .pipe(bonusMultiplierSchema);
28
+ exports.bonusFormSchema = zod_1.default.object({
29
+ rewardMode: zod_1.default.enum(['linear', 'exponential']),
30
+ baseReward: bonusAmountSchema,
31
+ streakIncrement: bonusAmountSchema.optional(),
32
+ streakMultiplier: bonusMultiplierInputSchema,
33
+ maxReward: bonusAmountSchema,
34
+ resetOnMax: zod_1.default.boolean(),
35
+ milestoneBonus: zod_1.default.object({
36
+ weekly: bonusAmountSchema,
37
+ monthly: bonusAmountSchema
38
+ })
39
+ });
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getStreakDisplay = exports.getStreakAfterClaim = exports.canClaimDailyBonus = void 0;
3
+ exports.getStreakDisplay = exports.getEffectiveStreak = exports.getStreakAfterClaim = exports.canClaimDailyBonus = void 0;
4
4
  const DAY_MS = 24 * 60 * 60 * 1000;
5
5
  const canClaimDailyBonus = (lastClaim, now) => {
6
6
  if (!lastClaim)
@@ -17,6 +17,15 @@ const getStreakAfterClaim = (lastClaim, now, currentStreak) => {
17
17
  return 1;
18
18
  };
19
19
  exports.getStreakAfterClaim = getStreakAfterClaim;
20
+ const getEffectiveStreak = (lastClaim, now, storedStreak) => {
21
+ if (!lastClaim)
22
+ return 0;
23
+ const diff = now.getTime() - lastClaim.getTime();
24
+ if (diff >= 2 * DAY_MS)
25
+ return 0;
26
+ return storedStreak;
27
+ };
28
+ exports.getEffectiveStreak = getEffectiveStreak;
20
29
  const getStreakDisplay = (lastClaim, now, streak) => {
21
30
  if (!lastClaim) {
22
31
  return { currentStreak: 0, nextStreak: 1 };
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.calculateBonusReward = void 0;
4
- const getCycleLength = (rewardMode, baseReward, maxReward, streakIncrement, streakMultiplier) => {
3
+ exports.calculateBonusReward = exports.getBonusCycleLength = void 0;
4
+ const getBonusCycleLength = (rewardMode, baseReward, maxReward, streakIncrement, streakMultiplier) => {
5
5
  if (rewardMode === 'linear') {
6
6
  return streakIncrement > 0
7
7
  ? Math.floor((maxReward - baseReward) / streakIncrement) + 1
@@ -11,6 +11,7 @@ const getCycleLength = (rewardMode, baseReward, maxReward, streakIncrement, stre
11
11
  ? Math.floor(Math.log(maxReward / baseReward) / Math.log(streakMultiplier)) + 1
12
12
  : 1;
13
13
  };
14
+ exports.getBonusCycleLength = getBonusCycleLength;
14
15
  const calculateBonusReward = ({ streak, settings }) => {
15
16
  const { rewardMode, baseReward, streakIncrement = 0, streakMultiplier = 1, maxReward, resetOnMax, milestoneBonus } = settings;
16
17
  let base = rewardMode === 'linear'
@@ -18,7 +19,7 @@ const calculateBonusReward = ({ streak, settings }) => {
18
19
  : baseReward * Math.pow(streakMultiplier, streak - 1);
19
20
  let isReset = false;
20
21
  if (maxReward > 0 && resetOnMax && base > maxReward) {
21
- const cycle = getCycleLength(rewardMode, baseReward, maxReward, streakIncrement, streakMultiplier);
22
+ const cycle = (0, exports.getBonusCycleLength)(rewardMode, baseReward, maxReward, streakIncrement, streakMultiplier);
22
23
  const cycleStreak = ((streak - 1) % cycle) + 1;
23
24
  isReset = streak > cycle && cycleStreak === 1;
24
25
  base =
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.CASINO_GAME_IDS = void 0;
4
+ const defaultConfig_1 = require("./defaultConfig");
5
+ exports.CASINO_GAME_IDS = Object.keys(defaultConfig_1.defaultCasinoSettings).filter((key) => key !== 'winAnnouncements');
@@ -14,14 +14,10 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./bonusLimits"), exports);
18
- __exportStar(require("./commonTimezones"), exports);
19
- __exportStar(require("./defaultGlobalSettings"), exports);
17
+ __exportStar(require("./blackjack"), exports);
18
+ __exportStar(require("./casinoGames"), exports);
20
19
  __exportStar(require("./defaultConfig"), exports);
21
- __exportStar(require("./maxSimulations"), exports);
22
20
  __exportStar(require("./lotteryConfig"), exports);
23
- __exportStar(require("./rouletteConfig"), exports);
24
- __exportStar(require("./gameRecordFields"), exports);
21
+ __exportStar(require("./maxSimulations"), exports);
25
22
  __exportStar(require("./plinkoConfig"), exports);
26
- __exportStar(require("./transaction"), exports);
27
- __exportStar(require("./blackjack"), exports);
23
+ __exportStar(require("./rouletteConfig"), exports);
@@ -25,7 +25,7 @@ const expandPlinkoBinMultipliers = (editable) => {
25
25
  const defaults = defaultBinMultipliers();
26
26
  const result = {};
27
27
  for (const bin of exports.PLINKO_EDITABLE_BINS) {
28
- result[String(bin)] = toNumber(editable[bin] ?? editable[String(bin)] ?? plinkoBinAt(defaults, bin));
28
+ result[String(bin)] = toNumber(editable[bin] ?? plinkoBinAt(defaults, bin));
29
29
  }
30
30
  for (let bin = exports.PLINKO_CENTER_BIN + 1; bin <= exports.PLINKO_BIN_COUNT; bin++) {
31
31
  const mirror = (0, exports.getPlinkoMirrorBin)(bin);
@@ -0,0 +1,30 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ exports.BlackjackGameSchema = void 0;
18
+ __exportStar(require("./constants"), exports);
19
+ __exportStar(require("./types/casinoSettings"), exports);
20
+ __exportStar(require("./types/blackjackGame"), exports);
21
+ __exportStar(require("./utils/calculateRTP"), exports);
22
+ __exportStar(require("./utils/validateBetAmount"), exports);
23
+ __exportStar(require("./utils/normalizeCasinoSettings"), exports);
24
+ __exportStar(require("./utils/winAnnouncements"), exports);
25
+ __exportStar(require("./services/casinoBet.service"), exports);
26
+ __exportStar(require("./schemas/casino.forms"), exports);
27
+ var blackjackGame_mongoose_1 = require("./blackjackGame.mongoose");
28
+ Object.defineProperty(exports, "BlackjackGameSchema", { enumerable: true, get: function () { return blackjackGame_mongoose_1.BlackjackGameSchema; } });
29
+ __exportStar(require("./constants/plinkoConfig"), exports);
30
+ __exportStar(require("../transactions/constants/gameRecordFields"), exports);
@@ -0,0 +1,80 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.casinoSettingsSchema = exports.casinoChannelsFormSchema = void 0;
7
+ const zod_1 = __importDefault(require("zod"));
8
+ const zod_2 = require("../../common/zod");
9
+ const plinkoConfig_1 = require("../constants/plinkoConfig");
10
+ exports.casinoChannelsFormSchema = zod_1.default.object({
11
+ casinoChannelIds: zod_1.default.array(zod_1.default.string()),
12
+ winAnnouncementsChannelId: zod_1.default.string()
13
+ });
14
+ exports.casinoSettingsSchema = zod_1.default.object({
15
+ dice: zod_1.default.object({
16
+ winMultiplier: zod_2.num,
17
+ minBet: zod_2.num,
18
+ maxBet: zod_2.num
19
+ }),
20
+ coinflip: zod_1.default.object({
21
+ winMultiplier: zod_2.num,
22
+ minBet: zod_2.num,
23
+ maxBet: zod_2.num
24
+ }),
25
+ slots: zod_1.default.object({
26
+ winMultipliers: zod_1.default.record(zod_1.default.string(), zod_2.num),
27
+ symbolWeights: zod_1.default.record(zod_1.default.string(), zod_2.num),
28
+ minBet: zod_2.num,
29
+ maxBet: zod_2.num
30
+ }),
31
+ lottery: zod_1.default.object({
32
+ winMultipliers: zod_1.default.record(zod_1.default.string(), zod_2.num),
33
+ minBet: zod_2.num,
34
+ maxBet: zod_2.num
35
+ }),
36
+ roulette: zod_1.default.object({
37
+ winMultipliers: zod_1.default.record(zod_1.default.string(), zod_2.num),
38
+ minBet: zod_2.num,
39
+ maxBet: zod_2.num
40
+ }),
41
+ rps: zod_1.default.object({
42
+ casinoCut: zod_2.num,
43
+ minBet: zod_2.num,
44
+ maxBet: zod_2.num
45
+ }),
46
+ goldenJackpot: zod_1.default.object({
47
+ winMultiplier: zod_2.num,
48
+ oneInChance: zod_2.num,
49
+ minBet: zod_2.num,
50
+ maxBet: zod_2.num
51
+ }),
52
+ blackjack: zod_1.default.object({
53
+ minBet: zod_2.num,
54
+ maxBet: zod_2.num
55
+ }),
56
+ prediction: zod_1.default.object({
57
+ minBet: zod_2.num,
58
+ maxBet: zod_2.num
59
+ }),
60
+ raffle: zod_1.default.object({
61
+ casinoCut: zod_2.num
62
+ }),
63
+ plinko: zod_1.default.object({
64
+ binMultipliers: zod_1.default
65
+ .record(zod_1.default.string(), zod_2.num)
66
+ .transform(plinkoConfig_1.normalizePlinkoBinMultipliers),
67
+ minBet: zod_2.num,
68
+ maxBet: zod_2.num
69
+ }),
70
+ winAnnouncements: zod_1.default.object({
71
+ plinkoMinMultiplier: zod_2.num,
72
+ goldenJackpotMinMultiplier: zod_2.num,
73
+ slotsMinMultiplier: zod_2.num,
74
+ lotteryMinMultiplier: zod_2.num,
75
+ rouletteMinMultiplier: zod_2.num,
76
+ blackjackMinMultiplier: zod_2.num,
77
+ diceMinMultiplier: zod_2.num,
78
+ coinflipMinMultiplier: zod_2.num
79
+ })
80
+ });
@@ -0,0 +1,146 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createCasinoBetService = createCasinoBetService;
4
+ function createCasinoBetService({ userModel, transactionModel }) {
5
+ async function refundLockedBet({ userId, guildId, amount, betId, game }) {
6
+ const session = await userModel.db.startSession();
7
+ try {
8
+ await session.withTransaction(async () => {
9
+ const user = await userModel
10
+ .findOne({ userId, guildId })
11
+ .session(session);
12
+ if (!user)
13
+ throw new Error('USER_NOT_FOUND');
14
+ if (user.lockedBalance < amount) {
15
+ return;
16
+ }
17
+ user.lockedBalance -= amount;
18
+ user.balance += amount;
19
+ await user.save({ session });
20
+ await transactionModel.create([
21
+ {
22
+ userId,
23
+ guildId,
24
+ amount,
25
+ type: 'refund',
26
+ source: 'casino',
27
+ betId,
28
+ meta: { game }
29
+ }
30
+ ], { session });
31
+ });
32
+ }
33
+ finally {
34
+ session.endSession();
35
+ }
36
+ }
37
+ async function settleCasinoWinnings({ userId, guildId, totalBet, winnings, betId, game }) {
38
+ const session = await userModel.db.startSession();
39
+ try {
40
+ let finalBalance = 0;
41
+ await session.withTransaction(async () => {
42
+ const user = await userModel
43
+ .findOne({ userId, guildId })
44
+ .session(session);
45
+ if (!user)
46
+ throw new Error('USER_NOT_FOUND');
47
+ if (user.lockedBalance < totalBet) {
48
+ finalBalance = user.balance + user.lockedBalance;
49
+ return;
50
+ }
51
+ user.lockedBalance -= totalBet;
52
+ if (winnings > 0) {
53
+ const winExists = await transactionModel
54
+ .exists({
55
+ betId,
56
+ type: 'win'
57
+ })
58
+ .session(session);
59
+ if (!winExists) {
60
+ user.balance += winnings;
61
+ await transactionModel.create([
62
+ {
63
+ userId,
64
+ guildId,
65
+ amount: winnings,
66
+ type: 'win',
67
+ source: 'casino',
68
+ betId,
69
+ meta: { game }
70
+ }
71
+ ], { session });
72
+ }
73
+ }
74
+ await user.save({ session });
75
+ finalBalance = user.balance + user.lockedBalance;
76
+ });
77
+ return finalBalance;
78
+ }
79
+ finally {
80
+ session.endSession();
81
+ }
82
+ }
83
+ // Raffle cancellation refunds go to normal balance even if bonus funds were used.
84
+ async function refundRafflePurchase({ userId, guildId, amount, raffleId, game }) {
85
+ const session = await userModel.db.startSession();
86
+ try {
87
+ await session.withTransaction(async () => {
88
+ const user = await userModel
89
+ .findOne({ userId, guildId })
90
+ .session(session);
91
+ if (!user)
92
+ throw new Error('USER_NOT_FOUND');
93
+ user.balance += amount;
94
+ await user.save({ session });
95
+ await transactionModel.create([
96
+ {
97
+ userId,
98
+ guildId,
99
+ amount,
100
+ type: 'refund',
101
+ source: 'casino',
102
+ betId: raffleId,
103
+ meta: { game }
104
+ }
105
+ ], { session });
106
+ });
107
+ }
108
+ finally {
109
+ session.endSession();
110
+ }
111
+ }
112
+ async function payRaffleWinner({ userId, guildId, amount, raffleId, game }) {
113
+ const session = await userModel.db.startSession();
114
+ try {
115
+ await session.withTransaction(async () => {
116
+ const user = await userModel
117
+ .findOne({ userId, guildId })
118
+ .session(session);
119
+ if (!user)
120
+ throw new Error('USER_NOT_FOUND');
121
+ user.balance += amount;
122
+ await user.save({ session });
123
+ await transactionModel.create([
124
+ {
125
+ userId,
126
+ guildId,
127
+ amount,
128
+ type: 'win',
129
+ source: 'casino',
130
+ betId: raffleId,
131
+ meta: { game }
132
+ }
133
+ ], { session });
134
+ });
135
+ }
136
+ finally {
137
+ session.endSession();
138
+ }
139
+ }
140
+ return {
141
+ refundLockedBet,
142
+ settleCasinoWinnings,
143
+ refundRafflePurchase,
144
+ payRaffleWinner
145
+ };
146
+ }
@@ -3,8 +3,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.calculateRTP = void 0;
4
4
  const constants_1 = require("../constants");
5
5
  const combination = (n, k) => {
6
- if (k > n)
7
- return 0;
8
6
  let result = 1;
9
7
  for (let i = 1; i <= k; i++) {
10
8
  result = (result * (n - i + 1)) / i;
@@ -97,9 +95,12 @@ const calculateRTP = (game, settings) => {
97
95
  const { winMultiplier, oneInChance } = settings;
98
96
  return (toNumber(winMultiplier) / toNumber(oneInChance)) * 100;
99
97
  }
98
+ case 'raffle': {
99
+ const { casinoCut } = settings;
100
+ return (1 - toNumber(casinoCut)) * 100;
101
+ }
100
102
  case 'blackjack':
101
103
  case 'prediction':
102
- case 'raffle':
103
104
  return 0;
104
105
  case 'plinko': {
105
106
  const { binMultipliers } = settings;
@@ -114,7 +115,9 @@ const calculateRTP = (game, settings) => {
114
115
  return rtp * 100;
115
116
  }
116
117
  default:
117
- console.warn(`RTP for ${game} not implemented`);
118
+ if (game !== 'winAnnouncements') {
119
+ console.warn(`RTP for ${game} not implemented`);
120
+ }
118
121
  return 0;
119
122
  }
120
123
  };
@@ -1,7 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getReadableName = exports.formatNumberToPercentage = exports.formatMoneyExact = exports.formatMoney = exports.formatNumberWithSpaces = exports.parseReadableStringToNumber = exports.formatNumberToReadableString = void 0;
4
- const globalSettings_1 = require("./globalSettings");
3
+ exports.formatTransactionTypeLabel = exports.formatTransactionSourceLabel = exports.formatCasinoGameLabel = exports.getReadableName = exports.formatNumberToPercentage = exports.formatMoneyExact = exports.formatMoney = exports.formatNumberWithSpaces = exports.parseReadableStringToNumber = exports.formatNumberToReadableString = void 0;
4
+ const defaultConfig_1 = require("../casino/constants/defaultConfig");
5
+ const globalSettings_1 = require("../guild/utils/globalSettings");
5
6
  const formatAmountWithCurrency = (amount, formattedAbsAmount, globalSettings) => {
6
7
  const negative = amount < 0;
7
8
  const sign = negative ? '-' : '';
@@ -68,3 +69,9 @@ const getReadableName = (key, map) => {
68
69
  return found ? found.name : key;
69
70
  };
70
71
  exports.getReadableName = getReadableName;
72
+ const formatCasinoGameLabel = (gameId) => (0, exports.getReadableName)(gameId, defaultConfig_1.readableGameNames).toUpperCase();
73
+ exports.formatCasinoGameLabel = formatCasinoGameLabel;
74
+ const formatTransactionSourceLabel = (source) => source.toUpperCase();
75
+ exports.formatTransactionSourceLabel = formatTransactionSourceLabel;
76
+ const formatTransactionTypeLabel = (type) => type.toUpperCase();
77
+ exports.formatTransactionTypeLabel = formatTransactionTypeLabel;
@@ -14,4 +14,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./mongoose"), exports);
17
+ __exportStar(require("./formatters"), exports);
18
+ __exportStar(require("./generateId"), exports);
19
+ __exportStar(require("./parseTimeToSeconds"), exports);
20
+ __exportStar(require("./zod"), exports);
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.num = void 0;
7
+ const zod_1 = __importDefault(require("zod"));
8
+ exports.num = zod_1.default
9
+ .union([zod_1.default.number(), zod_1.default.string()])
10
+ .transform((val) => {
11
+ if (val === '' || val === undefined || val === null)
12
+ return 0;
13
+ const parsed = typeof val === 'string' ? Number(val) : val;
14
+ return Number.isNaN(parsed) ? 0 : parsed;
15
+ })
16
+ .pipe(zod_1.default.number());
@@ -2,7 +2,8 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.GuildConfigurationSchema = void 0;
4
4
  const mongoose_1 = require("mongoose");
5
- const constants_1 = require("../constants");
5
+ const defaultConfig_1 = require("../casino/constants/defaultConfig");
6
+ const defaultGlobalSettings_1 = require("./constants/defaultGlobalSettings");
6
7
  exports.GuildConfigurationSchema = new mongoose_1.Schema({
7
8
  guildId: {
8
9
  type: String,
@@ -54,7 +55,7 @@ exports.GuildConfigurationSchema = new mongoose_1.Schema({
54
55
  },
55
56
  casinoSettings: {
56
57
  type: mongoose_1.Schema.Types.Mixed,
57
- default: constants_1.defaultCasinoSettings
58
+ default: defaultConfig_1.defaultCasinoSettings
58
59
  },
59
60
  vipSettings: {
60
61
  roleOwnerId: {
@@ -115,15 +116,15 @@ exports.GuildConfigurationSchema = new mongoose_1.Schema({
115
116
  disableDailyBonus: { type: Boolean, default: false },
116
117
  disableVip: { type: Boolean, default: false },
117
118
  maintenanceMode: { type: Boolean, default: false },
118
- timezone: { type: String, default: constants_1.defaultGlobalSettings.timezone },
119
+ timezone: { type: String, default: defaultGlobalSettings_1.defaultGlobalSettings.timezone },
119
120
  currencySymbol: {
120
121
  type: String,
121
- default: constants_1.defaultGlobalSettings.currencySymbol
122
+ default: defaultGlobalSettings_1.defaultGlobalSettings.currencySymbol
122
123
  },
123
124
  currencyPlacement: {
124
125
  type: String,
125
126
  enum: ['prefix', 'suffix'],
126
- default: constants_1.defaultGlobalSettings.currencyPlacement
127
+ default: defaultGlobalSettings_1.defaultGlobalSettings.currencyPlacement
127
128
  }
128
129
  }
129
130
  });
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ exports.GuildConfigurationSchema = void 0;
18
+ __exportStar(require("./constants/defaultGlobalSettings"), exports);
19
+ __exportStar(require("./constants/commonTimezones"), exports);
20
+ __exportStar(require("./types/guildConfiguration"), exports);
21
+ __exportStar(require("./utils/globalSettings"), exports);
22
+ __exportStar(require("./utils/normalizeGlobalSettings"), exports);
23
+ __exportStar(require("./utils/guildTimezone"), exports);
24
+ __exportStar(require("./schemas/guild.forms"), exports);
25
+ var guildConfiguration_mongoose_1 = require("./guildConfiguration.mongoose");
26
+ Object.defineProperty(exports, "GuildConfigurationSchema", { enumerable: true, get: function () { return guildConfiguration_mongoose_1.GuildConfigurationSchema; } });