-
Notifications
You must be signed in to change notification settings - Fork 112
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Battlemetrics Upcoming Wipe v2 #305
base: master
Are you sure you want to change the base?
Changes from 5 commits
08c2d4a
75c1c56
9524f2d
17b04e4
d858073
a483654
7e9e328
4b1aaa6
c7d2a20
27dc613
d2034f1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -699,6 +699,40 @@ module.exports = { | |
const guildId = rustplus.guildId; | ||
const instance = Client.client.getInstance(guildId); | ||
|
||
const emptyFieldValue = { name: '\u200B', value: '\u200B', inline: true }; | ||
let firstWipe = emptyFieldValue; | ||
let secondWipe = emptyFieldValue; | ||
|
||
const battlemetricsId = instance.activeServer !== null ? | ||
instance.serverList[instance.activeServer].battlemetricsId : null; | ||
|
||
if (battlemetricsId && instance.generalSettings.displayInformationBattlemetricsUpcomingWipes){ | ||
const bmInstance = Client.client.battlemetricsInstances[battlemetricsId]; | ||
const upcomingWipes = bmInstance.getUpcomingWipesOrderedByTime(); | ||
|
||
if (upcomingWipes.length > 0){ | ||
const closestWipe = upcomingWipes[0]; | ||
if (closestWipe.type === 'map' || closestWipe.type === 'full') { | ||
// try match next map or full wipe | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To make me happy, use /**/ |
||
const nextMapWipe = upcomingWipes.find((upcoming)=> upcoming.type === 'map') | ||
if (nextMapWipe){ | ||
firstWipe = { name: Client.client.intlGet(guildId, 'nextMapWipe'), value: `<t:${nextMapWipe.discordTimestamp}:R>`, inline: true} | ||
} | ||
const nextFullWipe = upcomingWipes.find((upcoming)=> upcoming.type === 'full') | ||
if (nextFullWipe){ | ||
secondWipe = { name: Client.client.intlGet(guildId, 'nextFullWipe'), value: `<t:${nextFullWipe.discordTimestamp}:R> `, inline: true } | ||
} | ||
} else { | ||
//if closest wipe is not matched type | ||
firstWipe = { | ||
name: Client.client.intlGet(guildId, 'nextWipe'), | ||
value: `<t:${closestWipe.discordTimestamp}:R> `, | ||
inline: true | ||
} | ||
} | ||
} | ||
} | ||
|
||
const time = rustplus.getCommandTime(true); | ||
const timeLeftTitle = Client.client.intlGet(rustplus.guildId, 'timeTill', { | ||
event: rustplus.time.isDay() ? Constants.NIGHT_EMOJI : Constants.DAY_EMOJI | ||
|
@@ -719,18 +753,20 @@ module.exports = { | |
fields: [ | ||
{ name: playersFieldName, value: `\`${rustplus.getCommandPop(true)}\``, inline: true }, | ||
{ name: timeFieldName, value: `\`${time[0]}\``, inline: true }, | ||
{ name: wipeFieldName, value: `\`${rustplus.getCommandWipe(true)}\``, inline: true }], | ||
time[1] ? { name: timeLeftTitle, value: `\`${time[1]}\``, inline: true } : emptyFieldValue, | ||
], | ||
timestamp: true | ||
}); | ||
|
||
if (time[1] !== null) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why is this dependent on time? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I switched field If you want it in different order i can fix it however you like. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What I dont understand is why you write out wipe stuff only if time[1] is present... This part:
|
||
embed.addFields( | ||
{ name: timeLeftTitle, value: `\`${time[1]}\``, inline: true }, | ||
{ name: '\u200B', value: '\u200B', inline: true }, | ||
{ name: '\u200B', value: '\u200B', inline: true }); | ||
{ name: wipeFieldName, value: `\`${rustplus.getCommandWipe(true)}\``, inline: true }, | ||
firstWipe, | ||
secondWipe, | ||
); | ||
} | ||
else { | ||
embed.addFields({ name: '\u200B', value: '\u200B', inline: false }); | ||
embed.addFields(emptyFieldValue); | ||
} | ||
|
||
embed.addFields( | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -766,5 +766,8 @@ | |
"wipeDetected": "Wipe detected!", | ||
"yield": "Yield", | ||
"youAreAlreadyLeader": "You are already leader.", | ||
"youAreNotPairedWithServer": "Leader command does not work because you're not paired with the server." | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. phrases should be in order (alphabetical) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Dont remove "youAreNotPairedWithServer" |
||
"nextFullWipe": "Next full wipe", | ||
"nextMapWipe": "Next map wipe", | ||
"nextWipe": "Next wipe", | ||
"displayInformationBattlemetricsUpcomingWipes": "Should be closest wipe from Battlemetrics be displayed in the information channel?" | ||
} |
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should consider adding server_rust_wipes to evaluation function. But from testing it looks like a few more elements have been added to the API. I could fix it. |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -106,6 +106,7 @@ class Battlemetrics { | |
this.server_rust_last_wipe = null; | ||
this.server_rust_last_wipe_ent = null; | ||
this.server_serverSteamId = null; | ||
this.server_rust_wipes = null; | ||
this.map_url = null; | ||
this.map_thumbnailUrl = null; | ||
this.map_monuments = null; | ||
|
@@ -153,6 +154,7 @@ class Battlemetrics { | |
set offlinePlayers(offlinePlayers) { this._offlinePlayers = offlinePlayers; } | ||
get serverEvaluation() { return this._serverEvaluation; } | ||
set serverEvaluation(serverEvaluation) { this._serverEvaluation = serverEvaluation; } | ||
get rustWipes() { return this.server_rust_wipes; } | ||
|
||
/** | ||
* Construct the Battlemetrics API call for searching servers by name. | ||
|
@@ -725,6 +727,7 @@ class Battlemetrics { | |
this.server_rust_last_wipe = details.rust_last_wipe; | ||
this.server_rust_last_wipe_ent = details.rust_last_wipe_ent; | ||
this.server_serverSteamId = details.serverSteamId; | ||
this.server_rust_wipes = details.rust_wipes | ||
|
||
const rustMaps = details.rust_maps; | ||
if (rustMaps) { | ||
|
@@ -801,6 +804,18 @@ class Battlemetrics { | |
return ordered.map(e => e[1]); | ||
} | ||
|
||
getUpcomingWipesOrderedByTime() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does this run even if there is a server that does not give any details about upcoming wipes? Or is rust_wipes always available in the battlemetrics API call? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also add a comment header for the function |
||
const unordered = []; | ||
for (const wipe of this.rustWipes) { | ||
const timestampDate = new Date(wipe.timestamp) | ||
wipe.discordTimestamp = timestampDate.getTime() / 1000; | ||
const timestampSplit = timestampDate.toISOString().split('T') | ||
wipe.readableTimestamp = timestampSplit.length === 2 ?`${timestampSplit[0]} T ${timestampSplit[1]}`: timestampDate.toISOString() | ||
unordered.push(wipe); | ||
} | ||
return unordered.sort(function (a, b) { return a.discordTimestamp - b.discordTimestamp }) | ||
} | ||
|
||
/** | ||
* Get the offline time from a player. | ||
* @param {string} playerId The id of the player to get offline time from. | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -51,7 +51,8 @@ module.exports = (client, guild) => { | |
server: null, | ||
event: null, | ||
team: null, | ||
battlemetricsPlayers: null | ||
battlemetricsPlayers: null, | ||
battlemetricsUpcomingWipes:null | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove this |
||
}, | ||
activeServer: null, | ||
serverList: {}, | ||
|
@@ -153,7 +154,8 @@ module.exports = (client, guild) => { | |
server: null, | ||
event: null, | ||
team: null, | ||
battlemetricsPlayers: null | ||
battlemetricsPlayers: null, | ||
battlemetricsUpcomingWipes:null | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove this |
||
} | ||
} | ||
else { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A little space please :D