Code Monkey home page Code Monkey logo

diskordin's Introduction

Tests status JitPack Bintray Github License

Diskordin

What is this?

Diskordin (Discord & Kotlin) is a Discord API wrapper written in Kotlin using functional approach which reached with Arrow library.


The state of this wrapper is ALPHA because most features are still in progress. So API can change very fast. See the road map.


Why I should use it?

There are a lot of other wrappers written in Java (whole 4). Diskordin allows us to write polymorphic programs in functional style, separating effects from pure functions.

Also, there already been presented other kotlin wrappers. Diskordin gives us flexible builders, and we can choose a layer of abstraction.

How can I get it?

Gradle

repositories {
    maven { url "https://oss.sonatype.org/content/repositories/snapshots" }
    jcenter()
}
dependencies {
    compile 'org.tesserakt.diskordin:diskordin:{version}'
}

For snapshot versions use

repositories {
    mavencentral()
    maven { url "https://oss.sonatype.org/content/repositories/snapshots" } // for scarlet (if you're using retrofit-integration module)
    maven { url "https://kotlin.bintray.com/kotlinx/" } // for kotlinx-datetime
    maven { url "https://oss.jfrog.org/artifactory/oss-snapshot-local/" } // for arrow
    maven { url 'https://jitpack.io' } // for this snapshot
}
dependencies {
    // ...
    implementation("com.github.ITesserakt.diskordin:diskordin-base:-SNAPSHOT")
    implementation("com.github.ITesserakt.diskordin:diskordin-ktor-integration:-SNAPSHOT") // use this
    implementation("com.github.ITesserakt.diskordin:diskordin-retrofit-integration:-SNAPSHOT") // OR this, else build errors are guaranteed
    implementation("com.github.ITesserakt.diskordin:diskordin-commands:-SNAPSHOT")
}

Also, you must add a dependency for logger. Simplest is 'org.slf4j:slf4j-simple:1.7.30'

How can I use it?

The future syntax may change!

Log on

Just logging into Discord as simple as possible

fun main() = DiscordClientBuilder {
    +token("Put your bot`s token here")
}.login().unsafeRunSync()

In DiscordClientBuilder lambda you can put other config options. Like other builders, type this. keyword in a lambda to see all of them.

If your token is in env variables the syntax will even more simple:

fun main() = DiscordClientBuilder().login().unsafeRunSync()

Most wrappers block main forever after login. In Diskordin login call is non-blocking, but you shouldn't pass delay(INFINITY) or something else. Wrapper creates another thread, so the program doesn't terminate.

Here is an example where you can see work with the Gateway. Currently, a type of readyEvent is Kind<ForFlowable, ReadyEvent> because of limitations in the Arrow. To repair it, use fix and flowable after it. In the future, this will change to S<ReadyEvent> where S is a concrete "streamable" type of the Gateway.

fun main() = with(DiscordClientBuilder()) {
   login().unsafeRunSync()
   val readyEvents = eventDispatcher.subscribeOn()
   // ...
}

Builders

In some functions like edit, you can meet with builders. These are state mutators, necessary parameters of which are "inlined" into the corresponding function. In a lambda of the builder, you can apply optional properties. You _ apply_ them and so you have to bind them with state. For this, there is a unary + operator.

//An example of ITextChannel.edit
channel.edit { //this is TextChannelEditBuilder
    +name("New fancy name")
    +topic("New fancy topic!")
    // ...
}

Auto-complete helps you to show all optional properties


Here will more use cases as they will implement.

Libraries

Libraries used in main module:

Name Reason
Arrow Functional approach in Kotlin
Kotlin logging Kotlin adapter for loggers
Kotest Powerful, elegant and flexible test framework for Kotlin

Libraries used in diskordin-commands:

Name Reason
ClassGraph An uber-fast, ultra-lightweight, parallelized Java classpath scanner and module scanner.
Kotlin reflection To access data, produced by ClassGraph

Libraries used in diskordin-ktor-integration:

Name Reason
Ktor Framework for quickly creating connected applications in Kotlin with minimal effort

Libraries used in diskordin-retrofit-integration:

Name Reason
Retrofit A type-safe HTTP client for Android and the JVM
Scarlet A Retrofit inspired WebSocket client for Kotlin, Java, and Android

diskordin's People

Contributors

itesserakt avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

pltnoff

diskordin's Issues

JitPack builds broken

Trying to get the current commit through JitPack breaks as it can't find artifacts.

Fix creating multiple clients

Currently, if an exception happened in the DiscordClientBuilder and you successfully caught it, you can't create DiscordClient once more.
This happens because of security from multiple instantiating of the client.

Message unwrapping cause NPE

When a member joins in some guild, discord creates an event and message in the corresponding channel, if it doesn't disabled. This message is auto-generated so it hasn't many fields. Unwrapping its response to a normal Message entity causes NPE.

  • A possible fix is to create another, special entity for this case.

Roadmap

  • Create README
  • Post this framework into a repository and make it available for Gradle, Maven
  • Cache data from gateway events (Almost done)
  • Split project to independent modules to lower coupling
  • Make rate limiter
  • Make sharding mechanic
  • Use Intents (discord/discord-api-docs#1307)
  • Wait while Arrow Meta come to release and use it
  • Make command module
  • Write tests
  • Write a lot of documentation
  • Rewrite from Arrow's Fx to Fx-Coroutines
  • Remove kinds as it will be deleted in Arrow 0.13.0
  • Rewrite shard controller with more readable construction using actors
  • Replace most of the typeclasses with fun interfaces

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.