gambling-bot-shared 0.1.18 → 0.1.20

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.
package/README.MD CHANGED
@@ -9,15 +9,18 @@ https://www.krouskystepan.com/projects/discord-gambling-hub
9
9
 
10
10
  The project is split into three repositories:
11
11
 
12
- - **Admin Panel**
13
- Web interface for managing data and configuration.
14
- 🔗 https://github.com/krouskystepan/gambling-bot-admin
12
+ - **Admin Panel**
15
13
 
16
- - **Discord Bot**
17
- Uses the shared data and logic to run the gambling system inside Discord.
18
- 🔗 https://github.com/krouskystepan/gambling-bot-discord
14
+ - Web interface for managing data and configuration.
15
+ - 🔗 https://github.com/krouskystepan/gambling-bot-admin
19
16
 
20
- - **Shared Package**
21
- Common types, database models, and business logic shared between the admin panel and the bot.
17
+ - **Discord Bot**
18
+
19
+ - Uses the shared data and logic to run the gambling system inside Discord.
20
+ - 🔗 https://github.com/krouskystepan/gambling-bot-discord
21
+
22
+ - **Shared Package (this repository)**
23
+
24
+ - Common types, database models, and business logic shared between the admin panel and the bot.
22
25
 
23
26
  All architecture decisions, data flow, and detailed explanations are documented in the case study linked above.
@@ -0,0 +1,13 @@
1
+ import type { RewardMode } from './guildConfiguration';
2
+ export type BonusSettings = {
3
+ rewardMode: RewardMode;
4
+ baseReward: number;
5
+ streakIncrement?: number;
6
+ streakMultiplier?: number;
7
+ maxReward: number;
8
+ resetOnMax: boolean;
9
+ milestoneBonus: {
10
+ weekly: number;
11
+ monthly: number;
12
+ };
13
+ };
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,4 +1,5 @@
1
1
  import { defaultCasinoSettings } from '../constants';
2
+ import { BonusSettings } from './bonus';
2
3
  export type RewardMode = 'linear' | 'exponential';
3
4
  export type TGuildConfiguration = {
4
5
  guildId: string;
@@ -22,16 +23,5 @@ export type TGuildConfiguration = {
22
23
  pricePerAdditionalMember: number;
23
24
  maxMembers: number;
24
25
  };
25
- bonusSettings: {
26
- rewardMode: RewardMode;
27
- baseReward: number;
28
- streakIncrement?: number;
29
- streakMultiplier?: number;
30
- maxReward: number;
31
- resetOnMax: boolean;
32
- milestoneBonus: {
33
- weekly: number;
34
- monthly: number;
35
- };
36
- };
26
+ bonusSettings: BonusSettings;
37
27
  };
@@ -5,3 +5,4 @@ export * from './vipRoom';
5
5
  export * from './prediction';
6
6
  export * from './transaction';
7
7
  export * from './guildConfiguration';
8
+ export * from './bonus';
@@ -19,3 +19,5 @@ __exportStar(require("./vipRoom"), exports);
19
19
  __exportStar(require("./prediction"), exports);
20
20
  __exportStar(require("./transaction"), exports);
21
21
  __exportStar(require("./guildConfiguration"), exports);
22
+ // No db
23
+ __exportStar(require("./bonus"), exports);
@@ -0,0 +1,13 @@
1
+ import type { BonusSettings } from '../types';
2
+ export type CalculateBonusRewardInput = {
3
+ streak: number;
4
+ settings: BonusSettings;
5
+ };
6
+ export type CalculateBonusRewardResult = {
7
+ reward: number;
8
+ base: number;
9
+ weekly: number;
10
+ monthly: number;
11
+ isReset: boolean;
12
+ };
13
+ export declare const calculateBonusReward: ({ streak, settings }: CalculateBonusRewardInput) => CalculateBonusRewardResult;
@@ -0,0 +1,42 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.calculateBonusReward = void 0;
4
+ const calculateBonusReward = ({ streak, settings }) => {
5
+ const { rewardMode, baseReward, streakIncrement = 0, streakMultiplier = 1, maxReward, resetOnMax, milestoneBonus } = settings;
6
+ let base = rewardMode === 'linear'
7
+ ? baseReward + (streak - 1) * streakIncrement
8
+ : baseReward * Math.pow(streakMultiplier, streak - 1);
9
+ let isReset = false;
10
+ if (maxReward > 0 && base > maxReward) {
11
+ if (resetOnMax) {
12
+ isReset = true;
13
+ if (rewardMode === 'linear') {
14
+ const cycle = streakIncrement > 0
15
+ ? Math.floor((maxReward - baseReward) / streakIncrement) + 1
16
+ : 1;
17
+ const newStreak = ((streak - 1) % cycle) + 1;
18
+ base = baseReward + (newStreak - 1) * streakIncrement;
19
+ }
20
+ else {
21
+ const cycle = streakMultiplier > 1
22
+ ? Math.floor(Math.log(maxReward / baseReward) / Math.log(streakMultiplier)) + 1
23
+ : 1;
24
+ const newStreak = ((streak - 1) % cycle) + 1;
25
+ base = baseReward * Math.pow(streakMultiplier, newStreak - 1);
26
+ }
27
+ }
28
+ else {
29
+ base = maxReward;
30
+ }
31
+ }
32
+ const weekly = streak % 7 === 0 ? milestoneBonus.weekly : 0;
33
+ const monthly = streak % 28 === 0 ? milestoneBonus.monthly : 0;
34
+ return {
35
+ base: Number(base.toFixed(2)),
36
+ weekly,
37
+ monthly,
38
+ reward: Number((base + weekly + monthly).toFixed(2)),
39
+ isReset
40
+ };
41
+ };
42
+ exports.calculateBonusReward = calculateBonusReward;
@@ -0,0 +1,11 @@
1
+ import type { BonusSettings } from '../types';
2
+ export declare const PREVIEW_DAYS = 60;
3
+ export type PreviewDay = {
4
+ day: number;
5
+ reward: number;
6
+ base: number;
7
+ weekly: number;
8
+ monthly: number;
9
+ isReset: boolean;
10
+ };
11
+ export declare const generateBonusPreview: (settings: BonusSettings, days?: number) => PreviewDay[];
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.generateBonusPreview = exports.PREVIEW_DAYS = void 0;
4
+ const calculateBonusReward_1 = require("./calculateBonusReward");
5
+ exports.PREVIEW_DAYS = 60;
6
+ const generateBonusPreview = (settings, days = exports.PREVIEW_DAYS) => {
7
+ const result = [];
8
+ for (let day = 1; day <= days; day++) {
9
+ const r = (0, calculateBonusReward_1.calculateBonusReward)({
10
+ streak: day,
11
+ settings
12
+ });
13
+ result.push({
14
+ day,
15
+ reward: r.reward,
16
+ base: r.base,
17
+ weekly: r.weekly,
18
+ monthly: r.monthly,
19
+ isReset: r.isReset
20
+ });
21
+ }
22
+ return result;
23
+ };
24
+ exports.generateBonusPreview = generateBonusPreview;
@@ -1 +1,3 @@
1
1
  export * from './calculateRTP';
2
+ export * from './calculateBonusReward';
3
+ export * from './generateBonusPreview';
@@ -15,3 +15,5 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./calculateRTP"), exports);
18
+ __exportStar(require("./calculateBonusReward"), exports);
19
+ __exportStar(require("./generateBonusPreview"), exports);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gambling-bot-shared",
3
- "version": "0.1.18",
3
+ "version": "0.1.20",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "license": "MIT",