gambling-bot-shared 1.0.7 → 1.0.9

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 (51) hide show
  1. package/README.MD +1 -1
  2. package/dist/blackjack/index.d.ts +1 -0
  3. package/dist/blackjack/index.js +1 -0
  4. package/dist/casino/blackjackGame.mongoose.d.ts +9 -0
  5. package/dist/casino/blackjackGame.mongoose.js +2 -1
  6. package/dist/casino/constants/blackjackWorkers.d.ts +5 -0
  7. package/dist/casino/constants/blackjackWorkers.js +17 -0
  8. package/dist/casino/constants/index.d.ts +1 -0
  9. package/dist/casino/constants/index.js +1 -0
  10. package/dist/casino/types/blackjackGame.d.ts +1 -0
  11. package/dist/common/durations.d.ts +5 -0
  12. package/dist/common/durations.js +8 -0
  13. package/dist/common/index.d.ts +1 -0
  14. package/dist/common/index.js +1 -0
  15. package/dist/dev/guildDataWipe.d.ts +1 -0
  16. package/dist/dev/guildDataWipe.js +15 -4
  17. package/dist/guild/guildConfiguration.mongoose.d.ts +9 -0
  18. package/dist/guild/guildConfiguration.mongoose.js +4 -0
  19. package/dist/guild/index.d.ts +1 -0
  20. package/dist/guild/index.js +1 -0
  21. package/dist/guild/schemas/guild.forms.d.ts +1 -0
  22. package/dist/guild/schemas/guild.forms.js +2 -1
  23. package/dist/guild/types/guildConfiguration.d.ts +1 -0
  24. package/dist/guild/utils/workerLogChannel.d.ts +2 -0
  25. package/dist/guild/utils/workerLogChannel.js +6 -0
  26. package/dist/mongoose/index.d.ts +1 -0
  27. package/dist/mongoose/index.js +3 -1
  28. package/dist/predictions/services/prediction.db.d.ts +1 -8
  29. package/dist/predictions/services/prediction.db.js +0 -8
  30. package/dist/predictions/services/types.d.ts +0 -4
  31. package/dist/transactions/constants/staffAudit.d.ts +4 -2
  32. package/dist/transactions/constants/staffAudit.js +5 -1
  33. package/dist/user/index.d.ts +1 -0
  34. package/dist/user/index.js +1 -0
  35. package/dist/user/types/user.d.ts +1 -8
  36. package/dist/user/types/userBan.d.ts +13 -0
  37. package/dist/user/types/userBan.js +2 -0
  38. package/dist/user/user.mongoose.d.ts +0 -9
  39. package/dist/user/user.mongoose.js +1 -8
  40. package/dist/user/userBan.d.ts +2 -0
  41. package/dist/user/userBan.js +18 -0
  42. package/dist/user/userBan.mongoose.d.ts +111 -0
  43. package/dist/user/userBan.mongoose.js +18 -0
  44. package/dist/user/utils/userBan.d.ts +3 -0
  45. package/dist/user/utils/userBan.js +12 -0
  46. package/dist/user/utils/userModeration.d.ts +12 -11
  47. package/dist/user/utils/userModeration.js +46 -22
  48. package/dist/vip/types/vipRoom.d.ts +2 -0
  49. package/dist/vip/vipRoom.mongoose.d.ts +9 -0
  50. package/dist/vip/vipRoom.mongoose.js +5 -0
  51. package/package.json +1 -1
package/README.MD CHANGED
@@ -44,7 +44,7 @@ See [docs/LOCAL_DEVELOPMENT.md](./docs/LOCAL_DEVELOPMENT.md) for the local linki
44
44
 
45
45
  ## Package imports
46
46
 
47
- Domain subpath exports only see [docs/ARCHITECTURE.md](./docs/ARCHITECTURE.md) for the domain map.
47
+ Domain subpath exports only - see [docs/ARCHITECTURE.md](./docs/ARCHITECTURE.md) for the domain map.
48
48
 
49
49
  ## GitHub / CI
50
50
 
@@ -1,2 +1,3 @@
1
1
  export * from '../casino/constants/blackjack';
2
+ export * from '../casino/constants/blackjackWorkers';
2
3
  export * from '../casino/types/blackjackGame';
@@ -15,4 +15,5 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("../casino/constants/blackjack"), exports);
18
+ __exportStar(require("../casino/constants/blackjackWorkers"), exports);
18
19
  __exportStar(require("../casino/types/blackjackGame"), exports);
@@ -108,6 +108,15 @@ export declare const BlackjackGameSchema: Schema<TBlackjackGame, import("mongoos
108
108
  }, "id"> & {
109
109
  id: string;
110
110
  }> | undefined;
111
+ idleNudgeSentAt?: import("mongoose").SchemaDefinitionProperty<Date | null | undefined, TBlackjackGame, import("mongoose").Document<unknown, {}, TBlackjackGame, {
112
+ id: string;
113
+ }, import("mongoose").DefaultSchemaOptions> & Omit<TBlackjackGame & {
114
+ _id: import("mongoose").Types.ObjectId;
115
+ } & {
116
+ __v: number;
117
+ }, "id"> & {
118
+ id: string;
119
+ }> | undefined;
111
120
  createdAt?: import("mongoose").SchemaDefinitionProperty<Date, TBlackjackGame, import("mongoose").Document<unknown, {}, TBlackjackGame, {
112
121
  id: string;
113
122
  }, import("mongoose").DefaultSchemaOptions> & Omit<TBlackjackGame & {
@@ -29,6 +29,7 @@ exports.BlackjackGameSchema = new mongoose_1.Schema({
29
29
  default: 'PLAYER'
30
30
  },
31
31
  activeHandIndex: { type: Number, required: true, default: 0 },
32
- dealerCards: [cardSchema]
32
+ dealerCards: [cardSchema],
33
+ idleNudgeSentAt: { type: Date, default: null }
33
34
  }, { timestamps: true });
