thesobersobber / alertbot Goto Github PK
View Code? Open in Web Editor NEWAlert Bot for Colleges! (yes, for all of em!)
Home Page: https://alertbot.vercel.app
License: GNU General Public License v3.0
Alert Bot for Colleges! (yes, for all of em!)
Home Page: https://alertbot.vercel.app
License: GNU General Public License v3.0
implement a store to fix the waiting for message issue
quoting
/** * fetch a message from your store * implement this so that messages failed to send (solves the "this message can take a while" issue) can be retried * */ getMessage: (key: proto.IMessageKey) => Promise<proto.IMessage | undefined>
from https://adiwajshing.github.io/Baileys/
also refrence
https://github.com/adiwajshing/Baileys/issues/1555
add dev dependencies
node-fetch
yarn
nodemon
aren't required dependencies
add a dev script in package.json
use ws.ev.on("group-participants-update") event to keep group.json up to current state.
code base looks shit, clean and indent it
before linkArr didn't exist, so updates with multiple links were impossible
now that linkArr has been added to data json interface, some parsers can be fixed.
nsutParser and iiitbhParser are good and easy.
i think a deadlock is occuring cus the bot tries to spam in all groups as soon as an update is available.
i think this is the reason for stale session on groups too.
maybe we need some kind of wait before trying second.
look into that.
some issues for refrence, tho not very helpful
https://github.com/adiwajshing/Baileys/issues/2386
btw this is getting logged due to pino : {logger : error} level, making it silent should help make the terminal more clean and sane
Axios implementation
const fs = require('fs/promises');
class Leetcode {
/**
* Creates an instance of Leetcode.
* @param {string} userDataFile - The path to the file containing user data.
* @param {string} groupId - The ID of the user group.
*/
constructor(userDataFile, groupId) {
this.userDataFile = userDataFile;
this.groupId = groupId;
this.LEETCODE_PREDICT_URL = "https://lccn.lbao.site/api/v1";
this.LEETCODE_MULTIPLE_USER_PREDICTIONS = this.LEETCODE_PREDICT_URL + "/contest-records/predicted-rating";
this.userData = [];
}
async initializeUserData() {
try {
const userData = await fs.readFile(this.userDataFile, 'utf8');
const userGroups = JSON.parse(userData);
this.userData = userGroups[this.groupId] || [];
} catch (error) {
console.error('Error initializing user data:', error);
}
}
async fetchMultipleRatingPredictions(contestName) {
try {
const url = this.LEETCODE_MULTIPLE_USER_PREDICTIONS;
const response = await fetch(url, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
contest_name: contestName,
users: this.userData.map(user => ({ username: user, data_region: 'US' }))
})
});
const jsonData = await response.json();
const predictions = {};
jsonData.forEach(jsonRow => {
if (jsonRow && this.userData.includes(jsonRow.username)) {
predictions[jsonRow.username] = { newRating: jsonRow.new_rating, deltaRating: jsonRow.delta_rating };
}
});
return predictions;
} catch (error) {
console.error('Error:', error);
return {};
}
}
async getFormattedMessage(contest) {
try {
if (this.userData.length === 0) await this.initializeUserData();
const predictions = await this.fetchMultipleRatingPredictions(contest);
let message = 'PREDICTIONS\n';
for (const [username, prediction] of Object.entries(predictions)) {
message += `${username}: ${prediction.newRating}\n`;
}
return message;
} catch (error) {
console.error('Error generating message:', error);
return 'Error generating message';
}
}
}
// Example usage:
const leetcode = new Leetcode('./data/lc-users.txt', 'groupId1');
const contestName = "someContestName";
leetcode.getFormattedMessage(contestName)
.then(message => console.log(message))
.catch(error => console.error('Error:', error));
module.exports = Leetcode;
try {
functionThatCanThrowError();
} catch (err) {
throw new Error("Error: ", { cause: err });
// or "cause" in err
}
since vercel doesn't support "Groups-AlertBot"
When groupId Json object fetch fails then AlertBot throws a JSON.parse error as when groupIds is down there is a 404 page instead of that which it tries to parse and hence throws the error that html is not json
A copy of the error
^
SyntaxError: Unexpected token < in JSON at position 0 at JSON.parse () at main (/data/data/com.termux/files/home/AlertBot/main.js:56:39)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
Node.js v18.12.1
error Command failed with exit code 1.
just clean up main.js ffs
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.