Skip to content

Commit

Permalink
Add events command
Browse files Browse the repository at this point in the history
  • Loading branch information
alexemanuelol committed Sep 16, 2023
1 parent 0ef4b81 commit 2e02fe9
Show file tree
Hide file tree
Showing 10 changed files with 174 additions and 2 deletions.
12 changes: 12 additions & 0 deletions docs/commands.md
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,7 @@ In-Game Command | Description
[**connection/connections**](commands.md#connectionconnections) | Get recent connection events.
[**death/deaths**](commands.md#deathdeaths) | Get recent death events.
[**decay**](commands.md#decay) | Get time before structure decay.
[**events**](commands.md#events) | Get recent events.
[**heli**](commands.md#heli) | Get information about Patrol Helicopter (Location, time since last downed, time since last on map).
[**large**](commands.md#large) | Get information about Large Oil Rig (Time till crate unlocks, time since last trigger).
[**leader**](commands.md#leader-1) | Give/Take the Team Leadership.
Expand Down Expand Up @@ -339,6 +340,17 @@ In-Game Command | Description
![In-Game Command decay Image](images/ingame_commands/decay_ingame.png)


## **events**

> **Get recent In-Game events.** Available events are cargo, heli, small, large, chinook
<br>Command: `!events` - Get last 5 events
<br>Command: `!events 3` - Get last 3 events
<br>Command: `!events cargo` - Get last 5 events from cargo
<br>Command: `!events cargo 2` - Get last 2 events from cargo
![In-Game Command events Image](images/ingame_commands/events_ingame.png)


## **heli**

> **Get information about Patrol Helicopter (Location, time since last downed, time since last on map).**
Expand Down
1 change: 1 addition & 0 deletions docs/full_list_features.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
- **connection/connections** - Display latest team connections.
- **death/deaths** - Display latest deaths.
- **decay** - Get decay time of different wall-types.
- **events** - Get recent events.
- **heli** - Get information regarding Patrol Helicopter.
- **large** - Get information regarding Large Oil Rig.
- **leader** - Transfer leadership.
Expand Down
Binary file added docs/images/ingame_commands/events_ingame.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions src/handlers/discordCommandHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ module.exports = {
commandLowerCase.startsWith(`${prefix}${client.intlGet(guildId, 'commandSyntaxDecay')}`)) {
response = rustplus.getCommandDecay(command);
}
else if (commandLowerCase.startsWith(`${prefix}${client.intlGet('en', 'commandSyntaxEvents')}`) ||
commandLowerCase.startsWith(`${prefix}${client.intlGet(guildId, 'commandSyntaxEvents')}`)) {
response = rustplus.getCommandEvents(command);
}
else if (commandLowerCase === `${prefix}${client.intlGet('en', 'commandSyntaxHeli')}` ||
commandLowerCase === `${prefix}${client.intlGet(guildId, 'commandSyntaxHeli')}`) {
response = rustplus.getCommandHeli();
Expand Down
4 changes: 4 additions & 0 deletions src/handlers/inGameCommandHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@ module.exports = {
commandLowerCase.startsWith(`${prefix}${client.intlGet(guildId, 'commandSyntaxDecay')}`)) {
rustplus.printCommandOutput(rustplus.getCommandDecay(command));
}
else if (commandLowerCase.startsWith(`${prefix}${client.intlGet('en', 'commandSyntaxEvents')}`) ||
commandLowerCase.startsWith(`${prefix}${client.intlGet(guildId, 'commandSyntaxEvents')}`)) {
rustplus.printCommandOutput(rustplus.getCommandEvents(command));
}
else if (commandLowerCase === `${prefix}${client.intlGet('en', 'commandSyntaxHeli')}` ||
commandLowerCase === `${prefix}${client.intlGet(guildId, 'commandSyntaxHeli')}`) {
rustplus.printCommandOutput(rustplus.getCommandHeli());
Expand Down
2 changes: 2 additions & 0 deletions src/languages/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@
"commandSyntaxDeath": "death",
"commandSyntaxDeaths": "deaths",
"commandSyntaxDecay": "decay",
"commandSyntaxEvents": "events",
"commandSyntaxHeli": "heli",
"commandSyntaxLanguage": "language",
"commandSyntaxLarge": "large",
Expand Down Expand Up @@ -446,6 +447,7 @@
"noRegisteredConnectionEventsUser": "No registered connection events for {user}.",
"noRegisteredDeathEvents": "No registered death events yet.",
"noRegisteredDeathEventsUser": "No registered death events for {user}.",
"noRegisteredEvents": "No registered events yet.",
"noRegisteredMarkers": "No registered markers.",
"noSavedNotes": "There are no saved notes.",
"noToolCupboardWereFound": "No Tool Cupboard monitors were found.",
Expand Down
15 changes: 15 additions & 0 deletions src/structures/MapMarkers.js
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,7 @@ class MapMarkers {
this.rustplus.sendEvent(
this.rustplus.notificationSettings.vendingMachineDetectedSetting,
this.client.intlGet(this.rustplus.guildId, 'newVendingMachine', { location: pos.string }),
null,
Constants.COLOR_NEW_VENDING_MACHINE);
}
}
Expand Down Expand Up @@ -361,6 +362,7 @@ class MapMarkers {
this.rustplus.notificationSettings.heavyScientistCalledSetting,
this.client.intlGet(this.rustplus.guildId, 'heavyScientistsCalledSmall',
{ location: oilRigLocation.location }),
'small',
Constants.COLOR_HEAVY_SCIENTISTS_CALLED_SMALL,
this.rustplus.isFirstPoll,
'small_oil_rig_logo.png');
Expand Down Expand Up @@ -395,6 +397,7 @@ class MapMarkers {
this.rustplus.notificationSettings.heavyScientistCalledSetting,
this.client.intlGet(this.rustplus.guildId, 'heavyScientistsCalledLarge',
{ location: oilRigLocation.location }),
'large',
Constants.COLOR_HEAVY_SCIENTISTS_CALLED_LARGE,
this.rustplus.isFirstPoll,
'large_oil_rig_logo.png');
Expand Down Expand Up @@ -426,12 +429,14 @@ class MapMarkers {
this.rustplus.sendEvent(
this.rustplus.notificationSettings.chinook47DetectedSetting,
this.client.intlGet(this.rustplus.guildId, 'chinook47EntersMap', { location: pos.string }),
'chinook',
Constants.COLOR_CHINOOK47_ENTERS_MAP);
}
else {
this.rustplus.sendEvent(
this.rustplus.notificationSettings.chinook47DetectedSetting,
this.client.intlGet(this.rustplus.guildId, 'chinook47Located', { location: pos.string }),
'chinook',
Constants.COLOR_CHINOOK47_LOCATED);
}
marker.ch47Type = 'crate';
Expand Down Expand Up @@ -486,6 +491,7 @@ class MapMarkers {
this.rustplus.sendEvent(
this.rustplus.notificationSettings.cargoShipDetectedSetting,
this.client.intlGet(this.rustplus.guildId, 'cargoShipEntersMap', { location: pos.string }),
'cargo',
Constants.COLOR_CARGO_SHIP_ENTERS_MAP);

let instance = this.client.getInstance(this.rustplus.guildId);
Expand All @@ -499,6 +505,7 @@ class MapMarkers {
this.rustplus.sendEvent(
this.rustplus.notificationSettings.cargoShipDetectedSetting,
this.client.intlGet(this.rustplus.guildId, 'cargoShipLocated', { location: pos.string }),
'cargo',
Constants.COLOR_CARGO_SHIP_LOCATED);
}

Expand All @@ -510,6 +517,7 @@ class MapMarkers {
this.rustplus.sendEvent(
this.rustplus.notificationSettings.cargoShipLeftSetting,
this.client.intlGet(this.rustplus.guildId, 'cargoShipLeftMap', { location: marker.location.string }),
'cargo',
Constants.COLOR_CARGO_SHIP_LEFT_MAP);

if (this.cargoShipEgressTimers[marker.id]) {
Expand Down Expand Up @@ -585,6 +593,7 @@ class MapMarkers {
this.client.intlGet(this.rustplus.guildId, 'patrolHelicopterEntersMap', {
location: pos.string
}),
'heli',
Constants.COLOR_PATROL_HELICOPTER_ENTERS_MAP);
}
else {
Expand All @@ -593,6 +602,7 @@ class MapMarkers {
this.client.intlGet(this.rustplus.guildId, 'patrolHelicopterLocatedAt', {
location: pos.string
}),
'heli',
Constants.COLOR_PATROL_HELICOPTER_LOCATED_AT);
}

Expand All @@ -609,6 +619,7 @@ class MapMarkers {
this.client.intlGet(this.rustplus.guildId, 'patrolHelicopterLeftMap', {
location: marker.location.string
}),
'heli',
Constants.COLOR_PATROL_HELICOPTER_LEFT_MAP);

this.timeSincePatrolHelicopterWasOnMap = new Date();
Expand All @@ -619,6 +630,7 @@ class MapMarkers {
this.client.intlGet(this.rustplus.guildId, 'patrolHelicopterTakenDown', {
location: marker.location.string
}),
'heli',
Constants.COLOR_PATROL_HELICOPTER_TAKEN_DOWN);

this.timeSincePatrolHelicopterWasDestroyed = new Date();
Expand Down Expand Up @@ -656,6 +668,7 @@ class MapMarkers {
this.client.intlGet(this.rustplus.guildId, 'cargoShipEntersEgressStage', {
location: marker.location.string
}),
'cargo',
Constants.COLOR_CARGO_SHIP_ENTERS_EGRESS_STAGE);

if (this.cargoShipEgressTimers[id]) {
Expand All @@ -674,6 +687,7 @@ class MapMarkers {
this.client.intlGet(this.rustplus.guildId, 'lockedCrateSmallOilRigUnlocked', {
location: oilRigLocation
}),
'small',
Constants.COLOR_LOCKED_CRATE_SMALL_OILRIG_UNLOCKED,
this.rustplus.isFirstPoll,
'locked_crate_small_oil_rig_logo.png');
Expand All @@ -691,6 +705,7 @@ class MapMarkers {
this.client.intlGet(this.rustplus.guildId, 'lockedCrateLargeOilRigUnlocked', {
location: oilRigLocation
}),
'large',
Constants.COLOR_LOCKED_CRATE_LARGE_OILRIG_UNLOCKED,
this.rustplus.isFirstPoll,
'locked_crate_large_oil_rig_logo.png');
Expand Down
134 changes: 133 additions & 1 deletion src/structures/RustPlus.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,14 @@ class RustPlus extends RustPlusLib {
this.playerConnections = new Object();
this.allDeaths = [];
this.playerDeaths = new Object();
this.events = {
all: [],
cargo: [],
heli: [],
small: [],
large: [],
chinook: []
};
this.patrolHelicopterTracers = new Object();
this.cargoShipTracers = new Object();

Expand Down Expand Up @@ -222,6 +230,27 @@ class RustPlus extends RustPlusLib {
this.playerDeaths[steamId].unshift(data);
}

updateEvents(event, message) {
const commandCargoEn = `${Client.client.intlGet('en', 'commandSyntaxCargo')}`;
const commandHeliEn = `${Client.client.intlGet('en', 'commandSyntaxHeli')}`;
const commandSmallEn = `${Client.client.intlGet('en', 'commandSyntaxSmall')}`;
const commandLargeEn = `${Client.client.intlGet('en', 'commandSyntaxLarge')}`;
const commandChinookEn = `${Client.client.intlGet('en', 'commandSyntaxChinook')}`;
if (![commandCargoEn, commandHeliEn, commandSmallEn, commandLargeEn, commandChinookEn].includes(event)) return;

const str = `${Timer.getCurrentDateTime()} - ${message}`;

if (this.events['all'].length === 10) {
this.events['all'].pop();
}
this.events['all'].unshift(str);

if (this.events[event].length === 10) {
this.events[event].pop();
}
this.events[event].unshift(str);
}

deleteThisRustplusInstance() {
this.isDeleted = true;
this.disconnect();
Expand Down Expand Up @@ -286,9 +315,11 @@ class RustPlus extends RustPlusLib {
}
}

async sendEvent(setting, text, embed_color, firstPoll = false, image = null) {
async sendEvent(setting, text, event, embed_color, firstPoll = false, image = null) {
const img = (image !== null) ? image : setting.image;

this.updateEvents(event, text);

if (!firstPoll && setting.discord) {
await DiscordMessages.sendDiscordEventMessage(this.guildId, this.serverId, text, img, embed_color);
}
Expand Down Expand Up @@ -1108,6 +1139,107 @@ class RustPlus extends RustPlusLib {
}
}

getCommandEvents(command) {
const prefix = this.generalSettings.prefix;
const commandEvents = `${prefix}${Client.client.intlGet(this.guildId, 'commandSyntaxEvents')}`;
const commandEventsEn = `${prefix}${Client.client.intlGet('en', 'commandSyntaxEvents')}`;
const commandCargo = `${Client.client.intlGet(this.guildId, 'commandSyntaxCargo')}`;
const commandCargoEn = `${Client.client.intlGet('en', 'commandSyntaxCargo')}`;
const commandHeli = `${Client.client.intlGet(this.guildId, 'commandSyntaxHeli')}`;
const commandHeliEn = `${Client.client.intlGet('en', 'commandSyntaxHeli')}`;
const commandSmall = `${Client.client.intlGet(this.guildId, 'commandSyntaxSmall')}`;
const commandSmallEn = `${Client.client.intlGet('en', 'commandSyntaxSmall')}`;
const commandLarge = `${Client.client.intlGet(this.guildId, 'commandSyntaxLarge')}`;
const commandLargeEn = `${Client.client.intlGet('en', 'commandSyntaxLarge')}`;
const commandChinook = `${Client.client.intlGet(this.guildId, 'commandSyntaxChinook')}`;
const commandChinookEn = `${Client.client.intlGet('en', 'commandSyntaxChinook')}`;

const EVENTS = [commandCargo, commandCargoEn, commandHeli, commandHeliEn, commandSmall,
commandSmallEn, commandLarge, commandLargeEn, commandChinook, commandChinookEn];

if (command.toLowerCase().startsWith(`${commandEvents}`)) {
command = command.slice(`${commandEvents}`.length).trim();
}
else {
command = command.slice(`${commandEventsEn}`.length).trim();
}

let event = command.replace(/ .*/, '').toLowerCase();
let number = command.slice(event.length + 1);

if (event === '') {
event = 'all';
number = 5;
}
else if (event !== '' && EVENTS.includes(event)) {
if (number === '') {
number = 5;
}
else {
number = parseInt(number);
if (isNaN(number)) {
number = 5;
}
}
}
else if (event !== '' && !EVENTS.includes(event)) {
number = parseInt(event);
event = 'all';
if (isNaN(number)) {
number = 5;
}
}
else {
event = 'all';
number = 5;
}

switch (event) {
case commandCargoEn:
case commandCargo: {
event = 'cargo';
} break;

case commandHeliEn:
case commandHeli: {
event = 'heli';
} break;

case commandSmallEn:
case commandSmall: {
event = 'small';
} break;

case commandLargeEn:
case commandLarge: {
event = 'large';
} break;

case commandChinookEn:
case commandChinook: {
event = 'chinook';
} break;

default: {
event = 'all';
} break;
}

const strings = [];
let counter = 0;
for (const e of this.events[event]) {
if (counter === 5 || counter === number) break;
strings.push(e);
counter += 1;
}

if (strings.length === 0) {
return Client.client.intlGet(this.guildId, 'noRegisteredEvents');
}

return strings;
}

getCommandHeli(isInfoChannel = false) {
const strings = [];
for (const patrolHelicopter of this.mapMarkers.patrolHelicopters) {
Expand Down
2 changes: 1 addition & 1 deletion src/structures/RustPlusLite.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ async function rustPlusLiteDisconnectedEvent(rustplusLite) {
}

async function rustPlusLiteErrorEvent(rustplusLite, error) {
rustplusLite.log(Client.client.intlGet(null, 'errorCap'), err, 'error');
rustplusLite.log(Client.client.intlGet(null, 'errorCap'), error, 'error');
}

module.exports = RustPlusLite;
2 changes: 2 additions & 0 deletions src/util/keywords.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ module.exports = {
client.intlGet(guildId, 'commandSyntaxDeath'),
client.intlGet(guildId, 'commandSyntaxDeaths'),
client.intlGet(guildId, 'commandSyntaxDecay'),
client.intlGet(guildId, 'commandSyntaxEvents'),
client.intlGet(guildId, 'commandSyntaxHeli'),
client.intlGet(guildId, 'commandSyntaxLarge'),
client.intlGet(guildId, 'commandSyntaxLeader'),
Expand Down Expand Up @@ -68,6 +69,7 @@ module.exports = {
client.intlGet('en', 'commandSyntaxDeath'),
client.intlGet('en', 'commandSyntaxDeaths'),
client.intlGet('en', 'commandSyntaxDecay'),
client.intlGet('en', 'commandSyntaxEvents'),
client.intlGet('en', 'commandSyntaxHeli'),
client.intlGet('en', 'commandSyntaxLarge'),
client.intlGet('en', 'commandSyntaxLeader'),
Expand Down

0 comments on commit 2e02fe9

Please sign in to comment.