gambling-bot-shared 1.0.6 → 1.0.8

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
@@ -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
 
@@ -0,0 +1,30 @@
1
+ export type GuildWipeEntity = 'all' | 'users' | 'transactions' | 'atm' | 'raffles' | 'predictions' | 'vip' | 'blackjack';
2
+ export type GuildDataWipeDeleteResult = {
3
+ deletedCount?: number;
4
+ };
5
+ export type GuildDataWipeModel = {
6
+ deleteMany: (filter: {
7
+ guildId: string;
8
+ }) => Promise<GuildDataWipeDeleteResult>;
9
+ };
10
+ export type GuildDataWipeModels = {
11
+ transactions: GuildDataWipeModel;
12
+ atmRequests: GuildDataWipeModel;
13
+ raffles: GuildDataWipeModel;
14
+ predictions: GuildDataWipeModel;
15
+ vipRooms: GuildDataWipeModel;
16
+ blackjackGames: GuildDataWipeModel;
17
+ userBans: GuildDataWipeModel;
18
+ users: GuildDataWipeModel;
19
+ };
20
+ export type GuildDataWipeSummary = {
21
+ entities: GuildWipeEntity[];
22
+ deleted: Record<string, number>;
23
+ };
24
+ export declare function normalizeGuildWipeEntities(entities: GuildWipeEntity[]): Exclude<GuildWipeEntity, 'all'>[];
25
+ export declare function runGuildDataWipe({ guildId, entities, models }: {
26
+ guildId: string;
27
+ entities: GuildWipeEntity[];
28
+ models: GuildDataWipeModels;
29
+ }): Promise<GuildDataWipeSummary>;
30
+ export declare function formatGuildDataWipeSummary(summary: GuildDataWipeSummary): string;
@@ -0,0 +1,88 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.normalizeGuildWipeEntities = normalizeGuildWipeEntities;
4
+ exports.runGuildDataWipe = runGuildDataWipe;
5
+ exports.formatGuildDataWipeSummary = formatGuildDataWipeSummary;
6
+ const formatters_1 = require("../common/formatters");
7
+ const WIPE_ENTITY_ORDER = [
8
+ 'transactions',
9
+ 'atm',
10
+ 'raffles',
11
+ 'predictions',
12
+ 'vip',
13
+ 'blackjack',
14
+ 'users'
15
+ ];
16
+ const ENTITY_TO_MODEL_KEY = {
17
+ transactions: 'transactions',
18
+ atm: 'atmRequests',
19
+ raffles: 'raffles',
20
+ predictions: 'predictions',
21
+ vip: 'vipRooms',
22
+ blackjack: 'blackjackGames',
23
+ users: 'users'
24
+ };
25
+ const WIPE_LABELS = {
26
+ transactions: 'Transactions',
27
+ atmRequests: 'ATM requests',
28
+ raffles: 'Raffles',
29
+ predictions: 'Predictions',
30
+ vipRooms: 'VIP rooms',
31
+ blackjackGames: 'Blackjack games',
32
+ userBans: 'User bans',
33
+ users: 'Users'
34
+ };
35
+ async function countDeleted(result) {
36
+ return result.deletedCount ?? 0;
37
+ }
38
+ function normalizeGuildWipeEntities(entities) {
39
+ const withoutAll = entities.filter((entity) => entity !== 'all');
40
+ if (withoutAll.length !== entities.length) {
41
+ return [...WIPE_ENTITY_ORDER];
42
+ }
43
+ const selected = new Set(withoutAll);
44
+ return WIPE_ENTITY_ORDER.filter((entity) => selected.has(entity));
45
+ }
46
+ function buildWipeTargets(guildId, entities, models) {
47
+ const selected = new Set(entities);
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
+ }
58
+ const key = ENTITY_TO_MODEL_KEY[entity];
59
+ targets.push({
60
+ key,
61
+ label: WIPE_LABELS[key],
62
+ entity,
63
+ run: async () => countDeleted(await models[key].deleteMany({ guildId }))
64
+ });
65
+ return targets;
66
+ });
67
+ }
68
+ async function runGuildDataWipe({ guildId, entities, models }) {
69
+ const normalizedEntities = normalizeGuildWipeEntities(entities);
70
+ const targets = buildWipeTargets(guildId, normalizedEntities, models);
71
+ const deleted = {};
72
+ for (const target of targets) {
73
+ deleted[target.key] = await target.run();
74
+ }
75
+ return {
76
+ entities: normalizedEntities,
77
+ deleted
78
+ };
79
+ }
80
+ function formatGuildDataWipeSummary(summary) {
81
+ const lines = Object.entries(summary.deleted)
82
+ .filter(([, count]) => count > 0)
83
+ .map(([key, count]) => `• **${WIPE_LABELS[key] ?? key}**: ${(0, formatters_1.formatNumberToReadableString)(count)} removed`);
84
+ if (lines.length === 0) {
85
+ return 'Nothing to remove - guild operational data was already empty.';
86
+ }
87
+ return lines.join('\n');
88
+ }
@@ -1,4 +1,5 @@
1
1
  export * from './devAccess';
2
2
  export * from './bonusStressTest';
3
3
  export * from './casinoMonteCarlo';
4
+ export * from './guildDataWipe';
4
5
  export * from './yieldToEventLoop';
package/dist/dev/index.js CHANGED
@@ -17,4 +17,5 @@ Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./devAccess"), exports);
18
18
  __exportStar(require("./bonusStressTest"), exports);
19
19
  __exportStar(require("./casinoMonteCarlo"), exports);
20
+ __exportStar(require("./guildDataWipe"), exports);
20
21
  __exportStar(require("./yieldToEventLoop"), exports);
@@ -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");
@@ -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
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gambling-bot-shared",
3
- "version": "1.0.6",
3
+ "version": "1.0.8",
4
4
  "license": "MIT",
5
5
  "type": "commonjs",
6
6
  "repository": {