Skip to content

Latest commit

 

History

History

gateway

Kord gateway

A low-level implementation of discord's gateway.

Example usage

suspend fun main(args: Array<String>) {
    val token = args.firstOrNull() ?: error("token required")

    val gateway = DefaultGateway { // optional builder for custom configuration
        client = HttpClient {
            install(WebSockets)
            install(JsonFeature)
        }
        reconnectRetry = LinearRetry(2.seconds, 20.seconds, 10)
        sendRateLimiter = IntervalRateLimiter(120, 60.seconds)
        dispatcher = Dispatchers.Default
    }

    gateway.events.filterIsInstance<MessageCreate>().onEach {
        val words = it.message.content.split(' ')
        when (words.firstOrNull()) {
            "!close" -> gateway.stop()
            "!detach" -> gateway.detach()
            "!status" -> when (words.getOrNull(1)) {
                "playing" -> gateway.editPresence {
                    status = PresenceStatus.Online
                    afk = false
                    playing("Kord")
                }
            }
        }
    }.launchIn(gateway)

    gateway.start(token) {
        @OptIn(PrivilegedIntent::class)
        intents += Intent.MessageContent
    }
}

Installation

Replace {version} with the latest version number on maven central.

For Snapshots replace {version} with {branch}-SNAPSHOT

e.g: 0.7.x-SNAPSHOT

Download Snapshot

Gradle (groovy)

repositories {
    mavenCentral()
    // Kord Snapshots Repository (Optional):
    maven("https://oss.sonatype.org/content/repositories/snapshots")
}
dependencies {
    implementation("dev.kord:kord-gateway:{version}")
}

Gradle (kotlin)

repositories {
    mavenCentral()
    // Kord Snapshots Repository (Optional):
    maven("https://oss.sonatype.org/content/repositories/snapshots")
}

dependencies {
    implementation("dev.kord:kord-gateway:{version}")
}

Maven

Kord Snapshots Repository (Optional):
<repository>
    <id>snapshots-repo</id>
    <url>https://oss.sonatype.org/content/repositories/snapshots</url>
    <releases>
        <enabled>false</enabled>
    </releases>
    <snapshots>
        <enabled>true</enabled>
    </snapshots>
</repository>

<dependency>
    <groupId>dev.kord</groupId>
    <artifactId>kord-gateway-jvm</artifactId>
    <version>{version}</version>
</dependency>