Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support Kotlin/JS #775

Merged
merged 141 commits into from
Apr 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
141 commits
Select commit Hold shift + click to select a range
7e9ae30
A lot of MPP
DRSchlaubi Feb 24, 2023
afdb8ac
Add generated files
DRSchlaubi Feb 24, 2023
bcc603d
Delete old generated output
DRSchlaubi Feb 24, 2023
213c3dc
Add new generated files
DRSchlaubi Feb 24, 2023
8471d32
Fix JVM tests on MPP
DRSchlaubi Feb 25, 2023
22affd9
Cleanup DiscordBitSet code
DRSchlaubi Feb 25, 2023
7353c03
Fix DiscordBitSet tests
DRSchlaubi Feb 25, 2023
d1ec4f0
Migrate rest module to MPP
DRSchlaubi Feb 25, 2023
089c02d
Improve tests
DRSchlaubi Feb 25, 2023
330917a
Update publishing for MPP
DRSchlaubi Feb 25, 2023
4ac3a83
Put explicitApi() to kord-multiplatform-module.gradle.kts
DRSchlaubi Feb 25, 2023
8d0f9c9
Add samples for mpp modules
DRSchlaubi Feb 25, 2023
bec1437
Fix publishing for bom
DRSchlaubi Feb 25, 2023
3ec7fe9
Migrate gateway test to kotlin.test
DRSchlaubi Feb 25, 2023
a5445de
Migrate gateway to MPP
DRSchlaubi Feb 25, 2023
13cb3e4
Fix core tests
DRSchlaubi Feb 25, 2023
ca1c841
Make gradlew executable again
DRSchlaubi Feb 25, 2023
6d2a8c1
Whoops
DRSchlaubi Feb 25, 2023
93849d5
Migrate core
DRSchlaubi Feb 27, 2023
b97e1a4
Remove outdated samples plugin
DRSchlaubi Feb 27, 2023
193f127
Add EncryptionMode.kt
DRSchlaubi Feb 28, 2023
00b9554
Api dump
DRSchlaubi Feb 28, 2023
e1708a4
Update SnowflakeTest
DRSchlaubi Feb 28, 2023
e21264d
Final touches
DRSchlaubi Mar 1, 2023
e1088be
Update KSP generated files
DRSchlaubi Mar 25, 2023
39e955c
Add qualified import for @JvmName in DiscordChannel.kt
DRSchlaubi Mar 25, 2023
50fb779
Type-alias to JDK for BigInteger and ConcurrentHashMap
DRSchlaubi Mar 25, 2023
f061a8c
Remove remaining JVM function in common
DRSchlaubi Mar 25, 2023
74b9ce8
Dump api
DRSchlaubi Mar 25, 2023
e30bceb
Clarify comment on hash function
DRSchlaubi Mar 25, 2023
8badb69
Fix compilation error
DRSchlaubi Mar 25, 2023
22d4bf0
Fix compilation issues with Integration.kt
DRSchlaubi Mar 25, 2023
e54a49f
Fix gateway tests
DRSchlaubi Mar 25, 2023
f021146
Move some more core tests to common
DRSchlaubi Mar 25, 2023
dc1eb18
Upgrade to new cache version
DRSchlaubi Mar 25, 2023
526216a
Ignore EventDropTest on JS
DRSchlaubi Mar 26, 2023
9a21352
Fix live tests failing
DRSchlaubi Mar 26, 2023
a63b62e
Fix live tests failing
DRSchlaubi Mar 26, 2023
8970371
Fix task dependency
DRSchlaubi Mar 26, 2023
255aaec
[ci skip] Fix duplicated publication
DRSchlaubi Mar 26, 2023
79de31e
Trigger CI
DRSchlaubi Mar 26, 2023
9eaaaa5
Apply some requested changes
DRSchlaubi Mar 27, 2023
0b4569e
Fix dokkaHtmlMultiModule task
DRSchlaubi Mar 27, 2023
78b9500
Apply suggestions from code review
DRSchlaubi Mar 27, 2023
1e6c460
Update gradle/libs.versions.toml
DRSchlaubi Mar 27, 2023
24fe65a
No longer apply compiler options to internal module
DRSchlaubi Mar 27, 2023
62f88dd
Remove outdated link
DRSchlaubi Mar 27, 2023
00c7f62
Use more explicit names for integer formatting
DRSchlaubi Mar 27, 2023
0e9306c
Revert formatting
DRSchlaubi Mar 27, 2023
1592e0f
Some fixes
DRSchlaubi Mar 27, 2023
1fc42c0
Fix formatting
DRSchlaubi Mar 27, 2023
e253092
[ci skip] clarify why allWarningsAsErrors is disabled
DRSchlaubi Mar 27, 2023
1762cb0
Some small changes
lukellmann Mar 27, 2023
7991bd6
No need for @JvmName
lukellmann Mar 27, 2023
89ffc2f
Some more changes
lukellmann Mar 27, 2023
f6609ee
Also publish kspAnnotations for js target
DRSchlaubi Mar 28, 2023
132daa5
Remove no longer needed @ObsoleteCoroutinesApi annotations
DRSchlaubi Mar 30, 2023
d5d3580
oops
lukellmann Mar 29, 2023
a5f641c
preserve class name
lukellmann Mar 30, 2023
dd4ed48
unused imports
lukellmann Mar 30, 2023
50f0406
links to javadoc
lukellmann Mar 30, 2023
210032b
Rename files
lukellmann Mar 30, 2023
631600f
Wrong old name for VoiceBaseVoiceChannelBehavior
lukellmann Mar 30, 2023
78b00ad
Use FQNs instead of import aliases
lukellmann Mar 30, 2023
93f3ffd
Omit common root package from directory structure
lukellmann Mar 30, 2023
01509cf
BaseKordBuilder instead of KordBuilderBase
lukellmann Mar 30, 2023
2fbfb9f
Don't depend on ksp-annotations in core:live-tests
lukellmann Mar 30, 2023
08ad26e
Merge branch '0.9.x' into feature/mpp
lukellmann Mar 30, 2023
71d9c37
Make Inflate class no longer open
DRSchlaubi Mar 30, 2023
f709936
Cleanup Inflater code
DRSchlaubi Mar 30, 2023
1af8261
Specify platform type explicitly
DRSchlaubi Mar 30, 2023
a18ed6c
Remove unnecessary runTest
lukellmann Mar 30, 2023
80656c0
Restore suspend function
lukellmann Mar 30, 2023
d010227
[ci skip] Update readme files to reflect MPP
DRSchlaubi Mar 30, 2023
4726b8f
Use assertFalse
lukellmann Mar 30, 2023
d7b05c7
Remove unused imports
lukellmann Mar 30, 2023
a2c8029
Remove unused import
lukellmann Mar 30, 2023
dbb880a
Remove unused var
lukellmann Mar 30, 2023
cbba0b1
Remove suspend from Inflater
lukellmann Mar 30, 2023
193e134
Initial delay
lukellmann Mar 30, 2023
81e4a5b
Unused import
lukellmann Mar 30, 2023
11b75e2
Remove duplicate sample
lukellmann Mar 30, 2023
9674e34
No buildconfig in rest
lukellmann Mar 30, 2023
7a09dbc
Remove unused imports
lukellmann Mar 30, 2023
74cc849
Restore assertions
lukellmann Mar 30, 2023
d0f0dd6
order like in ide
lukellmann Mar 30, 2023
83e40de
Fix test
lukellmann Mar 31, 2023
5e6f6a0
Adjust Gradle config
lukellmann Mar 31, 2023
31d706d
Merge branch '0.9.x' into feature/mpp
lukellmann Mar 31, 2023
fc1c475
Remove unnecessary task dependency
lukellmann Mar 31, 2023
0cf7731
More tweaks to build logic
lukellmann Mar 31, 2023
cdeca21
Restore formatting for RegressionTests
lukellmann Mar 31, 2023
62b0cd8
Remove explicit coroutines dependency in gateway
lukellmann Mar 31, 2023
1e6d979
Empty error message instead of kotlin.Unit
lukellmann Mar 31, 2023
de614b2
Clean dependencies in build scripts
lukellmann Mar 31, 2023
005ca20
Remove unused bundle
lukellmann Mar 31, 2023
ec332d2
Remove @KordInternal from public API
DRSchlaubi Apr 2, 2023
cec147c
Add comments for ksp-annotations publishing
lukellmann Apr 2, 2023
1636137
Merge branch '0.9.x' into feature/mpp
lukellmann Apr 2, 2023
7cb02d5
Merge branch '0.9.x' into feature/mpp
lukellmann Apr 2, 2023
8da2c57
Clean BCV config
lukellmann Apr 2, 2023
761366e
A single dokkaJar task is enough
lukellmann Apr 2, 2023
f4bacfa
Use previous logic to format DiscordBitSet on JVM
lukellmann Apr 2, 2023
f37e698
That's an implementation dependency
lukellmann Apr 2, 2023
b0bb52f
Restore redundant suspend modifier
lukellmann Apr 2, 2023
5a8fbf1
const val for Platform.IS_JVM on JS
lukellmann Apr 2, 2023
5fbbfe6
Move version of fast-zlib to libs.versions.toml
lukellmann Apr 2, 2023
46c53d1
Remove unused imports
lukellmann Apr 2, 2023
e4fc17a
Restore formatting
lukellmann Apr 2, 2023
a67d587
Clean libs.versions.toml
lukellmann Apr 2, 2023
0667576
Clean test-kit annotations
lukellmann Apr 2, 2023
8e12712
Don't keep reference to ticker Flow
lukellmann Apr 2, 2023
7eb4a64
Fix KordEventDropTest on JS
lukellmann Apr 3, 2023
f430b47
Restore formatting
lukellmann Apr 3, 2023
b2a8692
Restore formatting
lukellmann Apr 3, 2023
d529286
Remove comment that wasn't there before
lukellmann Apr 3, 2023
262fef1
Remove unused imports
lukellmann Apr 3, 2023
5c28674
Remove unused imports
lukellmann Apr 3, 2023
ada7e92
Remove last plain assert() calls
lukellmann Apr 3, 2023
b573d62
Clean KSPUtils
lukellmann Apr 3, 2023
e15c5da
Clean KSPUtils
lukellmann Apr 3, 2023
413e55a
Clean KordEnum.kt
lukellmann Apr 3, 2023
b17faeb
Apply requested changes
DRSchlaubi Apr 4, 2023
85b4f4e
Make IS_JVM const
DRSchlaubi Apr 4, 2023
d2859d2
Fix test on JVM
DRSchlaubi Apr 4, 2023
7ff0b16
Remove useless OptIn
lukellmann Apr 4, 2023
44d118b
Remove dependency on common in test-kit
lukellmann Apr 4, 2023
8da5428
Rename nonJvm source set to nonJvmMain
lukellmann Apr 4, 2023
cbe5e46
Remove addTestKit()
lukellmann Apr 4, 2023
c120f36
Merge branch '0.9.x' into feature/mpp
lukellmann Apr 5, 2023
202da8a
Fix locale formatting in GuildModifyBuilder
lukellmann Apr 5, 2023
80c1b43
voice is not yet mpp
lukellmann Apr 5, 2023
e2d6ea0
Fix whitespace
lukellmann Apr 5, 2023
e9b07c3
Simpler links to subprojects
lukellmann Apr 5, 2023
759c592
Up-to-date snapshot example
lukellmann Apr 5, 2023
b4d8a1c
Add common to modules table
lukellmann Apr 5, 2023
f72b493
Add @suppress to internal API
lukellmann Apr 5, 2023
7f0455e
Actual issue for duplicate library warning
lukellmann Apr 5, 2023
eb685d1
.
lukellmann Apr 5, 2023
a9d12d2
Less indentation
lukellmann Apr 5, 2023
ab19dde
No documentation for ksp-annotations
lukellmann Apr 5, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
151 changes: 29 additions & 122 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ you to try out our library, we don't recommend you use this in production just y

