Skip to content

Commit

Permalink
Moved status label functions to their own module
Browse files Browse the repository at this point in the history
  • Loading branch information
dioxair committed Jun 2, 2023
1 parent 12d1ad9 commit cfb2e60
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 32 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "kasu",
"version": "1.13.7",
"version": "1.14.8",
"description": "An app made in Electron to keep Aternos servers up as long as possible",
"main": "src/main.js",
"scripts": {
Expand Down
1 change: 1 addition & 0 deletions src/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link href="style.css" rel="stylesheet" />
<script defer src="index.js"></script>
<script defer src="util/statusLabels.js"></script>
</head>
<body>
<h1>Kasu</h1>
Expand Down
44 changes: 13 additions & 31 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
const mineflayer = require("mineflayer");
const statusLabel = document.getElementById("statusLabel");
const botStatusLabel = document.getElementById("botStatusLabel");
const statusLabels = require("./util/statusLabels");

let startKasuButton = document.getElementById("startKasuButton");
let stopKasuButton = document.getElementById("stopKasuButton");

let bot;

console.stdinfo = console.info.bind(console);
console.info = function () {
const infoLog = Array.from(arguments)[0];
Expand All @@ -12,7 +14,7 @@ console.info = function () {
new RegExp("[A-Z0-9]{8}").test(infoLog) // https://regex101.com/r/NqqPGH/1
) {
let authCode = infoLog.match("[A-Z0-9]{8}");
statusLabelWarning(
statusLabels.statusLabelWarning(
`Looks like it's your first time using Kasu with that email. You'll need to authenticate with Microsoft. To authenticate, open the website https://www.microsoft.com/link and enter the code ${authCode}`
);
}
Expand All @@ -24,23 +26,24 @@ function onKasuStart() {
document.getElementById("serverPort").value === "" ||
document.getElementById("userEmail").value === ""
) {
statusLabelError("Please fill out all the forms!");
statusLabels.statusLabelError("Please fill out all the forms!");
return;
} else {
statusLabelIdle();
statusLabels.statusLabelIdle();
}

botStatusLabelIdle();
statusLabels.botStatusLabelIdle();
createBot();
}

function stopKasu() {
bot.quit("quit");
statusLabelIdle();
botStatusLabelIdle();
statusLabels.statusLabelIdle();
statusLabels.botStatusLabelIdle();
stopKasuButton.disabled = true;
startKasuButton.disabled = false;
}

function createBot() {
let serverIP = document.getElementById("serverIP").value;
let serverPort = document.getElementById("serverPort").value;
Expand All @@ -54,14 +57,14 @@ function createBot() {
});

bot.on("login", () => {
statusLabelSuccess(
statusLabels.statusLabelSuccess(
`Successfully logged into ${serverIP} with port ${serverPort}`
);
startKasuButton.disabled = true;
stopKasuButton.disabled = false;
});
bot.on("kicked", (reason, loggedIn) => {
statusLabelError(
statusLabels.statusLabelError(
`You've been kicked from ${serverIP} for ${reason}. Logged in: ${loggedIn}`
);
startKasuButton.disabled = true;
Expand All @@ -77,24 +80,3 @@ function createBot() {
}
});
}

function statusLabelSuccess(text) {
statusLabel.textContent = `Status: ${text}`;
statusLabel.style.color = "LightGreen";
}
function statusLabelWarning(text) {
statusLabel.textContent = `Status: ${text}`;
statusLabel.style.color = "Khaki";
}
function statusLabelError(text) {
statusLabel.textContent = `Status: ${text}`;
statusLabel.style.color = "LightCoral";
}
function statusLabelIdle() {
statusLabel.textContent = "Status: Idle";
statusLabel.style.color = "peachpuff";
}
function botStatusLabelIdle() {
botStatusLabel.textContent = "Bot status: Idle";
botStatusLabel.style.color = "peachpuff";
}
25 changes: 25 additions & 0 deletions src/util/statusLabels.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
const statusLabel = document.getElementById("statusLabel");
const botStatusLabel = document.getElementById("botStatusLabel");

module.exports = {
statusLabelSuccess: function (text) {
statusLabel.textContent = `Status: ${text}`;
statusLabel.style.color = "LightGreen";
},
statusLabelWarning: function (text) {
statusLabel.textContent = `Status: ${text}`;
statusLabel.style.color = "Khaki";
},
statusLabelError: function (text) {
statusLabel.textContent = `Status: ${text}`;
statusLabel.style.color = "LightCoral";
},
statusLabelIdle: function () {
statusLabel.textContent = "Status: Idle";
statusLabel.style.color = "peachpuff";
},
botStatusLabelIdle: function () {
botStatusLabel.textContent = "Bot status: Idle";
botStatusLabel.style.color = "peachpuff";
},
};

0 comments on commit cfb2e60

Please sign in to comment.