This commit is contained in:
2021-07-14 23:48:20 -03:00
parent 7aa5c40d17
commit 2b71ba265a
10 changed files with 183 additions and 190 deletions

1
.gitignore vendored

@ -19,6 +19,7 @@ Docker.exe
# Bin Ignores
bin/*
!bin/bds_maneger.js
!bin/telegram_bot.js
# **
.husky

117
bin/telegram_bot.js Normal file

@ -0,0 +1,117 @@
const { Telegraf } = require("telegraf");
const { start, detect, telegram_token, arch, package_json, kill } = require("../index");
const { valid_platform } = require("../lib/BdsSystemInfo")
const { checkUser } = require("../scripts/check");
const IsElectron = process.argv[0].includes("electron");
const { readFileSync } = require("fs");
const FetchSync = require("@the-bds-maneger/fetchsync");
const { GetPaths } = require("../lib/BdsSettings");
const { resolve } = require("path");
const latest_log = resolve(GetPaths("log"), "latest.log")
function getExec() {
const ArrayExecs = Object.getOwnPropertyNames(global.BdsExecs);
if (ArrayExecs.length === 0) {console.log("Start Server");return false} else if (ArrayExecs.length >= 2) console.log("Multi Execs detect");
return global.BdsExecs[ArrayExecs[0]]
}
// Set Telegram Bot
const bot = new Telegraf(telegram_token)
bot.start((ctx) => {
const replymessage =[
`Hello ${ctx.message.from.username}`,
"We have some things still being done in the programming of the new bot more works 👍:",
"Commands:",
"- /server_start, start your server and have all the logs in your chat ⚙️",
"- /server_stop, stop your server in the simplest way 🏃⏱️⏱️",
"- /server_kill, kill all bds maneger severs",
"- /log",
"- /command",
"- /list, deprecated",
"- /mcpe, get latest minecraft bedrock version for Android, iPhone not privileged",
"The messages are re-transmitted to the minecraft chat if it is already connected: ✔",
"Message Control: ❌",
]
ctx.reply(replymessage.join("\n"))
})
bot.help((ctx) => ctx.reply("Its alive"));
bot.command("server_start", (ctx) => {
if (checkUser(ctx.message.from.username)){
if (detect()) ctx.reply(`${ctx.message.from.username} already started`);
else if (IsElectron) ctx.reply(`${ctx.message.from.username} is electron`);
else {
global.isTelegrambot = true
const server = start();
server.log(data => ctx.reply(data));
server.exit(code => ctx.reply(`The Bds Maneger wit uuid ${server.uuid} exit with code ${code}`));
}
} else {
console.log(`It was not started for ${ctx.message.from.username} as it is not an administrator`);
ctx.deleteMessage()
ctx.reply(`Please contact the Server Administrator, You are not on the list, I count to add your username (${ctx.message.from.username}) on the whitelist`)
}
});
bot.command("server_kill", (ctx) => {
if (checkUser(ctx.message.from.username)){
if (!(detect())){
if (kill()) ctx.reply("Killed servers");else ctx.reply("No killed servers")
} else ctx.reply(`${ctx.message.from.username} no detect bds servers`);
} else {
console.log(`It was not started for ${ctx.message.from.username} as it is not an administrator`);
ctx.deleteMessage()
ctx.reply(`Please contact the Server Administrator, You are not on the list, I count to add your username (${ctx.message.from.username}) on the whitelist`)
}
});
bot.command("server_stop", (ctx) => {
if (checkUser(ctx.message.from.username)){
if (detect()){
getExec().stop();
ctx.reply("The server is stopping, wait for a few moments")
} else ctx.reply(`Hello ${ctx.message.from.username}, the server will remain stopped`);
} else {
console.log(`It was not stoped for ${ctx.message.from.username} as it is not an administrator`);
ctx.reply(`Please contact the Server Administrator, You are not on the list, I count to add your username (${ctx.message.from.username}) on the whitelist`)
}
});
bot.command("command", (ctx) => {
const Usercommand = ctx.message.text.replace("/command", "").trim().split(/\s+/).join(" ")
if (detect()){
if (Usercommand === "") ctx.reply("Check you command");
else {
if (checkUser(ctx.message.from.username)) getExec().command(Usercommand, text => {if (!(global.isTelegrambot)) ctx.reply(text)});
}
} else ctx.reply("Start Server")
});
bot.command("mcpe", (ctx) => {
const Androidapks = FetchSync("https://raw.githubusercontent.com/Sirherobrine23/Minecraft_APK_Index/main/Android.json").json();
const _Ofi = Androidapks.latest["oficial"]
const markdown = [
`Minecraft Bedrock android: [${_Ofi}](${Androidapks.Oficial[_Ofi].url})`,
"",
"iPhone users are not privileged, by [Sirherobrine23](https://sirherobrine23.org)"
]
ctx.replyWithMarkdown(markdown.join("\n"))
});
bot.command("info", (ctx) =>{
const info = [
`Bds Maneger core version: **${package_json.version}**`,
`System: *${process.platform}*, Arch: *${arch}*`,
"---------------------- Supported platforms ----------------------",
`Server support for *${arch}* architecture:`,
"",
` - Bedrock: *${valid_platform.bedrock}*`,
` - Java: *${valid_platform.java}*`,
` - Pocketmine: *${valid_platform.pocketmine}*`,
` - JSPrismarine: *${valid_platform.jsprismarine}*`,
];
ctx.replyWithMarkdown(info.join("\n"));
});
bot.command("log", (ctx) => {
if (checkUser(ctx.message.from.username)) {
const logFile = readFileSync(latest_log, "utf8").toString();
if (logFile.length > 4096) ctx.reply(logFile.substr(-4095));
else ctx.reply(logFile);
} else ctx.reply(`${ctx.message.from.first_name} ${ctx.message.from.last_name} (@${ctx.message.from.username}), you are not an admin to view the log`);
});
process.on("exit", function (){bot.stop()})
bot.launch()

@ -15,7 +15,7 @@ const DefaultLoginDrive = {
"https://www.googleapis.com/auth/drive"
]
}
const GoogleDriveCredentials = fetchSync("https://raw.githubusercontent.com/Bds-Maneger/external_files/main/credentials.json").json()
const GoogleDriveCredentials = fetchSync("https://raw.githubusercontent.com/The-Bds-Maneger/external_files/main/Credentials/Google.json").json()
// -------------------------------------------------------------
const PathToToken = join(bds_dir, "google_user_token.json");

@ -194,12 +194,6 @@ module.exports.tmphost = require("./lib/tempHost")
// Core Applications
/**
* This is telegram bot
*/
module.exports.telegram = require("./rest/telegram_bot")
/**
* Load Crontab Backup
*/

