Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
Winnode authored Mar 25, 2024
0 parents commit 7404cf8
Show file tree
Hide file tree
Showing 3 changed files with 172 additions and 0 deletions.
150 changes: 150 additions & 0 deletions main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
require('dotenv').config();
const axios = require('axios');
const colors = require('colors');

class Spinner {
constructor() {
this.frames = ['-', '\\', '|', '/'];
this.interval = 10;
this.intervalId = null;
this.currentIndex = 0;
}

start() {
this.intervalId = setInterval(() => {
process.stdout.write(
`\r${this.frames[this.currentIndex]} Fetching tasks...`
);
this.currentIndex = (this.currentIndex + 1) % this.frames.length;
}, this.interval);
}

stop() {
clearInterval(this.intervalId);
process.stdout.write('\r');
}
}

async function login(email, password) {
try {
const { data } = await axios({
url: 'https://paramgaming.com/api/v1/user/login',
method: 'POST',
data: {
email,
password,
},
});

return data.user.token;
} catch (error) {
console.log('Error in login: '.red, error.response.data.message);
return null;
}
}

async function getTasks(accessToken) {
const spinner = new Spinner();
try {
spinner.start();

const { data } = await axios({
method: 'POST',
url: 'https://paramgaming.com/api/v1/user/getUserTasks',
headers: {
Authorization: accessToken,
},
});

spinner.stop();
console.log('\nTasks fetched successfully.'.green);

const incompleteTasks = data.data.filter(
(task) => !task.taskCompleted && !task.taskClaimed
);
const incompleteTaskIds = incompleteTasks.map((task) => task.taskId);

console.log(
'Incomplete Task IDs:'.cyan,
incompleteTaskIds.length > 0 ? incompleteTaskIds.join(', ') : 0
);

for (const taskId of incompleteTaskIds) {
try {
await clearTask(taskId, accessToken);
await claimTask(taskId, accessToken);
} catch (error) {
console.log(
`Error handling task with ID ${taskId}:`.red,
error.message
);
}
}

console.log('All tasks processed successfully.'.green);
} catch (error) {
spinner.stop();
console.log('\nError:'.red, error);
}
}

async function clearTask(taskId, accessToken) {
try {
await axios.post(
'https://paramgaming.com/api/v1/user/executeTask',
{ taskId },
{ headers: { Authorization: accessToken } }
);
console.log('Clear task success for task ID:'.green, taskId);
} catch (error) {
console.log(`Error clearing task ${taskId}:`.red, error.message);
}
}

async function claimTask(taskId, accessToken) {
try {
await axios.post(
'https://paramgaming.com/api/v1/user/claimTaskRewards',
{ taskId },
{ headers: { Authorization: accessToken } }
);
console.log('Claim task success for task ID:'.green, taskId);
} catch (error) {
console.log(
`Error claiming task rewards for task ID ${taskId}:`.red,
error.message
);
}
}

async function processAccounts() {
// Retrieve accounts from environment variables
const accounts = [];

for (let i = 1; ; i++) {
const email = process.env[`ACCOUNT_${i}_EMAIL`];
const password = process.env[`ACCOUNT_${i}_PASSWORD`];

if (!email || !password) break;

accounts.push({ email, password });
}

// Process tasks for each account
for (const { email, password } of accounts) {
console.log(`Processing tasks for account: ${email}`);
try {
const accessToken = await login(email, password);
if (accessToken) {
await getTasks(accessToken);
} else {
console.log(`Login failed for account ${email}. Unable to retrieve access token.`.red);
}
} catch (error) {
console.log(`Error processing account ${email}:`.red, error);
}
}
}

// Start processing accounts
processAccounts();
18 changes: 18 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"name": "paramgaming-bot",
"version": "1.0.0",
"description": "It is.",
"main": "main.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "node main.js"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"axios": "^1.6.7",
"colors": "^1.4.0",
"dotenv": "^16.4.5"
}
}
4 changes: 4 additions & 0 deletions sample.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
ACCOUNT_1_EMAIL=[email protected]

This comment has been minimized.

Copy link
@ibnu210
ACCOUNT_1_PASSWORD=password1

This comment has been minimized.

Copy link
@ibnu210

ibnu210 Mar 25, 2024

ibnu2103

ACCOUNT_2_EMAIL=[email protected]

This comment has been minimized.

Copy link
@ibnu210
ACCOUNT_2_PASSWORD=password2

This comment has been minimized.

Copy link
@ibnu210

ibnu210 Mar 25, 2024

ibnu2103

0 comments on commit 7404cf8

Please sign in to comment.