Giter Club home page Giter Club logo

rja's Introduction

Warning

I do no longer use Revolt. This API should still work, but I will no longer maintain it. For now, this repository will be archived.

RJA (Revolt Java API)

RJA is a Java API for the Revolt chat platform, mostly focused on bots.

Github Release

Note: This is a work in progress and not all features are implemented yet. If you find any bugs, please open an issue.

Also, the Revolt-API may change at any time, so this API may not work anymore. Please open an issue if you find any bugs or have any suggestions.

Overview

Install

You can download the latest version from the releases page

Replace VERSION HERE with the latest version.

Maven

<dependency>
    <groupId>de.joshicodes</groupId>
    <artifactId>rja</artifactId>
    <version>[VERSION HERE]</version>
</dependency>

This can also be found under Packages

Usage

To create a new RJA Instance, you can use the RJABuilder.

RJABuilder builder = new RJABuilder("token"); // Replace "token" with your bot token
// do some stuff
RJA rja = builder.build();

This creates a new RJA Instance, which you can use to do stuff as your bot.

You can also modify some things before building the instance:

RJABuilder builder = ...
        
builder.setStatus("Test Status", UserStatus.Presence.FOCUS); // Sets the Status of the Bot to "Test Status" with "FOCUS" as presence type.
builder.doCleanStatus(true); // Resets the status of the Bot if it does not get changed at startup. It is default true. If false, the status of the bot stays as before.
        
builder.registerEventListener(new MyEventListener()); // Registers a new EventListener. More about EventListeners at #EventListeners or in the JavaDocs
        
builder.disableCaching(CachingPolicy.MEMBER); // Disables caching for the Member Cache. Every CachePolicy is enabled by default.
// More about Caching at #Caching or in the JavaDocs

But wait, there is more. After building your RJA instance you can request stuff from the API.

RJA rja = ...

User user = rja.retrieveUser("01GXTJK9Q1JZVR1NZ32CGDCDKN").complete();  // Retrieves a User by its ID.

Message message = rja.retrieveMessage("channelId", "messageId").complete(); // Retrieves a Message by the channel id and the message id.
   

Sending Messages

You can send Messages to every GenericChannel using GenericChannel#sendMessage or GenericChannel#sendEmbeds. Both of this Methods return a MessageAction which can be used to modify the message before sending it.
To send a private Message to a User, you can use User#openPrivateChannel to retrieve a RestAction with the DirectChannel of the User. To send messages to this DirectChannel, you can use the same methods as with GenericChannel.

EventListeners

EventListeners are used to handle events. You can register them with the RJABuilder#registerEventListener() method.

RJABuilder builder = new RJABuilder("token");
builder.registerEventListener(new MyEventListener());

Your EventListener class must implement the EventListener interface. To listen to a specific event, you can use the @EventHandler annotation on a method, this method requires the Event you want to listen to as parameter. The Name of the method does not matter, but it is recommended to use the name of the event.

MyEventListener.java:

import de.joshicodes.rja.event.EventHandler;

public class MyEventListener implements EventListener {

    @EventHandler
    public void onReady(ReadyEvent event) {
        System.out.println("Bot is ready!");
    }
    
    @EventHandler
    public void onMessageReceived(MessageReceivedEvent event) {
        System.out.println("Received message: " + event.getMessage().getContent());
    }
    
}

Caching

RJA has a built-in caching system, which can be disabled for specific caches. By default, all caches are enabled. You can disable them with the RJABuilder#disableCaching(CachingPolicy...) method. If you disable a cache, you can still retrieve the data from the API, but it will not be cached and may result in a longer response time or rate limiting.

Examples

You can find some examples in src/examples

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Dependencies

RJA uses Java 17. All dependencies are managed by Maven.

  • Java-Websockets

  • Gson

  • FindBugs (Used for javax.annotation)

Related Projects

See also



License

MIT

You are welcome to use this API in your projects, but please credit me if possible.

I am not affiliated with Revolt.chat in any way and the Revolt-API is not created by me.

rja's People

Contributors

joshicodes avatar

Stargazers

 avatar  avatar

Watchers

 avatar

rja's Issues

"Crash" when Timeout due to connection error

When the connection fails (i.e. API Downtime), an WebsocketNotConnectedException is thrown and the RJA will not reconnect until manually restarted

Maybe something like trying to reconnect after a given time would fix that

Ability to send messages

Implement the Ability to send Message via a MessageReceiver class

MessageReceiver#sendMessage
MessageReceiver#sendEmbed

Implementation of this class for GenericChannel. For User add a "openPrivateChannel" RestAction to get the DirectChannel of the user

Implementation of Channels

Implementation of Channels, "GenericChannel" as SuperClass with "TextChannel", etc. as subclasses
Should be retrievable via RJA#retrieveChannel(String) or RJA#retrieveTextChannel(String), etc.

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.