Merge #20

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

View File

@ -47,11 +47,18 @@ module.exports = () => {
return res.send(json_http);
});
app.get("/", (req, res) => {
return res.send({
"info": "/info",
"Bds Commnd": "/bds_command (POST)",
"Log": "/log",
"bds_maneger_API_version": require("../package.json").version
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}`);
});
app.get("/themes", (req, res) => {
fetch("https://raw.githubusercontent.com/Bds-Maneger/Raw_files/main/themes.json").then(response => response.json()).then(array => {
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");

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 command_bds = '';
const tokens = JSON.parse(fs.readFileSync(path.join(bds.bds_dir, "bds_tokens.json"), "utf-8"))
var pass = false;
for (let token_verify in tokens) {const element = tokens[token_verify].token;if (body.token == element){pass = true} else {token_verify++}}
if (pass){
if (command_bds === 'start'){
var bds_init = bds.start()
var command_status = `Bds Started`
} else if (command_bds === 'stop'){
bds.stop()
var command_status = `Stopping the bds server`
} else if (command_bds === 'reload'){
const bds_status = bds.detect()
if (bds_detect){
bds.stop()
}
var bds_init = bds.start()
var command_status = `Reloading`
} else {
var command_status = `no command identified`
}
res.send({
"status": 200,
"bds_status": command_status
})
} else {
res.send({
"status": 401,
"message": `Not authorized: ${body.token}`
})
}
res.send({
"command": req.params.command
})
// for (let token_verify in tokens) {const element = tokens[token_verify].token;if (body.token == element){pass = true} else {token_verify++}}
// if (pass){
// if (command_bds === 'start'){
// var bds_init = bds.start()
// var command_status = `Bds Started`
// } else if (command_bds === 'stop'){
// bds.stop()
// var command_status = `Stopping the bds server`
// } else if (command_bds === 'reload'){
// const bds_status = bds.detect()
// if (bds_detect){
// bds.stop()
// }
// var bds_init = bds.start()
// var command_status = `Reloading`
// } else {
// var command_status = `no command identified`
// }
// res.send({
// "status": 200,
// "bds_status": command_status
// })
// } else {
// res.send({
// "status": 401,
// "message": `Not authorized: ${body.token}`
// })
// }
});
app.post("/bds_command", (req, res) => {
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 = () => {
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')
if (process.platform == "win32") {
var today = bds.date()
@ -14,7 +14,7 @@ module.exports.World_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 path = require("path");
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");
} else {
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);
for(index in adm){
if (USERNAME == index){
return true
} else if (index == "sh23_bot_not_config"){
console.log("Allow all")
console.warn("Allow all")
return true
}; index++;
};

View File

@ -56,10 +56,9 @@ bot.command("command", (ctx) =>{
const detect_log_file = fs.existsSync(bds.log_file);
bds_command(command)
if (detect_log_file){
const old = fs.readFileSync(bds.log_file, "utf8");
const old = bds_log_string;
setTimeout(() => {
var out = fs.readFileSync(bds.log_file, "utf8");
var name = out.replace(old, "");
var name = bds_log_string.replace(old, "");
ctx.reply(name)
}, 1000);
} else {
@ -71,12 +70,11 @@ bot.command("list", (ctx) =>{
const fs = require("fs");
const bds = require("../index");
const detect_log_file = fs.existsSync(bds.log_file);
bds_command("list")
if (detect_log_file){
const old = fs.readFileSync(bds.log_file, "utf8");
bds_command("list")
var old = bds_log_string;
setTimeout(() => {
var out = fs.readFileSync(bds.log_file, "utf8");
var name = out.replace(old, "");
var name = bds_log_string.replace(old, "");
ctx.reply(name)
}, 1000);
} 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>`)
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)
});

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;}
// 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"}
if (typeof fetch === "undefined"){global.fetch = require("node-fetch")}

View File

@ -1,68 +1,32 @@
module.exports.World_BAckup = () => {
if (require("./detect_bds").bds_detect()){require("../global/stop").Server_stop()}
const bds = require('../index')
if (process.platform == "win32") {
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 today = bds.date()
var name = `${process.env.USERPROFILE}/Desktop/bds_backup_World_${today}.zip`
var dir_zip = `${require("../index").bds_dir}/worlds/`
} else if (process.platform == "linux") {
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 today = bds.date()
var name = `${process.env.HOME}/bds_backup_World_${today}.zip`
var dir_zip = `${require("../index").bds_dir_bedrock}/worlds/`
}; /* End Files name */
/* Compress the folders */
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"
var dir_zip = `${require("../index").bds_dir_java}/world/`
};
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")
};
module.exports.Drive_backup = () => {
if (require("./detect_bds").bds_detect()){
require("../global/stop").Server_stop()
}
if (require("./detect_bds").bds_detect()){require("../global/stop").Server_stop()}
const bds = require("../index");
const path = require("path");
if (localStorage.getItem('bds_edititon') === 'java')
var dir_zip = path.join(bds.bds_dir_java, "world");
else
var dir_zip = path.join(bds.bds_dir_bedrock, "worlds");
var dir_zip = path.join(bds.bds_dir_java, "world");
const today = bds.date();
const file_name = `bds_backup_World_${today}.zip`
const name = path.join(bds.tmp_dir, file_name)
/* Compress the folders */
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 JSON.parse(`{
"file_dir": "${name.replaceAll("\\", "/")}",
"file_name": "${file_name}"
}`)
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 json_return = {
file_dir: name.replaceAll("\\", "/"),
file_name: file_name
}
return json_return
};

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",
"open": "^7.3.1",
"properties-to-json": "^0.1.7",
"qr-image": "^3.2.0",
"qrcode": "^1.4.4",
"shelljs": "^0.8.4",
"systeminformation": "^4.34.5",