Coder Social home page Coder Social logo

revoltchat / revolt.js Goto Github PK

View Code? Open in Web Editor NEW
214.0 3.0 54.0 5.24 MB

Modern Typescript library for interacting with Revolt.

Home Page: https://revolt.js.org

License: MIT License

TypeScript 99.80% JavaScript 0.20%
revolt javascript library typescript

revolt.js's Introduction

revolt.js

Warning

revolt.js is currently being rewritten. While it's ready for use for most applications, it is still not entirely feature complete.
You can find the version 6 README here.

revolt.js revolt-api

revolt.js is a JavaScript library for interacting with the entire Revolt API.

Example Usage

// esm / typescript
import { Client } from "revolt.js";
// ...or commonjs
const { Client } = require("revolt.js");

let client = new Client();

client.on("ready", async () =>
  console.info(`Logged in as ${client.user.username}!`)
);

client.on("messageCreate", async (message) => {
  if (message.content === "hello") {
    message.channel.sendMessage("world");
  }
});

client.loginBot("..");

Reactivity with Signals & Solid.js Primitives

All objects have reactivity built-in and can be dropped straight into any Solid.js project.

const client = new Client();
// initialise the client

function MyApp() {
  return (
    <h1>Your username is: {client.user?.username ?? "[logging in...]"}</h1>
  );
}

Revolt API Types

Warning

It is advised you do not use this unless necessary. If you find somewhere that isn't covered by the library, please open an issue as this library aims to transform all objects.

All revolt-api types are re-exported from this library under API.

import { API } from "revolt.js";

// API.Channel;
// API.[..];

revolt.js's People

Contributors

abdulrahman1s avatar aeongdesu avatar declanchidlow avatar dependabot[bot] avatar insertish avatar kyundothost avatar mafineeek avatar net-tech avatar nightscript370 avatar revolt-ci avatar rexogamer avatar snazzah avatar sussycatgirl avatar web-flow avatar

Stargazers

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

Watchers

 avatar  avatar  avatar

revolt.js's Issues

revolt.js bug

When my bot tries to delete a message, this error happens. Im not the only one who have this error, and I don't know how to fix it.

Code:

import { Message } from "revolt.js/dist/maps/Messages";

msg: Message

msg.delete();

kmbSI91rXYBnjSKd3yhLb0bjUlgX6rYHnJLYHR0y5i

feature request: Export Events Type

Issue Summary:
I'm currently working on a Revolt bot using revolt.js, and I noticed that the events type is not exported. Having access to the events type would be nice so that I can enforce type safety better in my own event handler.

Steps to Reproduce:
N/A

Expected Behavior:
I expected the library to export the events type so that developers can ensure type safety in their event handlers.

Actual Behavior:
The events type is not exported.

Additional Information:
N/A

Proposed Solution:
Export the events type in the API library to facilitate better type safety in event handling. I will open a GitHub PR.

Environment:

  • revolt.js Version: v7.0.0-beta.10
  • Node.js Version: v20.4.0
  • TypeScript Version: Version 5.3.3

Screenshots/Code Snippets:
N/A

feature request: add ability for client to delete emojis

What do you want to see?

In the latest version of the revolt.js npm package, which as of writing this issue is 7.0.0-beta.9, the client can fetch and add emojis to an server (though the fetchEmojis and createEmoji method), but not delete the emojis. So adding the ability to delete emojis would help add more capabilities to the packages.

Add webhook support

Webhook support would probably be a good idea, as github commits and other stuff support them, so I can have a github feed in a server

bug: MessageReact event crashes with: TypeError: reactions.get is not a function

What happened?

