Merge #20

Merged
Sirherobrine23 merged 26 commits from main into stable 2021-01-31 02:44:49 +00:00
11 changed files with 1581 additions and 99 deletions
Showing only changes of commit 4039364ae1 - Show all commits

View File

@@ -47,11 +47,18 @@ module.exports = () => {
return res.send(json_http); return res.send(json_http);
}); });
app.get("/", (req, res) => { app.get("/", (req, res) => {
return res.send({ return res.send(`Hello, welcome to the Bds Maneger API, If this page has loaded it means that the API is working as planned, More information access the API documentation at: https://docs.srherobrine23.com/bds-maneger-api_whatis.html, Version: ${require(__dirname+'/../package.json').version}`);
"info": "/info", });
"Bds Commnd": "/bds_command (POST)", app.get("/themes", (req, res) => {
"Log": "/log", fetch("https://raw.githubusercontent.com/Bds-Maneger/Raw_files/main/themes.json").then(response => response.json()).then(array => {
"bds_maneger_API_version": require("../package.json").version var themes_json;
for (let index = 0; index < array.length; index++) {
const name = array[index].name;
const zip_url = array[index].zip_url;
const git_url = array[index].git_url;
themes_json += `{Name: ${name},\n Url Zip: ${zip_url},\n Git url: ${git_url}},`
}
return res.send(themes_json);
}); });
}); });
const bodyParser = require("body-parser"); const bodyParser = require("body-parser");

View File