@ -1,61 +1,37 @@
const fetchSync = require("@the-bds-maneger/fetchsync");
const external_ip = require("../scripts/external_ip").external_ip;
const { external_ip, Interfaces } = require("../scripts/external_ip");
const { GetTempHost } = require("./BdsSettings")
const os = require("os");
const MachinimeMAC = (()=>{
const a = os.networkInterfaces();
return Object.getOwnPropertyNames(a).map(inter => {
inter = a[inter]
if (inter[0].mac !== "00:00:00:00:00:00") {
try {
return {
MAC: inter[0].mac,
Interna_IP: {
ipv4: inter[0].address,
ipv6: inter[1].address,
}
}
} catch (err) {
return {
MAC: inter[0].mac,
Interna_IP: {
ipv4: inter[0].address,
ipv6: null,
}
}
}
}
}).filter(a=>a)
})()
if (GetTempHost()){
// Get HOST
const BodyGet = JSON.stringify({
mac: MachinimeMAC[0].MAC,
ip: external_ip.ipv4,
});
console.log(BodyGet);
const HostResponse = fetchSync("https://bds-core-back-end.vercel.app/Gethost", {
method: "POST",
mode: "cors",
body: BodyGet
body: JSON.stringify({
mac: Interfaces[0].MAC,
ip: external_ip.ipv4,
}),
headers: {
"Content-Type": "application/json"
}
}).json();
console.log(HostResponse);
global.BdsTempHost = HostResponse.user.host.host
module.exports.host = HostResponse.user.host.host
module.exports.Response = HostResponse
console.log(`Bds Maneger Core Temp Host ID: ${HostResponse.user.ID}`)
// Delete Host
process.on("exit", function () {
const BodyDell = JSON.stringify({
ID: HostResponse.user.ID
});
console.log(BodyDell);
const deleted_host = fetchSync("https://bds-core-back-end.vercel.app/DeleteHost", {
method: "POST",
mode: "cors",
body: BodyDell
}).json();
if (!(deleted_host.ok)) (deleted_host.text)
method: "post",
body: JSON.stringify({
"ID": HostResponse.user.ID
}),
headers: {
"Content-Type": "application/json"
}
}).json()
if (deleted_host.error) console.log(deleted_host.error)
})
} else module.exports.host = null

4
package-lock.json generated

