@erlcjs/core 1.0.2 → 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/README.md +1 -1
- package/dist/index.d.mts +87 -3
- package/dist/index.d.ts +87 -3
- package/dist/index.js +124 -5
- package/dist/index.mjs +122 -5
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -102,7 +102,7 @@ console.log(`Vehicle model: ${vehicle.name}, Owner: ${vehicle.ownerUsername}`);
|
|
|
102
102
|
### Executing Commands
|
|
103
103
|
Issue custom commands directly:
|
|
104
104
|
```typescript
|
|
105
|
-
await client.commands.execute(':heal
|
|
105
|
+
await client.commands.execute(':heal user');
|
|
106
106
|
```
|
|
107
107
|
|
|
108
108
|
## Documentation
|
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
|
|
@@ -83,7 +85,6 @@ var RestManager = class {
|
|
|
83
85
|
* @throws Error - for other HTTP error codes.
|
|
84
86
|
*/
|
|
85
87
|
async request(method, endpoint, body) {
|
|
86
|
-
console.log(method, endpoint, body);
|
|
87
88
|
return new Promise((resolve, reject) => {
|
|
88
89
|
this.queue.push(async () => {
|
|
89
90
|
try {
|
|
@@ -1211,6 +1212,118 @@ var ModCallManager = class {
|
|
|
1211
1212
|
}
|
|
1212
1213
|
};
|
|
1213
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
|
+
|
|
1214
1327
|
// src/client/client.ts
|
|
1215
1328
|
var ERLCEvents = /* @__PURE__ */ ((ERLCEvents2) => {
|
|
1216
1329
|
ERLCEvents2["poll"] = "POLL";
|
|
@@ -1228,9 +1341,11 @@ var ERLCEvents = /* @__PURE__ */ ((ERLCEvents2) => {
|
|
|
1228
1341
|
ERLCEvents2["emergencyCallAdd"] = "EMERGENCY_CALL_ADD";
|
|
1229
1342
|
ERLCEvents2["emergencyCallRemove"] = "EMERGENCY_CALL_REMOVE";
|
|
1230
1343
|
ERLCEvents2["emergencyCallUpdate"] = "EMERGENCY_CALL_UPDATE";
|
|
1344
|
+
ERLCEvents2["staffAdd"] = "STAFF_ADD";
|
|
1345
|
+
ERLCEvents2["staffRemove"] = "STAFF_REMOVE";
|
|
1231
1346
|
return ERLCEvents2;
|
|
1232
1347
|
})(ERLCEvents || {});
|
|
1233
|
-
var
|
|
1348
|
+
var Client20 = class extends import_node_events.EventEmitter {
|
|
1234
1349
|
/**
|
|
1235
1350
|
* Creates an instance of Client.
|
|
1236
1351
|
* @param options - The ClientOptions configuration.
|
|
@@ -1247,6 +1362,7 @@ var Client18 = class extends import_node_events.EventEmitter {
|
|
|
1247
1362
|
this.emergencyCalls = new EmergencyCallManager(this);
|
|
1248
1363
|
this.killLogs = new KillLogManager(this);
|
|
1249
1364
|
this.modCalls = new ModCallManager(this);
|
|
1365
|
+
this.staff = new StaffManager(this);
|
|
1250
1366
|
if (options.webhook?.enabled) {
|
|
1251
1367
|
this.gateway = new WebhookServer(this);
|
|
1252
1368
|
this.gateway.listen();
|
|
@@ -1274,24 +1390,25 @@ var Client18 = class extends import_node_events.EventEmitter {
|
|
|
1274
1390
|
killLogs;
|
|
1275
1391
|
/** Manager for moderator call logs. */
|
|
1276
1392
|
modCalls;
|
|
1393
|
+
/** Manager for staff members. */
|
|
1394
|
+
staff;
|
|
1277
1395
|
/** Webhook Gateway server instance, if enabled. */
|
|
1278
1396
|
gateway;
|
|
1279
1397
|
/**
|
|
1280
1398
|
* Starts the periodic api-polling loop if enabled.
|
|
1281
1399
|
*/
|
|
1282
1400
|
startPolling() {
|
|
1283
|
-
console.log("begin polling");
|
|
1284
1401
|
setInterval(async () => {
|
|
1285
1402
|
try {
|
|
1286
1403
|
const server = await this.server.fetch();
|
|
1287
1404
|
this.emit("POLL" /* poll */, server);
|
|
1288
|
-
console.log("fetch");
|
|
1289
1405
|
if (server.Players) this.players.updateCache(server.Players);
|
|
1290
1406
|
if (server.Vehicles) this.vehicles.updateCache(server.Vehicles);
|
|
1291
1407
|
if (server.CommandLogs) this.commandLogs.updateCache(server.CommandLogs);
|
|
1292
1408
|
if (server.EmergencyCalls) this.emergencyCalls.updateCache(server.EmergencyCalls);
|
|
1293
1409
|
if (server.KillLogs) this.killLogs.updateCache(server.KillLogs);
|
|
1294
1410
|
if (server.ModCalls) this.modCalls.updateCache(server.ModCalls);
|
|
1411
|
+
if (server.Staff) this.staff.updateCache(server.Staff);
|
|
1295
1412
|
} catch (err) {
|
|
1296
1413
|
this.emit("error", err);
|
|
1297
1414
|
}
|
|
@@ -1318,6 +1435,8 @@ var Client18 = class extends import_node_events.EventEmitter {
|
|
|
1318
1435
|
RestManager,
|
|
1319
1436
|
Server,
|
|
1320
1437
|
ServerManager,
|
|
1438
|
+
Staff,
|
|
1439
|
+
StaffManager,
|
|
1321
1440
|
Vehicle,
|
|
1322
1441
|
VehicleManager,
|
|
1323
1442
|
WebhookServer
|
package/dist/index.mjs
CHANGED
|
@@ -37,7 +37,6 @@ var RestManager = class {
|
|
|
37
37
|
* @throws Error - for other HTTP error codes.
|
|
38
38
|
*/
|
|
39
39
|
async request(method, endpoint, body) {
|
|
40
|
-
console.log(method, endpoint, body);
|
|
41
40
|
return new Promise((resolve, reject) => {
|
|
42
41
|
this.queue.push(async () => {
|
|
43
42
|
try {
|
|
@@ -1165,6 +1164,118 @@ var ModCallManager = class {
|
|
|
1165
1164
|
}
|
|
1166
1165
|
};
|
|
1167
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
|
+
|
|
1168
1279
|
// src/client/client.ts
|
|
1169
1280
|
var ERLCEvents = /* @__PURE__ */ ((ERLCEvents2) => {
|
|
1170
1281
|
ERLCEvents2["poll"] = "POLL";
|
|
@@ -1182,9 +1293,11 @@ var ERLCEvents = /* @__PURE__ */ ((ERLCEvents2) => {
|
|
|
1182
1293
|
ERLCEvents2["emergencyCallAdd"] = "EMERGENCY_CALL_ADD";
|
|
1183
1294
|
ERLCEvents2["emergencyCallRemove"] = "EMERGENCY_CALL_REMOVE";
|
|
1184
1295
|
ERLCEvents2["emergencyCallUpdate"] = "EMERGENCY_CALL_UPDATE";
|
|
1296
|
+
ERLCEvents2["staffAdd"] = "STAFF_ADD";
|
|
1297
|
+
ERLCEvents2["staffRemove"] = "STAFF_REMOVE";
|
|
1185
1298
|
return ERLCEvents2;
|
|
1186
1299
|
})(ERLCEvents || {});
|
|
1187
|
-
var
|
|
1300
|
+
var Client20 = class extends EventEmitter {
|
|
1188
1301
|
/**
|
|
1189
1302
|
* Creates an instance of Client.
|
|
1190
1303
|
* @param options - The ClientOptions configuration.
|
|
@@ -1201,6 +1314,7 @@ var Client18 = class extends EventEmitter {
|
|
|
1201
1314
|
this.emergencyCalls = new EmergencyCallManager(this);
|
|
1202
1315
|
this.killLogs = new KillLogManager(this);
|
|
1203
1316
|
this.modCalls = new ModCallManager(this);
|
|
1317
|
+
this.staff = new StaffManager(this);
|
|
1204
1318
|
if (options.webhook?.enabled) {
|
|
1205
1319
|
this.gateway = new WebhookServer(this);
|
|
1206
1320
|
this.gateway.listen();
|
|
@@ -1228,24 +1342,25 @@ var Client18 = class extends EventEmitter {
|
|
|
1228
1342
|
killLogs;
|
|
1229
1343
|
/** Manager for moderator call logs. */
|
|
1230
1344
|
modCalls;
|
|
1345
|
+
/** Manager for staff members. */
|
|
1346
|
+
staff;
|
|
1231
1347
|
/** Webhook Gateway server instance, if enabled. */
|
|
1232
1348
|
gateway;
|
|
1233
1349
|
/**
|
|
1234
1350
|
* Starts the periodic api-polling loop if enabled.
|
|
1235
1351
|
*/
|
|
1236
1352
|
startPolling() {
|
|
1237
|
-
console.log("begin polling");
|
|
1238
1353
|
setInterval(async () => {
|
|
1239
1354
|
try {
|
|
1240
1355
|
const server = await this.server.fetch();
|
|
1241
1356
|
this.emit("POLL" /* poll */, server);
|
|
1242
|
-
console.log("fetch");
|
|
1243
1357
|
if (server.Players) this.players.updateCache(server.Players);
|
|
1244
1358
|
if (server.Vehicles) this.vehicles.updateCache(server.Vehicles);
|
|
1245
1359
|
if (server.CommandLogs) this.commandLogs.updateCache(server.CommandLogs);
|
|
1246
1360
|
if (server.EmergencyCalls) this.emergencyCalls.updateCache(server.EmergencyCalls);
|
|
1247
1361
|
if (server.KillLogs) this.killLogs.updateCache(server.KillLogs);
|
|
1248
1362
|
if (server.ModCalls) this.modCalls.updateCache(server.ModCalls);
|
|
1363
|
+
if (server.Staff) this.staff.updateCache(server.Staff);
|
|
1249
1364
|
} catch (err) {
|
|
1250
1365
|
this.emit("error", err);
|
|
1251
1366
|
}
|
|
@@ -1254,7 +1369,7 @@ var Client18 = class extends EventEmitter {
|
|
|
1254
1369
|
};
|
|
1255
1370
|
export {
|
|
1256
1371
|
Base,
|
|
1257
|
-
|
|
1372
|
+
Client20 as Client,
|
|
1258
1373
|
CommandLog,
|
|
1259
1374
|
CommandLogManager,
|
|
1260
1375
|
CommandManager,
|
|
@@ -1271,6 +1386,8 @@ export {
|
|
|
1271
1386
|
RestManager,
|
|
1272
1387
|
Server,
|
|
1273
1388
|
ServerManager,
|
|
1389
|
+
Staff,
|
|
1390
|
+
StaffManager,
|
|
1274
1391
|
Vehicle,
|
|
1275
1392
|
VehicleManager,
|
|
1276
1393
|
WebhookServer
|