Giter VIP home page Giter VIP logo

alertbot's People

Contributors

ota0912 avatar thesobersobber avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar

alertbot's Issues

Leetcode Plugin [Rating Predictor]

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;

Phase 2: Extending Surface

  • Allow Support for any number of Arbitrary parser(s) to sun parallely
  • Abstract the send logic in main (the main function)
  • Call the main function in such a way to allow sending to arbitrary college WA groups

stalkbot is broken

  • stalk bot's logic is broken, it send messages no matter whether it's the same in data
  • just debug the logic
  • :((

fix linkArr based parsers

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.

Stack Overflow, Better Error Handling

  • Just make all catch's throw errors instead of calling startBot() again.
  • We can use those Errors in a global try catch that we can use to spawn a subprocess, we can have that in a while loop.
  • Calling startBot is a good restart Mechanism but It fails because of stack overflow, if you want personalized logging for all the catche's then just throw personalized errors
    for example,
try {
  functionThatCanThrowError();
} catch (err) {
  throw new Error("Error: ", { cause: err });
  // or "cause" in err
}

Refactoring handleCommands.js

  • Convert handleCommands.js into a set of modules to ensure the code is DRY
  • Create a separate abstraction class for all the commands that are needed in both groups and dms.

"possible mutex deadlock"

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

groupIds JSON object fetch failing

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.

make plugins behave like actual plugins

  • generate main.js procedurally with plugins on the basis of this
  • Permissions:
    • if they want message.upsert even they need to ask for it and then we'll place them in there
    • ask the plugin entry point for each event they wanna subscribe to
  • this opens up the scope for creating a package manager for plugins and create mirrors for that (see how revanced manages plugins for refrence)
  • yk how npm generates a lock file? yeah, we'll need that with the id of the latest commit or something from the plugin repo but somehow individual for each plugin

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.