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.
- package/README.MD +4 -0
- package/dist/{mongoose/atmRequest.schema.js → atm/atmRequest.mongoose.js} +4 -1
- package/dist/{types → atm}/index.js +5 -10
- package/dist/atm/schemas/atm.forms.js +11 -0
- package/dist/blackjack/index.js +21 -0
- package/dist/bonus/index.js +23 -0
- package/dist/bonus/schemas/bonus.forms.js +39 -0
- package/dist/{utils → bonus/utils}/bonusStreak.js +10 -1
- package/dist/{utils → bonus/utils}/calculateBonusReward.js +4 -3
- package/dist/casino/constants/casinoGames.js +5 -0
- package/dist/{constants → casino/constants}/index.js +4 -8
- package/dist/{constants → casino/constants}/plinkoConfig.js +1 -1
- package/dist/casino/index.js +30 -0
- package/dist/casino/schemas/casino.forms.js +80 -0
- package/dist/casino/services/casinoBet.service.js +146 -0
- package/dist/{utils → casino/utils}/calculateRTP.js +7 -4
- package/dist/{utils → common}/formatters.js +9 -2
- package/dist/{server.js → common/index.js} +4 -1
- package/dist/common/zod.js +16 -0
- package/dist/{mongoose/guildConfiguration.schema.js → guild/guildConfiguration.mongoose.js} +6 -5
- package/dist/guild/index.js +26 -0
- package/dist/guild/schemas/guild.forms.js +43 -0
- package/dist/guild/utils/normalizeGlobalSettings.js +46 -0
- package/dist/mongoose/index.js +17 -22
- package/dist/predictions/index.js +29 -0
- package/dist/{mongoose/prediction.schema.js → predictions/prediction.mongoose.js} +3 -2
- package/dist/predictions/schemas/prediction.forms.js +24 -0
- package/dist/predictions/services/normalizePredictionInput.js +53 -0
- package/dist/predictions/services/parsePredictionAutolock.js +20 -0
- package/dist/predictions/services/parsePredictionChoices.js +26 -0
- package/dist/predictions/services/prediction.db.js +72 -0
- package/dist/predictions/services/predictionLifecycle.service.js +133 -0
- package/dist/predictions/services/predictionSummary.js +58 -0
- package/dist/raffle/index.js +24 -0
- package/dist/raffle/schemas/raffle.forms.js +17 -0
- package/dist/raffle/services/raffle.db.js +153 -0
- package/dist/raffle/services/raffleLifecycle.service.js +34 -0
- package/dist/{schemas → transactions/constants}/index.js +2 -1
- package/dist/{index.js → transactions/index.js} +3 -2
- package/dist/transactions/types/transaction.js +2 -0
- package/dist/user/index.js +20 -0
- package/dist/user/types/user.js +2 -0
- package/dist/vip/index.js +21 -0
- package/dist/vip/schemas/vip.forms.js +16 -0
- package/dist/vip/types/vipRoom.js +2 -0
- package/package.json +67 -27
- package/dist/constants/blackjack.d.ts +0 -41
- package/dist/constants/bonusLimits.d.ts +0 -4
- package/dist/constants/commonTimezones.d.ts +0 -4
- package/dist/constants/defaultConfig.d.ts +0 -108
- package/dist/constants/defaultGlobalSettings.d.ts +0 -20
- package/dist/constants/gameRecordFields.d.ts +0 -8
- package/dist/constants/index.d.ts +0 -11
- package/dist/constants/lotteryConfig.d.ts +0 -2
- package/dist/constants/maxSimulations.d.ts +0 -5
- package/dist/constants/plinkoConfig.d.ts +0 -15
- package/dist/constants/rouletteConfig.d.ts +0 -1
- package/dist/constants/transaction.d.ts +0 -2
- package/dist/index.d.ts +0 -3
- package/dist/mongoose/atmRequest.schema.d.ts +0 -139
- package/dist/mongoose/blackjackGame.schema.d.ts +0 -139
- package/dist/mongoose/guildConfiguration.schema.d.ts +0 -237
- package/dist/mongoose/index.d.ts +0 -8
- package/dist/mongoose/prediction.schema.d.ts +0 -112
- package/dist/mongoose/raffle.schema.d.ts +0 -151
- package/dist/mongoose/transaction.schema.d.ts +0 -103
- package/dist/mongoose/user.schema.d.ts +0 -103
- package/dist/mongoose/vipRoom.schema.d.ts +0 -85
- package/dist/schemas/forms.d.ts +0 -183
- package/dist/schemas/forms.js +0 -173
- package/dist/schemas/index.d.ts +0 -1
- package/dist/server.d.ts +0 -1
- package/dist/types/atmRequest.d.ts +0 -15
- package/dist/types/blackjackGame.d.ts +0 -30
- package/dist/types/bonus.d.ts +0 -13
- package/dist/types/guildConfiguration.d.ts +0 -35
- package/dist/types/index.d.ts +0 -11
- package/dist/types/prediction.d.ts +0 -20
- package/dist/types/raffle.d.ts +0 -19
- package/dist/types/transaction.d.ts +0 -11
- package/dist/types/user.d.ts +0 -11
- package/dist/types/vipRoom.d.ts +0 -9
- package/dist/utils/bonusStreak.d.ts +0 -6
- package/dist/utils/calculateBonusReward.d.ts +0 -13
- package/dist/utils/calculateRTP.d.ts +0 -2
- package/dist/utils/formatters.d.ts +0 -13
- package/dist/utils/generateBonusPreview.d.ts +0 -11
- package/dist/utils/generateId.d.ts +0 -1
- package/dist/utils/globalSettings.d.ts +0 -6
- package/dist/utils/guildTimezone.d.ts +0 -6
- package/dist/utils/index.d.ts +0 -15
- package/dist/utils/index.js +0 -31
- package/dist/utils/normalizeBonusSettings.d.ts +0 -6
- package/dist/utils/normalizeCasinoSettings.d.ts +0 -2
- package/dist/utils/normalizeGlobalSettings.d.ts +0 -2
- package/dist/utils/normalizeGlobalSettings.js +0 -45
- package/dist/utils/parseTimeToSeconds.d.ts +0 -1
- package/dist/utils/validateBetAmount.d.ts +0 -8
- package/dist/utils/validatePredictionBet.d.ts +0 -13
- package/dist/utils/winAnnouncements.d.ts +0 -4
- /package/dist/{types → atm/types}/atmRequest.js +0 -0
- /package/dist/{constants → bonus/constants}/bonusLimits.js +0 -0
- /package/dist/{types → bonus/types}/bonus.js +0 -0
- /package/dist/{utils → bonus/utils}/generateBonusPreview.js +0 -0
- /package/dist/{utils → bonus/utils}/normalizeBonusSettings.js +0 -0
- /package/dist/{mongoose/blackjackGame.schema.js → casino/blackjackGame.mongoose.js} +0 -0
- /package/dist/{constants → casino/constants}/blackjack.js +0 -0
- /package/dist/{constants → casino/constants}/defaultConfig.js +0 -0
- /package/dist/{constants → casino/constants}/lotteryConfig.js +0 -0
- /package/dist/{constants → casino/constants}/maxSimulations.js +0 -0
- /package/dist/{constants → casino/constants}/rouletteConfig.js +0 -0
- /package/dist/{types → casino/types}/blackjackGame.js +0 -0
- /package/dist/{types/guildConfiguration.js → casino/types/casinoSettings.js} +0 -0
- /package/dist/{utils → casino/utils}/normalizeCasinoSettings.js +0 -0
- /package/dist/{utils → casino/utils}/validateBetAmount.js +0 -0
- /package/dist/{utils → casino/utils}/winAnnouncements.js +0 -0
- /package/dist/{utils → common}/generateId.js +0 -0
- /package/dist/{utils → common}/parseTimeToSeconds.js +0 -0
- /package/dist/{constants → guild/constants}/commonTimezones.js +0 -0
- /package/dist/{constants → guild/constants}/defaultGlobalSettings.js +0 -0
- /package/dist/{types/prediction.js → guild/types/guildConfiguration.js} +0 -0
- /package/dist/{utils → guild/utils}/globalSettings.js +0 -0
- /package/dist/{utils → guild/utils}/guildTimezone.js +0 -0
- /package/dist/{types/raffle.js → predictions/services/types.js} +0 -0
- /package/dist/{types/transaction.js → predictions/types/prediction.js} +0 -0
- /package/dist/{utils → predictions/utils}/validatePredictionBet.js +0 -0
- /package/dist/{mongoose/raffle.schema.js → raffle/raffle.mongoose.js} +0 -0
- /package/dist/{types/user.js → raffle/services/types.js} +0 -0
- /package/dist/{types/vipRoom.js → raffle/types/raffle.js} +0 -0
- /package/dist/{constants → transactions/constants}/gameRecordFields.js +0 -0
- /package/dist/{constants → transactions/constants}/transaction.js +0 -0
- /package/dist/{mongoose/transaction.schema.js → transactions/transaction.mongoose.js} +0 -0
- /package/dist/{mongoose/user.schema.js → user/user.mongoose.js} +0 -0
- /package/dist/{mongoose/vipRoom.schema.js → vip/vipRoom.mongoose.js} +0 -0
|
@@ -0,0 +1,43 @@
|
|
|
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.globalSettingsFormSchema = exports.managerRoleFormSchema = exports.channelsFormSchema = void 0;
|
|
7
|
+
const zod_1 = __importDefault(require("zod"));
|
|
8
|
+
const atm_forms_1 = require("../../atm/schemas/atm.forms");
|
|
9
|
+
const casino_forms_1 = require("../../casino/schemas/casino.forms");
|
|
10
|
+
const prediction_forms_1 = require("../../predictions/schemas/prediction.forms");
|
|
11
|
+
const raffle_forms_1 = require("../../raffle/schemas/raffle.forms");
|
|
12
|
+
const commonTimezones_1 = require("../constants/commonTimezones");
|
|
13
|
+
exports.channelsFormSchema = zod_1.default.object({
|
|
14
|
+
atm: atm_forms_1.atmChannelsFormSchema,
|
|
15
|
+
casino: casino_forms_1.casinoChannelsFormSchema,
|
|
16
|
+
prediction: prediction_forms_1.predictionChannelsFormSchema,
|
|
17
|
+
raffle: raffle_forms_1.raffleChannelsFormSchema
|
|
18
|
+
});
|
|
19
|
+
exports.managerRoleFormSchema = zod_1.default.object({
|
|
20
|
+
managerRoleId: zod_1.default.string()
|
|
21
|
+
});
|
|
22
|
+
exports.globalSettingsFormSchema = zod_1.default.object({
|
|
23
|
+
disableRegistrations: zod_1.default.boolean(),
|
|
24
|
+
disableDeposits: zod_1.default.boolean(),
|
|
25
|
+
disableWithdrawals: zod_1.default.boolean(),
|
|
26
|
+
disableCasinoGames: zod_1.default.boolean(),
|
|
27
|
+
disableCasinoGamesForMods: zod_1.default.boolean(),
|
|
28
|
+
disablePredictions: zod_1.default.boolean(),
|
|
29
|
+
disablePredictionManagement: zod_1.default.boolean(),
|
|
30
|
+
disableRaffles: zod_1.default.boolean(),
|
|
31
|
+
disableRaffleManagement: zod_1.default.boolean(),
|
|
32
|
+
disableDailyBonus: zod_1.default.boolean(),
|
|
33
|
+
disableVip: zod_1.default.boolean(),
|
|
34
|
+
maintenanceMode: zod_1.default.boolean(),
|
|
35
|
+
timezone: zod_1.default.enum(commonTimezones_1.COMMON_TIMEZONES),
|
|
36
|
+
currencySymbol: zod_1.default
|
|
37
|
+
.string()
|
|
38
|
+
.max(8)
|
|
39
|
+
.refine((value) => value.trim().length > 0, {
|
|
40
|
+
message: 'Currency symbol is required'
|
|
41
|
+
}),
|
|
42
|
+
currencyPlacement: zod_1.default.enum(['prefix', 'suffix'])
|
|
43
|
+
});
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.normalizeGlobalSettings = void 0;
|
|
4
|
+
const commonTimezones_1 = require("../constants/commonTimezones");
|
|
5
|
+
const defaultGlobalSettings_1 = require("../constants/defaultGlobalSettings");
|
|
6
|
+
const coerceBool = (value, fallback) => {
|
|
7
|
+
if (typeof value === 'boolean')
|
|
8
|
+
return value;
|
|
9
|
+
if (value === 'true')
|
|
10
|
+
return true;
|
|
11
|
+
if (value === 'false')
|
|
12
|
+
return false;
|
|
13
|
+
return fallback;
|
|
14
|
+
};
|
|
15
|
+
const normalizeCurrencySymbol = (value) => {
|
|
16
|
+
if (typeof value !== 'string' || value.trim().length === 0) {
|
|
17
|
+
return defaultGlobalSettings_1.defaultGlobalSettings.currencySymbol;
|
|
18
|
+
}
|
|
19
|
+
return value.slice(0, 8);
|
|
20
|
+
};
|
|
21
|
+
const normalizeCurrencyPlacement = (value) => value === 'suffix' ? 'suffix' : 'prefix';
|
|
22
|
+
const normalizeTimezone = (value) => {
|
|
23
|
+
const raw = typeof value === 'string' ? value.trim() : '';
|
|
24
|
+
if (raw.length > 0 && commonTimezones_1.COMMON_TIMEZONES.includes(raw)) {
|
|
25
|
+
return raw;
|
|
26
|
+
}
|
|
27
|
+
return defaultGlobalSettings_1.defaultGlobalSettings.timezone;
|
|
28
|
+
};
|
|
29
|
+
const normalizeGlobalSettings = (settings) => ({
|
|
30
|
+
disableRegistrations: coerceBool(settings?.disableRegistrations, defaultGlobalSettings_1.defaultGlobalSettings.disableRegistrations),
|
|
31
|
+
disableDeposits: coerceBool(settings?.disableDeposits, defaultGlobalSettings_1.defaultGlobalSettings.disableDeposits),
|
|
32
|
+
disableWithdrawals: coerceBool(settings?.disableWithdrawals, defaultGlobalSettings_1.defaultGlobalSettings.disableWithdrawals),
|
|
33
|
+
disableCasinoGames: coerceBool(settings?.disableCasinoGames, defaultGlobalSettings_1.defaultGlobalSettings.disableCasinoGames),
|
|
34
|
+
disableCasinoGamesForMods: coerceBool(settings?.disableCasinoGamesForMods, defaultGlobalSettings_1.defaultGlobalSettings.disableCasinoGamesForMods),
|
|
35
|
+
disablePredictions: coerceBool(settings?.disablePredictions, defaultGlobalSettings_1.defaultGlobalSettings.disablePredictions),
|
|
36
|
+
disablePredictionManagement: coerceBool(settings?.disablePredictionManagement, defaultGlobalSettings_1.defaultGlobalSettings.disablePredictionManagement),
|
|
37
|
+
disableRaffles: coerceBool(settings?.disableRaffles, defaultGlobalSettings_1.defaultGlobalSettings.disableRaffles),
|
|
38
|
+
disableRaffleManagement: coerceBool(settings?.disableRaffleManagement, defaultGlobalSettings_1.defaultGlobalSettings.disableRaffleManagement),
|
|
39
|
+
disableDailyBonus: coerceBool(settings?.disableDailyBonus, defaultGlobalSettings_1.defaultGlobalSettings.disableDailyBonus),
|
|
40
|
+
disableVip: coerceBool(settings?.disableVip, defaultGlobalSettings_1.defaultGlobalSettings.disableVip),
|
|
41
|
+
maintenanceMode: coerceBool(settings?.maintenanceMode, defaultGlobalSettings_1.defaultGlobalSettings.maintenanceMode),
|
|
42
|
+
timezone: normalizeTimezone(settings?.timezone),
|
|
43
|
+
currencySymbol: normalizeCurrencySymbol(settings?.currencySymbol),
|
|
44
|
+
currencyPlacement: normalizeCurrencyPlacement(settings?.currencyPlacement)
|
|
45
|
+
});
|
|
46
|
+
exports.normalizeGlobalSettings = normalizeGlobalSettings;
|
package/dist/mongoose/index.js
CHANGED
|
@@ -1,24 +1,19 @@
|
|
|
1
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
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
3
|
+
exports.BlackjackGameSchema = exports.RaffleSchema = exports.AtmRequestSchema = exports.GuildConfigurationSchema = exports.TransactionSchema = exports.PredictionSchema = exports.VipRoomSchema = exports.UserSchema = void 0;
|
|
4
|
+
var user_mongoose_1 = require("../user/user.mongoose");
|
|
5
|
+
Object.defineProperty(exports, "UserSchema", { enumerable: true, get: function () { return user_mongoose_1.UserSchema; } });
|
|
6
|
+
var vipRoom_mongoose_1 = require("../vip/vipRoom.mongoose");
|
|
7
|
+
Object.defineProperty(exports, "VipRoomSchema", { enumerable: true, get: function () { return vipRoom_mongoose_1.VipRoomSchema; } });
|
|
8
|
+
var prediction_mongoose_1 = require("../predictions/prediction.mongoose");
|
|
9
|
+
Object.defineProperty(exports, "PredictionSchema", { enumerable: true, get: function () { return prediction_mongoose_1.PredictionSchema; } });
|
|
10
|
+
var transaction_mongoose_1 = require("../transactions/transaction.mongoose");
|
|
11
|
+
Object.defineProperty(exports, "TransactionSchema", { enumerable: true, get: function () { return transaction_mongoose_1.TransactionSchema; } });
|
|
12
|
+
var guildConfiguration_mongoose_1 = require("../guild/guildConfiguration.mongoose");
|
|
13
|
+
Object.defineProperty(exports, "GuildConfigurationSchema", { enumerable: true, get: function () { return guildConfiguration_mongoose_1.GuildConfigurationSchema; } });
|
|
14
|
+
var atmRequest_mongoose_1 = require("../atm/atmRequest.mongoose");
|
|
15
|
+
Object.defineProperty(exports, "AtmRequestSchema", { enumerable: true, get: function () { return atmRequest_mongoose_1.AtmRequestSchema; } });
|
|
16
|
+
var raffle_mongoose_1 = require("../raffle/raffle.mongoose");
|
|
17
|
+
Object.defineProperty(exports, "RaffleSchema", { enumerable: true, get: function () { return raffle_mongoose_1.RaffleSchema; } });
|
|
18
|
+
var blackjackGame_mongoose_1 = require("../casino/blackjackGame.mongoose");
|
|
19
|
+
Object.defineProperty(exports, "BlackjackGameSchema", { enumerable: true, get: function () { return blackjackGame_mongoose_1.BlackjackGameSchema; } });
|
|
@@ -0,0 +1,29 @@
|
|
|
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.PredictionSchema = void 0;
|
|
18
|
+
__exportStar(require("./types/prediction"), exports);
|
|
19
|
+
__exportStar(require("./utils/validatePredictionBet"), exports);
|
|
20
|
+
__exportStar(require("./services/types"), exports);
|
|
21
|
+
__exportStar(require("./services/parsePredictionChoices"), exports);
|
|
22
|
+
__exportStar(require("./services/parsePredictionAutolock"), exports);
|
|
23
|
+
__exportStar(require("./services/normalizePredictionInput"), exports);
|
|
24
|
+
__exportStar(require("./services/predictionSummary"), exports);
|
|
25
|
+
__exportStar(require("./services/prediction.db"), exports);
|
|
26
|
+
__exportStar(require("./services/predictionLifecycle.service"), exports);
|
|
27
|
+
__exportStar(require("./schemas/prediction.forms"), exports);
|
|
28
|
+
var prediction_mongoose_1 = require("./prediction.mongoose");
|
|
29
|
+
Object.defineProperty(exports, "PredictionSchema", { enumerable: true, get: function () { return prediction_mongoose_1.PredictionSchema; } });
|
|
@@ -30,14 +30,15 @@ exports.PredictionSchema = new mongoose_1.Schema({
|
|
|
30
30
|
bets: [
|
|
31
31
|
{
|
|
32
32
|
userId: { type: String, required: true },
|
|
33
|
-
amount: { type: Number, required: true }
|
|
33
|
+
amount: { type: Number, required: true },
|
|
34
|
+
betId: { type: String, required: true }
|
|
34
35
|
}
|
|
35
36
|
]
|
|
36
37
|
}
|
|
37
38
|
],
|
|
38
39
|
status: {
|
|
39
40
|
type: String,
|
|
40
|
-
enum: ['active', 'ended', 'paid', 'canceled'],
|
|
41
|
+
enum: ['active', 'ended', 'paying', 'paid', 'canceled'],
|
|
41
42
|
default: 'active'
|
|
42
43
|
},
|
|
43
44
|
autolock: {
|
|
@@ -0,0 +1,24 @@
|
|
|
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.payoutPredictionFormSchema = exports.createPredictionFormSchema = exports.predictionChoiceSchema = exports.predictionChannelsFormSchema = void 0;
|
|
7
|
+
const zod_1 = __importDefault(require("zod"));
|
|
8
|
+
const zod_2 = require("../../common/zod");
|
|
9
|
+
exports.predictionChannelsFormSchema = zod_1.default.object({
|
|
10
|
+
actions: zod_1.default.string(),
|
|
11
|
+
logs: zod_1.default.string()
|
|
12
|
+
});
|
|
13
|
+
exports.predictionChoiceSchema = zod_1.default.object({
|
|
14
|
+
choiceName: zod_1.default.string().min(1),
|
|
15
|
+
odds: zod_2.num.pipe(zod_1.default.number().positive())
|
|
16
|
+
});
|
|
17
|
+
exports.createPredictionFormSchema = zod_1.default.object({
|
|
18
|
+
title: zod_1.default.string().min(1).max(256),
|
|
19
|
+
choices: zod_1.default.array(exports.predictionChoiceSchema).min(2).max(3),
|
|
20
|
+
autolock: zod_1.default.string().optional()
|
|
21
|
+
});
|
|
22
|
+
exports.payoutPredictionFormSchema = zod_1.default.object({
|
|
23
|
+
winnerChoice: zod_1.default.string().min(1)
|
|
24
|
+
});
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.normalizePredictionChoices = normalizePredictionChoices;
|
|
4
|
+
exports.normalizePredictionAutolock = normalizePredictionAutolock;
|
|
5
|
+
const luxon_1 = require("luxon");
|
|
6
|
+
const parsePredictionAutolock_1 = require("./parsePredictionAutolock");
|
|
7
|
+
const parsePredictionChoices_1 = require("./parsePredictionChoices");
|
|
8
|
+
function normalizePredictionChoices(input) {
|
|
9
|
+
if (typeof input === 'string') {
|
|
10
|
+
return (0, parsePredictionChoices_1.parsePredictionChoices)(input);
|
|
11
|
+
}
|
|
12
|
+
if (input.length < 2 || input.length > 3) {
|
|
13
|
+
return { ok: false, error: 'INVALID_COUNT' };
|
|
14
|
+
}
|
|
15
|
+
for (const choice of input) {
|
|
16
|
+
if (!choice.choiceName?.trim() ||
|
|
17
|
+
typeof choice.odds !== 'number' ||
|
|
18
|
+
Number.isNaN(choice.odds) ||
|
|
19
|
+
choice.odds <= 0) {
|
|
20
|
+
return {
|
|
21
|
+
ok: false,
|
|
22
|
+
error: 'INVALID_FORMAT',
|
|
23
|
+
detail: choice.choiceName
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
return {
|
|
28
|
+
ok: true,
|
|
29
|
+
choices: input.map((choice) => ({
|
|
30
|
+
choiceName: choice.choiceName.trim(),
|
|
31
|
+
odds: choice.odds,
|
|
32
|
+
bets: []
|
|
33
|
+
}))
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
function normalizePredictionAutolock(input, format) {
|
|
37
|
+
if (format === 'discord') {
|
|
38
|
+
return (0, parsePredictionAutolock_1.parsePredictionAutolock)(input);
|
|
39
|
+
}
|
|
40
|
+
const trimmed = input.trim();
|
|
41
|
+
if (!trimmed) {
|
|
42
|
+
return { ok: false, error: 'INVALID_FORMAT' };
|
|
43
|
+
}
|
|
44
|
+
const parsed = luxon_1.DateTime.fromISO(trimmed, { zone: 'utc' });
|
|
45
|
+
if (!parsed.isValid) {
|
|
46
|
+
return { ok: false, error: 'INVALID_DATE' };
|
|
47
|
+
}
|
|
48
|
+
const autolock = parsed.toJSDate();
|
|
49
|
+
if (autolock.getTime() <= Date.now()) {
|
|
50
|
+
return { ok: false, error: 'PAST_DATE' };
|
|
51
|
+
}
|
|
52
|
+
return { ok: true, autolock };
|
|
53
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.parsePredictionAutolock = parsePredictionAutolock;
|
|
4
|
+
const luxon_1 = require("luxon");
|
|
5
|
+
const AUTOLOCK_REGEX = /^(\d{1,2})\.(\d{1,2})\.(\d{4}) (\d{2}):(\d{2})$/;
|
|
6
|
+
function parsePredictionAutolock(input, timezone = 'Europe/Prague') {
|
|
7
|
+
const match = input.match(AUTOLOCK_REGEX);
|
|
8
|
+
if (!match) {
|
|
9
|
+
return { ok: false, error: 'INVALID_FORMAT' };
|
|
10
|
+
}
|
|
11
|
+
const [, day, month, year, hour, minute] = match.map(Number);
|
|
12
|
+
const dt = luxon_1.DateTime.fromObject({ year, month, day, hour, minute }, { zone: timezone });
|
|
13
|
+
if (!dt.isValid) {
|
|
14
|
+
return { ok: false, error: 'INVALID_DATE' };
|
|
15
|
+
}
|
|
16
|
+
if (dt.toMillis() <= Date.now()) {
|
|
17
|
+
return { ok: false, error: 'PAST_DATE' };
|
|
18
|
+
}
|
|
19
|
+
return { ok: true, autolock: dt.toJSDate() };
|
|
20
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.parsePredictionChoices = parsePredictionChoices;
|
|
4
|
+
function parsePredictionChoices(input) {
|
|
5
|
+
const rawChoices = input.split(',').map((c) => c.trim());
|
|
6
|
+
if (rawChoices.length < 2 || rawChoices.length > 3) {
|
|
7
|
+
return { ok: false, error: 'INVALID_COUNT' };
|
|
8
|
+
}
|
|
9
|
+
const choicesArray = [];
|
|
10
|
+
for (const item of rawChoices) {
|
|
11
|
+
const [name, odds] = item.split(':').map((x) => x.trim());
|
|
12
|
+
if (!name || !odds || Number.isNaN(Number(odds))) {
|
|
13
|
+
return {
|
|
14
|
+
ok: false,
|
|
15
|
+
error: 'INVALID_FORMAT',
|
|
16
|
+
detail: item
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
choicesArray.push({
|
|
20
|
+
choiceName: name,
|
|
21
|
+
odds: Number(odds),
|
|
22
|
+
bets: []
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
return { ok: true, choices: choicesArray };
|
|
26
|
+
}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createPredictionDb = createPredictionDb;
|
|
4
|
+
function createPredictionDb(predictionModel) {
|
|
5
|
+
const getPredictionById = async ({ predictionId, guildId }) => {
|
|
6
|
+
return predictionModel.findOne({ predictionId, guildId });
|
|
7
|
+
};
|
|
8
|
+
const getPredictionToLock = async ({ status = 'active', useAutolock = true }) => {
|
|
9
|
+
const now = new Date();
|
|
10
|
+
return predictionModel.find({
|
|
11
|
+
status,
|
|
12
|
+
...(useAutolock ? { autolock: { $lte: now } } : {})
|
|
13
|
+
});
|
|
14
|
+
};
|
|
15
|
+
const getOldPredictions = async ({ statuses, olderThanDays }) => {
|
|
16
|
+
const cutoffDate = new Date(Date.now() - olderThanDays * 24 * 60 * 60 * 1000);
|
|
17
|
+
return predictionModel.find({
|
|
18
|
+
status: { $in: statuses },
|
|
19
|
+
updatedAt: { $lte: cutoffDate }
|
|
20
|
+
});
|
|
21
|
+
};
|
|
22
|
+
const createPrediction = async ({ predictionId, guildId, channelId, creatorId, title, choices, autolock, status }) => {
|
|
23
|
+
await predictionModel.create({
|
|
24
|
+
predictionId,
|
|
25
|
+
guildId,
|
|
26
|
+
channelId,
|
|
27
|
+
creatorId,
|
|
28
|
+
title,
|
|
29
|
+
choices,
|
|
30
|
+
autolock,
|
|
31
|
+
status
|
|
32
|
+
});
|
|
33
|
+
};
|
|
34
|
+
const updatePredictionStatus = async ({ predictionId, guildId, fromStatus, toStatus }) => {
|
|
35
|
+
return predictionModel.findOneAndUpdate({
|
|
36
|
+
predictionId,
|
|
37
|
+
guildId,
|
|
38
|
+
status: Array.isArray(fromStatus) ? { $in: fromStatus } : fromStatus
|
|
39
|
+
}, { $set: { status: toStatus } }, { returnDocument: 'after' });
|
|
40
|
+
};
|
|
41
|
+
const deletePrediction = async ({ predictionId }) => {
|
|
42
|
+
await predictionModel.deleteOne({ predictionId });
|
|
43
|
+
};
|
|
44
|
+
const findPredictions = async (query) => {
|
|
45
|
+
return predictionModel.find(query).limit(25);
|
|
46
|
+
};
|
|
47
|
+
const addPredictionBet = async ({ predictionId, guildId, choiceName, userId, amount, betId }) => {
|
|
48
|
+
return predictionModel.findOneAndUpdate({
|
|
49
|
+
predictionId,
|
|
50
|
+
guildId,
|
|
51
|
+
'choices.choiceName': choiceName
|
|
52
|
+
}, {
|
|
53
|
+
$push: {
|
|
54
|
+
'choices.$.bets': {
|
|
55
|
+
userId,
|
|
56
|
+
amount,
|
|
57
|
+
betId
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
};
|
|
62
|
+
return {
|
|
63
|
+
getPredictionById,
|
|
64
|
+
getPredictionToLock,
|
|
65
|
+
getOldPredictions,
|
|
66
|
+
createPrediction,
|
|
67
|
+
updatePredictionStatus,
|
|
68
|
+
deletePrediction,
|
|
69
|
+
findPredictions,
|
|
70
|
+
addPredictionBet
|
|
71
|
+
};
|
|
72
|
+
}
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createPredictionLifecycleService = createPredictionLifecycleService;
|
|
4
|
+
const predictionSummary_1 = require("./predictionSummary");
|
|
5
|
+
function createPredictionLifecycleService({ predictionDb, casinoBet }) {
|
|
6
|
+
const { getPredictionById, updatePredictionStatus } = predictionDb;
|
|
7
|
+
const { refundLockedBet, settleCasinoWinnings } = casinoBet;
|
|
8
|
+
const finalizePaid = async (predictionId, guildId) => {
|
|
9
|
+
const paid = await updatePredictionStatus({
|
|
10
|
+
predictionId,
|
|
11
|
+
guildId,
|
|
12
|
+
fromStatus: 'paying',
|
|
13
|
+
toStatus: 'paid'
|
|
14
|
+
});
|
|
15
|
+
if (!paid)
|
|
16
|
+
throw new Error('FINALIZE_FAILED');
|
|
17
|
+
return paid;
|
|
18
|
+
};
|
|
19
|
+
const rollbackPaying = async (predictionId, guildId) => {
|
|
20
|
+
await updatePredictionStatus({
|
|
21
|
+
predictionId,
|
|
22
|
+
guildId,
|
|
23
|
+
fromStatus: 'paying',
|
|
24
|
+
toStatus: 'ended'
|
|
25
|
+
});
|
|
26
|
+
};
|
|
27
|
+
const endPrediction = async ({ predictionId, guildId }) => {
|
|
28
|
+
return updatePredictionStatus({
|
|
29
|
+
predictionId,
|
|
30
|
+
guildId,
|
|
31
|
+
fromStatus: 'active',
|
|
32
|
+
toStatus: 'ended'
|
|
33
|
+
});
|
|
34
|
+
};
|
|
35
|
+
const cancelPrediction = async ({ predictionId, guildId }) => {
|
|
36
|
+
const updatedPrediction = await updatePredictionStatus({
|
|
37
|
+
predictionId,
|
|
38
|
+
guildId,
|
|
39
|
+
fromStatus: ['active', 'ended'],
|
|
40
|
+
toStatus: 'canceled'
|
|
41
|
+
});
|
|
42
|
+
if (!updatedPrediction)
|
|
43
|
+
return null;
|
|
44
|
+
const allBets = updatedPrediction.choices.flatMap((c) => c.bets);
|
|
45
|
+
for (const bet of allBets) {
|
|
46
|
+
await refundLockedBet({
|
|
47
|
+
userId: bet.userId,
|
|
48
|
+
guildId,
|
|
49
|
+
amount: bet.amount,
|
|
50
|
+
betId: (0, predictionSummary_1.resolvePredictionBetId)(bet, predictionId),
|
|
51
|
+
game: 'prediction'
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
return updatedPrediction;
|
|
55
|
+
};
|
|
56
|
+
const payoutPrediction = async ({ predictionId, guildId, winnerChoice }) => {
|
|
57
|
+
const prediction = await getPredictionById({ predictionId, guildId });
|
|
58
|
+
if (!prediction)
|
|
59
|
+
return { ok: false, code: 'NOT_FOUND' };
|
|
60
|
+
if (prediction.status !== 'ended') {
|
|
61
|
+
if (prediction.status === 'paid' || prediction.status === 'paying') {
|
|
62
|
+
return { ok: false, code: 'ALREADY_HANDLED' };
|
|
63
|
+
}
|
|
64
|
+
return { ok: false, code: 'INVALID_STATUS' };
|
|
65
|
+
}
|
|
66
|
+
const winner = prediction.choices.find((c) => c.choiceName === winnerChoice);
|
|
67
|
+
if (!winner)
|
|
68
|
+
return { ok: false, code: 'INVALID_WINNER' };
|
|
69
|
+
const locked = await updatePredictionStatus({
|
|
70
|
+
predictionId,
|
|
71
|
+
guildId,
|
|
72
|
+
fromStatus: 'ended',
|
|
73
|
+
toStatus: 'paying'
|
|
74
|
+
});
|
|
75
|
+
if (!locked)
|
|
76
|
+
return { ok: false, code: 'ALREADY_HANDLED' };
|
|
77
|
+
try {
|
|
78
|
+
const allBets = prediction.choices.flatMap((c) => c.bets);
|
|
79
|
+
if (winner.bets.length === 0) {
|
|
80
|
+
for (const bet of allBets) {
|
|
81
|
+
await refundLockedBet({
|
|
82
|
+
userId: bet.userId,
|
|
83
|
+
guildId,
|
|
84
|
+
amount: bet.amount,
|
|
85
|
+
betId: (0, predictionSummary_1.resolvePredictionBetId)(bet, predictionId),
|
|
86
|
+
game: 'prediction'
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
const paid = await finalizePaid(predictionId, guildId);
|
|
90
|
+
return { ok: true, outcome: 'refunded', prediction: paid };
|
|
91
|
+
}
|
|
92
|
+
for (const bet of winner.bets) {
|
|
93
|
+
await settleCasinoWinnings({
|
|
94
|
+
userId: bet.userId,
|
|
95
|
+
guildId,
|
|
96
|
+
totalBet: bet.amount,
|
|
97
|
+
winnings: bet.amount * winner.odds,
|
|
98
|
+
betId: (0, predictionSummary_1.resolvePredictionBetId)(bet, predictionId),
|
|
99
|
+
game: 'prediction'
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
const losingChoices = prediction.choices.filter((c) => c.choiceName !== winnerChoice);
|
|
103
|
+
for (const choice of losingChoices) {
|
|
104
|
+
for (const bet of choice.bets) {
|
|
105
|
+
await settleCasinoWinnings({
|
|
106
|
+
userId: bet.userId,
|
|
107
|
+
guildId,
|
|
108
|
+
totalBet: bet.amount,
|
|
109
|
+
winnings: 0,
|
|
110
|
+
betId: (0, predictionSummary_1.resolvePredictionBetId)(bet, predictionId),
|
|
111
|
+
game: 'prediction'
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
const paid = await finalizePaid(predictionId, guildId);
|
|
116
|
+
return {
|
|
117
|
+
ok: true,
|
|
118
|
+
outcome: 'paid',
|
|
119
|
+
prediction: paid,
|
|
120
|
+
winnerChoice
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
catch (error) {
|
|
124
|
+
await rollbackPaying(predictionId, guildId);
|
|
125
|
+
throw error;
|
|
126
|
+
}
|
|
127
|
+
};
|
|
128
|
+
return {
|
|
129
|
+
endPrediction,
|
|
130
|
+
cancelPrediction,
|
|
131
|
+
payoutPrediction
|
|
132
|
+
};
|
|
133
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.resolvePredictionBetId = resolvePredictionBetId;
|
|
4
|
+
exports.getPredictionCheckSummary = getPredictionCheckSummary;
|
|
5
|
+
exports.calculatePredictionPayoutSummary = calculatePredictionPayoutSummary;
|
|
6
|
+
function resolvePredictionBetId(bet, predictionId) {
|
|
7
|
+
return bet.betId ?? `${predictionId}:${bet.userId}`;
|
|
8
|
+
}
|
|
9
|
+
function getPredictionCheckSummary(prediction) {
|
|
10
|
+
const allBets = prediction.choices.flatMap((c) => c.bets);
|
|
11
|
+
const bettorCount = new Set(allBets.map((b) => b.userId)).size;
|
|
12
|
+
const totalBetAmount = allBets.reduce((acc, b) => acc + b.amount, 0);
|
|
13
|
+
const choices = prediction.choices.map((choice) => {
|
|
14
|
+
const totalBet = choice.bets.reduce((acc, b) => acc + b.amount, 0);
|
|
15
|
+
const payoutIfWins = choice.bets.reduce((acc, b) => acc + b.amount * choice.odds, 0);
|
|
16
|
+
return {
|
|
17
|
+
choiceName: choice.choiceName,
|
|
18
|
+
odds: choice.odds,
|
|
19
|
+
betCount: choice.bets.length,
|
|
20
|
+
totalBetAmount: totalBet,
|
|
21
|
+
payoutIfWins,
|
|
22
|
+
bets: choice.bets
|
|
23
|
+
};
|
|
24
|
+
});
|
|
25
|
+
return {
|
|
26
|
+
totalBetAmount,
|
|
27
|
+
bettorCount,
|
|
28
|
+
choices
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
function calculatePredictionPayoutSummary(prediction, winnerChoice) {
|
|
32
|
+
const winner = prediction.choices.find((c) => c.choiceName === winnerChoice);
|
|
33
|
+
if (!winner)
|
|
34
|
+
return null;
|
|
35
|
+
const totalBets = prediction.choices.flatMap((c) => c.bets);
|
|
36
|
+
const winners = winner.bets.map((b) => ({
|
|
37
|
+
userId: b.userId,
|
|
38
|
+
betAmount: b.amount,
|
|
39
|
+
winAmount: b.amount * winner.odds
|
|
40
|
+
}));
|
|
41
|
+
const losers = prediction.choices
|
|
42
|
+
.filter((c) => c.choiceName !== winnerChoice)
|
|
43
|
+
.flatMap((c) => c.bets.map((b) => ({
|
|
44
|
+
userId: b.userId,
|
|
45
|
+
betAmount: b.amount,
|
|
46
|
+
winAmount: 0
|
|
47
|
+
})));
|
|
48
|
+
const totalWon = winners.reduce((acc, w) => acc + w.winAmount, 0);
|
|
49
|
+
const totalLost = losers.reduce((acc, l) => acc + l.betAmount, 0);
|
|
50
|
+
return {
|
|
51
|
+
participants: totalBets.length,
|
|
52
|
+
winners,
|
|
53
|
+
losers,
|
|
54
|
+
totalWon,
|
|
55
|
+
totalLost,
|
|
56
|
+
casinoProfit: totalLost - totalWon
|
|
57
|
+
};
|
|
58
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
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.RaffleSchema = void 0;
|
|
18
|
+
__exportStar(require("./types/raffle"), exports);
|
|
19
|
+
__exportStar(require("./services/types"), exports);
|
|
20
|
+
__exportStar(require("./services/raffle.db"), exports);
|
|
21
|
+
__exportStar(require("./services/raffleLifecycle.service"), exports);
|
|
22
|
+
__exportStar(require("./schemas/raffle.forms"), exports);
|
|
23
|
+
var raffle_mongoose_1 = require("./raffle.mongoose");
|
|
24
|
+
Object.defineProperty(exports, "RaffleSchema", { enumerable: true, get: function () { return raffle_mongoose_1.RaffleSchema; } });
|
|
@@ -0,0 +1,17 @@
|
|
|
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.raffleCreateFormSchema = exports.raffleChannelsFormSchema = void 0;
|
|
7
|
+
const zod_1 = __importDefault(require("zod"));
|
|
8
|
+
exports.raffleChannelsFormSchema = zod_1.default.object({
|
|
9
|
+
actions: zod_1.default.string(),
|
|
10
|
+
logs: zod_1.default.string()
|
|
11
|
+
});
|
|
12
|
+
exports.raffleCreateFormSchema = zod_1.default.object({
|
|
13
|
+
ticketPrice: zod_1.default.string().min(1),
|
|
14
|
+
maxTickets: zod_1.default.number().int().min(1).max(100),
|
|
15
|
+
drawTime: zod_1.default.string().min(1),
|
|
16
|
+
interval: zod_1.default.string().min(2)
|
|
17
|
+
});
|