34
35
  exports.BlackjackGameSchema.index({ userId: 1, guildId: 1 }, { unique: true });
@@ -0,0 +1,5 @@
1
+ export declare const BLACKJACK_AUTOSTAND_IDLE_DAYS = 1;
2
+ export declare const BLACKJACK_IDLE_NUDGE_HOURS = 3;
3
+ export declare const blackjackIdleNudgeThresholdMs: () => number;
4
+ export declare const blackjackAutostandIdleMs: () => number;
5
+ export declare const hoursUntilBlackjackAutostand: (updatedAt: Date, nowMs?: number) => number;
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.hoursUntilBlackjackAutostand = exports.blackjackAutostandIdleMs = exports.blackjackIdleNudgeThresholdMs = exports.BLACKJACK_IDLE_NUDGE_HOURS = exports.BLACKJACK_AUTOSTAND_IDLE_DAYS = void 0;
4
+ exports.BLACKJACK_AUTOSTAND_IDLE_DAYS = 1;
5
+ exports.BLACKJACK_IDLE_NUDGE_HOURS = 3;
6
+ const MS_PER_HOUR = 60 * 60 * 1000;
7
+ const MS_PER_DAY = 24 * MS_PER_HOUR;
8
+ const blackjackIdleNudgeThresholdMs = () => exports.BLACKJACK_IDLE_NUDGE_HOURS * MS_PER_HOUR;
9
+ exports.blackjackIdleNudgeThresholdMs = blackjackIdleNudgeThresholdMs;
10
+ const blackjackAutostandIdleMs = () => exports.BLACKJACK_AUTOSTAND_IDLE_DAYS * MS_PER_DAY;
11
+ exports.blackjackAutostandIdleMs = blackjackAutostandIdleMs;
12
+ const hoursUntilBlackjackAutostand = (updatedAt, nowMs = Date.now()) => {
13
+ const autostandAt = updatedAt.getTime() + (0, exports.blackjackAutostandIdleMs)();
14
+ const hoursLeft = (autostandAt - nowMs) / MS_PER_HOUR;
15
+ return Math.max(1, Math.ceil(hoursLeft));
16
+ };
17
+ exports.hoursUntilBlackjackAutostand = hoursUntilBlackjackAutostand;
@@ -1,4 +1,5 @@
1
1
  export * from './blackjack';
2
+ export * from './blackjackWorkers';
2
3
  export * from './casinoGames';
3
4
  export * from './defaultConfig';
4
5
  export * from './lotteryConfig';
@@ -15,6 +15,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./blackjack"), exports);
18
+ __exportStar(require("./blackjackWorkers"), exports);
18
19
  __exportStar(require("./casinoGames"), exports);
19
20
  __exportStar(require("./defaultConfig"), exports);
20
21
  __exportStar(require("./lotteryConfig"), exports);
@@ -25,6 +25,7 @@ export type TBlackjackGame = {
25
25
  activeHandIndex: number;
26
26
  phase: GamePhase;
27
27
  dealerCards: Card[];
28
+ idleNudgeSentAt?: Date | null;
28
29
  createdAt: Date;
29
30
  updatedAt: Date;
30
31
  };
@@ -0,0 +1,5 @@
1
+ export declare const SECOND_MS = 1000;
2
+ export declare const MINUTE_MS: number;
3
+ export declare const HOUR_MS: number;
4
+ export declare const DAY_MS: number;
5
+ export declare const WEEK_MS: number;
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.WEEK_MS = exports.DAY_MS = exports.HOUR_MS = exports.MINUTE_MS = exports.SECOND_MS = void 0;
4
+ exports.SECOND_MS = 1000;
5
+ exports.MINUTE_MS = 60 * exports.SECOND_MS;
6
+ exports.HOUR_MS = 60 * exports.MINUTE_MS;
7
+ exports.DAY_MS = 24 * exports.HOUR_MS;
8
+ exports.WEEK_MS = 7 * exports.DAY_MS;
@@ -1,3 +1,4 @@
1
+ export * from './durations';
1
2
  export * from './formatters';
2
3
  export * from './generateId';
3
4
  export * from './parseTimeToSeconds';
@@ -14,6 +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("./durations"), exports);
17
18
  __exportStar(require("./formatters"), exports);
18
19
  __exportStar(require("./generateId"), exports);
19
20
  __exportStar(require("./parseTimeToSeconds"), exports);
@@ -14,6 +14,7 @@ export type GuildDataWipeModels = {
14
14
  predictions: GuildDataWipeModel;
15
15
  vipRooms: GuildDataWipeModel;
16
16
  blackjackGames: GuildDataWipeModel;
17
+ userBans: GuildDataWipeModel;
17
18
  users: GuildDataWipeModel;
18
19
  };
