A low-level implementation of discord's gateway.
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
}
}
Replace {version}
with the latest version number on maven central.
For Snapshots replace {version}
with {branch}-SNAPSHOT
e.g: 0.7.x-SNAPSHOT
repositories {
mavenCentral()
// Kord Snapshots Repository (Optional):
maven("https://oss.sonatype.org/content/repositories/snapshots")
}
dependencies {
implementation("dev.kord:kord-gateway:{version}")
}
repositories {
mavenCentral()
// Kord Snapshots Repository (Optional):
maven("https://oss.sonatype.org/content/repositories/snapshots")
}
dependencies {
implementation("dev.kord:kord-gateway:{version}")
}
<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>