Skip to content

Commit

Permalink
Fix: Updated to latest guild roles
Browse files Browse the repository at this point in the history
  • Loading branch information
Vliegenier04 committed Feb 15, 2025
1 parent 662c67b commit ae6cdb6
Show file tree
Hide file tree
Showing 16 changed files with 150 additions and 208 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,6 @@ export default {
const _target = target;

bot.executeCommand(`/gc ${playerName}, I'm sorry but this command is not available yet. | ${getRandomHexColor()}`);
console.error(`[DEBUG] ${_playerName} is checking the BLITZ stats of ${_playerName}, but failed. This command is not available yet.`);
}
} as Event;
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ export default {
const _kdr = _kills / _timesDied;
const _wlr = _wins / _losses;

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

bot.executeCommand(`/gc [DUELS-BRIDGE] IGN: ${_playerName} | KILLS: ${_kills} | WINS: ${_wins} | KDR: ${_kdr.toFixed(2)} | WLR: ${_wlr.toFixed(2)} | ${getRandomHexColor()}`);

Expand Down Expand Up @@ -123,7 +123,7 @@ export default {
const _kdr = _kills / _timesDied;
const _wlr = _wins / _losses;

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

bot.executeCommand(`/gc [DUELS-BRIDGE] IGN: ${_target} | KILLS: ${_kills} | WINS: ${_wins} | KDR: ${_kdr.toFixed(2)} | WLR: ${_wlr.toFixed(2)} | ${getRandomHexColor()}`);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,6 @@ export default {
const _target = target;

bot.executeCommand(`/gc ${playerName}, I'm sorry but this command is not available yet. | ${getRandomHexColor()}`);
console.error(`[DEBUG] ${_playerName} is checking the CLASSIC stats of ${_playerName}, but failed. This command is not available yet.`);
}
} as Event;
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,6 @@ export default {
const _target = target;

bot.executeCommand(`/gc ${playerName}, I'm sorry but this command is not available yet. | ${getRandomHexColor()}`);
console.error(`[DEBUG] ${_playerName} is checking the DUELS-OP stats of ${_playerName}, but failed. This command is not available yet.`);
}
} as Event;
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ export default {
const _kdr = _kills / _timesDied;
const _wlr = _wins / _losses;

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

bot.executeCommand(`/gc [DUELS] IGN: ${_playerName} | KILLS: ${_kills} | WINS: ${_wins} | KDR: ${_kdr.toFixed(2)} | WLR: ${_wlr.toFixed(2)} | ${getRandomHexColor()}`);

Expand Down Expand Up @@ -124,7 +124,7 @@ export default {
const _kdr = _kills / _timesDied;
const _wlr = _wins / _losses;

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

bot.executeCommand(`/gc [DUELS] IGN: ${_target} | KILLS: ${_kills} | WINS: ${_wins} | KDR: ${_kdr.toFixed(2)} | WLR: ${_wlr.toFixed(2)} | ${getRandomHexColor()}`);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,6 @@ export default {
const _target = target;

bot.executeCommand(`/gc ${playerName}, I'm sorry but this command is not available yet. | ${getRandomHexColor()}`);
console.error(`[DEBUG] ${_playerName} is checking the SUMO stats of ${_playerName}, but failed. This command is not available yet.`);
}
} as Event;
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,6 @@ export default {
const _target = target;

bot.executeCommand(`/gc ${playerName}, I'm sorry but this command is not available yet. | ${getRandomHexColor()}`);
console.error(`[DEBUG] ${_playerName} is checking the DUELS-SW stats of ${_playerName}, but failed. This command is not available yet.`);
}
} as Event;
134 changes: 134 additions & 0 deletions src/events/mineflayer/chat/fetch-stats/mm-stats.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
// Regex Pattern:
// 'chat:bw-stats': /^(Guild|Officer) > (\[.*])?\s*(\w{2,17}).*?(\[.{1,15}])?: (.*)!bw\s?(\w{2,17})?$/,
// Copyright © 2024 Vliegenier04

const commandCooldowns = new Map<string, number>();

function getRandomHexColor(): string {
return (
"#" +
Math.floor(Math.random() * 0xffffff)
.toString(16)
.padStart(6, "0")
);
}


export default {
name: "chat:mm-stats",
runOnce: false,
run: async (bot, channel: string, 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 cooldownTimeMember = 4 * 60 * 1000;
const cooldownTimeActive = 2 * 60 * 1000;

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. | ${getRandomHexColor()}`);
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. | ${getRandomHexColor()}`);
return;
}
}