@@ -49,39 +49,42 @@ module.exports = () => {
}) })
} }
}); });
app.post("/bds/:command", (req, res) => { app.get("/bds/:command", (req, res) => {
const body = req.body const body = req.body
const command_bds = ''; const command_bds = '';
const tokens = JSON.parse(fs.readFileSync(path.join(bds.bds_dir, "bds_tokens.json"), "utf-8")) const tokens = JSON.parse(fs.readFileSync(path.join(bds.bds_dir, "bds_tokens.json"), "utf-8"))
var pass = false; var pass = false;
for (let token_verify in tokens) {const element = tokens[token_verify].token;if (body.token == element){pass = true} else {token_verify++}} res.send({
if (pass){ "command": req.params.command
if (command_bds === 'start'){ })
var bds_init = bds.start() // for (let token_verify in tokens) {const element = tokens[token_verify].token;if (body.token == element){pass = true} else {token_verify++}}
var command_status = `Bds Started` // if (pass){
} else if (command_bds === 'stop'){ // if (command_bds === 'start'){
bds.stop() // var bds_init = bds.start()
var command_status = `Stopping the bds server` // var command_status = `Bds Started`
} else if (command_bds === 'reload'){ // } else if (command_bds === 'stop'){
const bds_status = bds.detect() // bds.stop()
if (bds_detect){ // var command_status = `Stopping the bds server`
bds.stop() // } else if (command_bds === 'reload'){
} // const bds_status = bds.detect()
var bds_init = bds.start() // if (bds_detect){
var command_status = `Reloading` // bds.stop()
} else { // }
var command_status = `no command identified` // var bds_init = bds.start()
} // var command_status = `Reloading`
res.send({ // } else {
"status": 200, // var command_status = `no command identified`
"bds_status": command_status // }
}) // res.send({
} else { // "status": 200,
res.send({ // "bds_status": command_status
"status": 401, // })
"message": `Not authorized: ${body.token}` // } else {
}) // res.send({
} // "status": 401,
// "message": `Not authorized: ${body.token}`
// })
// }
}); });
app.post("/bds_command", (req, res) => { app.post("/bds_command", (req, res) => {
const body = req.body const body = req.body

12
API/teste.js Normal file
View File

@@ -0,0 +1,12 @@
var qr = require('qr-image');
var express = require('express');
var app = express();
app.get('/', function(req, res) {
var code = qr.image(`list: ${Math.random()}`, { type: 'svg' });
res.type('svg');
code.pipe(res);
});
app.listen(3000);

View File

@@ -1,5 +1,5 @@
module.exports.World_BAckup = () => { module.exports.World_BAckup = () => {
if (require("./detect_bds").bds_detect()){require("./stop").Server_stop()} if (require("./detect_bds").bds_detect()){require("../global/stop").Server_stop()}
const bds = require('../index') const bds = require('../index')
if (process.platform == "win32") { if (process.platform == "win32") {
var today = bds.date() var today = bds.date()
@@ -14,7 +14,7 @@ module.exports.World_BAckup = () => {
}; };
module.exports.Drive_backup = () => { module.exports.Drive_backup = () => {
if (require("./detect_bds").bds_detect()){require("./stop").Server_stop()} if (require("./detect_bds").bds_detect()){require("../global/stop").Server_stop()}
const bds = require("../index"); const bds = require("../index");
const path = require("path"); const path = require("path");
var dir_zip = path.join(bds.bds_dir_bedrock, "worlds"); var dir_zip = path.join(bds.bds_dir_bedrock, "worlds");

View File

@@ -4,14 +4,15 @@ module.exports.checkUser = (USERNAME) => {
var admins = fs.readFileSync(`${require("../index").bds_dir}/telegram_admin.json`, "utf-8"); var admins = fs.readFileSync(`${require("../index").bds_dir}/telegram_admin.json`, "utf-8");
} else { } else {
var admins = `{"sh23_bot_not_config": {"allow": true}}`; var admins = `{"sh23_bot_not_config": {"allow": true}}`;
console.log("All allowed") console.warn("All allowed")
console.log(`Create file in with name: ${require("../index").bds_dir}/telegram_admin.json`)
} }
var adm = JSON.parse(admins); var adm = JSON.parse(admins);
for(index in adm){ for(index in adm){
if (USERNAME == index){ if (USERNAME == index){
return true return true
} else if (index == "sh23_bot_not_config"){ } else if (index == "sh23_bot_not_config"){
console.log("Allow all") console.warn("Allow all")
return true return true
}; index++; }; index++;
}; };

View File

@@ -56,10 +56,9 @@ bot.command("command", (ctx) =>{
const detect_log_file = fs.existsSync(bds.log_file); const detect_log_file = fs.existsSync(bds.log_file);
bds_command(command) bds_command(command)
if (detect_log_file){ if (detect_log_file){
const old = fs.readFileSync(bds.log_file, "utf8"); const old = bds_log_string;
setTimeout(() => { setTimeout(() => {
var out = fs.readFileSync(bds.log_file, "utf8"); var name = bds_log_string.replace(old, "");
var name = out.replace(old, "");
ctx.reply(name) ctx.reply(name)
}, 1000); }, 1000);
} else { } else {
@@ -71,12 +70,11 @@ bot.command("list", (ctx) =>{
const fs = require("fs"); const fs = require("fs");
const bds = require("../index"); const bds = require("../index");
const detect_log_file = fs.existsSync(bds.log_file); const detect_log_file = fs.existsSync(bds.log_file);
bds_command("list")
if (detect_log_file){ if (detect_log_file){
const old = fs.readFileSync(bds.log_file, "utf8"); bds_command("list")
var old = bds_log_string;
setTimeout(() => { setTimeout(() => {
var out = fs.readFileSync(bds.log_file, "utf8"); var name = bds_log_string.replace(old, "");
var name = out.replace(old, "");
ctx.reply(name) ctx.reply(name)
}, 1000); }, 1000);
} else { } else {
@@ -87,7 +85,7 @@ bot.command("mcpe", (ctx) =>{
// ctx.replyWithHTML(`<a href="https://storage.cloud.google.com/bds_mcpe_files/mcpe.apk">Minecraft for Android 1.16.201.01</a>`) // ctx.replyWithHTML(`<a href="https://storage.cloud.google.com/bds_mcpe_files/mcpe.apk">Minecraft for Android 1.16.201.01</a>`)
const text = `[Minecraft for Android 1.16.201.01](https://storage.googleapis.com/bds_mcpe_files/0.16.201.01.apk) const text = `[Minecraft for Android 1.16.201.01](https://storage.googleapis.com/bds_mcpe_files/0.16.201.01.apk)
[Minecraft for IOS](https://apps.apple.com/br/app/minecraft/id479516143) Iphone users are not privileged
` `
ctx.replyWithMarkdown(text) ctx.replyWithMarkdown(text)
}); });

View File

@@ -99,7 +99,9 @@ if (fs.existsSync(log_dir)){
if (require("fs").existsSync(`${bds_dir}/telegram_token.txt`)){module.exports.token = require("fs").readFileSync(`${bds_dir}/telegram_token.txt`, "utf8").replaceAll("\n", "");} else {module.exports.token = undefined;} if (require("fs").existsSync(`${bds_dir}/telegram_token.txt`)){module.exports.token = require("fs").readFileSync(`${bds_dir}/telegram_token.txt`, "utf8").replaceAll("\n", "");} else {module.exports.token = undefined;}
// Depacretd function // Depacretd function
module.exports.Storage = () => {var localStorage = require("node-localstorage").localStorage;return new localStorage(`${cache_dir}/Local_Storage`)();} // module.exports.Storage = () => {
// return new require("node-localstorage").localStorage(`${cache_dir}/Local_Storage`)();
// }
module.exports.telegram_token_save = (token) =>{fs.writeFileSync(`${bds_dir}/telegram_token.txt`, token);return "OK"} module.exports.telegram_token_save = (token) =>{fs.writeFileSync(`${bds_dir}/telegram_token.txt`, token);return "OK"}
if (typeof fetch === "undefined"){global.fetch = require("node-fetch")} if (typeof fetch === "undefined"){global.fetch = require("node-fetch")}

View File

@@ -1,68 +1,32 @@
module.exports.World_BAckup = () => { module.exports.World_BAckup = () => {
if (require("./detect_bds").bds_detect()){require("../global/stop").Server_stop()}
const bds = require('../index')
if (process.platform == "win32") { if (process.platform == "win32") {
var today = bds.date()
var dd = String(today.getDate()).padStart(2, "0");
var mm = String(today.getMonth() + 1).padStart(2, "0");
var yyyy = today.getFullYear();
var hour = today.getHours();
var minu = today.getMinutes();
today = `Date_${yyyy}-${mm}-${dd}(Hour_${hour}-Minutes_${minu})`;
var name = `${process.env.USERPROFILE}/Desktop/bds_backup_World_${today}.zip` var name = `${process.env.USERPROFILE}/Desktop/bds_backup_World_${today}.zip`
var dir_zip = `${require("../index").bds_dir}/worlds/` var dir_zip = `${require("../index").bds_dir}/worlds/`
} else if (process.platform == "linux") { } else if (process.platform == "linux") {
var today = bds.date()
var dd = String(today.getDate()).padStart(2, "0");
var mm = String(today.getMonth() + 1).padStart(2, "0");
var yyyy = today.getFullYear();
var hour = today.getHours();
var minu = today.getMinutes();
today = `Date_${yyyy}-${mm}-${dd} Hour_${hour}-Minutes_${minu}`;
var name = `${process.env.HOME}/bds_backup_World_${today}.zip` var name = `${process.env.HOME}/bds_backup_World_${today}.zip`
var dir_zip = `${require("../index").bds_dir_bedrock}/worlds/` var dir_zip = `${require("../index").bds_dir_java}/world/`
}; /* End Files name */ };
/* Compress the folders */ var AdmZip = require("adm-zip");var zip = new AdmZip();zip.addLocalFolder(dir_zip);zip.addZipComment(`Backup zip file in ${today}. \nBackup made to ${process.platform}, Free and open content for all\n\nSirherobrine23© By Bds Maneger.`);var zipEntries = zip.getEntries();zipEntries.forEach(function (zipEntry) {console.log(zipEntry.entryName.toString());});zip.writeZip(name);console.log("Backup Sucess")
var AdmZip = require("adm-zip");
var zip = new AdmZip();
zip.addLocalFolder(dir_zip); /* var willSendthis = zip.toBuffer(); */
zip.addZipComment(`Backup zip file in ${today}. \nBackup made to ${process.platform}, Free and open content for all\n\nSirherobrine23© By Bds Maneger.`)
var zipEntries = zip.getEntries();
zipEntries.forEach(function (zipEntry) {
console.log(zipEntry.entryName.toString());
});
zip.writeZip(name); /* Zip file destination */
console.log("Backup Sucess")
/* Compress the folders */
return "Sucess"
}; };
module.exports.Drive_backup = () => { module.exports.Drive_backup = () => {
if (require("./detect_bds").bds_detect()){ if (require("./detect_bds").bds_detect()){require("../global/stop").Server_stop()}
require("../global/stop").Server_stop()
}
const bds = require("../index"); const bds = require("../index");
const path = require("path"); const path = require("path");
if (localStorage.getItem('bds_edititon') === 'java') var dir_zip = path.join(bds.bds_dir_java, "world");
var dir_zip = path.join(bds.bds_dir_java, "world");
else
var dir_zip = path.join(bds.bds_dir_bedrock, "worlds");
const today = bds.date(); const today = bds.date();
const file_name = `bds_backup_World_${today}.zip` const file_name = `bds_backup_World_${today}.zip`
const name = path.join(bds.tmp_dir, file_name) const name = path.join(bds.tmp_dir, file_name)
/* Compress the folders */ /* Compress the folders */
var AdmZip = require("adm-zip"); var AdmZip = require("adm-zip");var zip = new AdmZip();zip.addLocalFolder(dir_zip);zip.addZipComment(`Backup zip file in ${today}. \nBackup made to ${process.platform}, Free and open content for all\n\nSirherobrine23© By Bds Maneger.`);var zipEntries = zip.getEntries();zip.writeZip(name);console.log("Backup Sucess")
var zip = new AdmZip(); var json_return = {
zip.addLocalFolder(dir_zip); /* var willSendthis = zip.toBuffer(); */ file_dir: name.replaceAll("\\", "/"),
zip.addZipComment(`Backup zip file in ${today}. \nBackup made to ${process.platform}, Free and open content for all\n\nSirherobrine23© By Bds Maneger.`) file_name: file_name
var zipEntries = zip.getEntries(); }
// zipEntries.forEach(function (zipEntry) { return json_return
// console.log(zipEntry.entryName.toString());
// });
zip.writeZip(name); /* Zip file destination */
console.log("Backup Sucess")
/* Compress the folders */
return JSON.parse(`{
"file_dir": "${name.replaceAll("\\", "/")}",
"file_name": "${file_name}"
}`)
}; };

1496
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@@ -38,6 +38,7 @@
"node-localstorage": "^2.1.6", "node-localstorage": "^2.1.6",
"open": "^7.3.1", "open": "^7.3.1",
"properties-to-json": "^0.1.7", "properties-to-json": "^0.1.7",
"qr-image": "^3.2.0",
"qrcode": "^1.4.4", "qrcode": "^1.4.4",
"shelljs": "^0.8.4", "shelljs": "^0.8.4",
"systeminformation": "^4.34.5", "systeminformation": "^4.34.5",