19
20
  export type GuildDataWipeSummary = {
@@ -29,6 +29,7 @@ const WIPE_LABELS = {
29
29
  predictions: 'Predictions',
30
30
  vipRooms: 'VIP rooms',
31
31
  blackjackGames: 'Blackjack games',
32
+ userBans: 'User bans',
32
33
  users: 'Users'
33
34
  };
34
35
  async function countDeleted(result) {
@@ -44,14 +45,24 @@ function normalizeGuildWipeEntities(entities) {
44
45
  }
45
46
  function buildWipeTargets(guildId, entities, models) {
46
47
  const selected = new Set(entities);
47
- return WIPE_ENTITY_ORDER.filter((entity) => selected.has(entity)).map((entity) => {
48
+ return WIPE_ENTITY_ORDER.filter((entity) => selected.has(entity)).flatMap((entity) => {
49
+ const targets = [];
50
+ if (entity === 'users') {
51
+ targets.push({
52
+ key: 'userBans',
53
+ label: WIPE_LABELS.userBans,
54
+ entity,
55
+ run: async () => countDeleted(await models.userBans.deleteMany({ guildId }))
56
+ });
57
+ }
48
58
  const key = ENTITY_TO_MODEL_KEY[entity];
49
- return {
59
+ targets.push({
50
60
  key,
51
61
  label: WIPE_LABELS[key],
52
62
  entity,
53
63
  run: async () => countDeleted(await models[key].deleteMany({ guildId }))
54
- };
64
+ });
65
+ return targets;
55
66
  });
56
67
  }
57
68
  async function runGuildDataWipe({ guildId, entities, models }) {
@@ -71,7 +82,7 @@ function formatGuildDataWipeSummary(summary) {
71
82
  .filter(([, count]) => count > 0)
72
83
  .map(([key, count]) => `• **${WIPE_LABELS[key] ?? key}**: ${(0, formatters_1.formatNumberToReadableString)(count)} removed`);
73
84
  if (lines.length === 0) {
74
- return 'Nothing to remove guild operational data was already empty.';
85
+ return 'Nothing to remove - guild operational data was already empty.';
75
86
  }
76
87
  return lines.join('\n');
77
88
  }
@@ -72,6 +72,15 @@ export declare const GuildConfigurationSchema: Schema<TGuildConfiguration, impor
72
72
  }, "id"> & {
73
73
  id: string;
74
74
  }> | undefined;
75
+ workerLogChannelId?: import("mongoose").SchemaDefinitionProperty<string, TGuildConfiguration, import("mongoose").Document<unknown, {}, TGuildConfiguration, {
76
+ id: string;
77
+ }, import("mongoose").DefaultSchemaOptions> & Omit<TGuildConfiguration & {
78
+ _id: import("mongoose").Types.ObjectId;
79
+ } & {
80
+ __v: number;
81
+ }, "id"> & {
82
+ id: string;
83
+ }> | undefined;
75
84
  managerRoleId?: import("mongoose").SchemaDefinitionProperty<string, TGuildConfiguration, import("mongoose").Document<unknown, {}, TGuildConfiguration, {
76
85
  id: string;
77
86
  }, import("mongoose").DefaultSchemaOptions> & Omit<TGuildConfiguration & {
@@ -49,6 +49,10 @@ exports.GuildConfigurationSchema = new mongoose_1.Schema({
49
49
  default: ''
50
50
  }
51
51
  },
52
+ workerLogChannelId: {
53
+ type: String,
54
+ default: ''
55
+ },
52
56
  managerRoleId: {
53
57
  type: String,
54
58
  default: ''
@@ -4,4 +4,5 @@ export * from './types/guildConfiguration';
4
4
  export * from './utils/globalSettings';
5
5
  export * from './utils/normalizeGlobalSettings';
6
6
  export * from './utils/guildTimezone';
7
+ export * from './utils/workerLogChannel';
7
8
  export * from './schemas/guild.forms';
@@ -20,4 +20,5 @@ __exportStar(require("./types/guildConfiguration"), exports);
20
20
  __exportStar(require("./utils/globalSettings"), exports);
21
21
  __exportStar(require("./utils/normalizeGlobalSettings"), exports);
22
22
  __exportStar(require("./utils/guildTimezone"), exports);
23
+ __exportStar(require("./utils/workerLogChannel"), exports);
23
24
  __exportStar(require("./schemas/guild.forms"), exports);
@@ -16,6 +16,7 @@ export declare const channelsFormSchema: z.ZodObject<{
16
16
  actions: z.ZodString;
17
17
  logs: z.ZodString;
18
18
  }, z.core.$strip>;
19
+ workerLogChannelId: z.ZodString;
19
20
  }, z.core.$strip>;
20
21
  export declare const managerRoleFormSchema: z.ZodObject<{
21
22
  managerRoleId: z.ZodString;
@@ -14,7 +14,8 @@ exports.channelsFormSchema = zod_1.default.object({
14
14
  atm: atm_forms_1.atmChannelsFormSchema,
15
15
  casino: casino_forms_1.casinoChannelsFormSchema,
16
16
  prediction: prediction_forms_1.predictionChannelsFormSchema,
17
- raffle: raffle_forms_1.raffleChannelsFormSchema
17
+ raffle: raffle_forms_1.raffleChannelsFormSchema,
18
+ workerLogChannelId: zod_1.default.string()
18
19
  });
19
20
  exports.managerRoleFormSchema = zod_1.default.object({
20
21
  managerRoleId: zod_1.default.string(),
@@ -18,6 +18,7 @@ export type TGuildConfiguration = {
18
18
  actions: string;
19
19
  logs: string;
20
20
  };
21
+ workerLogChannelId: string;
21
22
  managerRoleId: string;
22
23
  bannedRoleId: string;
23
24
  casinoSettings: typeof defaultCasinoSettings;
@@ -0,0 +1,2 @@
1
+ import type { TGuildConfiguration } from '../types/guildConfiguration';
2
+ export declare function isWorkerLogChannelConfigured(config: Pick<TGuildConfiguration, 'workerLogChannelId'> | null | undefined): boolean;
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isWorkerLogChannelConfigured = isWorkerLogChannelConfigured;
4
+ function isWorkerLogChannelConfigured(config) {
5
+ return Boolean(config?.workerLogChannelId);
6
+ }
@@ -1,4 +1,5 @@
1
1
  export { UserSchema } from '../user/user.mongoose';
2
+ export { UserBanSchema } from '../user/userBan.mongoose';
2
3
  export { VipRoomSchema } from '../vip/vipRoom.mongoose';
3
4
  export { PredictionSchema } from '../predictions/prediction.mongoose';
4
5
  export { TransactionSchema } from '../transactions/transaction.mongoose';
@@ -1,8 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.BlackjackGameSchema = exports.RaffleSchema = exports.AtmRequestSchema = exports.GuildConfigurationSchema = exports.TransactionSchema = exports.PredictionSchema = exports.VipRoomSchema = exports.UserSchema = void 0;
3
+ exports.BlackjackGameSchema = exports.RaffleSchema = exports.AtmRequestSchema = exports.GuildConfigurationSchema = exports.TransactionSchema = exports.PredictionSchema = exports.VipRoomSchema = exports.UserBanSchema = exports.UserSchema = void 0;
4
4
  var user_mongoose_1 = require("../user/user.mongoose");
5
5
  Object.defineProperty(exports, "UserSchema", { enumerable: true, get: function () { return user_mongoose_1.UserSchema; } });
6
+ var userBan_mongoose_1 = require("../user/userBan.mongoose");
7
+ Object.defineProperty(exports, "UserBanSchema", { enumerable: true, get: function () { return userBan_mongoose_1.UserBanSchema; } });
6
8
  var vipRoom_mongoose_1 = require("../vip/vipRoom.mongoose");
7
9
  Object.defineProperty(exports, "VipRoomSchema", { enumerable: true, get: function () { return vipRoom_mongoose_1.VipRoomSchema; } });
8
10
  var prediction_mongoose_1 = require("../predictions/prediction.mongoose");
@@ -1,6 +1,6 @@
1
1
  import type { Model } from 'mongoose';
2
2
  import type { TPrediction } from '../types/prediction';
3
- import type { TAddPredictionBet, TCreatePrediction, TGetOldPredictions, TGetPrediction, TUpdatePredictionStatus } from './types';
3
+ import type { TAddPredictionBet, TCreatePrediction, TGetPrediction, TUpdatePredictionStatus } from './types';
4
4
  export declare function createPredictionDb(predictionModel: Model<TPrediction>): {
5
5
  getPredictionById: ({ predictionId, guildId }: TGetPrediction) => Promise<(import("mongoose").Document<unknown, {}, TPrediction, {}, import("mongoose").DefaultSchemaOptions> & TPrediction & {
6
6
  _id: import("mongoose").Types.ObjectId;
@@ -19,13 +19,6 @@ export declare function createPredictionDb(predictionModel: Model<TPrediction>):
19
19
  } & {
20
20
  id: string;
21
21
  })[]>;
22
- getOldPredictions: ({ statuses, olderThanDays }: TGetOldPredictions) => Promise<(import("mongoose").Document<unknown, {}, TPrediction, {}, import("mongoose").DefaultSchemaOptions> & TPrediction & {
23
- _id: import("mongoose").Types.ObjectId;
24
- } & {
25
- __v: number;
26
- } & {
27
- id: string;
28
- })[]>;
29
22
  createPrediction: ({ predictionId, guildId, channelId, creatorId, title, choices, autolock, status }: TCreatePrediction) => Promise<void>;
30
23
  updatePredictionStatus: ({ predictionId, guildId, fromStatus, toStatus }: TUpdatePredictionStatus) => Promise<(import("mongoose").Document<unknown, {}, TPrediction, {}, import("mongoose").DefaultSchemaOptions> & TPrediction & {
31
24
  _id: import("mongoose").Types.ObjectId;
@@ -12,13 +12,6 @@ function createPredictionDb(predictionModel) {
12
12
  ...(useAutolock ? { autolock: { $lte: now } } : {})
13
13
  });
14
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
15
  const createPrediction = async ({ predictionId, guildId, channelId, creatorId, title, choices, autolock, status }) => {
23
16
  await predictionModel.create({
24
17
  predictionId,
@@ -62,7 +55,6 @@ function createPredictionDb(predictionModel) {
62
55
  return {
63
56
  getPredictionById,
64
57
  getPredictionToLock,
65
- getOldPredictions,
66
58
  createPrediction,
67
59
  updatePredictionStatus,
68
60
  deletePrediction,
@@ -1,10 +1,6 @@
1
1
  import type { TPrediction, TPredictionOption } from '../types/prediction';
2
2
  export type TCreatePrediction = Omit<TPrediction, 'createdAt' | 'updatedAt'>;
3
3
  export type TGetPrediction = Pick<TPrediction, 'predictionId' | 'guildId'>;
4
- export type TGetOldPredictions = {
5
- statuses: TPrediction['status'][];
6
- olderThanDays: number;
7
- };
8
4
  export type TUpdatePredictionStatus = Pick<TPrediction, 'predictionId' | 'guildId'> & {
9
5
  fromStatus: TPrediction['status'] | TPrediction['status'][];
10
6
  toStatus: TPrediction['status'];
@@ -10,8 +10,10 @@ export declare const STAFF_ADMIN_ACTIONS: {
10
10
  readonly ATM_REJECT: "atm-reject";
11
11
  readonly USER_BAN: "user-ban";
12
12
  readonly USER_UNBAN: "user-unban";
13
- readonly USER_NOTE: "user-note";
13
+ readonly USER_NOTE_CREATE: "user-note-create";
14
+ readonly USER_NOTE_UPDATE: "user-note-update";
15
+ readonly USER_NOTE_DELETE: "user-note-delete";
14
16
  };
15
17
  export type StaffAdminAction = (typeof STAFF_ADMIN_ACTIONS)[keyof typeof STAFF_ADMIN_ACTIONS];
16
- export declare const STAFF_ACTION_CATEGORIES: readonly ["balance", "atm", "vip", "raffle", "prediction", "user"];
18
+ export declare const STAFF_ACTION_CATEGORIES: readonly ["balance", "atm", "vip", "raffle", "prediction", "ban", "unban", "user"];
17
19
  export type StaffActionCategory = (typeof STAFF_ACTION_CATEGORIES)[number];
@@ -13,7 +13,9 @@ exports.STAFF_ADMIN_ACTIONS = {
13
13
  ATM_REJECT: 'atm-reject',
14
14
  USER_BAN: 'user-ban',
15
15
  USER_UNBAN: 'user-unban',
16
- USER_NOTE: 'user-note'
16
+ USER_NOTE_CREATE: 'user-note-create',
17
+ USER_NOTE_UPDATE: 'user-note-update',
18
+ USER_NOTE_DELETE: 'user-note-delete'
17
19
  };
18
20
  exports.STAFF_ACTION_CATEGORIES = [
19
21
  'balance',
@@ -21,5 +23,7 @@ exports.STAFF_ACTION_CATEGORIES = [
21
23
  'vip',
22
24
  'raffle',
23
25
  'prediction',
26
+ 'ban',
27
+ 'unban',
24
28
  'user'
25
29
  ];
@@ -1,2 +1,3 @@
1
1
  export * from './types/user';
2
2
  export * from './utils/userModeration';
3
+ export * from './userBan';
@@ -16,3 +16,4 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./types/user"), exports);
18
18
  __exportStar(require("./utils/userModeration"), exports);
19
+ __exportStar(require("./userBan"), exports);
@@ -1,15 +1,9 @@
1
1
  export type TUserStaffNote = {
2
+ noteId: string;
2
3
  text: string;
3
4
  authorId: string;
4
5
  createdAt: Date;
5
6
  };
6
- export type TUserBanHistoryEntry = {
7
- bannedAt: Date;
8
- bannedBy: string;
9
- unbannedAt: Date | null;
10
- unbannedBy: string | null;
11
- reason?: string;
12
- };
13
7
  export type TUser = {
14
8
  userId: string;
15
9
  guildId: string;
@@ -21,7 +15,6 @@ export type TUser = {
21
15
  banned: boolean;
22
16
  bannedAt: Date | null;
23
17
  bannedBy: string | null;
24
- banHistory: TUserBanHistoryEntry[];
25
18
  staffNotes: TUserStaffNote[];
26
19
  createdAt: Date;
27
20
  updatedAt: Date;
@@ -0,0 +1,13 @@
1
+ export type TUserBan = {
2
+ banId: string;
3
+ guildId: string;
4
+ userId: string;
5
+ bannedAt: Date;
6
+ bannedBy: string;
7
+ banReason?: string;
8
+ unbannedAt: Date | null;
9
+ unbannedBy: string | null;
10
+ unbanReason?: string;
11
+ createdAt: Date;
12
+ updatedAt: Date;
13
+ };
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -99,15 +99,6 @@ export declare const UserSchema: Schema<TUser, import("mongoose").Model<TUser, a
99
99
  }, "id"> & {
100
100
  id: string;
101
101
  }> | undefined;
102
- banHistory?: import("mongoose").SchemaDefinitionProperty<import("./types/user").TUserBanHistoryEntry[], TUser, import("mongoose").Document<unknown, {}, TUser, {
103
- id: string;
104
- }, import("mongoose").DefaultSchemaOptions> & Omit<TUser & {
105
- _id: import("mongoose").Types.ObjectId;
106
- } & {
107
- __v: number;
108
- }, "id"> & {
109
- id: string;
110
- }> | undefined;
111
102
  staffNotes?: import("mongoose").SchemaDefinitionProperty<import("./types/user").TUserStaffNote[], TUser, import("mongoose").Document<unknown, {}, TUser, {
112
103
  id: string;
113
104
  }, import("mongoose").DefaultSchemaOptions> & Omit<TUser & {
@@ -3,17 +3,11 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.UserSchema = void 0;
4
4
  const mongoose_1 = require("mongoose");
5
5
  const UserStaffNoteSchema = new mongoose_1.Schema({
6
+ noteId: { type: String, required: true },
6
7
  text: { type: String, required: true },
7
8
  authorId: { type: String, required: true },
8
9
  createdAt: { type: Date, required: true }
9
10
  }, { _id: false });
10
- const UserBanHistoryEntrySchema = new mongoose_1.Schema({
11
- bannedAt: { type: Date, required: true },
12
- bannedBy: { type: String, required: true },
13
- unbannedAt: { type: Date, default: null },
14
- unbannedBy: { type: String, default: null },
15
- reason: { type: String }
16
- }, { _id: false });
17
11
  exports.UserSchema = new mongoose_1.Schema({
18
12
  userId: { type: String, required: true },
19
13
  guildId: { type: String, required: true },
@@ -25,7 +19,6 @@ exports.UserSchema = new mongoose_1.Schema({
25
19
  banned: { type: Boolean, default: false },
26
20
  bannedAt: { type: Date, default: null },
27
21
  bannedBy: { type: String, default: null },
28
- banHistory: { type: [UserBanHistoryEntrySchema], default: [] },
29
22
  staffNotes: { type: [UserStaffNoteSchema], default: [] }
30
23
  }, { timestamps: true });
31
24
  exports.UserSchema.index({ userId: 1, guildId: 1 }, { unique: true });
@@ -0,0 +1,2 @@
1
+ export * from './types/userBan';
2
+ export * from './utils/userBan';
@@ -0,0 +1,18 @@
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("./types/userBan"), exports);
18
+ __exportStar(require("./utils/userBan"), exports);
@@ -0,0 +1,111 @@
1
+ import { Schema } from 'mongoose';
2
+ import { TUserBan } from './types/userBan';
3
+ export declare const UserBanSchema: Schema<TUserBan, import("mongoose").Model<TUserBan, any, any, any, any, any, TUserBan>, {}, {}, {}, {}, import("mongoose").DefaultSchemaOptions, TUserBan, import("mongoose").Document<unknown, {}, TUserBan, {
4
+ id: string;
5
+ }, import("mongoose").DefaultSchemaOptions> & Omit<TUserBan & {
6
+ _id: import("mongoose").Types.ObjectId;
7
+ } & {
8
+ __v: number;
9
+ }, "id"> & {
10
+ id: string;
11
+ }, {
12
+ banId?: import("mongoose").SchemaDefinitionProperty<string, TUserBan, import("mongoose").Document<unknown, {}, TUserBan, {
13
+ id: string;
14
+ }, import("mongoose").DefaultSchemaOptions> & Omit<TUserBan & {
15
+ _id: import("mongoose").Types.ObjectId;
16
+ } & {
17
+ __v: number;
18
+ }, "id"> & {
19
+ id: string;
20
+ }> | undefined;
21
+ guildId?: import("mongoose").SchemaDefinitionProperty<string, TUserBan, import("mongoose").Document<unknown, {}, TUserBan, {
22
+ id: string;
23
+ }, import("mongoose").DefaultSchemaOptions> & Omit<TUserBan & {
24
+ _id: import("mongoose").Types.ObjectId;
25
+ } & {
26
+ __v: number;
27
+ }, "id"> & {
28
+ id: string;
29
+ }> | undefined;
30
+ userId?: import("mongoose").SchemaDefinitionProperty<string, TUserBan, import("mongoose").Document<unknown, {}, TUserBan, {
31
+ id: string;
32
+ }, import("mongoose").DefaultSchemaOptions> & Omit<TUserBan & {
33
+ _id: import("mongoose").Types.ObjectId;
34
+ } & {
35
+ __v: number;
36
+ }, "id"> & {
37
+ id: string;
38
+ }> | undefined;
39
+ bannedAt?: import("mongoose").SchemaDefinitionProperty<Date, TUserBan, import("mongoose").Document<unknown, {}, TUserBan, {
40
+ id: string;
41
+ }, import("mongoose").DefaultSchemaOptions> & Omit<TUserBan & {
42
+ _id: import("mongoose").Types.ObjectId;
43
+ } & {
44
+ __v: number;
45
+ }, "id"> & {
46
+ id: string;
47
+ }> | undefined;
48
+ bannedBy?: import("mongoose").SchemaDefinitionProperty<string, TUserBan, import("mongoose").Document<unknown, {}, TUserBan, {
49
+ id: string;
50
+ }, import("mongoose").DefaultSchemaOptions> & Omit<TUserBan & {
51
+ _id: import("mongoose").Types.ObjectId;
52
+ } & {
53
+ __v: number;
54
+ }, "id"> & {
55
+ id: string;
56
+ }> | undefined;
57
+ banReason?: import("mongoose").SchemaDefinitionProperty<string | undefined, TUserBan, import("mongoose").Document<unknown, {}, TUserBan, {
58
+ id: string;
59
+ }, import("mongoose").DefaultSchemaOptions> & Omit<TUserBan & {
60
+ _id: import("mongoose").Types.ObjectId;
61
+ } & {
62
+ __v: number;
63
+ }, "id"> & {
64
+ id: string;
65
+ }> | undefined;
66
+ unbannedAt?: import("mongoose").SchemaDefinitionProperty<Date | null, TUserBan, import("mongoose").Document<unknown, {}, TUserBan, {
67
+ id: string;
68
+ }, import("mongoose").DefaultSchemaOptions> & Omit<TUserBan & {
69
+ _id: import("mongoose").Types.ObjectId;
70
+ } & {
71
+ __v: number;
72
+ }, "id"> & {
73
+ id: string;
74
+ }> | undefined;
75
+ unbannedBy?: import("mongoose").SchemaDefinitionProperty<string | null, TUserBan, import("mongoose").Document<unknown, {}, TUserBan, {
76
+ id: string;
77
+ }, import("mongoose").DefaultSchemaOptions> & Omit<TUserBan & {
78
+ _id: import("mongoose").Types.ObjectId;
79
+ } & {
80
+ __v: number;
81
+ }, "id"> & {
82
+ id: string;
83
+ }> | undefined;
84
+ unbanReason?: import("mongoose").SchemaDefinitionProperty<string | undefined, TUserBan, import("mongoose").Document<unknown, {}, TUserBan, {
85
+ id: string;
86
+ }, import("mongoose").DefaultSchemaOptions> & Omit<TUserBan & {
87
+ _id: import("mongoose").Types.ObjectId;
88
+ } & {
89
+ __v: number;
90
+ }, "id"> & {
91
+ id: string;
92
+ }> | undefined;
93
+ createdAt?: import("mongoose").SchemaDefinitionProperty<Date, TUserBan, import("mongoose").Document<unknown, {}, TUserBan, {
94
+ id: string;
95
+ }, import("mongoose").DefaultSchemaOptions> & Omit<TUserBan & {
96
+ _id: import("mongoose").Types.ObjectId;
97
+ } & {
98
+ __v: number;
99
+ }, "id"> & {
100
+ id: string;
101
+ }> | undefined;
102
+ updatedAt?: import("mongoose").SchemaDefinitionProperty<Date, TUserBan, import("mongoose").Document<unknown, {}, TUserBan, {
103
+ id: string;
104
+ }, import("mongoose").DefaultSchemaOptions> & Omit<TUserBan & {
105
+ _id: import("mongoose").Types.ObjectId;
106
+ } & {
107
+ __v: number;
108
+ }, "id"> & {
109
+ id: string;
110
+ }> | undefined;
111
+ }, TUserBan>;
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.UserBanSchema = void 0;
4
+ const mongoose_1 = require("mongoose");
5
+ exports.UserBanSchema = new mongoose_1.Schema({
6
+ banId: { type: String, required: true },
7
+ guildId: { type: String, required: true },
8
+ userId: { type: String, required: true },
9
+ bannedAt: { type: Date, required: true },
10
+ bannedBy: { type: String, required: true },
11
+ banReason: { type: String },
12
+ unbannedAt: { type: Date, default: null },
13
+ unbannedBy: { type: String, default: null },
14
+ unbanReason: { type: String }
15
+ }, { timestamps: true });
16
+ exports.UserBanSchema.index({ banId: 1, guildId: 1 }, { unique: true });
17
+ exports.UserBanSchema.index({ guildId: 1, userId: 1, bannedAt: -1 });
18
+ exports.UserBanSchema.index({ guildId: 1, userId: 1, unbannedAt: 1 });
@@ -0,0 +1,3 @@
1
+ import type { TUserBan } from '../types/userBan';
2
+ export declare function normalizeBanReason(reason?: string | null): string | undefined;
3
+ export declare function isUserBanActive(ban: Pick<TUserBan, 'unbannedAt'>): boolean;
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.normalizeBanReason = normalizeBanReason;
4
+ exports.isUserBanActive = isUserBanActive;
5
+ const userModeration_1 = require("./userModeration");
6
+ function normalizeBanReason(reason) {
7
+ const normalized = reason ? (0, userModeration_1.normalizeStaffNote)(reason) : null;
8
+ return normalized ?? undefined;
9
+ }
10
+ function isUserBanActive(ban) {
11
+ return ban.unbannedAt === null;
12
+ }
@@ -1,16 +1,17 @@
1
- import type { TUser, TUserBanHistoryEntry, TUserStaffNote } from '../types/user';
1
+ import type { TUser, TUserStaffNote } from '../types/user';
2
2
  export declare const USER_BANNED_ERROR = "USER_BANNED";
3
3
  export declare const USER_BANNED_MESSAGE = "Your account is restricted. Contact server staff.";
4
4
  export declare function isUserBanned(user: Pick<TUser, 'banned'>): boolean;
5
5
  export declare function normalizeStaffNote(text: string): string | null;
6
+ export declare function createStaffNoteEntry(text: string, authorId: string): TUserStaffNote | null;
7
+ type StaffNoteLike = {
8
+ noteId?: string;
9
+ text: string;
10
+ authorId: string;
11
+ createdAt?: Date | string;
12
+ };
13
+ export declare function normalizeStaffNotes(notes: StaffNoteLike[]): TUserStaffNote[];
6
14
  export declare function appendStaffNote(notes: TUserStaffNote[], entry: TUserStaffNote, maxNotes?: number): TUserStaffNote[];
7
- export declare function startBanHistoryEntry({ history, bannedBy, reason, maxEntries }: {
8
- history: TUserBanHistoryEntry[];
9
- bannedBy: string;
10
- reason?: string;
11
- maxEntries?: number;
12
- }): TUserBanHistoryEntry[];
13
- export declare function closeLatestBanHistoryEntry({ history, unbannedBy }: {
14
- history: TUserBanHistoryEntry[];
15
- unbannedBy: string;
16
- }): TUserBanHistoryEntry[];
15
+ export declare function updateStaffNote(notes: TUserStaffNote[], noteId: string, text: string): TUserStaffNote[] | null;
16
+ export declare function removeStaffNote(notes: TUserStaffNote[], noteId: string): TUserStaffNote[] | null;
17
+ export {};
@@ -3,9 +3,12 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.USER_BANNED_MESSAGE = exports.USER_BANNED_ERROR = void 0;
4
4
  exports.isUserBanned = isUserBanned;
5
5
  exports.normalizeStaffNote = normalizeStaffNote;
6
+ exports.createStaffNoteEntry = createStaffNoteEntry;
7
+ exports.normalizeStaffNotes = normalizeStaffNotes;
6
8
  exports.appendStaffNote = appendStaffNote;
7
- exports.startBanHistoryEntry = startBanHistoryEntry;
8
- exports.closeLatestBanHistoryEntry = closeLatestBanHistoryEntry;
9
+ exports.updateStaffNote = updateStaffNote;
10
+ exports.removeStaffNote = removeStaffNote;
11
+ const generateId_1 = require("../../common/generateId");
9
12
  exports.USER_BANNED_ERROR = 'USER_BANNED';
10
13
  exports.USER_BANNED_MESSAGE = 'Your account is restricted. Contact server staff.';
11
14
  function isUserBanned(user) {
@@ -17,28 +20,49 @@ function normalizeStaffNote(text) {
17
20
  return null;
18
21
  return trimmed.slice(0, 500);
19
22
  }
23
+ function createStaffNoteEntry(text, authorId) {
24
+ const normalized = normalizeStaffNote(text);
25
+ if (!normalized)
26
+ return null;
27
+ return {
28
+ noteId: (0, generateId_1.generateId)(),
29
+ text: normalized,
30
+ authorId,
31
+ createdAt: new Date()
32
+ };
33
+ }
34
+ function normalizeStaffNotes(notes) {
35
+ return notes.flatMap((note) => {
36
+ const text = normalizeStaffNote(note.text);
37
+ if (!text || !note.authorId)
38
+ return [];
39
+ return [
40
+ {
41
+ noteId: typeof note.noteId === 'string' && note.noteId.length > 0
42
+ ? note.noteId
43
+ : (0, generateId_1.generateId)(),
44
+ text,
45
+ authorId: note.authorId,
46
+ createdAt: note.createdAt ? new Date(note.createdAt) : new Date()
47
+ }
48
+ ];
49
+ });
50
+ }
20
51
  function appendStaffNote(notes, entry, maxNotes = 50) {
21
52
  return [entry, ...notes].slice(0, maxNotes);
22
53
  }
23
- function startBanHistoryEntry({ history, bannedBy, reason, maxEntries = 50 }) {
24
- const entry = {
25
- bannedAt: new Date(),
26
- bannedBy,
27
- unbannedAt: null,
28
- unbannedBy: null,
29
- ...(reason ? { reason } : {})
30
- };
31
- return [entry, ...history].slice(0, maxEntries);
32
- }
33
- function closeLatestBanHistoryEntry({ history, unbannedBy }) {
34
- const openIndex = history.findIndex((entry) => entry.unbannedAt === null);
35
- if (openIndex === -1)
36
- return history;
37
- const updated = [...history];
38
- updated[openIndex] = {
39
- ...updated[openIndex],
40
- unbannedAt: new Date(),
41
- unbannedBy
42
- };
54
+ function updateStaffNote(notes, noteId, text) {
55
+ const normalized = normalizeStaffNote(text);
56
+ if (!normalized)
57
+ return null;
58
+ const index = notes.findIndex((note) => note.noteId === noteId);
59
+ if (index === -1)
60
+ return null;
61
+ const updated = [...notes];
62
+ updated[index] = { ...updated[index], text: normalized };
43
63
  return updated;
44
64
  }
65
+ function removeStaffNote(notes, noteId) {
66
+ const next = notes.filter((note) => note.noteId !== noteId);
67
+ return next.length === notes.length ? null : next;
68
+ }
@@ -1,8 +1,10 @@
1
+ export type VipExpiryWarningTier = '24h' | '1h';
1
2
  export type TVipRoom = {
2
3
  ownerId: string;
3
4
  guildId: string;
4
5
  channelId: string;
5
6
  expiresAt: Date;
7
+ expiryWarningsSent?: VipExpiryWarningTier[];
6
8
  memberIds: string[];
7
9
  createdAt: Date;
8
10
  updatedAt: Date;
@@ -45,6 +45,15 @@ export declare const VipRoomSchema: Schema<TVipRoom, import("mongoose").Model<TV
45
45
  }, "id"> & {
46
46
  id: string;
47
47
  }> | undefined;
48
+ expiryWarningsSent?: import("mongoose").SchemaDefinitionProperty<import("./types/vipRoom").VipExpiryWarningTier[] | undefined, TVipRoom, import("mongoose").Document<unknown, {}, TVipRoom, {
49
+ id: string;
50
+ }, import("mongoose").DefaultSchemaOptions> & Omit<TVipRoom & {
51
+ _id: import("mongoose").Types.ObjectId;
52
+ } & {
53
+ __v: number;
54
+ }, "id"> & {
55
+ id: string;
56
+ }> | undefined;
48
57
  memberIds?: import("mongoose").SchemaDefinitionProperty<string[], TVipRoom, import("mongoose").Document<unknown, {}, TVipRoom, {
49
58
  id: string;
50
59
  }, import("mongoose").DefaultSchemaOptions> & Omit<TVipRoom & {
@@ -10,6 +10,11 @@ exports.VipRoomSchema = new mongoose_1.Schema({
10
10
  type: [String],
11
11
  default: []
12
12
  },
13
+ expiryWarningsSent: {
14
+ type: [String],
15
+ enum: ['24h', '1h'],
16
+ default: []
17
+ },
13
18
  expiresAt: { type: Date, required: true }
14
19
  }, { timestamps: true });
15
20
  exports.VipRoomSchema.index({ expiresAt: 1 });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gambling-bot-shared",
3
- "version": "1.0.7",
3
+ "version": "1.0.9",
4
4
  "license": "MIT",
5
5
  "type": "commonjs",
6
6
  "repository": {