This snippet of code causes the above error:

		case 'MessageReact': {
			const message = client.messages.getOrPartial(event.id);
			if (message) {
				const reactions = message.reactions;

				const set = reactions.get(event.emoji_id);

... when a messageReactionAdd event listener exists:

// ...
this.options.client.on('messageReactionAdd', this.listener);
// ...

This code was used to trigger the error:

				await msg.clearReactions();
				await msg.react(encodeURIComponent('โŒ'));

Explanation: The event tries to get which reaction was added (?), but, since clearReactions ran, message.reactions is {}, causing the reactions.get is not a function error, since reactions is not a Map anymore.

My temporary fix:

		case 'MessageReact': {
			const message = client.messages.getOrPartial(event.id);
			if (message) {
				let reactions = message.reactions;

				if (!(reactions instanceof Map)) reactions = new Map();

				const set = reactions.get(event.emoji_id);

bug: update events don't use hydration key mappings

What happened?

I believe this applies to almost all update events, but it's mainly been affecting me with channels, so I'll use those as an example.

From what I have gathered, when a ChannelUpdate event is received, revolt.js doesn't apply the key mappings. For example, when a channel's permissions are updated, the new Channel object looks like this:

rolePermissions here is the old data, role_permissions is the new data.

The result is that all data that revolt.js provides under a different key than what the API returns will not be updated and keep its initial value until the client reconnects.

ERR_REQUIRE_ESM when using TypeScript

`
Error [ERR_REQUIRE_ESM]: require() of ES Module /home//node_modules/revolt.js/dist/index.js from /home//Projects//src/util/client.js not supported.
Instead change the require of index.js in /home/
/Projects//src/util/client.js to a dynamic import() which is available in all CommonJS modules.
at Object. (/home/
/Projects//src/util/client.js:13:21)
at Object. (/home/
/Projects/*/src/index.js:3:18)
at async Promise.all (index 0) {
code: 'ERR_REQUIRE_ESM'
}

Node.js v17.5.0
`
When running with ts-node, this error is outputted.

bug: TextEmbed not working

What happened?

My code is this:

const embed = new TextEmbed(new MessageEmbed({ title: "Too many verse references!", description: "There are too many verse references in your message." }))

Yet, I keep getting this error:

TypeError: Cannot read properties of undefined (reading 'icon_url')
    at new TextEmbed (D:\Repos\KJV-Bot-Revolt\node_modules\revolt.js\lib\cjs\classes\MessageEmbed.js:166:28)
    at Object.execute (D:\Repos\KJV-Bot-Revolt\src\events\client\messageCreate.js:14:39)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)

I have tried putting a value icon_url in the TextEmbed, and even gave a valid image url, yet it keeps giving me the exact same error. I also tried putting it as iconUrl to see if that worked, and it didn't.

bug: TSC reports 17 errors

What happened?

When running tsc on any typescript project using revolt.js (including the example one provided in revolt.js.org), it'll give these errors:
image

Hastebin (posted there to prevent clutter)

Workaround

You can add skipLibCheck: true to your tsconfig.json, which would skip checking all libraries entirely. Alternatively you can just ignore the errors caused by revolt-api and start your code anyways.

Obviously though, that doesn't fix the wider issue, and some stuff might be broken.

Deno compatibility

It would be nice if we could use this within Deno. Here are the things that would have to occur if we were to proceed with this:

  • Switch axios to fetch (with the polyfill node-fetch for node.js)
  • Explicitly define '.ts' file extensions

There are many reasons to use Deno over Node, including the built-in TypeScript support, Permission system and much more

Is there a Revolt channel I could use to discuss revolt.js? It would be best for fast communication

ERR_REQUIRE_ESM on revolt.js 6.0.0-rc16

Seems latest 6.0.0 RC have some issues with ES Module, I tried using revolt.js on CommonJS and ESM and it throws same ERR_REQUIRE_ESM.

The last version that still works for me is 6.0.0-rc13.

Environment

  • OS: Arch Linux
  • Node.js Version: v16.15.0

Error output on CommonJS

/home/<username>/Documents/node-sandbox/node_modules/revolt.js/dist/websocket/client.js:27
const exponential_backoff_1 = require("@insertish/exponential-backoff");
                              ^

Error [ERR_REQUIRE_ESM]: require() of ES Module /home/<username>/Documents/node-sandbox/node_modules/@insertish/exponential-backoff/dist/backoff.js from /home/<username>/Documents/node-sandbox/node_modules/revolt.js/dist/websocket/client.js not supported.
Instead change the require of backoff.js in /home/<username>/Documents/node-sandbox/node_modules/revolt.js/dist/websocket/client.js to a dynamic import() which is available in all CommonJS modules.
    at Object.<anonymous> (/home/<username>/Documents/node-sandbox/node_modules/revolt.js/dist/websocket/client.js:27:31)
    at Object.<anonymous> (/home/<username>/Documents/node-sandbox/node_modules/revolt.js/dist/Client.js:26:18)
    at Object.<anonymous> (/home/<username>/Documents/node-sandbox/node_modules/revolt.js/dist/index.js:36:14)
    at Object.<anonymous> (/home/<username>/Documents/node-sandbox/rtest.js:3:20) {
  code: 'ERR_REQUIRE_ESM'
}

Error output on ESM

(node:36817) ExperimentalWarning: The Node.js specifier resolution flag is experimental. It could change or be removed at any time.
(Use `node --trace-warnings ...` to show where the warning was created)
/home/<username>/Documents/node-sandbox/node_modules/revolt.js/dist/websocket/client.js:27
const exponential_backoff_1 = require("@insertish/exponential-backoff");
                              ^

Error [ERR_REQUIRE_ESM]: require() of ES Module /home/<username>/Documents/node-sandbox/node_modules/@insertish/exponential-backoff/dist/backoff.js from /home/<username>/Documents/node-sandbox/node_modules/revolt.js/dist/websocket/client.js not supported.
Instead change the require of backoff.js in /home/<username>/Documents/node-sandbox/node_modules/revolt.js/dist/websocket/client.js to a dynamic import() which is available in all CommonJS modules.
    at Object.<anonymous> (/home/<username>/Documents/node-sandbox/node_modules/revolt.js/dist/websocket/client.js:27:31)
    at Object.<anonymous> (/home/<username>/Documents/node-sandbox/node_modules/revolt.js/dist/Client.js:26:18)
    at Object.<anonymous> (/home/<username>/Documents/node-sandbox/node_modules/revolt.js/dist/index.js:36:14)
    at async Promise.all (index 0) {
  code: 'ERR_REQUIRE_ESM'
}

bug: client.servers.fetch() not working due to missing permissions

What happened?

When using client.servers.fetch() to get the server promise for a specific server you are currently greeted with this lovely API response:

data: { error: { code: 401, reason: 'Unauthorized', description: 'The request requires user authentication.' } }

This is not a problem in v6 so I think most developers will be fine for the time being, but it's a pain in the ass when trying to use the v7 beta.

bug: Can't install from git

What happened?

npm i git+https://github.com/revoltchat/revolt.js.git

A successful package install from git.

Instead, missing lib directory.

bug: When fetching a member by user id from a server guild: the returned Member does not have a user property.

What happened?

Clarifications

Notice: username and nickname are not the same thing.
nickname is related to the server/guild member.
username is related to the revolt instance user.

Affected

Edit: Happens with invited bots that are second, third, fourth on the Guild/Server.
First invited bot on the server/guild does not have such issue.

I'm trying to get the username of a member on the server/guild.

For fetching a member I use .fetchMember

.user property/accessor is missing when fetching a member from a server using a user id.

Returned member object. (missing user: property/accessor )

    _id: [object Object]
    nickname: boqsc
    avatar: null
    roles: 01GK52Z15W78JM1WQ1NK7MMZCW
    timeout: null
    joined_at: Wed Nov 30 2022 12:52:54 GMT+0200 (Eastern European Standard Time)

Example:

client.on("packet", async (event) => {
	if ((event.type == "MessageReact" || event.type == "MessageUnreact") && (event.user_id != client.user._id)){
		console.log("Red reaction.");
		
		client.servers.forEach(async (values, keys, objects) => {
			if (values.channel_ids.includes(event.channel_id) ){
				guild = await client.servers.get(values._id);
				guild_member = await guild.fetchMember(event.user_id);
				for (const [key, value] of Object.entries(guild_member)) {
								  console.log(`    ${key}: ${value}`);
				}
				
				console.log(`  Guild Name:  ${guild.name}`);
				
				console.log(`  Guild_Member Id: ${guild_member._id.user}`);
				console.log(`  Guild_Member Nickname: ${guild_member.nickname}`);
				console.log(`  Guild_Member Joined at: ${guild_member.joined_at}`);
				console.log(`  Guild_Member Roles: ${guild_member.roles}`);
				console.log(`  Guild_Member User: ${guild_member.user.username}`);
				for (const [key, value] of Object.entries(guild_member)) {
								  console.log(`    ${key}: ${value}`);
				}
			}
		});
		
	}
	
});

Example output:

Red reaction.
    client: [object Object]
    _id: [object Object]
    nickname: boqsc
    avatar: null
    roles: 01GK52Z15W78JM1WQ1NK7MMZCW
    timeout: null
    joined_at: Wed Nov 30 2022 12:52:54 GMT+0200 (Eastern European Standard Time)
  Guild Name:  Colors Server
  Guild_Member Id: 01GHZS22KV2CPEVGGVC3HSQYFZ
  Guild_Member Nickname: boqsc
  Guild_Member Joined at: Wed Nov 30 2022 12:52:54 GMT+0200 (Eastern European Standard Time)
  Guild_Member Roles: 01GK52Z15W78JM1WQ1NK7MMZCW
(node:454029) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'username' of undefined
    at /root/bot.js:57:59
    at processTicksAndRejections (internal/process/task_queues.js:97:5)

bug: Focus isn't allowed in api.patch "/users/@me"

What happened?

So apparently the focus presence isn't defined in the api.patch function, returning a typeerror since it doesn't match "Online" | "Idle" | "Busy" | "Invisible" | undefined | null.

Screenshot_20220930_071417

But when testing, It does indeed change the status to Focus.

Screenshot_20220930_071500

revolt.js throws exception when uncached user leaves a server

It appears that when a user leaves a server (or gets kicked/banned) and is not already cached, revolt.js attempts to fetch that user. If it is unable to fetch it (Usually because of missing permission), an exception is thrown.

This is not a big issue in browser applications, but it almost certainly causes node.js applications such as bots to exit. (See attached video)

simplescreenrecorder-2021-12-11_12.10.36.mp4

bug: A simple CommonJS Bot, but: revolt-api/node_modules/axios: 404 error when someone joins server: http Request of members/00000000000000000000000000

What happened?

Plain simple bot gives an error of 404 when another bot joins the server.

OS: Linux/Debian

Setup: I'm using CommonJS, not TypeScript

Bot example:

const { Client } = require("revolt.js");

let client = new Client();


client.loginBot("YOUR_BOT_TOKEN");

Steps:

  1. Invite your bot example
  2. invite another bot for testing
  3. In the bot console you will see: 404 error with a Request of /members/00000000000000000000000000

Full error message: new 19.txt
image

TypeError: Client is not a constructor

I'm trying to write a revolt bot in javascript and this error shows up:

let client = new Client();
             ^

TypeError: Client is not a constructor
    at Object.<anonymous> (/home/tom/test.js:3:14)
    at Module._compile (node:internal/modules/cjs/loader:1103:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1157:10)
    at Module.load (node:internal/modules/cjs/loader:981:32)
    at Function.Module._load (node:internal/modules/cjs/loader:822:12)
    at ModuleWrap.<anonymous> (node:internal/modules/esm/translators:168:29)
    at ModuleJob.run (node:internal/modules/esm/module_job:197:25)
    at async Promise.all (index 0)
    at async ESMLoader.import (node:internal/modules/esm/loader:337:24)
    at async loadESM (node:internal/process/esm_loader:88:5)

I tried even typing it in TypeScript, but it didn't work and it told me some other error (I used example code). Here's example code, but in JavaScript:

let { Client } = require("revolt-api")

let client = new Client();

client.on("ready", async () =>
    console.info(`Logged in as ${client.user.username}!`),
);

client.on("message", async (message) => {
    if (message.content === "hello") {
        message.channel.sendMessage("world");
    }
});

client.loginBot("..");

Here's my error in TypeScript:

error TS2468: Cannot find global value 'Promise'.

test.ts:1:10 - error TS2305: Module '"revolt-api"' has no exported member 'Client'.

1 import { Client } from "revolt-api";
           ~~~~~~

test.ts:9:22 - error TS2705: An async function or method in ES5/ES3 requires the 'Promise' constructor.  Make sure you have a declaration for the 'Promise' constructor or include 'ES2015' in your '--lib' option.

9 client.on("message", async (message) => {
                       ~~~~~~~~~~~~~~~~~~~~


Found 3 errors in the same file, starting at: test.ts:1

Maybe I'm too dumb, but I tried fixing it for an hour and none other person had this same problem.

bug: Error deleting a message after bot sends DM to user

What happened?

Revolt.js 7 seems to not handle deleting messages using message.delete() or channel.deleteMessages() correctly after a DM is sent.

Error message:

/home/dumpling/Documents/Code/stationbot/packages/revolt.js/lib/cjs/classes/Message.js:96
        return __classPrivateFieldGet(this, _Message_collection, "f").getUnderlyingObject(this.id).authorId;
                                                                                                  ^

TypeError: Cannot read properties of undefined (reading 'authorId')
    at get authorId [as authorId] (/home/dumpling/Documents/Code/stationbot/packages/revolt.js/lib/cjs/classes/Message.js:96:99)
    at Timeout._onTimeout (/home/dumpling/Documents/Code/stationbot/packages/base/dist/index.js:244:53)
    at listOnTimeout (node:internal/timers:564:17)
    at process.processTimers (node:internal/timers:507:7)

Node.js v18.7.0

Code is available here

Removing message.delete()/channel.deleteMessages() seems to fix the issue.

Currently using revolt.js 7.0.0-beta.1. Built locally.

EDIT: Add version information

bug: explicitly importing the ESM version fails

What happened?

When importing revolt.js' ESM version directly from revolt.js/lib/esm/index.js, an error is thrown because it's interpreted as a CJS module by both Node and Deno.

How to reproduce:

import { Client } from "revolt.js/lib/esm/index.js";
// or "npm:[email protected]/lib/esm/index.js" when using Deno

const bot = new Client();

Logs:

file:///home/jersey/projects/revolt-repro/index.js:1
import { Client } from "revolt.js/lib/esm/index.js";
         ^^^^^^
SyntaxError: Named export 'Client' not found. The requested module 'revolt.js/lib/esm/index.js' is a CommonJS module, which may not support all module.exports as named exports.
CommonJS modules can always be imported via the default export, for example using:

import pkg from 'revolt.js/lib/esm/index.js';
const { Client } = pkg;

    at ModuleJob._instantiate (node:internal/modules/esm/module_job:123:21)
    at async ModuleJob.run (node:internal/modules/esm/module_job:189:5)

Node.js v19.8.1
error: 'import', and 'export' cannot be used outside of module code at file:///home/jersey/projects/revolt-repro/node_modules/.deno/[email protected]/node_modules/revolt.js/lib/esm/index.js:1:1

  export * from "./classes";
  ~~~~~~

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.