Skip to content
This repository has been archived by the owner on Feb 15, 2024. It is now read-only.

Commit

Permalink
Overwrites properly working in all modes, added setkey, not having an…
Browse files Browse the repository at this point in the history
… api does not break the application, added proper default settings to the application, hypixel.js now supports setkey, help now works for specific commands, added all parameter to onHover and onClick for Message class, nicks now give warnings
  • Loading branch information
MauritsWilke committed Feb 1, 2022
1 parent 7879812 commit 320fae8
Show file tree
Hide file tree
Showing 11 changed files with 224 additions and 99 deletions.
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
node_modules/
inStream.txt
HyProxyConfig.json
dist/
oldSRC/
dist/
8 changes: 5 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@
"@types/node": "^17.0.13"
},
"scripts": {
"build": "pkg src/index.js -c package.json --debug"
"build": "pkg src/index.js -c package.json"
},
"pkg": {
"scripts": "./src/**/*.js",
"scripts": [
"./src/**/**/*.js"
],
"assets": "./src/**/*",
"outputPath": "dist"
}
}
}
20 changes: 19 additions & 1 deletion src/commands/help.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,28 @@ module.exports = class extends Command {
.addText(`${capitalName}: `, { bold: true })
.addText(command.description, { bold: false })
.onHover(helpCard, 3)
.onClick("suggest_command", `${user.prefix}help ${command.name}`, 3)
.onClick("run_command", `${user.prefix}help ${command.name}`, 3)
}
msg.newLine().addText("-".repeat(45));
return client.write("chat", { message: msg.stringify() })
} else {
const command = user.commands.get(args[0]) ||
user.commands.get([...user.commands].find(command => command[1]?.aliases?.includes(args[0]))?.[0])
if (!command) {
const msg = new Message(`That command doesn't exist! Run /help to see a list of all commands`, { color: design.colours.failed })
.stringify();
client.write("chat", { message: msg })
return;
}
const helpMsg = new Message(`-`.repeat(53), { color: design.colours.default })
.addText(`Name: `, { bold: true }).addText(command.name).newLine()
.addText(`Description: `, { bold: true }).addText(command?.description ?? "none?").newLine()
.addText(`Example: `, { bold: true }).addText(command?.example ?? "none?").newLine()
.addText(`Aliases: `, { bold: true }).addText(command?.aliases.join() || "none").newLine()
.addText(`-`.repeat(53), { color: design.colours.default })
.onClick("suggest_command", `${user.prefix}${command.name}`, "all")
.stringify();
client.write("chat", { message: helpMsg })
}
}
}
40 changes: 40 additions & 0 deletions src/commands/setkey.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
const Command = require('../utils/classes/command')
const { Message } = require("../utils/classes/message")
const { writeFileSync } = require("fs")
const { join } = require("path")
const config = require(join(process.cwd(), "HyProxyConfig.json"))
const { keyInfo, setKey } = require("../utils/api/hypixel")
const design = config.config

module.exports = class extends Command {
constructor() {
super({
name: "setkey",
description: "Set the API key for HyProxy",
example: "setkey abcdefgh-ijkl-mnop-qrst-uvwxyz123456",
aliases: [
"rq"
]
})
}

async run(client, message, args, server, user) {
if (!args[0]) {
const msg = new Message("Please provide an API key, generate one using /api new", { color: design.colours.failed }).stringify();
client.write("chat", { message: msg })
} else {
try {
const info = await keyInfo(args[0]);
config.apiKey = info.key;
setKey(info.key)
writeFileSync(join(process.cwd(), "HyProxyConfig.json"), JSON.stringify(config, null, 4))
const msg = new Message("Successfully set API key!", { color: design.colours.success }).stringify();
client.write("chat", { message: msg })
} catch (e) {
console.log(e)
const msg = new Message("Invalid API key! Generate a new one using /api new", { color: design.colours.failed }).stringify();
client.write("chat", { message: msg })
}
}
}
}
11 changes: 6 additions & 5 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
const chalk = require("chalk")
const { readdirSync, writeFileSync, existsSync, appendFileSync } = require("fs")
const { resolve, join } = require('path');
const Proxy = require("./utils/classes/proxy");
const chalk = require("chalk")
const { name } = require("./utils/settings.json")
const configFile = join(process.cwd(), "./HyProxyConfig.json")
if (!existsSync(configFile)) appendFileSync(configFile, JSON.stringify({ prefix: "/" }, null, 4), (err) => { if (err) return })
const { name, configTemplate } = require("./utils/settings.json")
const configFile = join(process.cwd(), "HyProxyConfig.json")
if (!existsSync(configFile)) appendFileSync(configFile, JSON.stringify(configTemplate, null, 4), (err) => { if (err) return })
const config = require(configFile)