commandCooldowns.set(playerName, now);
if (_target === undefined || _target === null || _target === "") {
if (_guildRank.includes("Member") || _guildRank.includes("Active") || _guildRank.includes("Elite") || _guildRank.includes("Mod") || _guildRank.includes("Admin") || _guildRank.includes("GM")) {
return new Promise((resolve, reject) => {
fetch(`https://api.hypixel.net/player?key=${process.env.HYPIXEL_API_KEY}&name=${_playerName}`)
.then((response) => response.json())
.then((data) => {
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.`);
bot.executeCommand(`/gc ${_playerName}, the player ${_playerName} was looked up recently. Please try again later.`);
return reject("Player not found! Looked up recently.");
} else if (data.success === true && data.player === null) {
console.log(`[DEBUG] ${_playerName} is checking the stats of ${_playerName}, but failed.`);
bot.executeCommand(`/gc ${_playerName}, the player ${_playerName} was not found.`);
return reject("Player not found!");
}

if (!data.player.stats || !data.player.stats.MurderMystery || !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.MurderMystery;
const playerAchievements = data.player.achievements;

const _wins = playerStats.wins;
const _gamesPlayed = playerStats.games;
const _kills = playerStats.kills;
const _deaths = playerStats.deaths;
const _kdr = _kills / _deaths;

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

bot.executeCommand(`/gc [MM-STATS] IGN: ${_playerName} | KILLS: ${_kills} | WINS: ${_wins} | KDR: ${_kdr.toFixed(2)} | GAMES PLAYED: ${_gamesPlayed} | ${getRandomHexColor()}`);
resolve(data.player); // Ensure promise resolves
})
.catch((err) => {
console.error(`[ERROR] Failed to fetch player stats: ${err}`);
reject(err);
});
});
}
} else {
if (_guildRank.includes("Member") || _guildRank.includes("Active") || _guildRank.includes("Elite") || _guildRank.includes("Mod") || _guildRank.includes("Admin") || _guildRank.includes("GM")) {
return new Promise((resolve, reject) => {
fetch(`https://api.hypixel.net/player?key=${process.env.HYPIXEL_API_KEY}&name=${_target}`)
.then((response) => response.json())
.then((data) => {
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.`);
bot.executeCommand(`/gc ${_playerName}, the player ${_target} was looked up recently. Please try again later.`);
return reject("Player not found!");
} else if (data.success === true && data.player === null) {
console.log(`[DEBUG] ${_playerName} is checking the stats of ${_target}, but failed.`);
bot.executeCommand(`/gc ${_playerName}, the player ${_target} was not found.`);
return reject("Player not found!");
}

if (!data.player.stats || !data.player.stats.MurderMystery || !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.MurderMystery;
const playerAchievements = data.player.achievements;

const _wins = playerStats.wins;
const _gamesPlayed = playerStats.games;
const _kills = playerStats.kills;
const _deaths = playerStats.deaths;
const _kdr = _kills / _deaths;

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

bot.executeCommand(`/gc [MM-STATS] IGN: ${_target} | KILLS: ${_kills} | WINS: ${_wins} | KDR: ${_kdr.toFixed(2)} | GAMES PLAYED: ${_gamesPlayed} | ${getRandomHexColor()}`);

resolve(data.player); // Ensure promise resolves
})
.catch((err) => {
console.error(`[ERROR] Failed to fetch player stats: ${err}`);
reject(err);
});
});
}
}
},
} as Event;
2 changes: 1 addition & 1 deletion src/events/mineflayer/chat/fetch-stats/sw-stats.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ export default {

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

bot.executeCommand(`/gc [SW-STATS] IGN: ${_playerName} | LVL: ${rm_playerLevel} | WINS: ${playerWins} | KDR: ${playerKDR} | BBLR: ${playerLosses} | WLR: ${playerWLR.toFixed(2)} | ${getRandomHexColor()}`);
bot.executeCommand(`/gc [SW-STATS] IGN: ${_playerName} | LVL: ${rm_playerLevel} | WINS: ${playerWins} | KDR: ${playerKDR.toFixed(2)} | WLR: ${playerWLR.toFixed(2)} | Total Kills: ${playerKills} | ${getRandomHexColor()}`);

resolve(data.player); // Ensure promise resolves
})
Expand Down
Loading

0 comments on commit ae6cdb6

Please sign in to comment.