@erlcjs/core 1.0.3 → 1.1.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/dist/index.d.mts +87 -3
- package/dist/index.d.ts +87 -3
- package/dist/index.js +124 -2
- package/dist/index.mjs +122 -2
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -292,7 +292,7 @@ interface RawServerData {
|
|
|
292
292
|
/**
|
|
293
293
|
* Server staff lists.
|
|
294
294
|
*/
|
|
295
|
-
Staff?: RawStaffData
|
|
295
|
+
Staff?: RawStaffData;
|
|
296
296
|
/**
|
|
297
297
|
* Server join/leave logs.
|
|
298
298
|
*/
|
|
@@ -1069,6 +1069,82 @@ declare class ModCallManager {
|
|
|
1069
1069
|
updateCache(rawCommands: RawModCall[]): Map<string, ModCall>;
|
|
1070
1070
|
}
|
|
1071
1071
|
|
|
1072
|
+
/**
|
|
1073
|
+
* Represents a staff member.
|
|
1074
|
+
* @public
|
|
1075
|
+
*/
|
|
1076
|
+
declare class Staff extends Base {
|
|
1077
|
+
/**
|
|
1078
|
+
* The staff members user id.
|
|
1079
|
+
*/
|
|
1080
|
+
id: number;
|
|
1081
|
+
/**
|
|
1082
|
+
* The staff members username.
|
|
1083
|
+
*/
|
|
1084
|
+
username: string;
|
|
1085
|
+
/**
|
|
1086
|
+
* Whether or not the staff member is online.
|
|
1087
|
+
*/
|
|
1088
|
+
online: boolean;
|
|
1089
|
+
/**
|
|
1090
|
+
* The player instance of the staff member if they are online.
|
|
1091
|
+
*/
|
|
1092
|
+
player?: Player;
|
|
1093
|
+
/**
|
|
1094
|
+
* Creates an instance of Staff.
|
|
1095
|
+
* @param client - The ERLCApi client.
|
|
1096
|
+
* @param userId - The user id.
|
|
1097
|
+
* @param username - The username.
|
|
1098
|
+
*/
|
|
1099
|
+
constructor(client: Client, userId: string, username: string);
|
|
1100
|
+
/**
|
|
1101
|
+
* Patches the Staff structure with new raw data.
|
|
1102
|
+
* @param userId - The user id.
|
|
1103
|
+
* @param username - The username.
|
|
1104
|
+
* @returns This staff instance.
|
|
1105
|
+
*/
|
|
1106
|
+
_patch(userId: string, username: string): this;
|
|
1107
|
+
}
|
|
1108
|
+
|
|
1109
|
+
/**
|
|
1110
|
+
* Manager responsible for fetching, caching, and updating Vehicle structures.
|
|
1111
|
+
* @public
|
|
1112
|
+
*/
|
|
1113
|
+
declare class StaffManager {
|
|
1114
|
+
private readonly client;
|
|
1115
|
+
/**
|
|
1116
|
+
* Map cache of admins, keyed by their userId.
|
|
1117
|
+
*/
|
|
1118
|
+
admins: Map<number, Staff>;
|
|
1119
|
+
/**
|
|
1120
|
+
* Map cache of mods, keyed by their userId.
|
|
1121
|
+
*/
|
|
1122
|
+
mods: Map<number, Staff>;
|
|
1123
|
+
/**
|
|
1124
|
+
* Map cache of helpers, keyed by their userId.
|
|
1125
|
+
*/
|
|
1126
|
+
helpers: Map<number, Staff>;
|
|
1127
|
+
/**
|
|
1128
|
+
* Creates an instance of StaffManager.
|
|
1129
|
+
* @param client - The ERLCApi client.
|
|
1130
|
+
*/
|
|
1131
|
+
constructor(client: Client);
|
|
1132
|
+
/**
|
|
1133
|
+
* Fetches all staff members.
|
|
1134
|
+
* Updates the staff cache.
|
|
1135
|
+
* @returns A promise resolving to a Map of active Vehicles.
|
|
1136
|
+
*/
|
|
1137
|
+
fetchAll(): Promise<Map<string, Map<number, Staff>>>;
|
|
1138
|
+
/**
|
|
1139
|
+
* Re-synchronizes the cache with the raw staff list from the API.
|
|
1140
|
+
* Emits staffAdd and staffRemove events.
|
|
1141
|
+
* @param rawStaff - Raw staff list payload.
|
|
1142
|
+
* @returns The updated staff cache Map.
|
|
1143
|
+
*/
|
|
1144
|
+
updateCache(rawStaff: RawStaffData): Map<string, Map<number, Staff>>;
|
|
1145
|
+
private _updateCache;
|
|
1146
|
+
}
|
|
1147
|
+
|
|
1072
1148
|
/**
|
|
1073
1149
|
* Event names emitted by the ERLCApi Client.
|
|
1074
1150
|
* @public
|
|
@@ -1103,7 +1179,11 @@ declare enum ERLCEvents {
|
|
|
1103
1179
|
/** Emitted when an emergency call is cleared. */
|
|
1104
1180
|
emergencyCallRemove = "EMERGENCY_CALL_REMOVE",
|
|
1105
1181
|
/** Emitted when an emergency call is updated. */
|
|
1106
|
-
emergencyCallUpdate = "EMERGENCY_CALL_UPDATE"
|
|
1182
|
+
emergencyCallUpdate = "EMERGENCY_CALL_UPDATE",
|
|
1183
|
+
/** Emitted when a staff member is added */
|
|
1184
|
+
staffAdd = "STAFF_ADD",
|
|
1185
|
+
/** Emitted when a staff member is removed */
|
|
1186
|
+
staffRemove = "STAFF_REMOVE"
|
|
1107
1187
|
}
|
|
1108
1188
|
/**
|
|
1109
1189
|
* Interface mapping client event names to their callback parameters.
|
|
@@ -1140,6 +1220,8 @@ interface ClientEvents {
|
|
|
1140
1220
|
[ERLCEvents.emergencyCallRemove]: [call: EmergencyCall];
|
|
1141
1221
|
/** Emitted when an emergency call is updated. */
|
|
1142
1222
|
[ERLCEvents.emergencyCallUpdate]: [oldCall: EmergencyCall | null, newCall: EmergencyCall];
|
|
1223
|
+
[ERLCEvents.staffAdd]: [staff: Staff, type: 'Admin' | 'Mod' | 'Helper'];
|
|
1224
|
+
[ERLCEvents.staffRemove]: [staff: Staff, type: 'Admin' | 'Mod' | 'Helper'];
|
|
1143
1225
|
/** Emitted when an error is caught during polling or gateway operations. */
|
|
1144
1226
|
error: [error: unknown];
|
|
1145
1227
|
}
|
|
@@ -1167,6 +1249,8 @@ declare class Client extends EventEmitter<ClientEvents> {
|
|
|
1167
1249
|
killLogs: KillLogManager;
|
|
1168
1250
|
/** Manager for moderator call logs. */
|
|
1169
1251
|
modCalls: ModCallManager;
|
|
1252
|
+
/** Manager for staff members. */
|
|
1253
|
+
staff: StaffManager;
|
|
1170
1254
|
/** Webhook Gateway server instance, if enabled. */
|
|
1171
1255
|
private readonly gateway?;
|
|
1172
1256
|
/**
|
|
@@ -1215,4 +1299,4 @@ declare class InvalidServerKeyError extends Error {
|
|
|
1215
1299
|
constructor(message?: string);
|
|
1216
1300
|
}
|
|
1217
1301
|
|
|
1218
|
-
export { Base, Client, type ClientEvents, type ClientOptions, CommandLog, CommandLogManager, CommandManager, ERLCEvents, EmergencyCall, EmergencyCallManager, InvalidServerKeyError, KillLog, KillLogManager, ModCall, ModCallManager, Player, PlayerManager, type RawCommandLog, type RawEmergencyCall, type RawJoinLog, type RawKillLog, type RawModCall, type RawPlayerData, type RawServerData, type RawStaffData, type RawVehicle, RestManager, Server, ServerManager, Vehicle, VehicleManager, WebhookServer };
|
|
1302
|
+
export { Base, Client, type ClientEvents, type ClientOptions, CommandLog, CommandLogManager, CommandManager, ERLCEvents, EmergencyCall, EmergencyCallManager, InvalidServerKeyError, KillLog, KillLogManager, ModCall, ModCallManager, Player, PlayerManager, type RawCommandLog, type RawEmergencyCall, type RawJoinLog, type RawKillLog, type RawModCall, type RawPlayerData, type RawServerData, type RawStaffData, type RawVehicle, RestManager, Server, ServerManager, Staff, StaffManager, Vehicle, VehicleManager, WebhookServer };
|
package/dist/index.d.ts
CHANGED
|
@@ -292,7 +292,7 @@ interface RawServerData {
|
|
|
292
292
|
/**
|
|
293
293
|
* Server staff lists.
|
|
294
294
|
*/
|
|
295
|
-
Staff?: RawStaffData
|
|
295
|
+
Staff?: RawStaffData;
|
|
296
296
|
/**
|
|
297
297
|
* Server join/leave logs.
|
|
298
298
|
*/
|
|
@@ -1069,6 +1069,82 @@ declare class ModCallManager {
|
|
|
1069
1069
|
updateCache(rawCommands: RawModCall[]): Map<string, ModCall>;
|
|
1070
1070
|
}
|
|
1071
1071
|
|
|
1072
|
+
/**
|
|
1073
|
+
* Represents a staff member.
|
|
1074
|
+
* @public
|
|
1075
|
+
*/
|
|
1076
|
+
declare class Staff extends Base {
|
|
1077
|
+
/**
|
|
1078
|
+
* The staff members user id.
|
|
1079
|
+
*/
|
|
1080
|
+
id: number;
|
|
1081
|
+
/**
|
|
1082
|
+
* The staff members username.
|
|
1083
|
+
*/
|
|
1084
|
+
username: string;
|
|
1085
|
+
/**
|
|
1086
|
+
* Whether or not the staff member is online.
|
|
1087
|
+
*/
|
|
1088
|
+
online: boolean;
|
|
1089
|
+
/**
|
|
1090
|
+
* The player instance of the staff member if they are online.
|
|
1091
|
+
*/
|
|
1092
|
+
player?: Player;
|
|
1093
|
+
/**
|
|
1094
|
+
* Creates an instance of Staff.
|
|
1095
|
+
* @param client - The ERLCApi client.
|
|
1096
|
+
* @param userId - The user id.
|
|
1097
|
+
* @param username - The username.
|
|
1098
|
+
*/
|
|
1099
|
+
constructor(client: Client, userId: string, username: string);
|
|
1100
|
+
/**
|
|
1101
|
+
* Patches the Staff structure with new raw data.
|
|
1102
|
+
* @param userId - The user id.
|
|
1103
|
+
* @param username - The username.
|
|
1104
|
+
* @returns This staff instance.
|
|
1105
|
+
*/
|
|
1106
|
+
_patch(userId: string, username: string): this;
|
|
1107
|
+
}
|
|
1108
|
+
|
|
1109
|
+
/**
|
|
1110
|
+
* Manager responsible for fetching, caching, and updating Vehicle structures.
|
|
1111
|
+
* @public
|
|
1112
|
+
*/
|
|
1113
|
+
declare class StaffManager {
|
|
1114
|
+
private readonly client;
|
|
1115
|
+
/**
|
|
1116
|
+
* Map cache of admins, keyed by their userId.
|
|
1117
|
+
*/
|
|
1118
|
+
admins: Map<number, Staff>;
|
|
1119
|
+
/**
|
|
1120
|
+
* Map cache of mods, keyed by their userId.
|
|
1121
|
+
*/
|
|
1122
|
+
mods: Map<number, Staff>;
|
|
1123
|
+
/**
|
|
1124
|
+
* Map cache of helpers, keyed by their userId.
|
|
1125
|
+
*/
|
|
1126
|
+
helpers: Map<number, Staff>;
|
|
1127
|
+
/**
|
|
1128
|
+
* Creates an instance of StaffManager.
|
|
1129
|
+
* @param client - The ERLCApi client.
|
|
1130
|
+
*/
|
|
1131
|
+
constructor(client: Client);
|
|
1132
|
+
/**
|
|
1133
|
+
* Fetches all staff members.
|
|
1134
|
+
* Updates the staff cache.
|
|
1135
|
+
* @returns A promise resolving to a Map of active Vehicles.
|
|
1136
|
+
*/
|
|
1137
|
+
fetchAll(): Promise<Map<string, Map<number, Staff>>>;
|
|
1138
|
+
/**
|
|
1139
|
+
* Re-synchronizes the cache with the raw staff list from the API.
|
|
1140
|
+
* Emits staffAdd and staffRemove events.
|
|
1141
|
+
* @param rawStaff - Raw staff list payload.
|
|
1142
|
+
* @returns The updated staff cache Map.
|
|
1143
|
+
*/
|
|
1144
|
+
updateCache(rawStaff: RawStaffData): Map<string, Map<number, Staff>>;
|
|
1145
|
+
private _updateCache;
|
|
1146
|
+
}
|
|
1147
|
+
|
|
1072
1148
|
/**
|
|
1073
1149
|
* Event names emitted by the ERLCApi Client.
|
|
1074
1150
|
* @public
|
|
@@ -1103,7 +1179,11 @@ declare enum ERLCEvents {
|
|
|
1103
1179
|
/** Emitted when an emergency call is cleared. */
|
|
1104
1180
|
emergencyCallRemove = "EMERGENCY_CALL_REMOVE",
|
|
1105
1181
|
/** Emitted when an emergency call is updated. */
|
|
1106
|
-
emergencyCallUpdate = "EMERGENCY_CALL_UPDATE"
|
|
1182
|
+
emergencyCallUpdate = "EMERGENCY_CALL_UPDATE",
|
|
1183
|
+
/** Emitted when a staff member is added */
|
|
1184
|
+
staffAdd = "STAFF_ADD",
|
|
1185
|
+
/** Emitted when a staff member is removed */
|
|
1186
|
+
staffRemove = "STAFF_REMOVE"
|
|
1107
1187
|
}
|
|
1108
1188
|
/**
|
|
1109
1189
|
* Interface mapping client event names to their callback parameters.
|
|
@@ -1140,6 +1220,8 @@ interface ClientEvents {
|
|
|
1140
1220
|
[ERLCEvents.emergencyCallRemove]: [call: EmergencyCall];
|
|
1141
1221
|
/** Emitted when an emergency call is updated. */
|
|
1142
1222
|
[ERLCEvents.emergencyCallUpdate]: [oldCall: EmergencyCall | null, newCall: EmergencyCall];
|
|
1223
|
+
[ERLCEvents.staffAdd]: [staff: Staff, type: 'Admin' | 'Mod' | 'Helper'];
|
|
1224
|
+
[ERLCEvents.staffRemove]: [staff: Staff, type: 'Admin' | 'Mod' | 'Helper'];
|
|
1143
1225
|
/** Emitted when an error is caught during polling or gateway operations. */
|
|
1144
1226
|
error: [error: unknown];
|
|
1145
1227
|
}
|
|
@@ -1167,6 +1249,8 @@ declare class Client extends EventEmitter<ClientEvents> {
|
|
|
1167
1249
|
killLogs: KillLogManager;
|
|
1168
1250
|
/** Manager for moderator call logs. */
|
|
1169
1251
|
modCalls: ModCallManager;
|
|
1252
|
+
/** Manager for staff members. */
|
|
1253
|
+
staff: StaffManager;
|
|
1170
1254
|
/** Webhook Gateway server instance, if enabled. */
|
|
1171
1255
|
private readonly gateway?;
|
|
1172
1256
|
/**
|
|
@@ -1215,4 +1299,4 @@ declare class InvalidServerKeyError extends Error {
|
|
|
1215
1299
|
constructor(message?: string);
|
|
1216
1300
|
}
|
|
1217
1301
|
|
|
1218
|
-
export { Base, Client, type ClientEvents, type ClientOptions, CommandLog, CommandLogManager, CommandManager, ERLCEvents, EmergencyCall, EmergencyCallManager, InvalidServerKeyError, KillLog, KillLogManager, ModCall, ModCallManager, Player, PlayerManager, type RawCommandLog, type RawEmergencyCall, type RawJoinLog, type RawKillLog, type RawModCall, type RawPlayerData, type RawServerData, type RawStaffData, type RawVehicle, RestManager, Server, ServerManager, Vehicle, VehicleManager, WebhookServer };
|
|
1302
|
+
export { Base, Client, type ClientEvents, type ClientOptions, CommandLog, CommandLogManager, CommandManager, ERLCEvents, EmergencyCall, EmergencyCallManager, InvalidServerKeyError, KillLog, KillLogManager, ModCall, ModCallManager, Player, PlayerManager, type RawCommandLog, type RawEmergencyCall, type RawJoinLog, type RawKillLog, type RawModCall, type RawPlayerData, type RawServerData, type RawStaffData, type RawVehicle, RestManager, Server, ServerManager, Staff, StaffManager, Vehicle, VehicleManager, WebhookServer };
|
package/dist/index.js
CHANGED
|
@@ -21,7 +21,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
21
21
|
var index_exports = {};
|
|
22
22
|
__export(index_exports, {
|
|
23
23
|
Base: () => Base,
|
|
24
|
-
Client: () =>
|
|
24
|
+
Client: () => Client20,
|
|
25
25
|
CommandLog: () => CommandLog,
|
|
26
26
|
CommandLogManager: () => CommandLogManager,
|
|
27
27
|
CommandManager: () => CommandManager,
|
|
@@ -38,6 +38,8 @@ __export(index_exports, {
|
|
|
38
38
|
RestManager: () => RestManager,
|
|
39
39
|
Server: () => Server,
|
|
40
40
|
ServerManager: () => ServerManager,
|
|
41
|
+
Staff: () => Staff,
|
|
42
|
+
StaffManager: () => StaffManager,
|
|
41
43
|
Vehicle: () => Vehicle,
|
|
42
44
|
VehicleManager: () => VehicleManager,
|
|
43
45
|
WebhookServer: () => WebhookServer
|
|
@@ -1210,6 +1212,118 @@ var ModCallManager = class {
|
|
|
1210
1212
|
}
|
|
1211
1213
|
};
|
|
1212
1214
|
|
|
1215
|
+
// src/structures/staff.ts
|
|
1216
|
+
var Staff = class extends Base {
|
|
1217
|
+
/**
|
|
1218
|
+
* The staff members user id.
|
|
1219
|
+
*/
|
|
1220
|
+
id;
|
|
1221
|
+
/**
|
|
1222
|
+
* The staff members username.
|
|
1223
|
+
*/
|
|
1224
|
+
username;
|
|
1225
|
+
/**
|
|
1226
|
+
* Whether or not the staff member is online.
|
|
1227
|
+
*/
|
|
1228
|
+
online;
|
|
1229
|
+
/**
|
|
1230
|
+
* The player instance of the staff member if they are online.
|
|
1231
|
+
*/
|
|
1232
|
+
player;
|
|
1233
|
+
/**
|
|
1234
|
+
* Creates an instance of Staff.
|
|
1235
|
+
* @param client - The ERLCApi client.
|
|
1236
|
+
* @param userId - The user id.
|
|
1237
|
+
* @param username - The username.
|
|
1238
|
+
*/
|
|
1239
|
+
constructor(client, userId, username) {
|
|
1240
|
+
super(client);
|
|
1241
|
+
this._patch(userId, username);
|
|
1242
|
+
}
|
|
1243
|
+
/**
|
|
1244
|
+
* Patches the Staff structure with new raw data.
|
|
1245
|
+
* @param userId - The user id.
|
|
1246
|
+
* @param username - The username.
|
|
1247
|
+
* @returns This staff instance.
|
|
1248
|
+
*/
|
|
1249
|
+
_patch(userId, username) {
|
|
1250
|
+
this.id = Number(userId);
|
|
1251
|
+
this.username = username;
|
|
1252
|
+
this.online = this.client.players.cache.has(this.id);
|
|
1253
|
+
this.player = void 0;
|
|
1254
|
+
if (this.online === true) this.player = this.client.players.cache.get(this.id);
|
|
1255
|
+
return this;
|
|
1256
|
+
}
|
|
1257
|
+
};
|
|
1258
|
+
|
|
1259
|
+
// src/managers/staffmanager.ts
|
|
1260
|
+
var StaffManager = class {
|
|
1261
|
+
/**
|
|
1262
|
+
* Creates an instance of StaffManager.
|
|
1263
|
+
* @param client - The ERLCApi client.
|
|
1264
|
+
*/
|
|
1265
|
+
constructor(client) {
|
|
1266
|
+
this.client = client;
|
|
1267
|
+
}
|
|
1268
|
+
client;
|
|
1269
|
+
/**
|
|
1270
|
+
* Map cache of admins, keyed by their userId.
|
|
1271
|
+
*/
|
|
1272
|
+
admins = /* @__PURE__ */ new Map();
|
|
1273
|
+
/**
|
|
1274
|
+
* Map cache of mods, keyed by their userId.
|
|
1275
|
+
*/
|
|
1276
|
+
mods = /* @__PURE__ */ new Map();
|
|
1277
|
+
/**
|
|
1278
|
+
* Map cache of helpers, keyed by their userId.
|
|
1279
|
+
*/
|
|
1280
|
+
helpers = /* @__PURE__ */ new Map();
|
|
1281
|
+
/**
|
|
1282
|
+
* Fetches all staff members.
|
|
1283
|
+
* Updates the staff cache.
|
|
1284
|
+
* @returns A promise resolving to a Map of active Vehicles.
|
|
1285
|
+
*/
|
|
1286
|
+
async fetchAll() {
|
|
1287
|
+
const rawServer = await this.client.rest.request("GET", "/v2/server?Staff=true");
|
|
1288
|
+
const rawVehicles = rawServer.Staff;
|
|
1289
|
+
return this.updateCache(rawVehicles);
|
|
1290
|
+
}
|
|
1291
|
+
/**
|
|
1292
|
+
* Re-synchronizes the cache with the raw staff list from the API.
|
|
1293
|
+
* Emits staffAdd and staffRemove events.
|
|
1294
|
+
* @param rawStaff - Raw staff list payload.
|
|
1295
|
+
* @returns The updated staff cache Map.
|
|
1296
|
+
*/
|
|
1297
|
+
updateCache(rawStaff) {
|
|
1298
|
+
this._updateCache(rawStaff.Admins, "Admin");
|
|
1299
|
+
this._updateCache(rawStaff.Mods, "Mod");
|
|
1300
|
+
this._updateCache(rawStaff.Helpers, "Helper");
|
|
1301
|
+
return (/* @__PURE__ */ new Map()).set("Admins", this.admins).set("Mods", this.mods).set("Helpers", this.helpers);
|
|
1302
|
+
}
|
|
1303
|
+
_updateCache(data, type) {
|
|
1304
|
+
const activeUserIds = /* @__PURE__ */ new Set();
|
|
1305
|
+
const types = `${type}s`;
|
|
1306
|
+
let cache;
|
|
1307
|
+
if (type === "Admin") cache = this.admins;
|
|
1308
|
+
else if (type === "Mod") cache = this.mods;
|
|
1309
|
+
else cache = this.helpers;
|
|
1310
|
+
for (const [userId, username] of Object.entries(data)) {
|
|
1311
|
+
activeUserIds.add(Number(userId));
|
|
1312
|
+
const cachedUser = cache.get(Number(userId));
|
|
1313
|
+
if (cachedUser) return;
|
|
1314
|
+
const newStaff = new Staff(this.client, userId, username);
|
|
1315
|
+
cache.set(Number(userId), newStaff);
|
|
1316
|
+
this.client.emit("STAFF_ADD" /* staffAdd */, newStaff, type);
|
|
1317
|
+
}
|
|
1318
|
+
for (const cachedId of this.admins.keys()) {
|
|
1319
|
+
if (!activeUserIds.has(cachedId)) {
|
|
1320
|
+
this.client.emit("STAFF_REMOVE" /* staffRemove */, cache.get(cachedId), type);
|
|
1321
|
+
cache.delete(cachedId);
|
|
1322
|
+
}
|
|
1323
|
+
}
|
|
1324
|
+
}
|
|
1325
|
+
};
|
|
1326
|
+
|
|
1213
1327
|
// src/client/client.ts
|
|
1214
1328
|
var ERLCEvents = /* @__PURE__ */ ((ERLCEvents2) => {
|
|
1215
1329
|
ERLCEvents2["poll"] = "POLL";
|
|
@@ -1227,9 +1341,11 @@ var ERLCEvents = /* @__PURE__ */ ((ERLCEvents2) => {
|
|
|
1227
1341
|
ERLCEvents2["emergencyCallAdd"] = "EMERGENCY_CALL_ADD";
|
|
1228
1342
|
ERLCEvents2["emergencyCallRemove"] = "EMERGENCY_CALL_REMOVE";
|
|
1229
1343
|
ERLCEvents2["emergencyCallUpdate"] = "EMERGENCY_CALL_UPDATE";
|
|
1344
|
+
ERLCEvents2["staffAdd"] = "STAFF_ADD";
|
|
1345
|
+
ERLCEvents2["staffRemove"] = "STAFF_REMOVE";
|
|
1230
1346
|
return ERLCEvents2;
|
|
1231
1347
|
})(ERLCEvents || {});
|
|
1232
|
-
var
|
|
1348
|
+
var Client20 = class extends import_node_events.EventEmitter {
|
|
1233
1349
|
/**
|
|
1234
1350
|
* Creates an instance of Client.
|
|
1235
1351
|
* @param options - The ClientOptions configuration.
|
|
@@ -1246,6 +1362,7 @@ var Client18 = class extends import_node_events.EventEmitter {
|
|
|
1246
1362
|
this.emergencyCalls = new EmergencyCallManager(this);
|
|
1247
1363
|
this.killLogs = new KillLogManager(this);
|
|
1248
1364
|
this.modCalls = new ModCallManager(this);
|
|
1365
|
+
this.staff = new StaffManager(this);
|
|
1249
1366
|
if (options.webhook?.enabled) {
|
|
1250
1367
|
this.gateway = new WebhookServer(this);
|
|
1251
1368
|
this.gateway.listen();
|
|
@@ -1273,6 +1390,8 @@ var Client18 = class extends import_node_events.EventEmitter {
|
|
|
1273
1390
|
killLogs;
|
|
1274
1391
|
/** Manager for moderator call logs. */
|
|
1275
1392
|
modCalls;
|
|
1393
|
+
/** Manager for staff members. */
|
|
1394
|
+
staff;
|
|
1276
1395
|
/** Webhook Gateway server instance, if enabled. */
|
|
1277
1396
|
gateway;
|
|
1278
1397
|
/**
|
|
@@ -1289,6 +1408,7 @@ var Client18 = class extends import_node_events.EventEmitter {
|
|
|
1289
1408
|
if (server.EmergencyCalls) this.emergencyCalls.updateCache(server.EmergencyCalls);
|
|
1290
1409
|
if (server.KillLogs) this.killLogs.updateCache(server.KillLogs);
|
|
1291
1410
|
if (server.ModCalls) this.modCalls.updateCache(server.ModCalls);
|
|
1411
|
+
if (server.Staff) this.staff.updateCache(server.Staff);
|
|
1292
1412
|
} catch (err) {
|
|
1293
1413
|
this.emit("error", err);
|
|
1294
1414
|
}
|
|
@@ -1315,6 +1435,8 @@ var Client18 = class extends import_node_events.EventEmitter {
|
|
|
1315
1435
|
RestManager,
|
|
1316
1436
|
Server,
|
|
1317
1437
|
ServerManager,
|
|
1438
|
+
Staff,
|
|
1439
|
+
StaffManager,
|
|
1318
1440
|
Vehicle,
|
|
1319
1441
|
VehicleManager,
|
|
1320
1442
|
WebhookServer
|
package/dist/index.mjs
CHANGED
|
@@ -1164,6 +1164,118 @@ var ModCallManager = class {
|
|
|
1164
1164
|
}
|
|
1165
1165
|
};
|
|
1166
1166
|
|
|
1167
|
+
// src/structures/staff.ts
|
|
1168
|
+
var Staff = class extends Base {
|
|
1169
|
+
/**
|
|
1170
|
+
* The staff members user id.
|
|
1171
|
+
*/
|
|
1172
|
+
id;
|
|
1173
|
+
/**
|
|
1174
|
+
* The staff members username.
|
|
1175
|
+
*/
|
|
1176
|
+
username;
|
|
1177
|
+
/**
|
|
1178
|
+
* Whether or not the staff member is online.
|
|
1179
|
+
*/
|
|
1180
|
+
online;
|
|
1181
|
+
/**
|
|
1182
|
+
* The player instance of the staff member if they are online.
|
|
1183
|
+
*/
|
|
1184
|
+
player;
|
|
1185
|
+
/**
|
|
1186
|
+
* Creates an instance of Staff.
|
|
1187
|
+
* @param client - The ERLCApi client.
|
|
1188
|
+
* @param userId - The user id.
|
|
1189
|
+
* @param username - The username.
|
|
1190
|
+
*/
|
|
1191
|
+
constructor(client, userId, username) {
|
|
1192
|
+
super(client);
|
|
1193
|
+
this._patch(userId, username);
|
|
1194
|
+
}
|
|
1195
|
+
/**
|
|
1196
|
+
* Patches the Staff structure with new raw data.
|
|
1197
|
+
* @param userId - The user id.
|
|
1198
|
+
* @param username - The username.
|
|
1199
|
+
* @returns This staff instance.
|
|
1200
|
+
*/
|
|
1201
|
+
_patch(userId, username) {
|
|
1202
|
+
this.id = Number(userId);
|
|
1203
|
+
this.username = username;
|
|
1204
|
+
this.online = this.client.players.cache.has(this.id);
|
|
1205
|
+
this.player = void 0;
|
|
1206
|
+
if (this.online === true) this.player = this.client.players.cache.get(this.id);
|
|
1207
|
+
return this;
|
|
1208
|
+
}
|
|
1209
|
+
};
|
|
1210
|
+
|
|
1211
|
+
// src/managers/staffmanager.ts
|
|
1212
|
+
var StaffManager = class {
|
|
1213
|
+
/**
|
|
1214
|
+
* Creates an instance of StaffManager.
|
|
1215
|
+
* @param client - The ERLCApi client.
|
|
1216
|
+
*/
|
|
1217
|
+
constructor(client) {
|
|
1218
|
+
this.client = client;
|
|
1219
|
+
}
|
|
1220
|
+
client;
|
|
1221
|
+
/**
|
|
1222
|
+
* Map cache of admins, keyed by their userId.
|
|
1223
|
+
*/
|
|
1224
|
+
admins = /* @__PURE__ */ new Map();
|
|
1225
|
+
/**
|
|
1226
|
+
* Map cache of mods, keyed by their userId.
|
|
1227
|
+
*/
|
|
1228
|
+
mods = /* @__PURE__ */ new Map();
|
|
1229
|
+
/**
|
|
1230
|
+
* Map cache of helpers, keyed by their userId.
|
|
1231
|
+
*/
|
|
1232
|
+
helpers = /* @__PURE__ */ new Map();
|
|
1233
|
+
/**
|
|
1234
|
+
* Fetches all staff members.
|
|
1235
|
+
* Updates the staff cache.
|
|
1236
|
+
* @returns A promise resolving to a Map of active Vehicles.
|
|
1237
|
+
*/
|
|
1238
|
+
async fetchAll() {
|
|
1239
|
+
const rawServer = await this.client.rest.request("GET", "/v2/server?Staff=true");
|
|
1240
|
+
const rawVehicles = rawServer.Staff;
|
|
1241
|
+
return this.updateCache(rawVehicles);
|
|
1242
|
+
}
|
|
1243
|
+
/**
|
|
1244
|
+
* Re-synchronizes the cache with the raw staff list from the API.
|
|
1245
|
+
* Emits staffAdd and staffRemove events.
|
|
1246
|
+
* @param rawStaff - Raw staff list payload.
|
|
1247
|
+
* @returns The updated staff cache Map.
|
|
1248
|
+
*/
|
|
1249
|
+
updateCache(rawStaff) {
|
|
1250
|
+
this._updateCache(rawStaff.Admins, "Admin");
|
|
1251
|
+
this._updateCache(rawStaff.Mods, "Mod");
|
|
1252
|
+
this._updateCache(rawStaff.Helpers, "Helper");
|
|
1253
|
+
return (/* @__PURE__ */ new Map()).set("Admins", this.admins).set("Mods", this.mods).set("Helpers", this.helpers);
|
|
1254
|
+
}
|
|
1255
|
+
_updateCache(data, type) {
|
|
1256
|
+
const activeUserIds = /* @__PURE__ */ new Set();
|
|
1257
|
+
const types = `${type}s`;
|
|
1258
|
+
let cache;
|
|
1259
|
+
if (type === "Admin") cache = this.admins;
|
|
1260
|
+
else if (type === "Mod") cache = this.mods;
|
|
1261
|
+
else cache = this.helpers;
|
|
1262
|
+
for (const [userId, username] of Object.entries(data)) {
|
|
1263
|
+
activeUserIds.add(Number(userId));
|
|
1264
|
+
const cachedUser = cache.get(Number(userId));
|
|
1265
|
+
if (cachedUser) return;
|
|
1266
|
+
const newStaff = new Staff(this.client, userId, username);
|
|
1267
|
+
cache.set(Number(userId), newStaff);
|
|
1268
|
+
this.client.emit("STAFF_ADD" /* staffAdd */, newStaff, type);
|
|
1269
|
+
}
|
|
1270
|
+
for (const cachedId of this.admins.keys()) {
|
|
1271
|
+
if (!activeUserIds.has(cachedId)) {
|
|
1272
|
+
this.client.emit("STAFF_REMOVE" /* staffRemove */, cache.get(cachedId), type);
|
|
1273
|
+
cache.delete(cachedId);
|
|
1274
|
+
}
|
|
1275
|
+
}
|
|
1276
|
+
}
|
|
1277
|
+
};
|
|
1278
|
+
|
|
1167
1279
|
// src/client/client.ts
|
|
1168
1280
|
var ERLCEvents = /* @__PURE__ */ ((ERLCEvents2) => {
|
|
1169
1281
|
ERLCEvents2["poll"] = "POLL";
|
|
@@ -1181,9 +1293,11 @@ var ERLCEvents = /* @__PURE__ */ ((ERLCEvents2) => {
|
|
|
1181
1293
|
ERLCEvents2["emergencyCallAdd"] = "EMERGENCY_CALL_ADD";
|
|
1182
1294
|
ERLCEvents2["emergencyCallRemove"] = "EMERGENCY_CALL_REMOVE";
|
|
1183
1295
|
ERLCEvents2["emergencyCallUpdate"] = "EMERGENCY_CALL_UPDATE";
|
|
1296
|
+
ERLCEvents2["staffAdd"] = "STAFF_ADD";
|
|
1297
|
+
ERLCEvents2["staffRemove"] = "STAFF_REMOVE";
|
|
1184
1298
|
return ERLCEvents2;
|
|
1185
1299
|
})(ERLCEvents || {});
|
|
1186
|
-
var
|
|
1300
|
+
var Client20 = class extends EventEmitter {
|
|
1187
1301
|
/**
|
|
1188
1302
|
* Creates an instance of Client.
|
|
1189
1303
|
* @param options - The ClientOptions configuration.
|
|
@@ -1200,6 +1314,7 @@ var Client18 = class extends EventEmitter {
|
|
|
1200
1314
|
this.emergencyCalls = new EmergencyCallManager(this);
|
|
1201
1315
|
this.killLogs = new KillLogManager(this);
|
|
1202
1316
|
this.modCalls = new ModCallManager(this);
|
|
1317
|
+
this.staff = new StaffManager(this);
|
|
1203
1318
|
if (options.webhook?.enabled) {
|
|
1204
1319
|
this.gateway = new WebhookServer(this);
|
|
1205
1320
|
this.gateway.listen();
|
|
@@ -1227,6 +1342,8 @@ var Client18 = class extends EventEmitter {
|
|
|
1227
1342
|
killLogs;
|
|
1228
1343
|
/** Manager for moderator call logs. */
|
|
1229
1344
|
modCalls;
|
|
1345
|
+
/** Manager for staff members. */
|
|
1346
|
+
staff;
|
|
1230
1347
|
/** Webhook Gateway server instance, if enabled. */
|
|
1231
1348
|
gateway;
|
|
1232
1349
|
/**
|
|
@@ -1243,6 +1360,7 @@ var Client18 = class extends EventEmitter {
|
|
|
1243
1360
|
if (server.EmergencyCalls) this.emergencyCalls.updateCache(server.EmergencyCalls);
|
|
1244
1361
|
if (server.KillLogs) this.killLogs.updateCache(server.KillLogs);
|
|
1245
1362
|
if (server.ModCalls) this.modCalls.updateCache(server.ModCalls);
|
|
1363
|
+
if (server.Staff) this.staff.updateCache(server.Staff);
|
|
1246
1364
|
} catch (err) {
|
|
1247
1365
|
this.emit("error", err);
|
|
1248
1366
|
}
|
|
@@ -1251,7 +1369,7 @@ var Client18 = class extends EventEmitter {
|
|
|
1251
1369
|
};
|
|
1252
1370
|
export {
|
|
1253
1371
|
Base,
|
|
1254
|
-
|
|
1372
|
+
Client20 as Client,
|
|
1255
1373
|
CommandLog,
|
|
1256
1374
|
CommandLogManager,
|
|
1257
1375
|
CommandManager,
|
|
@@ -1268,6 +1386,8 @@ export {
|
|
|
1268
1386
|
RestManager,
|
|
1269
1387
|
Server,
|
|
1270
1388
|
ServerManager,
|
|
1389
|
+
Staff,
|
|
1390
|
+
StaffManager,
|
|
1271
1391
|
Vehicle,
|
|
1272
1392
|
VehicleManager,
|
|
1273
1393
|
WebhookServer
|