Code Monkey home page Code Monkey logo

amaribot.js's People

Contributors

brianwastaken avatar dependabot[bot] avatar github-actions[bot] avatar oirnoir avatar renovate[bot] avatar saif-cybersec avatar thewilloftheshadow avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

amaribot.js's Issues

Queue System

Queue System

This system will automatically queue requests that you make when you are ratelimited

  • Automatically queue requests
  • Disable queue in constructor
  • Cancel requests in the queue

Developers are required to provide the token two times in typescript

Describe the bug
In Typescript, developers are forced to provide both token: string and options: AmariBotOptions. options requires a token to be passed even though it was already passed. I believe that's because of this line:
https://github.com/amaribot/amaribot.js/blob/46070dbf47db07f13c3d31d9268665b3c2d1ef6e/src/index.d.ts#L10
where, unlike in the actual Javascript code, options is not being defaulted to {} .https://github.com/amaribot/amaribot.js/blob/46070dbf47db07f13c3d31d9268665b3c2d1ef6e/src/AmariBot.js#L17

To Reproduce
Steps to reproduce the behavior:

  1. In Typescript 4.9.5 import the package like so import amariBotImporter from "amaribot.js"
  2. Attept to create a new AmariBot via
const importer = new amariBotImporter.AmariBot(process.env.AMARIBOT_API_KEY as string)
  1. See error
Expected 2 arguments, but got 1. ts(2554)
index.d.ts(10, 43): An argument for 'options' was not provided.

Expected behavior
The developer only needs to provide the token once.

Screenshots
CleanShot 2023-02-18 at 19 13 08@2x

Versions

  • Node.js: 19.6.0
  • NPM: using pnpm, version 7.27.0
  • AmariBot.js: 1.6.1
  • Typescript: 4.9.5

Additional context
In addition to this being fixed, https://github.com/amaribot/amaribot.js/blob/46070dbf47db07f13c3d31d9268665b3c2d1ef6e/src/index.d.ts#L79 should be optional/not exist since the developer already provided the token in the first token: string argument.

Error: "baseURL must end with a /", even when it does

Describe the bug
Throws error when baseURL option ends with a slash (/).

AmariBot.js#L21

if (options.baseURL !== undefined && options.baseURL.endsWith("/")) throw new Error("baseURL must end with a /")

I'm assuming should be changed to

if (options.baseURL !== undefined && !options.baseURL.endsWith("/")) throw new Error("baseURL must end with a /")

To Reproduce
Steps to reproduce the behavior:

  1. new AmariBot("AMARIBOTAPITOKEN", { baseURL: "https://amaribot.com/api/" })

Expected behavior
No error.

Versions

  • Node.js: v16.6.1
  • NPM: v7.20.3
  • AmariBot.js: v1.0.1

Additional context
Unrelated to this but the leaderboard and rewards examples don't work.
Its reassigning the AmariBot constant in both examples:
SyntaxError: Identifier 'AmariBot' has already been declared
and the in the rewards example something similar is happening:
SyntaxError: Identifier 'level' has already been declared.
Also in the rewards example message is not declared, but I don't
know if that example is meant to be in a message event.

Feature: Custom fetch function for proxies

I've made a proxy with CloudFlare workers to hide my exact IP address. I want to be able to use it with amaribot.js, but amaribot.js only uses the regular fetch API, which doesn't go through the proxy.

I would like to be able to replace the fetch module within amaribot.js as a config option upon initiating the client with one of my own methods or functions, such as this one:

/**
 * @param {String} endpoint 
 * @param {RequestInit} options 
 * @returns {Promise<Response>}
 */
async function fetch(endpoint, options={}) {
    return new Promise(async (resolve) => {
        const res = await fetch("https://uri.to.my.request.proxy.worker.oirnoir.workers.dev/", {...options, headers: {endpoint, headers: options.headers == null ? "{}" : JSON.stringify(options.headers)}, cache: "no-cache"});
        const receivedHeaders = res.headers.has("incomingHeaders") ? JSON.parse(res.headers.get("incomingHeaders")) : null;
        res.proxyHeaders = res.headers;
        if (receivedHeaders != null) {
            Object.defineProperty(res, "headers", {get: () => new Headers(receivedHeaders)});
        }
        return resolve(res);
    });
}

The function has the exact same syntax as the built-in fetch API, but requests through my cloudflare workers proxy. It returns the data in the exact same format. I want to be able to replace the fetch api within amaribot.js with my own function (it can do anything, it just needs to accept and return similar values as the fetch api would). The function above is just an example input.

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.