Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
Nasrullahmalik authored Feb 18, 2024
1 parent 1037b9d commit 1852857
Showing 1 changed file with 23 additions and 6 deletions.
29 changes: 23 additions & 6 deletions lib/makesession.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,39 @@
import axios from 'axios';
import { fileURLToPath } from 'url';
import path from 'path';
import { writeFileSync } from 'fs';
import { BufferJSON } from '@whiskeysockets/baileys';
import PastebinAPI from 'pastebin-js';
let pastebin = new PastebinAPI('bR1GcMw175fegaIFV2PfignYVtF0b_Bl')

async function processTxtAndSaveCredentials(txt) {
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);

const pasteId = txt.replace("GuruBot~", "");
let decodedData;

let decodedData = await pastebin.getPaste(pasteId);
const isBase64 = /^[a-zA-Z0-9+/]+={0,2}$/.test(txt);

if (isBase64) {
decodedData = Buffer.from(txt, 'base64').toString('utf-8');
} else {
const url = `https://pastebin.guruapi.tech/pastes?action=getpaste&id=${txt}`;

try {
const response = await axios.get(url);

const base64Data = response.data.content;

decodedData = Buffer.from(base64Data, 'base64').toString('utf-8');
} catch (error) {
console.error('Error retrieving or processing data:', error);
return;
}
}

try {
const credentials = JSON.parse(decodedData, BufferJSON.reviver);
const credsPath = path.join(__dirname, '..', 'session', 'creds.json');
writeFileSync(credsPath, decodedData.toString());
console.log('Saved credentials to', credsPath);
writeFileSync(credsPath, JSON.stringify(credentials, BufferJSON.replacer, 2));
console.log('Credentials saved to creds.json');
} catch (jsonError) {
console.error('Error parsing JSON:', jsonError);
}
Expand Down

0 comments on commit 1852857

Please sign in to comment.