const Proxy = require("./utils/classes/proxy");

process.stdout.write("\033]0;" + name + "\007");

if (!config.username || !config.password || !config.auth) login();
Expand Down
90 changes: 54 additions & 36 deletions src/overwrites/bedwars.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const Overwrite = require("../utils/classes/overwrite");
const { Message, Card } = require("../utils/classes/message");
const { playerStats } = require("../utils/api/hypixel")
const starColours = require("../utils/api/json//starColours.json")
const { join } = require("path")
const config = require(join(process.cwd(), "HyProxyConfig.json"))
const design = config.config
Expand All @@ -12,44 +13,61 @@ module.exports = class extends Overwrite {
})
}

async overwrite(client, parsed, classic, clean, username) {
const player = await playerStats(username, "Bedwars");
const FKDR = Math.round((player.final_kills_bedwars / player.final_deaths_bedwars) * 100) / 100 || 0;
const soloFKDR = Math.round((player.eight_one_final_kills_bedwars / player.eight_one_final_deaths_bedwars) * 100) / 100 || 0;
const doublesFKDR = Math.round((player.eight_two_final_kills_bedwars / player.eight_two_final_deaths_bedwars) * 100) / 100 || 0;
const threesFKDR = Math.round((player.four_three_final_kills_bedwars / player.four_three_final_deaths_bedwars) * 100) / 100 || 0;
const foursFKDR = Math.round((player.four_four_final_kills_bedwars / player.four_four_final_deaths_bedwars) * 100) / 100 || 0;
const fkdrCard = new Card(`${username} - FKDR`)
.addField("Overall: ", FKDR)
.addField("Solo: ", soloFKDR)
.addField("Doubles: ", doublesFKDR)
.addField("Threes: ", threesFKDR)
.addField("Fours: ", foursFKDR)
.classic();
async overwrite(client, parsed, classic, clean, username, styledUsername) {
// const styledUsername = classic.replace(/ has joined.*/, "")
try {
const player = await playerStats(username);
const star = player.achievements.bedwars_level
const FKDR = Math.round((player.stats.Bedwars.final_kills_bedwars / player.stats.Bedwars.final_deaths_bedwars) * 100) / 100 || 0;
const soloFKDR = Math.round((player.stats.Bedwars.eight_one_final_kills_bedwars / player.stats.Bedwars.eight_one_final_deaths_bedwars) * 100) / 100 || 0;
const doublesFKDR = Math.round((player.stats.Bedwars.eight_two_final_kills_bedwars / player.stats.Bedwars.eight_two_final_deaths_bedwars) * 100) / 100 || 0;
const threesFKDR = Math.round((player.stats.Bedwars.four_three_final_kills_bedwars / player.stats.Bedwars.four_three_final_deaths_bedwars) * 100) / 100 || 0;
const foursFKDR = Math.round((player.stats.Bedwars.four_four_final_kills_bedwars / player.stats.Bedwars.four_four_final_deaths_bedwars) * 100) / 100 || 0;
const fkdrCard = new Card(`${username} - FKDR`)
.addField("Overall: ", FKDR)
.addField("Solo: ", soloFKDR)
.addField("Doubles: ", doublesFKDR)
.addField("Threes: ", threesFKDR)
.addField("Fours: ", foursFKDR)
.classic();

const winstreak = player.winstreak || 0;
const soloWinstreak = player.eight_one_winstreak || 0;
const doublesWinstreak = player.eight_two_winstreak || 0;
const threesWinstreak = player.four_three_winstreak || 0;
const foursWinstreak = player.four_four_winstreak || 0;
const winstreakCard = new Card(`${username} - Winstreaks`)
.addField("Overall: ", winstreak)
.addField("Solo: ", soloWinstreak)
.addField("Doubles: ", doublesWinstreak)
.addField("Threes: ", threesWinstreak)
.addField("Fours: ", foursWinstreak)
.classic();
const winstreak = player.stats.Bedwars?.winstreak ?? "disabled";
const soloWinstreak = player.stats?.Bedwars.eight_one_winstreak ?? "disabled";
const doublesWinstreak = player.stats?.Bedwars.eight_two_winstreak ?? "disabled";
const threesWinstreak = player.stats?.Bedwars.four_three_winstreak ?? "disabled";
const foursWinstreak = player.stats?.Bedwars.four_four_winstreak ?? "disabled";
const winstreakCard = new Card(`${username} - Winstreaks`)
.addField("Overall: ", winstreak)
.addField("Solo: ", soloWinstreak)
.addField("Doubles: ", doublesWinstreak)
.addField("Threes: ", threesWinstreak)
.addField("Fours: ", foursWinstreak)
.classic();

const styledUsername = classic.replace(/ has joined.*/, "")
const msg = new Message(` ${design.joinIcon} ${styledUsername} `, { color: "yellow" })
.addText("fkdr: ", { color: "red" })
.addText(`${FKDR} `, { color: "red" })
.onHover(fkdrCard, 2)
.addText("ws: ", { color: "red" })
.addText(`${winstreak} `, { color: "red" })
.onHover(winstreakCard, 2)
.addText(clean.match(/\(\d\/\d\)/)[0])
const msg = new Message(` ${design.joinIcon} `, { color: "yellow" })
.addText(`[${star}✫] `, { color: starColours[Math.floor(star / 100)] })
.addText(`${styledUsername} `)
.addText("fkdr: ", { color: "red" })
.addText(`${FKDR} `, { color: "red" })
.onHover(fkdrCard, 2)
.addText("ws: ", { color: "red" })
.addText(`${winstreak} `, { color: "red" })
.onHover(winstreakCard, 2)
.addText(clean.match(/\(\d{1,2}\/\d{1,2}\)/)?.[0] || "")

client.write("chat", { message: msg.stringify() })
client.write("chat", { message: msg.stringify() })
} catch (e) {
if (String(e).match("does not exist")) {
const msg = new Message(` ${design.joinIcon} `, { color: "dark_red" })
.addText(styledUsername)
.addText(" is nicked!")
.stringify()
client.write("chat", { message: msg })
} else {
console.log(e)
const msg = new Message(`Overwrite failed, please check application and report the bug!`, { color: "dark_red" })
client.write("chat", { message: msg.stringify() })
}
}
}
}
24 changes: 14 additions & 10 deletions src/utils/api/hypixel.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const fetch = require('node-fetch');
const { getUUID, getUsername } = require('./mojang.js');
const { join } = require("path")
const { apiKey } = require(join(process.cwd(), "./HyProxyConfig.json"))
let { apiKey } = require(join(process.cwd(), "./HyProxyConfig.json"))
const Cache = require("./cache")