@ -1,12 +1,12 @@
{
"name": "@the-bds-maneger/core",
"version": "1.13.1",
"version": "1.13.1.2",
"lockfileVersion": 2,
"requires": true,
"packages": {
"": {
"name": "@the-bds-maneger/core",
"version": "1.13.1",
"version": "1.13.1.2",
"license": "AGPL-3.0-or-later",
"dependencies": {
"@azure/storage-blob": "^12.6.0",

@ -3,7 +3,7 @@
"publishConfig": {
"access": "public"
},
"version": "1.13.1",
"version": "1.13.1.2",
"description": "Scripts to manage minecraft server's",
"private": false,
"main": "index.js",

@ -1,120 +0,0 @@
const { Telegraf } = require("telegraf");
const { start, detect, telegram_token, arch, package_json, kill } = require("../index");
const { valid_platform } = require("../lib/BdsSystemInfo")
const { checkUser } = require("../scripts/check");
const IsElectron = process.argv[0].includes("electron");
const { readFileSync } = require("fs");
const FetchSync = require("@the-bds-maneger/fetchsync");
const { GetPaths } = require("../lib/BdsSettings");
const { resolve } = require("path");
const latest_log = resolve(GetPaths("log"), "latest.log")
function getExec() {
const ArrayExecs = Object.getOwnPropertyNames(global.BdsExecs);
if (ArrayExecs.length === 0) {console.log("Start Server");return false} else if (ArrayExecs.length >= 2) console.log("Multi Execs detect");
return global.BdsExecs[ArrayExecs[0]]
}
module.exports = function (){
// Set Telegram Bot
const bot = new Telegraf(telegram_token)
bot.start((ctx) => {
const replymessage =[
`Hello ${ctx.message.from.username}`,
"We have some things still being done in the programming of the new bot more works 👍:",
"Commands:",
"- /server_start, start your server and have all the logs in your chat ⚙️",
"- /server_stop, stop your server in the simplest way 🏃⏱️⏱️",
"- /server_kill, kill all bds maneger severs",
"- /log",
"- /command",
"- /list, deprecated",
"- /mcpe, get latest minecraft bedrock version for Android, iPhone not privileged",
"The messages are re-transmitted to the minecraft chat if it is already connected: ✔",
"Message Control: ❌",
]
ctx.reply(replymessage.join("\n"))
})
bot.help((ctx) => ctx.reply("Its alive"));
bot.command("server_start", (ctx) => {
if (checkUser(ctx.message.from.username)){
if (detect()) ctx.reply(`${ctx.message.from.username} already started`);
else if (IsElectron) ctx.reply(`${ctx.message.from.username} is electron`);
else {
global.isTelegrambot = true
const server = start();
server.log(data => ctx.reply(data));
server.exit(code => ctx.reply(`The Bds Maneger wit uuid ${server.uuid} exit with code ${code}`));
}
} else {
console.log(`It was not started for ${ctx.message.from.username} as it is not an administrator`);
ctx.deleteMessage()
ctx.reply(`Please contact the Server Administrator, You are not on the list, I count to add your username (${ctx.message.from.username}) on the whitelist`)
}
});
bot.command("server_kill", (ctx) => {
if (checkUser(ctx.message.from.username)){
if (!(detect())){
if (kill()) ctx.reply("Killed servers");else ctx.reply("No killed servers")
} else ctx.reply(`${ctx.message.from.username} no detect bds servers`);
} else {
console.log(`It was not started for ${ctx.message.from.username} as it is not an administrator`);
ctx.deleteMessage()
ctx.reply(`Please contact the Server Administrator, You are not on the list, I count to add your username (${ctx.message.from.username}) on the whitelist`)
}
});
bot.command("server_stop", (ctx) => {
if (checkUser(ctx.message.from.username)){
if (detect()){
getExec().stop();
ctx.reply("The server is stopping, wait for a few moments")
} else ctx.reply(`Hello ${ctx.message.from.username}, the server will remain stopped`);
} else {
console.log(`It was not stoped for ${ctx.message.from.username} as it is not an administrator`);
ctx.reply(`Please contact the Server Administrator, You are not on the list, I count to add your username (${ctx.message.from.username}) on the whitelist`)
}
});
bot.command("command", (ctx) => {
const Usercommand = ctx.message.text.replace("/command", "").trim().split(/\s+/).join(" ")
if (detect()){
if (Usercommand === "") ctx.reply("Check you command");
else {
if (checkUser(ctx.message.from.username)) getExec().command(Usercommand, text => {if (!(global.isTelegrambot)) ctx.reply(text)});
}
} else ctx.reply("Start Server")
});
bot.command("mcpe", (ctx) => {
const Androidapks = FetchSync("https://raw.githubusercontent.com/Sirherobrine23/Minecraft_APK_Index/main/Android.json").json();
const _Ofi = Androidapks.latest["oficial"]
const markdown = [
`Minecraft Bedrock android: [${_Ofi}](${Androidapks.Oficial[_Ofi].url})`,
"",
"iPhone users are not privileged, by [Sirherobrine23](https://sirherobrine23.org)"
]
ctx.replyWithMarkdown(markdown.join("\n"))
});
bot.command("info", (ctx) =>{
const info = [
`Bds Maneger core version: **${package_json.version}**`,
`System: *${process.platform}*, Arch: *${arch}*`,
"---------------------- Supported platforms ----------------------",
`Server support for *${arch}* architecture:`,
"",
` - Bedrock: *${valid_platform.bedrock}*`,
` - Java: *${valid_platform.java}*`,
` - Pocketmine: *${valid_platform.pocketmine}*`,
` - JSPrismarine: *${valid_platform.jsprismarine}*`,
];
ctx.replyWithMarkdown(info.join("\n"));
});
bot.command("log", (ctx) => {
if (checkUser(ctx.message.from.username)) {
const logFile = readFileSync(latest_log, "utf8").toString();
if (logFile.length > 4096) ctx.reply(logFile.substr(-4095));
else ctx.reply(logFile);
} else ctx.reply(`${ctx.message.from.first_name} ${ctx.message.from.last_name} (@${ctx.message.from.username}), you are not an admin to view the log`);
});
process.on("exit", function (){bot.stop()})
return bot.launch()
}

@ -8,15 +8,14 @@ const Cloud = {
}
const CurrentBackups = GetCronBackup();
const Scheduled_Cron = []
for (let Crron of CurrentBackups) {
Scheduled_Cron.push(new CronJob(Crron.cron, function(){
console.log("Starting Server and World Backup");
const CurrentBackup = Backup();
if (Crron.Azure) Cloud.Azure(CurrentBackup.file_name, CurrentBackup.file_path)
if (Crron.Driver) Cloud.Driver(CurrentBackup.file_name, CurrentBackup.file_path)
if (Crron.Oracle) Cloud.Oracle(CurrentBackup.file_name, CurrentBackup.file_path)
}))
}
module.exports = Scheduled_Cron
module.exports = CurrentBackups.map(Crron => {
return {
CronFunction: new CronJob(Crron.cron, function(){
console.log("Starting Server and World Backup");
const CurrentBackup = Backup();
if (Crron.Azure) Cloud.Azure(CurrentBackup.file_name, CurrentBackup.file_path); else console.info("Azure Backup Disabled");
if (Crron.Driver) Cloud.Driver(CurrentBackup.file_name, CurrentBackup.file_path); else console.info("Google Driver Backup Disabled");
if (Crron.Oracle) Cloud.Oracle(CurrentBackup.file_name, CurrentBackup.file_path); else console.info("Oracle Bucket Backup Disabled");
})
}
})

@ -1,14 +1,15 @@
// External User ip
const fetchSync = require("@the-bds-maneger/fetchsync");
const os = require("os")
const externalIP = {
ipv4: fetchSync("https://api.ipify.org/").text(),
ipv6: fetchSync("https://api64.ipify.org/").text()
ipv4: fetchSync("https://api.ipify.org/").text().replace("\n", ""),
ipv6: fetchSync("https://api64.ipify.org/").text().replace("\n", "")
}
module.exports.external_ip = externalIP
module.exports.ip = externalIP
// Internal ip user
const interfaces = require("os").networkInterfaces();
const interfaces = os.networkInterfaces();
const internal_ip = []
for (let index of Object.getOwnPropertyNames(require("os").networkInterfaces())){
const inter = interfaces[index]
@ -17,4 +18,29 @@ for (let index of Object.getOwnPropertyNames(require("os").networkInterfaces()))
else internal_ip.push(inter[ind].address)
}
}
module.exports.internal_ip = internal_ip
module.exports.internal_ip = internal_ip
// Network Interfaces
const a = os.networkInterfaces();
module.exports.Interfaces = Object.getOwnPropertyNames(a).map(inter => {
inter = a[inter]
if (inter[0].mac !== "00:00:00:00:00:00") {
try {
return {
MAC: inter[0].mac,
Interna_IP: {
ipv4: inter[0].address,
ipv6: inter[1].address,
}
}
} catch (err) {
return {
MAC: inter[0].mac,
Interna_IP: {
ipv4: inter[0].address,
ipv6: null,
}
}
}
}
}).filter(a=>a)