@ilyadrmx/aminojs

1.0.97 • Public • Published

Project logo

AminoJS

Library for access to the Amino API (AminoApps)

Status GitHub Issues License


📝 Table of Contents

🧐 About

This library easily allows you to use Amino API. Notice that this library is not official AND according to Narvii's TOS it is prohibited. You can get banned if you use this library. The author is not responsible for the use of AminoJS.

🎈 Usage

Here will be some notes how to use AminoJS.

Prerequisites

Firstly, you should have up-to-date Node JS version. Do not forget to install NPM manager.

Installing

After installing Node JS and NPM, you should create your project. Just make a folder for your bot. For example, we will create folder named "AminoJSBot". Then you should open your CMD or Terminal and open this folder.

Open terminal and type

cd PATH_TO_YOUR_FOLDER

And then you need to install AminoJS package.

npm install @ilyadrmx/aminojs

NPM manager will download all files that you need.

Setting bot folder

I recommend that you create a folder named "bot" inside of our "AminoJSBot" folder. Then, inside of "bot" folder you should create two files:

  • main.mjs
  • config.mjs

So, we have a project structure like this:

AminoJSBot
¦    package-lock.json
¦    package.json
¦
+--- bot
¦       config.mjs
¦       main.mjs
¦       
L--- node_modules
     ...

Creating simple bot

Firstly, let's login our bot. Open "main.mjs" file (/AminoJSBot/bot). Now, let's import AminoJS library.

import { Client, SubClient } from "@ilyadrmx/aminojs";

So, we've imported library and now we need to make an instance of Client class. It allows us to use Amino's global user features.

const client = new Client(null, false); // Don't change if you don't know what is this
client.login("YOUR_EMAIL", "YOUR_PASSWORD"); // Here you should replace text

Lines that we've added above allows our bot to login. Now we should to make an instance of SubClient class. It allows us to use Amino's community user features.

const client = new Client(null, false);
client.login("YOUR_EMAIL", "YOUR_PASSWORD")
    .then(() => { // .then() is necessary
        const subClient = new SubClient(client, "COM_ID");
    });

Com ID is an ID that allows you to enter in community. You can easily get a list of communities by this code:

const client = new Client(null, true);
client.login("YOUR_EMAIL", "YOUR_PASSWORD")
    .then(() => {
        client.getSubClients()
            .then((communities) => { // .then() is necessary
                for (let community in communities) {
                    let com = communities[community];
                    console.log(`${com.name}: ${com.ndcId}`);
                }
            });
    });

Copy the id of the current community and paste it in "COM_ID" field. Now, let's create a message listener. You should make a WebSocket listener for amino by using

client.startListeningMessages();

But if you don't know how to do it, just get code here. Paste this code in "config.mjs" (/AminoJSBot/bot). Now your "config.mjs" code structure is

export function customSocketListening(client, subClient) {
    client.startListeningMessages();
    client.ws.then((webSocket) => {
        /**
         * It's when everyting works
         */
         webSocket.on(
            "open", () => {
                // ...
            }
        );

        /**
         * It's when client got Amino message
         */
        webSocket.on(
            "message", (message) => {
                // ... 
            }
        );

        /**
         * It's when something does not work and it needs to restart
         */
        webSocket.on(
            // ... 
        );
    });
}

We are going to create a bot, that replies user the message after command. How it will work:

User:
/say Hello!

Bot:
Reply to: User
Hello!

So, we need to take user's text after "/say" word. In JavaScript, we use

String.substring()

Now, let's implement this to our code

// ...

webSocket.on(
    "message", (message) => {
        var data = toJson(message).o; // This is necessary
        data = data.chatMessage;
        /**
         * Empty text check
         */
        if (typeof data.content !== "undefined" && data.author.uid !== client.profile.uid) {
            /**
             * Command "/say" check
             */
            if (data.content.toLowerCase().startsWith("/say ")) {
                try {
                    subClient.replyTo(
                        data.threadId,
                        data.messageId,
                        data.content.substring(5)
                    );
                } catch (e) {
                    console.log("Noncritical error. " + e.toString());
                }
            }
        }
    }
);

// ...

We created the main logic for our command. Let's add it to Client.

import { Client, SubClient } from "../index";
import  { customSocketListening } from "./config"; // Import our function above from config file

const client = new Client(null, true);
client.login("YOUR_EMAIL", "YOUR_PASSWORD")
    .then(() => {
        const subClient = new SubClient(client, "COM_ID");
        customSocketListening(client, subClient);
    });

And that's all!

✍️ Authors

Package Sidebar

Install

npm i @ilyadrmx/aminojs

Weekly Downloads

2

Version

1.0.97

License

MIT

Unpacked Size

30 kB

Total Files

16

Last publish

Collaborators

  • ilyadrmx