If you have any feedback, we'd love to hear it, hit us up on discord or write up an issue if you have any suggestions!

## What is Kord
## What is Kord?

Kord is a [coroutine-based](https://kotlinlang.org/docs/reference/coroutines-overview.html), modularized implementation
of the Discord API, written 100% in [Kotlin](https://kotlinlang.org/).
Expand All @@ -26,28 +26,42 @@ unconventional things, and we want to allow you to do those in a safe and suppor

## Status of Kord

* [X] [Discord Gateway](https://github.com/kordlib/kord/tree/master/gateway)
* [x] [Discord Rest API](https://github.com/kordlib/kord/tree/master/rest)
* [X] [High level abstraction + caching](https://github.com/kordlib/kord/tree/master/core)
* [X] [Discord Voice](https://github.com/kordlib/kord/tree/master/voice)
* [X] [Discord Gateway](gateway)
* [x] [Discord Rest API](rest)
* [X] [High level abstraction + caching](core)
* [X] [Discord Voice](voice)
* [ ] Support for multiple processes [#7](https://github.com/kordlib/kord/issues/7)

Right now Kord *should* provide a full mapping of the non-voice API. We're currently working on a testing library for
easy bot testing against a semi mocked client as well as our own command system to facilitate more complex bot
development.
Right now, Kord *should* provide a full mapping of the non-voice API on Kotlin/JVM and Kotlin/JS and an experimental
mapping of the Voice API on Kotlin/JVM

## Documentation

* [Dokka docs](https://kordlib.github.io/kord/)
* [Wiki](https://github.com/kordlib/kord/wiki)

## Modules

| Module | Docs | Artifact | JVM | JS | Native² |
|--------------------------|---------------------------------------------------------|-------------------|-----|----|---------|
| [common](common) | [common](https://kordlib.github.io/kord/common) | `kord-common`¹ | ✅ | ✅ | ❌ |
| [rest](rest) | [rest](https://kordlib.github.io/kord/rest) | `kord-rest`¹ | ✅ | ✅ | ❌ |
| [gateway](gateway) | [gateway](https://kordlib.github.io/kord/gateway) | `kord-gateway`¹ | ✅ | ✅ | ❌ |
| [core](core) | [core](https://kordlib.github.io/kord/core) | `kord-core`¹ | ✅ | ✅ | ❌ |
| [voice](voice) | [voice](https://kordlib.github.io/kord/voice) | `kord-voice` | ✅ | ❌³ | ❌ |
| [core-voice](core-voice) | [core-voice](https://kordlib.github.io/kord/core-voice) | `kord-core-voice` | ✅ | ❌ | ❌ |

¹ These artifacts only supports Gradle Version 5.3 or higher, for older Gradle versions and Maven please append `-jvm`
² For Native Support please see #69
³ For Voice JS please see #69

## Installation

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

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

e.g: `0.7.x-SNAPSHOT`
e.g: `0.9.x-SNAPSHOT` for the branch `0.9.x` or `feature-mpp-SNAPSHOT` for the branch `feature/mpp`

[![Download](https://img.shields.io/maven-central/v/dev.kord/kord-core.svg?label=Maven%20Central&style=for-the-badge)](https://search.maven.org/search?q=g:%22dev.kord%22%20AND%20a:%22kord-core%22)

Expand Down Expand Up @@ -111,129 +125,22 @@ dependencies {

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

## Modules

### Core

A higher level API, combining `rest` and `gateway`, with additional (optional) caching. Unless you're writing your own
abstractions, we'd recommend using this.

```kotlin
suspend fun main() {
val kord = Kord("your bot token")
val pingPong = ReactionEmoji.Unicode("\uD83C\uDFD3")

kord.on<MessageCreateEvent> {
if (message.content != "!ping") return@on

val response = message.channel.createMessage("Pong!")
response.addReaction(pingPong)

delay(5000)
message.delete()
response.delete()
}

kord.login {
@OptIn(PrivilegedIntent::class)
intents += Intent.MessageContent
}
}
```

### Rest

A low level mapping of Discord's REST API. Requests follow
Discord's [rate limits](https://discord.com/developers/docs/topics/rate-limits).

```kotlin
suspend fun main() {
val rest = RestClient("your bot token")
val channelId = Snowflake(605212557522763787)

rest.channel.createMessage(channelId) {
content = "Hello Kord!"

embed {
color = Color(red = 0, green = 0, blue = 255)
description = "Hello embed!"
}
}
}
```

### Gateway

A low level mapping of [Discord's Gateway](https://discord.com/developers/docs/topics/gateway), which maintains the
connection and rate limits commands.

```kotlin
suspend fun main() {
val gateway = DefaultGateway()

gateway.on<MessageCreate> {
println("${message.author.username}: ${message.content}")
val words = message.content.split(' ')
when (words.firstOrNull()) {
"!close" -> gateway.stop()
"!detach" -> gateway.detach()
}
}

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


### Voice

A mapping of [Discord's Voice Connection](https://discord.com/developers/docs/topics/voice-connections), which maintains the connection and handles audio transmission.

If you want to use voice, you need to enable the voice capability,
which is only available for Gradle

```kotlin
dependencies {
implementation("dev.kord", "core", "<version>") {
capabilities {
requireCapability("dev.kord:core-voice:<version>")
}
}
}
```

```kotlin
suspend fun main() {
val kord = Kord("your token")
val voiceChannel = kord.getChannelOf<VoiceChannel>(id = Snowflake(1))!!

voiceChannel.connect {
audioProvider { AudioFrame.fromData(/* your opus encoded audio */) }
}

kord.login()
}
```

## FAQ

## Will you support kotlin multi-platform

We will, there's an [issue](https://github.com/kordlib/kord/issues/69) open to track the features we want/need to make a
transition to MPP smooth.
Currently we're supporting both Kotlin/JVM and Kotlin/JS for the majority of our API, for more information check
[Modules](#modules) and #69

## When will you document your code
## When will you document your code?

Yes.

# This project is supported by JetBrains

[![JetBrains Logo (Main) logo](https://resources.jetbrains.com/storage/products/company/brand/logos/jb_beam.svg)](https://jb.gg/OpenSourceSupport)
[![JetBrains Logo (Main) logo](https://resources.jetbrains.com/storage/products/company/brand/logos/jb_beam.svg)](https://jb.gg/OpenSourceSupport)
5 changes: 5 additions & 0 deletions buildSrc/src/main/kotlin/BinaryCompatibility.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import kotlinx.validation.ApiValidationExtension

fun ApiValidationExtension.applyKordBCVOptions() {
nonPublicMarkers += "dev.kord.common.annotation.KordInternal"
}
49 changes: 37 additions & 12 deletions buildSrc/src/main/kotlin/Compiler.kt
Original file line number Diff line number Diff line change
@@ -1,21 +1,46 @@
import org.jetbrains.kotlin.gradle.dsl.KotlinJvmCompilerOptions
import kotlinx.atomicfu.plugin.gradle.AtomicFUPluginExtension
import org.gradle.api.Project
import org.gradle.api.artifacts.VersionCatalogsExtension
import org.gradle.kotlin.dsl.configure
import org.gradle.kotlin.dsl.getByType
import org.jetbrains.kotlin.gradle.dsl.KotlinCommonCompilerOptions
import org.jetbrains.kotlin.gradle.plugin.KotlinSourceSet

object CompilerArguments {
const val time = "-opt-in=kotlin.time.ExperimentalTime"
const val contracts = "-opt-in=kotlin.contracts.ExperimentalContracts"
object OptIns {
const val coroutines = "kotlinx.coroutines.ExperimentalCoroutinesApi"
}

const val kordPreview = "-opt-in=dev.kord.common.annotation.KordPreview"
const val kordExperimental = "-opt-in=dev.kord.common.annotation.KordExperimental"
const val kordVoice = "-opt-in=dev.kord.common.annotation.KordVoice"
val kordOptIns = listOf(
"kotlin.time.ExperimentalTime",
"kotlin.contracts.ExperimentalContracts",

const val progressive = "-progressive"
}
"dev.kord.common.annotation.KordInternal",
"dev.kord.common.annotation.KordPreview",
"dev.kord.common.annotation.KordExperimental",
"dev.kord.common.annotation.KordVoice",
)

object Jvm {
const val target = 8
}

fun KotlinJvmCompilerOptions.applyKordCompilerOptions() {
allWarningsAsErrors.set(true)
freeCompilerArgs.add(CompilerArguments.progressive)
fun KotlinCommonCompilerOptions.applyKordCompilerOptions() {
// TODO: set to true again once https://github.com/Kotlin/kotlinx-atomicfu/issues/289 is fixed
allWarningsAsErrors.set(false)
lukellmann marked this conversation as resolved.
Show resolved Hide resolved
freeCompilerArgs.add("-progressive")
}

fun KotlinSourceSet.applyKordOptIns() {
languageSettings {
if ("Test" in name) optIn(OptIns.coroutines)
kordOptIns.forEach(::optIn)
}
}

fun Project.configureAtomicFU() {
// https://github.com/Kotlin/kotlinx-atomicfu/issues/210
configure<AtomicFUPluginExtension> {
val libs = extensions.getByType<VersionCatalogsExtension>().named("libs")
dependenciesVersion = libs.findVersion("kotlinx-atomicfu").get().requiredVersion
}
}
33 changes: 33 additions & 0 deletions buildSrc/src/main/kotlin/Documentation.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import org.jetbrains.dokka.gradle.AbstractDokkaLeafTask
import java.net.URL

fun AbstractDokkaLeafTask.applyKordDokkaOptions() {
failOnWarning.set(true)

dokkaSourceSets.configureEach {

jdkVersion.set(Jvm.target)

suppressGeneratedFiles.set(false)

sourceLink {
localDirectory.set(project.projectDir)
remoteUrl.set(URL("https://github.com/kordlib/kord/blob/${Library.commitHashOrDefault("0.9.x")}/${project.name}"))
remoteLineSuffix.set("#L")
}

externalDocumentationLink("https://kotlinlang.org/api/kotlinx.coroutines/")
externalDocumentationLink("https://kotlinlang.org/api/kotlinx.serialization/")
externalDocumentationLink(
url = "https://kotlinlang.org/api/kotlinx-datetime/",
packageListUrl = "https://kotlinlang.org/api/kotlinx-datetime/kotlinx-datetime/package-list",
)
externalDocumentationLink("https://api.ktor.io/")

// don't list `TweetNaclFast` in docs
perPackageOption {
matchingRegex.set("""com\.iwebpp\.crypto""")
suppress.set(true)
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
plugins {
org.jetbrains.kotlin.multiplatform
}

repositories {
mavenCentral()
}

kotlin {
jvm()
js(IR) {
nodejs()
}
jvmToolchain(Jvm.target)

targets {
all {
compilations.all {
compilerOptions.options.applyKordCompilerOptions()
}
}
}
}
Loading