Skip to content

Commit

Permalink
feat: added stats; changed delays for Active and Member
Browse files Browse the repository at this point in the history
  • Loading branch information
Vliegenier04 committed Jan 26, 2025
1 parent 5593e84 commit 06a774b
Show file tree
Hide file tree
Showing 18 changed files with 859 additions and 187 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,24 +13,31 @@ export default {
playerRank: string,
playerName: string,
guildRank: string,
unknownGroup: string,
target: string
) => {

const _channel = channel;
const _playerRank = playerRank;
const _playerName = playerName;
const _guildRank = guildRank;
const _unknownGroup = unknownGroup;
const _target = target;

const now = Date.now();
const cooldownTime = 4 * 60 * 1000;
const cooldownTimeMember = 4 * 60 * 1000;
const cooldownTimeActive = 2 * 60 * 1000;

if (commandCooldowns.has(playerName) && _guildRank.includes('Active')) {
if (commandCooldowns.has(playerName) && _guildRank.includes('Member')) {
const lastRun = commandCooldowns.get(playerName);
if (lastRun && now - lastRun < cooldownTimeMember) {
const remainingTime = Math.ceil((cooldownTimeMember - (now - lastRun)) / 1000);
bot.executeCommand(
`/gc ${playerName}, you can only use this command again in ${remainingTime} seconds. Please wait.`
);
return;
}
} else if (commandCooldowns.has(playerName) && _guildRank.includes('Active')) {
const lastRun = commandCooldowns.get(playerName);
if (lastRun && now - lastRun < cooldownTime) {
const remainingTime = Math.ceil((cooldownTime - (now - lastRun)) / 1000);
if (lastRun && now - lastRun < cooldownTimeActive) {
const remainingTime = Math.ceil((cooldownTimeActive - (now - lastRun)) / 1000);
bot.executeCommand(
`/gc ${playerName}, you can only use this command again in ${remainingTime} seconds. Please wait.`
);
Expand All @@ -39,13 +46,10 @@ export default {
}

commandCooldowns.set(playerName, now);

if (_target === undefined || _target === null || _target === '') {
if (_guildRank.includes('Member')) {
bot.executeCommand(
`/gc ${_playerName}, you must have Guild Rank "Active" or higher to check the stats of ${_playerName}! Aborting...`
);
} else if (
if (
_guildRank.includes('Member') ||
_guildRank.includes('Active') ||
_guildRank.includes('Res') ||
_guildRank.includes('Mod') ||
Expand All @@ -58,7 +62,10 @@ export default {
)
.then((response) => response.json())
.then((data) => {
if (data.success === false && data.cause === "You have already looked up this name recently") {
if (
data.success === false &&
data.cause === 'You have already looked up this name recently'
) {
console.log(
`[DEBUG] ${_playerName} is checking the stats of ${_playerName}, but failed.`
);
Expand All @@ -74,19 +81,22 @@ export default {
`/gc ${_playerName}, the player ${_playerName} was not found.`
);
return reject('Player not found!');

}

if (!data.player.stats || !data.player.stats.Bedwars || !data.player.achievements) {

if (
!data.player.stats ||
!data.player.stats.Bedwars ||
!data.player.achievements
) {
console.log(
`[DEBUG] ${_playerName} is checking the stats of ${_playerName}, but incomplete data was received.`
);
return reject('Incomplete player data received!');
}

const playerStats = data.player.stats.Bedwars;
const playerAchievements = data.player.achievements;

const playerLevel = playerAchievements.bedwars_level;
const playerWins = playerAchievements.bedwars_wins;
const playerFinalKills = playerStats.final_kills_bedwars;
Expand All @@ -97,17 +107,17 @@ export default {
const playerLosses = playerStats.losses_bedwars;
const playerWLR = playerWins / playerLosses;
const playerBBLR = playerBedsBroken / playerBedsLost;

console.log(
`[DEBUG] ${_playerName} is checking the stats of ${_playerName} and succeeded`
);

bot.executeCommand(
`/gc [BW-STATS] IGN: ${_playerName} | LVL: ${playerLevel} | WINS: ${playerWins} | FKDR: ${playerFKDR.toFixed(
2
)} | BBLR: ${playerBBLR.toFixed(2)} | WLR: ${playerWLR.toFixed(2)}`
);

resolve(data.player); // Ensure promise resolves
})
.catch((err) => {
Expand All @@ -117,11 +127,8 @@ export default {
});
}
} else {
if (_guildRank.includes('Member')) {
bot.executeCommand(
`/gc ${_playerName}, you must have Guild Rank "Active" or higher to check the stats of ${_target}! Aborting...`
);
} else if (
if (
_guildRank.includes('Member') ||
_guildRank.includes('Active') ||
_guildRank.includes('Res') ||
_guildRank.includes('Mod') ||
Expand All @@ -134,7 +141,10 @@ export default {
)
.then((response) => response.json())
.then((data) => {
if (data.success === false && data.cause === "You have already looked up this name recently") {
if (
data.success === false &&
data.cause === 'You have already looked up this name recently'
) {
console.log(
`[DEBUG] ${_playerName} is checking the stats of ${_target}, but failed.`
);
Expand All @@ -150,19 +160,22 @@ export default {
`/gc ${_playerName}, the player ${_target} was not found.`
);
return reject('Player not found!');

}

if (!data.player.stats || !data.player.stats.Bedwars || !data.player.achievements) {

if (
!data.player.stats ||
!data.player.stats.Bedwars ||
!data.player.achievements
) {
console.log(
`[DEBUG] ${_playerName} is checking the stats of ${_target}, but incomplete data was received.`
);
return reject('Incomplete player data received!');
}

const playerStats = data.player.stats.Bedwars;
const playerAchievements = data.player.achievements;

const playerLevel = playerAchievements.bedwars_level;
const playerWins = playerAchievements.bedwars_wins;
const playerFinalKills = playerStats.final_kills_bedwars;
Expand All @@ -173,17 +186,17 @@ export default {
const playerLosses = playerStats.losses_bedwars;
const playerWLR = playerWins / playerLosses;
const playerBBLR = playerBedsBroken / playerBedsLost;

console.log(
`[DEBUG] ${_playerName} is checking the stats of ${_target} and succeeded`
);

bot.executeCommand(
`/gc [BW-STATS] IGN: ${_target} | LVL: ${playerLevel} | WINS: ${playerWins} | FKDR: ${playerFKDR.toFixed(
2
)} | BBLR: ${playerBBLR.toFixed(2)} | WLR: ${playerWLR.toFixed(2)}`
);

resolve(data.player); // Ensure promise resolves
})
.catch((err) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,31 @@ export default {
playerRank: string,
playerName: string,
guildRank: string,
unknownGroup: string,
target: string
) => {
const _channel = channel;
const _playerRank = playerRank;
const _playerName = playerName;
const _guildRank = guildRank;
const _unknownGroup = unknownGroup;
const _target = target;

const now = Date.now();
const cooldownTime = 4 * 60 * 1000;
const cooldownTimeMember = 4 * 60 * 1000;
const cooldownTimeActive = 2 * 60 * 1000;

if (commandCooldowns.has(playerName) && _guildRank.includes('Active')) {
if (commandCooldowns.has(playerName) && _guildRank.includes('Member')) {
const lastRun = commandCooldowns.get(playerName);
if (lastRun && now - lastRun < cooldownTime) {
const remainingTime = Math.ceil((cooldownTime - (now - lastRun)) / 1000);
if (lastRun && now - lastRun < cooldownTimeMember) {
const remainingTime = Math.ceil((cooldownTimeMember - (now - lastRun)) / 1000);
bot.executeCommand(
`/gc ${playerName}, you can only use this command again in ${remainingTime} seconds. Please wait.`
);
return;
}
} else if (commandCooldowns.has(playerName) && _guildRank.includes('Active')) {
const lastRun = commandCooldowns.get(playerName);
if (lastRun && now - lastRun < cooldownTimeActive) {
const remainingTime = Math.ceil((cooldownTimeActive - (now - lastRun)) / 1000);
bot.executeCommand(
`/gc ${playerName}, you can only use this command again in ${remainingTime} seconds. Please wait.`
);
Expand All @@ -40,11 +48,8 @@ export default {
commandCooldowns.set(playerName, now);

if (_target === undefined || _target === null || _target === '') {
if (_guildRank.includes('Member')) {
bot.executeCommand(
`/gc ${_playerName}, you must have Guild Rank "Active" or higher to check the stats of ${_playerName}! Aborting...`
);
} else if (
if (
_guildRank.includes('Member') ||
_guildRank.includes('Active') ||
_guildRank.includes('Res') ||
_guildRank.includes('Mod') ||
Expand Down Expand Up @@ -122,11 +127,8 @@ export default {
});
}
} else {
if (_guildRank.includes('Member')) {
bot.executeCommand(
`/gc ${_playerName}, you must have Guild Rank "Active" or higher to check the stats of ${_target}! Aborting...`
);
} else if (
if (
_guildRank.includes('Member') ||
_guildRank.includes('Active') ||
_guildRank.includes('Res') ||
_guildRank.includes('Mod') ||
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,31 @@ export default {
playerRank: string,
playerName: string,
guildRank: string,
unknownGroup: string,
target: string
) => {
const _channel = channel;
const _playerRank = playerRank;
const _playerName = playerName;
const _guildRank = guildRank;
const _unknownGroup = unknownGroup;
const _target = target;

const now = Date.now();
const cooldownTime = 4 * 60 * 1000;
const cooldownTimeMember = 4 * 60 * 1000;
const cooldownTimeActive = 2 * 60 * 1000;

if (commandCooldowns.has(playerName) && _guildRank.includes('Active')) {
if (commandCooldowns.has(playerName) && _guildRank.includes('Member')) {
const lastRun = commandCooldowns.get(playerName);
if (lastRun && now - lastRun < cooldownTime) {
const remainingTime = Math.ceil((cooldownTime - (now - lastRun)) / 1000);
if (lastRun && now - lastRun < cooldownTimeMember) {
const remainingTime = Math.ceil((cooldownTimeMember - (now - lastRun)) / 1000);
bot.executeCommand(
`/gc ${playerName}, you can only use this command again in ${remainingTime} seconds. Please wait.`
);
return;
}
} else if (commandCooldowns.has(playerName) && _guildRank.includes('Active')) {
const lastRun = commandCooldowns.get(playerName);
if (lastRun && now - lastRun < cooldownTimeActive) {
const remainingTime = Math.ceil((cooldownTimeActive - (now - lastRun)) / 1000);
bot.executeCommand(
`/gc ${playerName}, you can only use this command again in ${remainingTime} seconds. Please wait.`
);
Expand All @@ -40,11 +48,8 @@ export default {
commandCooldowns.set(playerName, now);

if (_target === undefined || _target === null || _target === '') {
if (_guildRank.includes('Member')) {
bot.executeCommand(
`/gc ${_playerName}, you must have Guild Rank "Active" or higher to check the stats of ${_playerName}! Aborting...`
);
} else if (
if (
_guildRank.includes('Member') ||
_guildRank.includes('Active') ||
_guildRank.includes('Res') ||
_guildRank.includes('Mod') ||
Expand Down Expand Up @@ -125,11 +130,8 @@ export default {
});
}
} else {
if (_guildRank.includes('Member')) {
bot.executeCommand(
`/gc ${_playerName}, you must have Guild Rank "Active" or higher to check the stats of ${_target}! Aborting...`
);
} else if (
if (
_guildRank.includes('Member') ||
_guildRank.includes('Active') ||
_guildRank.includes('Res') ||
_guildRank.includes('Mod') ||
Expand Down Expand Up @@ -211,4 +213,4 @@ export default {
}
}
},
} as Event;
} as Event;
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,31 @@ export default {
playerRank: string,
playerName: string,
guildRank: string,
unknownGroup: string,
target: string
) => {
const _channel = channel;
const _playerRank = playerRank;
const _playerName = playerName;
const _guildRank = guildRank;
const _unknownGroup = unknownGroup;
const _target = target;

const now = Date.now();
const cooldownTime = 4 * 60 * 1000;
const cooldownTimeMember = 4 * 60 * 1000;
const cooldownTimeActive = 2 * 60 * 1000;

if (commandCooldowns.has(playerName) && _guildRank.includes('Active')) {
if (commandCooldowns.has(playerName) && _guildRank.includes('Member')) {
const lastRun = commandCooldowns.get(playerName);
if (lastRun && now - lastRun < cooldownTime) {
const remainingTime = Math.ceil((cooldownTime - (now - lastRun)) / 1000);
if (lastRun && now - lastRun < cooldownTimeMember) {
const remainingTime = Math.ceil((cooldownTimeMember - (now - lastRun)) / 1000);
bot.executeCommand(
`/gc ${playerName}, you can only use this command again in ${remainingTime} seconds. Please wait.`
);
return;
}
} else if (commandCooldowns.has(playerName) && _guildRank.includes('Active')) {
const lastRun = commandCooldowns.get(playerName);
if (lastRun && now - lastRun < cooldownTimeActive) {
const remainingTime = Math.ceil((cooldownTimeActive - (now - lastRun)) / 1000);
bot.executeCommand(
`/gc ${playerName}, you can only use this command again in ${remainingTime} seconds. Please wait.`
);
Expand All @@ -40,11 +48,8 @@ export default {
commandCooldowns.set(playerName, now);

if (_target === undefined || _target === null || _target === '') {
if (_guildRank.includes('Member')) {
bot.executeCommand(
`/gc ${_playerName}, you must have Guild Rank "Active" or higher to check the stats of ${_playerName}! Aborting...`
);
} else if (
if (
_guildRank.includes('Member') ||
_guildRank.includes('Active') ||
_guildRank.includes('Res') ||
_guildRank.includes('Mod') ||
Expand Down Expand Up @@ -117,11 +122,8 @@ export default {
});
}
} else {
if (_guildRank.includes('Member')) {
bot.executeCommand(
`/gc ${_playerName}, you must have Guild Rank "Active" or higher to check the stats of ${_target}! Aborting...`
);
} else if (
if (
_guildRank.includes('Member') ||
_guildRank.includes('Active') ||
_guildRank.includes('Res') ||
_guildRank.includes('Mod') ||
Expand Down
Loading

0 comments on commit 06a774b

Please sign in to comment.