Telegram bot commands #6
@ -1,9 +1,9 @@
|
||||
const fs = require('fs');
|
||||
const readline = require('readline');
|
||||
const {google} = require('googleapis');
|
||||
const bds = require('../../index')
|
||||
const bds = require("../../index");
|
||||
const SCOPES = ['https://www.googleapis.com/auth/drive'];
|
||||
const TOKEN_PATH = path.join(bds.server_dir, 'google_token.json');
|
||||
const TOKEN_PATH = path.join(bds.server_dir, "google_token.json");
|
||||
|
||||
|
||||
function authorize(credentials, callback) {
|
||||
@ -40,7 +40,7 @@ function getAccessToken(oAuth2Client, callback) {
|
||||
});
|
||||
};
|
||||
|
||||
const CREDENTIAL = require('../../index').google_drive_credential
|
||||
const CREDENTIAL = require("../../index").google_drive_credential
|
||||
module.exports.drive_backup = (parent_id) => {
|
||||
function upload_backup(auth) {
|
||||
const bds_backup = require('../backup').Drive_backup();
|
||||
@ -58,12 +58,19 @@ module.exports.drive_backup = (parent_id) => {
|
||||
};
|
||||
|
||||
module.exports.mcpe = () => {
|
||||
global.mcpe_file_end = false;
|
||||
function download_mcpe(auth) {
|
||||
const drive = google.drive({version: 'v3', auth});
|
||||
var fileId = '11jJjMZRtrQus3Labo_kr85EgtgSVRPLI';
|
||||
var dest = fs.createWriteStream(path.join(bds.tmp_dir, 'mcpe.apk'));
|
||||
let progress = 0;
|
||||
drive.files.get({fileId: fileId, alt: 'media'}, {responseType: 'stream'},function(err, res){res.data.on('end', () => {console.log('\nDone');}).on('error', err => {console.log('\nError', err)}).on('data', d => {
|
||||
drive.files.get({fileId: fileId, alt: 'media'}, {responseType: 'stream'},function(err, res){res.data.on('end', () => {
|
||||
console.log(`\nDone, Save in ${path.join(bds.tmp_dir, 'mcpe.apk')}`);
|
||||
global.mcpe_file_end = true;
|
||||
}).on('error', err => {
|
||||
console.log('\nError', err)
|
||||
global.mcpe_file_end = undefined;
|
||||
}).on('data', d => {
|
||||
progress += d.length / 1024 / 1024;
|
||||
if (process.stdout.isTTY) {process.stdout.clearLine();process.stdout.cursorTo(0);process.stdout.write(`Downloaded ${Math.trunc(progress)} Mbytes`);}
|
||||
}).pipe(dest)});
|
||||
|
@ -10,5 +10,5 @@ module.exports.Server_stop = () => {
|
||||
};
|
||||
});
|
||||
};
|
||||
return !(require('../Services/detect_bds').bds_detect())
|
||||
return !(require('./detect_bds').bds_detect())
|
||||
}
|
@ -83,17 +83,46 @@ bot.command('list', (ctx) =>{
|
||||
ctx.reply('NO log file to get list player')
|
||||
}
|
||||
});
|
||||
bot.command('mcpe', (ctx) =>{
|
||||
const fs = require('fs');
|
||||
const bds = require('../../index');
|
||||
const path = require('path')
|
||||
// doc = fs.ReadStream(path.join(bds.tmp_dir, 'mcpe.apk'))
|
||||
const buff = fs.ReadStream(path.join(bds.tmp_dir, 'mcpe.apk'))
|
||||
console.log(`mcpe.apk buffer: ${buff}`)
|
||||
ctx.replyWithDocument({ source: buff}, {filename: 'Bds.apk' })
|
||||
// https://telegraf.js.org/#/?id=senddocument
|
||||
// bot.sendDocument(ctx.chatId, doc)
|
||||
});
|
||||
// bot.command('mcpe', (ctx) =>{
|
||||
// const fs = require('fs');
|
||||
// const bds = require('../../index');
|
||||
// const path = require('path')
|
||||
// if (!(fs.existsSync(path.join(bds.tmp_dir, 'mcpe.apk')))){
|
||||
// require('../drive/auth').mcpe()
|
||||
// }
|
||||
// // doc = fs.ReadStream(path.join(bds.tmp_dir, 'mcpe.apk'))
|
||||
// let te = 0;
|
||||
// if (typeof mcpe_file_end == 'undefined'){
|
||||
// global.mcpe_file_end = true
|
||||
// }
|
||||
// while (te++ < te++ + 1){
|
||||
// if (mcpe_file_end){
|
||||
// break
|
||||
// } else if (mcpe_file_end == undefined){
|
||||
// ctx.reply('Um erro ocorreu');
|
||||
// break
|
||||
// } else {
|
||||
// te++
|
||||
// }
|
||||
// process.stdout.clearLine();
|
||||
// process.stdout.cursorTo(0);
|
||||
// process.stdout.write(`Teste ${te}`);
|
||||
// }
|
||||
// var buff = fs.ReadStream(path.join(bds.tmp_dir, 'mcpe.apk'));
|
||||
// console.log(`mcpe.apk buffer: ${buff}`)
|
||||
|
||||
// // delete(mcpe_file_end)
|
||||
// const requestListener = function (req, res) {
|
||||
// res.writeHead(200);
|
||||
// res.end(buff);
|
||||
// }
|
||||
|
||||
// const server = http.createServer(requestListener);
|
||||
// server.listen(8187);
|
||||
// // ctx.replyWithDocument({ source: buff}, {filename: 'Bds.apk' })
|
||||
// ctx.reply('http://localhost:8187')
|
||||
// // https://telegraf.js.org/#/?id=senddocument
|
||||
// });
|
||||
bot.command('log', (ctx) => {
|
||||
const file_log_path = require('../../index').log_file;
|
||||
const fs = require("fs")
|
||||
|
Reference in New Issue
Block a user