const BASE_KEY = "https://api.hypixel.net"
Expand All @@ -21,24 +21,28 @@ module.exports = {
getActiveBoosters,
playerCounts,
getPunishments,
clearCache
clearCache,
setKey
}

async function keyInfo() {
const response = await fetch(`${BASE_KEY}/key?&key=${apiKey}`);
function setKey(key) {
apiKey = key;
}

async function keyInfo(key) {
const response = await fetch(`${BASE_KEY}/key?&key=${key || apiKey}`);
if (!response.ok) return Promise.reject(`${response.status} ${response.statusText}`);
const r = await response.json();
return r.record;
}

async function playerStats(player, gamemode) {
if (!player) return Promise.reject(`This function requires an input`);
const UUID = player.length < 16 ? uuidCache.get(player) || uuidCache.set(player, await getUUID(player)).value : player;
const UUID = player.length <= 16 ? uuidCache.get(player) || await getUUID(player).then(r => uuidCache.set(player, r).value) : player;
const response = await fetch(`${BASE_KEY}/player?uuid=${UUID}&key=${apiKey}`);
if (!response.ok) return Promise.reject(`${response.status} ${response.statusText}`);
const json = await response.json();
return gamemode ? json.player.stats[gamemode] : json.player;

}

async function friendList(player) {
Expand All @@ -49,15 +53,15 @@ async function friendList(player) {

async function recentGames(player) {
if (!player) return Promise.reject(`This function requires an input`);
const UUID = player.length < 16 ? uuidCache.get(player) || uuidCache.set(player, await getUUID(player)).value : player;
const UUID = player.length <= 16 ? uuidCache.get(player) || await getUUID(player).then(r => uuidCache.set(player, r).value) : player;
const response = await fetch(`${BASE_KEY}/recentgames?uuid=${UUID}&key=${apiKey}`);
const r = await response.json();
return r.games;
}

async function playerStatus(player) {
if (!player) return Promise.reject(`This function requires an input`);
const UUID = player.length < 16 ? uuidCache.get(player) || uuidCache.set(player, await getUUID(player)).value : player;
const UUID = player.length <= 16 ? uuidCache.get(player) || await getUUID(player).then(r => uuidCache.set(player, r).value) : player;
const response = await fetch(`${BASE_KEY}/status?uuid=${UUID}&key=${apiKey}`);
if (!response.ok) return Promise.reject(`${response.status} ${response.statusText}`);
const json = await response.json();
Expand Down Expand Up @@ -120,7 +124,7 @@ async function clearCache() {

async function getFriendList(player) {
let friendList = new Map()
const UUID = player.length < 16 ? uuidCache.get(player) || uuidCache.set(player, await getUUID(player)).value : player;
const UUID = player.length <= 16 ? uuidCache.get(player) || await getUUID(player).then(r => uuidCache.set(player, r).value) : player;
const response = await fetch(`${BASE_KEY}/friends?uuid=${UUID}&key=${apiKey}`);
if (!response.ok) return Promise.reject(`${response.status} ${response.statusText}`);
const { records } = await response.json();
Expand All @@ -133,7 +137,7 @@ async function getFriendList(player) {
}

async function getPlayerGuild(player) {
const UUID = player.length < 16 ? uuidCache.get(player) || uuidCache.set(player, await getUUID(player)).value : player;
const UUID = player.length <= 16 ? uuidCache.get(player) || await getUUID(player).then(r => uuidCache.set(player, r).value) : player;
const response = await fetch(`${BASE_KEY}/guild?player=${UUID}&key=${apiKey}`);
if (!response.ok) return Promise.reject(`${response.status} ${response.statusText}`);
const json = await response.json();
Expand Down
33 changes: 33 additions & 0 deletions src/utils/api/json/starColours.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
"0": "gray",
"1": "white",
"2": "gold",
"3": "aqua",
"4": "dark_green",
"5": "dark_aqua",
"6": "dark_red",
"7": "light_purple",
"8": "blue",
"9": "dark_purple",
"10": "yellow",
"11": "white",
"12": "gold",
"13": "aqua",
"14": "dark_green",
"15": "dark_aqua",
"16": "dark_red",
"17": "light_purple",
"18": "blue",
"19": "dark_purple",
"20": "dark_gray",
"21": "yellow",
"22": "yellow",
"23": "yellow",
"24": "yellow",
"25": "yellow",
"26": "yellow",
"27": "yellow",
"28": "yellow",
"29": "yellow",
"30": "yellow"
}
4 changes: 2 additions & 2 deletions src/utils/classes/message.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ class Message {
}

onHover(text, amount = 1) {
if (amount > this.message.extra.length) amount = this.message.extra.length
if (amount > this.message.extra.length || amount === "all") amount = this.message.extra.length
while (amount) {
this.message.extra[this.message.extra.length - amount].hoverEvent = {
"action": "show_text",
Expand All @@ -127,7 +127,7 @@ class Message {
}

onClick(type, value, amount = 1) {
if (amount > this.message.extra.length) amount = this.message.extra.length
if (amount > this.message.extra.length || amount === "all") amount = this.message.extra.length
while (amount) {
if (!["open_url", "run_command", "suggest_command", "copy_to_clipboard"].includes(type)) throw new Error("Invalid type")
this.message.extra[this.message.extra.length - amount].clickEvent = { action: type, value: value }
Expand Down
Loading

0 comments on commit 320fae8

Please sign in to comment.