sunrod-api
TypeScript icon, indicating that this package has built-in type declarations

2.1.0 • Public • Published

Logo

SunRod v2.0.0

Find out about SunRod on our website or our Discord server.

Installation

Install the package with NPM:

npm install sunrod-api@latest

Install the package with YARN:

yarn add sunrod-api@latest

Installing the latest version is more reccommended, as dev versions may not work as you wish.

Token

A token is required for SunRod to work, and you can receive one just by joining the SunRod Project.

SunRod Tokens are used to login to the API. They are 30-characters long passwords, and each bot participating to SunRod has its own token.

Tokens are useful for us to monitor how bots use the API, and to identify who is authorized to use it and who is not.

ATTENTION: We do NOT receive any private information about you and your bot from this API and we do NOT share how you interact with the API.
Also, a SunRod token is different from your discord bot token and should not be shared with us or anybody else.

Look up our Security Section for more info.

Documentation

Welcome to our documentation! Here you can learn how the constructor and the methods work.

If you need any help or explanation, ask for support in our Discord Server!

Constructor

To log into the API you must insert your token:

const SunRod = require('sunrod-api'); // Requires the library

const client = new SunRod(token); // Logs into the API

The token parameter must be your SunRod Token.

If you want to bypass every possible error that could generate over time, use this:

const client = new SunRod(token, { bypass: true });

IMPORTANT: If the token is not authorized to SunRod, you'll get an error.

For ease, in your discord bot you would probably set SunRod inside the client variable:

client.sunrod = new SunRod(token);

Classes

These are multiple classes you should know about.

SunRod

const SunRod = require('sunrod-api');

This contains complete access to the API. More info on Methods.

User

This class contains all necessary info about a user.

const user = client.get('604790617138266149'); // Returns the User class

console.log(user.id); // '604790617138266149' (the id of the user)
console.log(user.coins); // 100 (the amount of coins)

You can find it in these methods:
SunRod#get, SunRod#set, SunRod#add, SunRod#remove, SunRod#transfer.

Admin

const admin = client.profile(); // Returns the Admin class

console.log(admin.id); // Your admin id
console.log(admin.name); // Your name as an admin
console.log(admin.token); // Your token
console.log(admin.permissions); // Your permission level

You can find it in these methods:
SunRod#profile.

Methods

These are the methods inside the SunRod class:

Whenever an error should appear, it will be returned as { error: 'your error' } .
This makes it easier to prevent your bot from crashing.

SunRod#profile

The profile method returns your Admin Profile.

No Parameters required.

const profile = await client.profile(); // The Admin class is returned

console.log(profile.permissions) // Your permission level

This method returns an Admin.

SunRod#get

The get method returns the amount of coins the user has.

Parameters:
id: string

const user = await client.get(id); // The User class is returned

console.log(user.coins); // The amount of coins

Most methods return a User.

SunRod#has

The has method returns a boolean: if the user has the minimum amount of coins, its true.

Parameters:
id: string
coins: number

const hasCoins = await client.has(id, coins);

console.log(hasCoins); // true or false

SunRod#set

The set method sets to the user a specific amount of coins, and returns the user data.

Parameters:
id: string
coins: number

const user = await client.set(id, coins); // The user amount of coins gets modified

console.log(user.coins); // The new amount of coins

Inside the data property you can find user data, with how many coins does he have in total and his id.

SunRod#add

The add method adds a specific amount of coins to a user and returns user data.

Parameters:
id: string
coins: number

await client.add({ user: 'id', coins: 0 }); // Add the amount of coins to the user

Structure is similar to the set method, although this sums to the current user balance and adds the given amount.

SunRod#remove

The remove method removes a specific amount of coins to a user and returns user data.

Parameters:
id: string
coins: number

await client.remove({ user: 'id', coins: 0 }); // Remove the amount of coins from the user

This method has the same structure as the set and the add method, but this subtracts coins from the user.

ATTENTION: The user may not have enough coins in some situations, and { error: 'Insufficient coins' } could be returned instead.

SunRod#transfer

The transfer method transfers an amount of coins from a user to another and returns an array of 2 Users.

Parameters:
firstId: string
secondId: string
coins: number

const users = await client.transfer(firstId, secondId, coins); // Transfers coins from first to second user

console.log(users[0].coins); // The first user new amount of coins
console.log(users[1].coins); // The second user new amount of coins

Errors

Sometimes you may get { error: 'your error' } instead of the actual response.

That doesn't mean that there's anything wrong with your code, but it's possible.

NOTICE: These are SunRod errors, while actual errors get thrown and you can prevented using the bypass parameter.

Error Meaning
Insufficient coins This could come out using SunRod#remove or SunRod#transfer, and means that the user you're taking coins from has not enough.

It's just one, but in the future they could become more.

Other Errors

There could also be other errors, that would eventually stop your bot from running without an error handler.

There's not a list, but

When the returned status code is not 0, your application (usually your bot) would crash ans give a TypeError on your console.
To avoid this add bypass: true as a property inside the object you insert as the method parameter, and inside the returned object you will find a result property which will be the status code that relates to the problem.

Security

Read about this to learn more about how we protect your data.

  • SunRod does NOT retreive any personal or professional information from your code or hosting device.
  • SunRod does NOT share the information you share with us, with anyone else. (es. token, activity, etc.)
  • This is the official SunRod Package, as you find on our website. Do NOT use 3rd-party packages.

Participate to SunRod!

Ask to participate to SunRod Project in our Discord Server: Join us!

Else just dm to GabrieleAGenius#0001 on discord.

Package Sidebar

Install

npm i sunrod-api

Weekly Downloads

6

Version

2.1.0

License

ISC

Unpacked Size

32.9 kB

Total Files

10

Last publish

Collaborators

  • gabrieleyt9768