Telegram bot commands #6

Merged
Sirherobrine23 merged 4 commits from Telegram_Bot_Commands into main 2021-01-08 23:29:54 +00:00
4 changed files with 74 additions and 3 deletions
Showing only changes of commit fe98b1421e - Show all commits

View File

@ -80,4 +80,67 @@ module.exports.drive_backup = (parent_id) => {
});
}
return 'Use backup_id para ter o id do ultimo arquivo'
}; /*End*/
// Donwnload
module.exports.drive_download = (parent_id) => {
const fs = require('fs');
const readline = require('readline');
const {google} = require('googleapis');
const SCOPES = ['https://www.googleapis.com/auth/drive'];
const TOKEN_PATH = __dirname+'/token.json';
return fs.readFile(__dirname+'/credentials.json', (err, content) => {
if (err) return console.log('Error loading client secret file:', err);
return authorize(JSON.parse(content), listFiles);
});
function authorize(credentials, callback) {
const {client_secret, client_id, redirect_uris} = credentials.installed;
const oAuth2Client = new google.auth.OAuth2(
client_id, client_secret, redirect_uris[0]);
fs.readFile(TOKEN_PATH, (err, token) => {
if (err) return getAccessToken(oAuth2Client, callback);
oAuth2Client.setCredentials(JSON.parse(token));
callback(oAuth2Client);
});
}
function getAccessToken(oAuth2Client, callback) {
const authUrl = oAuth2Client.generateAuthUrl({
access_type: 'offline',
scope: SCOPES,
});
console.log('Authorize this app by visiting this url:', authUrl);
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout,
});
rl.question('Enter the code from that page here: ', (code) => {
rl.close();
oAuth2Client.getToken(code, (err, token) => {
if (err) return console.error('Error retrieving access token', err);
oAuth2Client.setCredentials(token);
fs.writeFile(TOKEN_PATH, JSON.stringify(token), (err) => {
if (err) return console.error(err);
console.log('Token stored to', TOKEN_PATH);
});
callback(oAuth2Client);
});
});
};
function listFiles(auth) {
const bds = require('../../index').tmp_dir
const drive = google.drive({version: 'v3', auth});
var fileId = '11jJjMZRtrQus3Labo_kr85EgtgSVRPLI';
var dest = fs.createWriteStream(`${bds}/mcpe.apk`);
drive.files.get({fileId: fileId, alt: 'media'}, {responseType: 'stream'},function(err, res){
res.data.on('end', () => {
console.log('Done');}).on('error', err => {
console.log('Error', err)}).pipe(dest)})
}
// return 'Use backup_id para ter o id do ultimo arquivo'
}; /*End*/

View File

@ -83,6 +83,12 @@ 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');
// https://telegraf.js.org/#/?id=senddocument
telegram.sendDocument(ctx.chatId, doc)
});
bot.command('log', (ctx) => {
const file_log_path = require('../../index').log_file;
const fs = require("fs")

View File

@ -102,6 +102,7 @@ module.exports.date = date
module.exports.command = require('./Services/command').command
module.exports.backup = require("./Services/backup").World_BAckup
module.exports.drive_backup = require('./Services/drive/auth').drive_backup
module.exports.mcpe_file = require('./Services/drive/auth').drive_download
module.exports.kill = require("./Services/kill").bds_kill
module.exports.version_Download = require("./Services/download").DownloadBDS
module.exports.set_config = require("./Services/bds_settings").config