Skip to content

Commit 152f416

Browse files
committed
Add createTracker in-game command
- refactor getCommandTracker
1 parent 669776c commit 152f416

File tree

1 file changed

+31
-5
lines changed

1 file changed

+31
-5
lines changed

src/structures/RustPlus.js

+31-5
Original file line numberDiff line numberDiff line change
@@ -2751,23 +2751,49 @@ class RustPlus extends RustPlusLib {
27512751
async getCommandTracker(commandString) {
27522752
const args = commandString.split(' ');
27532753
const subCommand = args[1]?.toLowerCase();
2754-
const playerId = args[2];
2755-
const trackerId = args[3] ?? null;
2756-
2757-
if (playerId === null || playerId === undefined) {
2758-
return;
2754+
2755+
if (subCommand === 'create') {
2756+
const trackerIdParts = args.slice(2);
2757+
const customTrackerId = trackerIdParts.length > 0 ? trackerIdParts.join(' ') : null;
2758+
return await this.createTracker(customTrackerId);
27592759
}
27602760

27612761
if (subCommand === 'add') {
2762+
const playerId = args[2];
2763+
const trackerId = args.slice(3).join(' ').trim() || null;
2764+
if (!playerId) return;
27622765
return await this.addPlayerToTracker(trackerId, playerId);
27632766
}
27642767

27652768
if (subCommand === 'remove') {
2769+
const playerId = args[2];
2770+
const trackerId = args.slice(3).join(' ').trim() || null;
2771+
if (!playerId) return;
27662772
return await this.removePlayerFromTracker(trackerId, playerId);
27672773
}
2774+
2775+
if (!args[2]) return;
27682776
}
27692777

27702778

2779+
async createTracker(inputTrackerId = null) {
2780+
const instance = Client.client.getInstance(this.guildId);
2781+
const serverId = instance?.activeServer;
2782+
if (!serverId) {
2783+
return Client.client.intlGet(this.guildId, 'activeRustServerNotFound');
2784+
}
2785+
2786+
const trackerId = await Client.client.createTrackerInstance(this.guildId, serverId, inputTrackerId);
2787+
2788+
if (!trackerId) {
2789+
return Client.client.intlGet(this.guildId, 'trackerIdAlreadyExists', { trackerId: inputTrackerId });
2790+
}
2791+
2792+
await DiscordMessages.sendTrackerMessage(this.guildId, trackerId);
2793+
2794+
return Client.client.intlGet(this.guildId, 'trackerCreated', { trackerId });
2795+
}
2796+
27712797
async addPlayerToTracker(trackerId, id) {
27722798
const instance = Client.client.getInstance(this.guildId);
27732799
if (!instance) {

0 commit comments

Comments
 (0)