├── .github └── workflows │ └── build.yml ├── .gitignore ├── LICENSE.md ├── README.md ├── build.gradle.kts ├── buildSrc ├── build.gradle.kts ├── settings.gradle.kts └── src │ └── main │ └── kotlin │ ├── Library.kt │ └── deck-publishing.gradle.kts ├── deck-common ├── build.gradle.kts ├── gradle.properties └── src │ └── main │ └── kotlin │ ├── Embeds.kt │ ├── entity │ ├── Channels.kt │ ├── Emotes.kt │ ├── Members.kt │ ├── Messages.kt │ ├── Roles.kt │ ├── Servers.kt │ ├── Users.kt │ └── Webhooks.kt │ ├── log │ ├── Logging.kt │ └── Microutils.kt │ └── util │ ├── Annotations.kt │ ├── Constants.kt │ ├── Emoji.kt │ ├── Objects.kt │ └── Optional.kt ├── deck-core ├── build.gradle.kts └── src │ └── main │ ├── kotlin │ ├── DeckClient.kt │ ├── entity │ │ ├── Ban.kt │ │ ├── CalendarEvent.kt │ │ ├── CalendarEventComment.kt │ │ ├── CalendarEventRsvp.kt │ │ ├── Documentation.kt │ │ ├── DocumentationComment.kt │ │ ├── ForumTopic.kt │ │ ├── ForumTopicComment.kt │ │ ├── ListItem.kt │ │ ├── Member.kt │ │ ├── Mentions.kt │ │ ├── Message.kt │ │ ├── Server.kt │ │ ├── SocialLink.kt │ │ ├── User.kt │ │ ├── Webhook.kt │ │ ├── channel │ │ │ ├── CalendarChannel.kt │ │ │ ├── Channel.kt │ │ │ ├── DocumentationChannel.kt │ │ │ ├── ForumChannel.kt │ │ │ ├── ListChannel.kt │ │ │ ├── MessageChannel.kt │ │ │ └── ServerChannel.kt │ │ └── impl │ │ │ ├── Channels.kt │ │ │ ├── DeckCalendarEvent.kt │ │ │ ├── DeckCalendarEventComment.kt │ │ │ ├── DeckCalendarEventRsvp.kt │ │ │ ├── DeckDocumentation.kt │ │ │ ├── DeckDocumentationComment.kt │ │ │ ├── DeckForumTopic.kt │ │ │ ├── DeckForumTopicComment.kt │ │ │ ├── DeckListItem.kt │ │ │ ├── DeckMember.kt │ │ │ ├── DeckMessage.kt │ │ │ ├── DeckServer.kt │ │ │ ├── DeckUser.kt │ │ │ └── DeckWebhook.kt │ ├── event │ │ ├── Wrapping.kt │ │ ├── calendar │ │ │ ├── CalendarEventCommentReactionAdd.kt │ │ │ ├── CalendarEventCommentReactionRemove.kt │ │ │ ├── CalendarEventCreate.kt │ │ │ ├── CalendarEventDelete.kt │ │ │ ├── CalendarEventReactionAdd.kt │ │ │ ├── CalendarEventReactionRemove.kt │ │ │ ├── CalendarEventRsvpBulkUpdate.kt │ │ │ ├── CalendarEventRsvpDelete.kt │ │ │ ├── CalendarEventRsvpUpdate.kt │ │ │ └── CalendarEventUpdate.kt │ │ ├── channel │ │ │ ├── ServerChannelCreate.kt │ │ │ ├── ServerChannelDelete.kt │ │ │ └── ServerChannelUpdate.kt │ │ ├── documentation │ │ │ ├── DocumentationCommentReactionAdd.kt │ │ │ ├── DocumentationCommentReactionRemove.kt │ │ │ ├── DocumentationCreate.kt │ │ │ ├── DocumentationDelete.kt │ │ │ ├── DocumentationReactionAdd.kt │ │ │ ├── DocumentationReactionRemove.kt │ │ │ └── DocumentationUpdate.kt │ │ ├── forum │ │ │ ├── ForumTopicCommentCreate.kt │ │ │ ├── ForumTopicCommentDelete.kt │ │ │ ├── ForumTopicCommentReactionAdd.kt │ │ │ ├── ForumTopicCommentReactionRemove.kt │ │ │ ├── ForumTopicCommentUpdate.kt │ │ │ ├── ForumTopicCreate.kt │ │ │ ├── ForumTopicDelete.kt │ │ │ ├── ForumTopicLocked.kt │ │ │ ├── ForumTopicPin.kt │ │ │ ├── ForumTopicReactionAdd.kt │ │ │ ├── ForumTopicReactionRemove.kt │ │ │ ├── ForumTopicUnlocked.kt │ │ │ ├── ForumTopicUnpin.kt │ │ │ └── ForumTopicUpdate.kt │ │ ├── list │ │ │ ├── ListItemComplete.kt │ │ │ ├── ListItemCreate.kt │ │ │ ├── ListItemDelete.kt │ │ │ ├── ListItemIncomplete.kt │ │ │ └── ListItemUpdate.kt │ │ ├── message │ │ │ ├── MessageCreate.kt │ │ │ ├── MessageDelete.kt │ │ │ ├── MessageReactionAdd.kt │ │ │ ├── MessageReactionRemove.kt │ │ │ └── MessageUpdate.kt │ │ ├── server │ │ │ ├── BotMembershipCreate.kt │ │ │ ├── BotMembershipDelete.kt │ │ │ ├── MemberBan.kt │ │ │ ├── MemberJoin.kt │ │ │ ├── MemberLeave.kt │ │ │ ├── MemberSocialLinkCreate.kt │ │ │ ├── MemberSocialLinkDelete.kt │ │ │ ├── MemberSocialLinkUpdate.kt │ │ │ ├── MemberUnban.kt │ │ │ ├── MemberUpdate.kt │ │ │ └── ServerRolesUpdate.kt │ │ ├── user │ │ │ └── Hello.kt │ │ └── webhook │ │ │ ├── WebhookCreate.kt │ │ │ └── WebhookUpdate.kt │ ├── stateless │ │ ├── StatelessEntity.kt │ │ ├── StatelessGroup.kt │ │ ├── StatelessMember.kt │ │ ├── StatelessMessage.kt │ │ ├── StatelessRole.kt │ │ ├── StatelessServer.kt │ │ ├── StatelessUser.kt │ │ ├── StatelessWebhook.kt │ │ └── channel │ │ │ ├── StatelessCalendarChannel.kt │ │ │ ├── StatelessChannel.kt │ │ │ ├── StatelessDocumentationChannel.kt │ │ │ ├── StatelessForumChannel.kt │ │ │ ├── StatelessListChannel.kt │ │ │ ├── StatelessMessageChannel.kt │ │ │ ├── StatelessServerChannel.kt │ │ │ └── content │ │ │ ├── StatelessCalendarEvent.kt │ │ │ ├── StatelessCalendarEventComment.kt │ │ │ ├── StatelessCalendarEventRsvp.kt │ │ │ ├── StatelessCalendarEventSeries.kt │ │ │ ├── StatelessChannelContent.kt │ │ │ ├── StatelessDocumentation.kt │ │ │ ├── StatelessDocumentationComment.kt │ │ │ ├── StatelessForumTopic.kt │ │ │ ├── StatelessForumTopicComment.kt │ │ │ └── StatelessListItem.kt │ └── util │ │ ├── Client.kt │ │ ├── Entities.kt │ │ ├── Events.kt │ │ ├── Patches.kt │ │ ├── Reactions.kt │ │ └── Statelesses.kt │ └── resources │ └── logback.xml ├── deck-extras ├── build.gradle.kts └── src │ └── main │ └── kotlin │ ├── Emojis.kt │ ├── content │ ├── Content.kt │ ├── Entities.kt │ ├── Util.kt │ └── node │ │ ├── Node.kt │ │ └── Strategy.kt │ ├── conversation │ ├── AbstractMessageChannelConversation.kt │ ├── Conversation.kt │ ├── ConversationMessage.kt │ └── type │ │ └── DefaultMessageChannelConversation.kt │ └── misc │ ├── Logging.kt │ └── Reactions.kt ├── deck-gateway ├── build.gradle.kts └── src │ └── main │ └── kotlin │ ├── DefaultGateway.kt │ ├── Gateway.kt │ ├── GatewayOrchestrator.kt │ ├── GatewayState.kt │ ├── entity │ ├── Messages.kt │ ├── Reactions.kt │ └── User.kt │ ├── event │ ├── Events.kt │ └── type │ │ ├── ChannelEvents.kt │ │ ├── GeneralEvents.kt │ │ ├── MemberEvents.kt │ │ ├── MessageEvents.kt │ │ ├── ReactionEvents.kt │ │ └── ServerEvents.kt │ └── util │ ├── Events.kt │ ├── GatewayConstants.kt │ └── GatewayOpcode.kt ├── deck-rest ├── build.gradle.kts └── src │ └── main │ └── kotlin │ ├── RestClient.kt │ ├── builder │ ├── ChannelBuilders.kt │ ├── RequestBuilder.kt │ └── WebhookBuilders.kt │ ├── request │ ├── ChannelRequests.kt │ ├── MemberRequests.kt │ ├── ServerRequests.kt │ └── WebhookRequests.kt │ ├── route │ ├── ChannelRoutes.kt │ ├── GroupRoutes.kt │ ├── ServerRoutes.kt │ ├── UserRoutes.kt │ └── WebhookRoutes.kt │ └── util │ ├── Exceptions.kt │ ├── Logging.kt │ ├── Properties.kt │ ├── Requests.kt │ └── Route.kt ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── libs.versions.toml └── settings.gradle.kts /.github/workflows/build.yml: -------------------------------------------------------------------------------- 1 | # This workflow will build a Java project with Gradle 2 | # For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-gradle 3 | 4 | name: Build and Publish 5 | 6 | on: [ push, pull_request ] 7 | 8 | jobs: 9 | build: 10 | name: Build modules 11 | runs-on: ubuntu-latest 12 | 13 | steps: 14 | - uses: actions/checkout@v2 15 | 16 | - name: Set up JDK 17 17 | uses: actions/setup-java@v1 18 | with: 19 | java-version: 17 20 | 21 | - name: Grant execute permission for gradlew 22 | run: chmod +x gradlew 23 | 24 | - name: Build with Gradle 25 | uses: gradle/gradle-build-action@v2 26 | with: 27 | arguments: --stacktrace --info build 28 | 29 | - uses: actions/upload-artifact@v2 30 | name: Upload Common 31 | with: 32 | name: Common 33 | path: deck-common/build/libs/ 34 | 35 | - uses: actions/upload-artifact@v2 36 | name: Upload Rest 37 | with: 38 | name: Rest 39 | path: deck-rest/build/libs/ 40 | 41 | - uses: actions/upload-artifact@v2 42 | name: Upload Gateway 43 | with: 44 | name: Gateway 45 | path: deck-gateway/build/libs/ 46 | 47 | - uses: actions/upload-artifact@v2 48 | name: Upload Extras 49 | with: 50 | name: Gateway 51 | path: deck-extras/build/libs/ -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2022 SrGaabriel 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated 6 | documentation files (the "Software"), to deal in the Software without restriction, including without limitation the 7 | rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit 8 | persons to whom the Software is furnished to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the 11 | Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE 14 | WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 15 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 16 | OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 17 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ![GitHub Workflow Status](https://img.shields.io/github/actions/workflow/status/SrGaabriel/deck/build.yml?branch=development&style=for-the-badge) 2 | ![GitHub issues](https://img.shields.io/github/issues/SrGaabriel/deck?color=orange&style=for-the-badge) 3 | ![GitHub Repo stars](https://img.shields.io/github/stars/SrGaabriel/deck?color=yellow&style=for-the-badge) 4 | ![Nexus badge](https://img.shields.io/nexus/r/io.github.srgaabriel.deck/deck-core?color=%2329B472&server=https%3A%2F%2Fs01.oss.sonatype.org&style=for-the-badge) 5 | 6 | 7 | # 🎲 deck [WIP] 8 | 9 | This is the official bot API deck implementation, which is still in an early and experimental phase. We'll be adding and implementing features as Guilded releases new API updates. 10 | 11 | ## Example 12 | 13 | Below is an example of deck's powerful API, mainly inspired by [kord](https://github.com/kordlib/kord). 14 | 15 | ```kotlin 16 | suspend fun main() { 17 | val client = DeckClient("token") 18 | client.on { 19 | if (!message.content.startsWith("+hello")) 20 | return@on 21 | val message: Message = channel.sendMessage("Hello, World!") 22 | message.sendReply("Hello, this is a reply!") 23 | } 24 | client.login() 25 | } 26 | ``` 27 | 28 | For tutorials and documentation, check out our [wiki](https://github.com/SrGaabriel/deck/wiki). 29 | 30 | ## Using 31 | 32 | To use deck in your project, you just need to add the dependency `com.github.SrGaabriel.deck:deck-core:$version` and make sure you have `mavenCentral` registered as a repository. 33 | 34 | You can replace `deck-core` with the name of the module you wish to import, and for the version you may use the latest one: 35 | ![GitHub release (latest by date)](https://img.shields.io/github/v/release/SrGaabriel/deck?style=social) 36 | 37 | ```kotlin 38 | dependencies { 39 | implementation("io.github.srgaabriel.deck:deck-core:$version") 40 | } 41 | ``` 42 | -------------------------------------------------------------------------------- /build.gradle.kts: -------------------------------------------------------------------------------- 1 | import org.jetbrains.dokka.gradle.DokkaPlugin 2 | 3 | @Suppress("DSL_SCOPE_VIOLATION", "UnstableApiUsage") 4 | plugins { 5 | kotlin("jvm") 6 | alias(libs.plugins.kotlinx.serialization) 7 | alias(libs.plugins.dokka) 8 | `maven-publish` 9 | idea 10 | } 11 | 12 | subprojects { 13 | group = Library.Group 14 | version = Library.Version 15 | apply() 16 | apply() 17 | apply() 18 | apply(plugin = "org.jetbrains.kotlin.jvm") 19 | apply(plugin = "org.jetbrains.kotlin.plugin.serialization") 20 | 21 | tasks { 22 | withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile::class) { 23 | kotlinOptions { 24 | freeCompilerArgs = freeCompilerArgs + listOf("-Xexplicit-api=strict", "-opt-in=kotlin.RequiresOptIn") 25 | jvmTarget = "1.8" 26 | } 27 | } 28 | } 29 | } 30 | 31 | repositories { 32 | mavenCentral() 33 | } 34 | 35 | dependencies { 36 | implementation(kotlin("stdlib")) 37 | } 38 | 39 | idea { 40 | module { 41 | isDownloadSources = true 42 | isDownloadJavadoc = true 43 | 44 | excludeDirs = excludeDirs + layout.files( 45 | ".idea", 46 | "gradle/wrapper" 47 | ) 48 | } 49 | } -------------------------------------------------------------------------------- /buildSrc/build.gradle.kts: -------------------------------------------------------------------------------- 1 | plugins { 2 | `kotlin-dsl` 3 | } 4 | 5 | repositories { 6 | mavenCentral() 7 | } 8 | 9 | dependencies { 10 | implementation("org.jetbrains.kotlin:kotlin-gradle-plugin:${libs.versions.kotlin.get()}") 11 | } -------------------------------------------------------------------------------- /buildSrc/settings.gradle.kts: -------------------------------------------------------------------------------- 1 | rootProject.name = "buildSrc" 2 | 3 | enableFeaturePreview("VERSION_CATALOGS") 4 | 5 | dependencyResolutionManagement { 6 | versionCatalogs { 7 | create("libs") { 8 | from(files("../libs.versions.toml")) 9 | } 10 | } 11 | } -------------------------------------------------------------------------------- /buildSrc/src/main/kotlin/Library.kt: -------------------------------------------------------------------------------- 1 | object Library { 2 | const val Group = "io.github.srgaabriel.deck" 3 | const val Version = "0.9" 4 | const val Url = "https://srgaabriel.github.io/deck/" 5 | 6 | const val Release = true 7 | const val ReleasesRepository = "https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/" 8 | } -------------------------------------------------------------------------------- /buildSrc/src/main/kotlin/deck-publishing.gradle.kts: -------------------------------------------------------------------------------- 1 | import java.util.Base64 2 | 3 | plugins { 4 | kotlin("jvm") 5 | `maven-publish` 6 | signing 7 | } 8 | 9 | tasks { 10 | val sourcesJar by registering(Jar::class) { 11 | archiveClassifier.set("sources") 12 | from(sourceSets.main.get().allSource) 13 | } 14 | 15 | val docsJar by registering(Jar::class) { 16 | group = JavaBasePlugin.DOCUMENTATION_GROUP 17 | description = "Javadocs" 18 | archiveExtension.set("javadoc") 19 | from(javadoc) 20 | dependsOn(javadoc) 21 | } 22 | 23 | publishing { 24 | publications { 25 | create("Deck") { 26 | groupId = Library.Group 27 | version = Library.Version 28 | 29 | from(components["java"]) 30 | artifact(sourcesJar.get()) 31 | artifact(docsJar.get()) 32 | 33 | pom { 34 | name.set("Deck") 35 | description.set("A powerful and simple-to-use guilded wrapper made in Kotlin. ") 36 | url.set(Library.Url) 37 | 38 | developers { 39 | developer { 40 | name.set("SrGaabriel") 41 | email.set("srgaabreil@protonmail.com") 42 | } 43 | } 44 | 45 | licenses { 46 | license { 47 | name.set("MIT") 48 | url.set("https://opensource.org/licenses/mit-license.php") 49 | } 50 | } 51 | 52 | scm { 53 | connection.set("scm:git:git://github.com/SrGaabriel/deck.git") 54 | developerConnection.set("scm:git:ssh://github.com:SrGaabriel/deck.git") 55 | url.set("https://github.com/SrGaabriel/deck") 56 | } 57 | } 58 | 59 | repositories { 60 | maven(Library.ReleasesRepository) { 61 | credentials { 62 | username = System.getenv("NEXUS_USER") 63 | password = System.getenv("NEXUS_PASSWORD") 64 | } 65 | } 66 | } 67 | } 68 | } 69 | } 70 | } 71 | 72 | signing { 73 | sign(publishing.publications["Deck"]) 74 | } -------------------------------------------------------------------------------- /deck-common/build.gradle.kts: -------------------------------------------------------------------------------- 1 | plugins { 2 | kotlin("jvm") 3 | `deck-publishing` 4 | } 5 | 6 | repositories { 7 | mavenCentral() 8 | } 9 | 10 | dependencies { 11 | implementation(kotlin("stdlib")) 12 | api(libs.kotlin.logging.jvm) 13 | api(libs.kotlinx.datetime) 14 | api(libs.kotlinx.coroutines) 15 | api(libs.kotlinx.serialization.json) 16 | } -------------------------------------------------------------------------------- /deck-common/gradle.properties: -------------------------------------------------------------------------------- 1 | version=y -------------------------------------------------------------------------------- /deck-common/src/main/kotlin/entity/Emotes.kt: -------------------------------------------------------------------------------- 1 | package io.github.srgaabriel.deck.common.entity 2 | 3 | import io.github.srgaabriel.deck.common.util.IntGenericId 4 | import kotlinx.serialization.Serializable 5 | 6 | @Serializable 7 | public data class RawEmote( 8 | val id: IntGenericId, 9 | val name: String, 10 | val url: String 11 | ) -------------------------------------------------------------------------------- /deck-common/src/main/kotlin/entity/Members.kt: -------------------------------------------------------------------------------- 1 | package io.github.srgaabriel.deck.common.entity 2 | 3 | import io.github.srgaabriel.deck.common.util.GenericId 4 | import io.github.srgaabriel.deck.common.util.OptionalProperty 5 | import kotlinx.datetime.Instant 6 | import kotlinx.serialization.Serializable 7 | 8 | @Serializable 9 | public data class RawServerMember( 10 | val user: RawUser, 11 | val roleIds: List, 12 | val nickname: OptionalProperty = OptionalProperty.NotPresent, 13 | val joinedAt: Instant, 14 | val isOwner: Boolean = false 15 | ) 16 | 17 | @Serializable 18 | public data class RawServerMemberSummary( 19 | val user: RawUserSummary, 20 | val roleIds: List, 21 | ) 22 | 23 | @Serializable 24 | public data class RawServerBan( 25 | val user: RawUserSummary, 26 | val reason: OptionalProperty = OptionalProperty.NotPresent, 27 | val createdBy: GenericId, 28 | val createdAt: Instant 29 | ) -------------------------------------------------------------------------------- /deck-common/src/main/kotlin/entity/Roles.kt: -------------------------------------------------------------------------------- 1 | package io.github.srgaabriel.deck.common.entity 2 | 3 | import io.github.srgaabriel.deck.common.util.IntGenericId 4 | import kotlinx.serialization.Serializable 5 | 6 | @Serializable 7 | public class RawRoleId(public val id: IntGenericId) -------------------------------------------------------------------------------- /deck-common/src/main/kotlin/entity/Servers.kt: -------------------------------------------------------------------------------- 1 | @file:UseSerializers(UUIDSerializer::class) 2 | 3 | package io.github.srgaabriel.deck.common.entity 4 | 5 | import io.github.srgaabriel.deck.common.util.GenericId 6 | import io.github.srgaabriel.deck.common.util.OptionalProperty 7 | import io.github.srgaabriel.deck.common.util.UUIDSerializer 8 | import kotlinx.datetime.Instant 9 | import kotlinx.serialization.SerialName 10 | import kotlinx.serialization.Serializable 11 | import kotlinx.serialization.UseSerializers 12 | import java.util.* 13 | 14 | @Serializable 15 | public data class RawServer( 16 | val id: GenericId, 17 | val ownerId: GenericId, 18 | val type: OptionalProperty = OptionalProperty.NotPresent, 19 | val name: String, 20 | val url: OptionalProperty = OptionalProperty.NotPresent, 21 | val about: OptionalProperty = OptionalProperty.NotPresent, 22 | val avatar: OptionalProperty = OptionalProperty.NotPresent, 23 | val banner: OptionalProperty = OptionalProperty.NotPresent, 24 | val timezone: OptionalProperty = OptionalProperty.NotPresent, 25 | val isVerified: Boolean = false, 26 | val defaultChannelId: OptionalProperty = OptionalProperty.NotPresent, 27 | val createdAt: Instant 28 | ) 29 | 30 | @Serializable 31 | public enum class ServerType { 32 | @SerialName("team") 33 | Team, 34 | @SerialName("organization") 35 | Organization, 36 | @SerialName("community") 37 | Community, 38 | @SerialName("clan") 39 | Clan, 40 | @SerialName("guild") 41 | Guild, 42 | @SerialName("friends") 43 | Friends, 44 | @SerialName("streaming") 45 | Streaming, 46 | @SerialName("other") 47 | Other; 48 | } -------------------------------------------------------------------------------- /deck-common/src/main/kotlin/entity/Users.kt: -------------------------------------------------------------------------------- 1 | package io.github.srgaabriel.deck.common.entity 2 | 3 | import io.github.srgaabriel.deck.common.util.GenericId 4 | import io.github.srgaabriel.deck.common.util.OptionalProperty 5 | import kotlinx.datetime.Instant 6 | import kotlinx.serialization.SerialName 7 | import kotlinx.serialization.Serializable 8 | 9 | @Serializable 10 | public data class RawUser( 11 | val id: GenericId, 12 | val type: UserType = UserType.USER, 13 | val name: String, 14 | val avatar: OptionalProperty = OptionalProperty.NotPresent, 15 | val banner: OptionalProperty = OptionalProperty.NotPresent, 16 | val createdAt: Instant 17 | ) 18 | 19 | @Serializable 20 | public data class RawUserSummary( 21 | val id: GenericId, 22 | val type: UserType = UserType.USER, 23 | val name: String, 24 | val avatar: OptionalProperty = OptionalProperty.NotPresent, 25 | ) 26 | 27 | @Serializable 28 | public data class RawUserSocialLink( 29 | val handle: OptionalProperty = OptionalProperty.NotPresent, 30 | val serviceId: OptionalProperty = OptionalProperty.NotPresent, 31 | val type: SocialLinkType, 32 | val userId: GenericId, 33 | val createdAt: Instant 34 | ) 35 | 36 | @Serializable 37 | public enum class UserType { 38 | @SerialName("user") 39 | USER, 40 | @SerialName("bot") 41 | BOT 42 | } 43 | 44 | @Serializable 45 | public class RawUserId(public val id: String) 46 | 47 | @Serializable 48 | public enum class SocialLinkType(public val id: String) { 49 | @SerialName("twitch") 50 | Twitch("twitch"), 51 | @SerialName("bnet") 52 | BattleNet("bnet"), 53 | @SerialName("psn") 54 | PlaystationNetwork("psn"), 55 | @SerialName("xbox") 56 | Xbox("xbox"), 57 | @SerialName("steam") 58 | Steam("steam"), 59 | @SerialName("origin") 60 | Origin("origin"), 61 | @SerialName("youtube") 62 | Youtube("youtube"), 63 | @SerialName("twitter") 64 | Twitter("twitter"), 65 | @SerialName("facebook") 66 | Facebook("facebook"), 67 | @SerialName("switch") 68 | Switch("switch"), 69 | @SerialName("patreon") 70 | Patreon("patreon"), 71 | @SerialName("roblox") 72 | Roblox("roblox"); 73 | } -------------------------------------------------------------------------------- /deck-common/src/main/kotlin/entity/Webhooks.kt: -------------------------------------------------------------------------------- 1 | @file:UseSerializers(UUIDSerializer::class) 2 | 3 | package io.github.srgaabriel.deck.common.entity 4 | 5 | import io.github.srgaabriel.deck.common.util.GenericId 6 | import io.github.srgaabriel.deck.common.util.OptionalProperty 7 | import io.github.srgaabriel.deck.common.util.UUIDSerializer 8 | import kotlinx.datetime.Instant 9 | import kotlinx.serialization.Serializable 10 | import kotlinx.serialization.UseSerializers 11 | import java.util.* 12 | 13 | @Serializable 14 | public data class RawWebhook( 15 | val id: UUID, 16 | val name: String, 17 | val serverId: GenericId, 18 | val channelId: UUID, 19 | val createdAt: Instant, 20 | val createdBy: GenericId, 21 | val deletedAt: OptionalProperty = OptionalProperty.NotPresent, 22 | val token: OptionalProperty = OptionalProperty.NotPresent, 23 | val avatar: OptionalProperty = OptionalProperty.NotPresent 24 | ) -------------------------------------------------------------------------------- /deck-common/src/main/kotlin/log/Logging.kt: -------------------------------------------------------------------------------- 1 | package io.github.srgaabriel.deck.common.log 2 | 3 | public typealias LoggingMessage = () -> Any 4 | 5 | public interface DeckLogger { 6 | public fun log( 7 | level: LoggingLevel, 8 | message: LoggingMessage, 9 | exception: Throwable? = null 10 | ) 11 | } 12 | 13 | public enum class LoggingLevel { 14 | Debug, 15 | Info, 16 | Warning, 17 | Error 18 | } 19 | 20 | 21 | @DslMarker 22 | public annotation class LoggingDsl 23 | 24 | @LoggingDsl 25 | @Suppress("NOTHING_TO_INLINE") 26 | public inline fun DeckLogger.debug(exception: Throwable? = null, noinline message: LoggingMessage): Unit = 27 | log(LoggingLevel.Debug, message, exception) 28 | 29 | @LoggingDsl 30 | @Suppress("NOTHING_TO_INLINE") 31 | public inline fun DeckLogger.info(exception: Throwable? = null, noinline message: LoggingMessage): Unit = 32 | log(LoggingLevel.Info, message, exception) 33 | 34 | @LoggingDsl 35 | @Suppress("NOTHING_TO_INLINE") 36 | public inline fun DeckLogger.warning(exception: Throwable? = null, noinline message: LoggingMessage): Unit = 37 | log(LoggingLevel.Warning, message, exception) 38 | 39 | @LoggingDsl 40 | @Suppress("NOTHING_TO_INLINE") 41 | public inline fun DeckLogger.error(exception: Throwable? = null, noinline message: LoggingMessage): Unit = 42 | log(LoggingLevel.Error, message, exception) -------------------------------------------------------------------------------- /deck-common/src/main/kotlin/log/Microutils.kt: -------------------------------------------------------------------------------- 1 | package io.github.srgaabriel.deck.common.log 2 | 3 | import mu.KLoggable 4 | import mu.KLogger 5 | 6 | public class MicroutilsLogger(name: String): DeckLogger, KLoggable { 7 | override val logger: KLogger = logger(name) 8 | 9 | override fun log(level: LoggingLevel, message: LoggingMessage, exception: Throwable?) { 10 | when (level) { 11 | LoggingLevel.Info -> logger.info(exception, message) 12 | LoggingLevel.Debug -> logger.debug(exception, message) 13 | LoggingLevel.Warning -> logger.warn(exception, message) 14 | LoggingLevel.Error -> logger.error(exception, message) 15 | } 16 | } 17 | } -------------------------------------------------------------------------------- /deck-common/src/main/kotlin/util/Constants.kt: -------------------------------------------------------------------------------- 1 | package io.github.srgaabriel.deck.common.util 2 | 3 | public object Constants { 4 | public const val GuildedDomain: String = "www.guilded.gg" 5 | public const val GuildedGatewayPath: String = "/websocket/v1" 6 | 7 | public const val GuildedRestApiRoute: String = "/api/v1" 8 | public const val GuildedRestApi: String = "https://$GuildedDomain$GuildedRestApiRoute" 9 | 10 | public const val GuildedMedia: String = "https://media.guilded.gg" 11 | } -------------------------------------------------------------------------------- /deck-common/src/main/kotlin/util/Emoji.kt: -------------------------------------------------------------------------------- 1 | package io.github.srgaabriel.deck.common.util 2 | 3 | import io.github.srgaabriel.deck.common.entity.RawEmote 4 | 5 | public data class Emote( 6 | public val id: Int, 7 | public val name: String, 8 | public val url: String 9 | ) { 10 | val isAnimated: Boolean get() = url.endsWith(".gif") 11 | 12 | public companion object { 13 | public fun from(raw: RawEmote): Emote = Emote( 14 | id = raw.id, 15 | name = raw.name, 16 | url = raw.url 17 | ) 18 | } 19 | } -------------------------------------------------------------------------------- /deck-core/build.gradle.kts: -------------------------------------------------------------------------------- 1 | plugins { 2 | `deck-publishing` 3 | } 4 | 5 | repositories { 6 | mavenCentral() 7 | } 8 | 9 | dependencies { 10 | implementation(kotlin("stdlib")) 11 | api(project(":deck-common")) 12 | api(project(":deck-rest")) 13 | api(project(":deck-gateway")) 14 | implementation(libs.logback) 15 | 16 | testImplementation(kotlin("test")) 17 | testImplementation(libs.mockk) 18 | testImplementation(libs.valiktor.core) 19 | } -------------------------------------------------------------------------------- /deck-core/src/main/kotlin/entity/Ban.kt: -------------------------------------------------------------------------------- 1 | package io.github.srgaabriel.deck.core.entity 2 | 3 | import io.github.srgaabriel.deck.common.entity.RawServerBan 4 | import io.github.srgaabriel.deck.common.entity.UserType 5 | import io.github.srgaabriel.deck.common.util.GenericId 6 | import io.github.srgaabriel.deck.common.util.asNullable 7 | import io.github.srgaabriel.deck.core.DeckClient 8 | import io.github.srgaabriel.deck.core.stateless.StatelessUser 9 | import io.github.srgaabriel.deck.core.util.BlankStatelessUser 10 | import kotlinx.datetime.Instant 11 | 12 | /** 13 | * Represents a user ban from a server 14 | */ 15 | public data class Ban( 16 | val client: DeckClient, 17 | val userData: ServerBannedUser, 18 | val reason: String?, 19 | val authorId: GenericId, 20 | val timestamp: Instant 21 | ) { 22 | public val user: StatelessUser get() = BlankStatelessUser(client, userData.id) 23 | public val author: StatelessUser get() = BlankStatelessUser(client, authorId) 24 | 25 | public companion object { 26 | public fun from(client: DeckClient, raw: RawServerBan): Ban = Ban( 27 | client = client, 28 | userData = ServerBannedUser(raw.user.id, raw.user.type, raw.user.name), 29 | reason = raw.reason.asNullable(), 30 | authorId = raw.createdBy, 31 | timestamp = raw.createdAt 32 | ) 33 | } 34 | } 35 | 36 | public data class ServerBannedUser( 37 | val id: GenericId, 38 | val type: UserType, 39 | val name: String 40 | ) -------------------------------------------------------------------------------- /deck-core/src/main/kotlin/entity/CalendarEventComment.kt: -------------------------------------------------------------------------------- 1 | package io.github.srgaabriel.deck.core.entity 2 | 3 | import io.github.srgaabriel.deck.common.util.GenericId 4 | import io.github.srgaabriel.deck.core.stateless.StatelessUser 5 | import io.github.srgaabriel.deck.core.stateless.channel.content.StatelessCalendarEventComment 6 | import io.github.srgaabriel.deck.core.util.BlankStatelessUser 7 | import kotlinx.datetime.Instant 8 | 9 | /** 10 | * Represents a comment posted in a [CalendarEvent] 11 | */ 12 | public interface CalendarEventComment: StatelessCalendarEventComment { 13 | /** The comment's content */ 14 | public val content: String 15 | 16 | /** The id of this comment's author */ 17 | public val authorId: GenericId 18 | public val author: StatelessUser get() = BlankStatelessUser(client, authorId) 19 | 20 | /** The date when this comment was created */ 21 | public val createdAt: Instant 22 | /** The date when this comment was updated, if it was ever updated */ 23 | public val updatedAt: Instant? 24 | 25 | /** The mentions in this comment, null if none */ 26 | public val mentions: Mentions? 27 | } -------------------------------------------------------------------------------- /deck-core/src/main/kotlin/entity/CalendarEventRsvp.kt: -------------------------------------------------------------------------------- 1 | package io.github.srgaabriel.deck.core.entity 2 | 3 | import io.github.srgaabriel.deck.common.entity.CalendarEventRsvpStatus 4 | import io.github.srgaabriel.deck.common.util.GenericId 5 | import io.github.srgaabriel.deck.core.stateless.StatelessUser 6 | import io.github.srgaabriel.deck.core.stateless.channel.content.StatelessCalendarEventRsvp 7 | import io.github.srgaabriel.deck.core.util.BlankStatelessUser 8 | import kotlinx.datetime.Instant 9 | 10 | /** 11 | * Represents an RSVP (invite) to a [CalendarEvent] 12 | */ 13 | public interface CalendarEventRsvp: StatelessCalendarEventRsvp { 14 | /** RSVP status */ 15 | public val status: CalendarEventRsvpStatus 16 | 17 | /** The RSVP author/sender/creator **(NOT THE RECEIVER)** */ 18 | public val creatorId: GenericId 19 | public val creator: StatelessUser get() = BlankStatelessUser(client, creatorId) 20 | 21 | /** The last person to edit this RSVP */ 22 | public val editorId: GenericId? 23 | public val editor: StatelessUser? get() = editorId?.let { BlankStatelessUser(client, it) } 24 | 25 | /** Time of creation of this RSVP */ 26 | public val createdAt: Instant 27 | /** Time of the last update of this RSVP */ 28 | public val updatedAt: Instant? 29 | } -------------------------------------------------------------------------------- /deck-core/src/main/kotlin/entity/Documentation.kt: -------------------------------------------------------------------------------- 1 | package io.github.srgaabriel.deck.core.entity 2 | 3 | import io.github.srgaabriel.deck.common.util.GenericId 4 | import io.github.srgaabriel.deck.core.entity.channel.DocumentationChannel 5 | import io.github.srgaabriel.deck.core.stateless.StatelessUser 6 | import io.github.srgaabriel.deck.core.stateless.channel.content.StatelessDocumentation 7 | import io.github.srgaabriel.deck.core.util.BlankStatelessUser 8 | import io.github.srgaabriel.deck.rest.builder.CreateDocumentationRequestBuilder 9 | import kotlinx.datetime.Instant 10 | 11 | /** 12 | * A documentation page from a [DocumentationChannel] 13 | */ 14 | public interface Documentation: StatelessDocumentation { 15 | /** Documentation page title */ 16 | public val title: String 17 | /** Documentation page content */ 18 | public val content: String 19 | 20 | /** When was the documentation page created */ 21 | public val createdAt: Instant 22 | /** When was the documentation page last updated */ 23 | public val updatedAt: Instant? 24 | 25 | /** The id of the author of the documentation page */ 26 | public val authorId: GenericId 27 | /** The id of the user who last updated the documentation page, null if never updated */ 28 | public val editorId: GenericId? 29 | 30 | public val author: StatelessUser get() = BlankStatelessUser(client, authorId) 31 | public val editor: StatelessUser? get() = editorId?.let { BlankStatelessUser(client, it) } 32 | 33 | /** 34 | * Patches **(NOT UPDATES)** this documentation 35 | * 36 | * @param builder patch builder 37 | * 38 | * @return the updated documentation 39 | */ 40 | public suspend fun patch(builder: CreateDocumentationRequestBuilder.() -> Unit): Documentation = 41 | update { 42 | title = this@Documentation.title 43 | content = this@Documentation.content 44 | builder() 45 | } 46 | } -------------------------------------------------------------------------------- /deck-core/src/main/kotlin/entity/DocumentationComment.kt: -------------------------------------------------------------------------------- 1 | package io.github.srgaabriel.deck.core.entity 2 | 3 | import io.github.srgaabriel.deck.common.util.GenericId 4 | import io.github.srgaabriel.deck.core.stateless.StatelessUser 5 | import io.github.srgaabriel.deck.core.stateless.channel.content.StatelessDocumentationComment 6 | import io.github.srgaabriel.deck.core.util.BlankStatelessUser 7 | import kotlinx.datetime.Instant 8 | 9 | /** 10 | * Represents a comment posted in a [Documentation] 11 | */ 12 | public interface DocumentationComment: StatelessDocumentationComment { 13 | /** The comment's content */ 14 | public val content: String 15 | 16 | /** The id of this comment's author */ 17 | public val authorId: GenericId 18 | public val author: StatelessUser get() = BlankStatelessUser(client, authorId) 19 | 20 | /** The date when this comment was created */ 21 | public val createdAt: Instant 22 | /** The date when this comment was updated, if it was ever updated */ 23 | public val updatedAt: Instant? 24 | 25 | /** The mentions in this comment, null if none */ 26 | public val mentions: Mentions? 27 | } -------------------------------------------------------------------------------- /deck-core/src/main/kotlin/entity/ForumTopicComment.kt: -------------------------------------------------------------------------------- 1 | package io.github.srgaabriel.deck.core.entity 2 | 3 | import io.github.srgaabriel.deck.core.stateless.channel.content.StatelessForumTopicComment 4 | import kotlinx.datetime.Instant 5 | 6 | /** 7 | * Represents a comment posted in a [ForumTopic] 8 | */ 9 | public interface ForumTopicComment: StatelessForumTopicComment { 10 | /** The comment's content */ 11 | public val content: String 12 | /** The entities mentioned in this comment, null if none */ 13 | public val mentions: Mentions? 14 | 15 | /** The date when this comment was created */ 16 | public val createdAt: Instant 17 | /** The date when this comment was updated, if it was ever updated */ 18 | public val updatedAt: Instant? 19 | } -------------------------------------------------------------------------------- /deck-core/src/main/kotlin/entity/Member.kt: -------------------------------------------------------------------------------- 1 | package io.github.srgaabriel.deck.core.entity 2 | 3 | import io.github.srgaabriel.deck.common.entity.RawServerMemberSummary 4 | import io.github.srgaabriel.deck.common.entity.UserType 5 | import io.github.srgaabriel.deck.common.util.GenericId 6 | import io.github.srgaabriel.deck.common.util.IntGenericId 7 | import io.github.srgaabriel.deck.common.util.asNullable 8 | import io.github.srgaabriel.deck.core.DeckClient 9 | import io.github.srgaabriel.deck.core.entity.impl.DeckMember 10 | import io.github.srgaabriel.deck.core.stateless.StatelessMember 11 | import io.github.srgaabriel.deck.core.stateless.StatelessUser 12 | import io.github.srgaabriel.deck.core.util.BlankStatelessUser 13 | import kotlinx.datetime.Instant 14 | 15 | /** 16 | * This represents a guilded user. 17 | * This interface's default implementation is [DeckMember]. 18 | */ 19 | public interface Member: StatelessMember { 20 | /** The user's name, not to be confused with his [nickname] */ 21 | public val name: String 22 | /** Whether this member is a bot or an actual user */ 23 | public val type: UserType 24 | 25 | /** A stateless user instance of this user */ 26 | public val user: StatelessUser get() = BlankStatelessUser(client, id) 27 | 28 | /** This user's avatar, null if not set (default doggo avatar) */ 29 | public val avatar: String? 30 | /** This user's banner, null if not set */ 31 | public val banner: String? 32 | 33 | /** The user's nickname in this server */ 34 | public val nickname: String? 35 | /** A list of all role ids assigned to this member */ 36 | public val roleIds: List 37 | 38 | /** True if this member is the server's owner */ 39 | public val isOwner: Boolean 40 | 41 | /** The instant the user was registered in guilded */ 42 | public val createdAt: Instant 43 | /** The instant the user joined the server */ 44 | public val joinedAt: Instant 45 | 46 | public fun asSummary(): MemberSummary = 47 | MemberSummary(client, id, serverId, name, type, avatar, roleIds) 48 | } 49 | 50 | public data class MemberSummary( 51 | override val client: DeckClient, 52 | override val id: GenericId, 53 | override val serverId: GenericId, 54 | val name: String, 55 | val type: UserType, 56 | val avatar: String?, 57 | val roleIds: List, 58 | ): StatelessMember { 59 | public companion object { 60 | public fun from(client: DeckClient, serverId: GenericId, raw: RawServerMemberSummary): MemberSummary = MemberSummary( 61 | client = client, 62 | id = raw.user.id, 63 | name = raw.user.name, 64 | type = raw.user.type, 65 | avatar = raw.user.avatar.asNullable(), 66 | serverId = serverId, 67 | roleIds = raw.roleIds 68 | ) 69 | } 70 | } -------------------------------------------------------------------------------- /deck-core/src/main/kotlin/entity/Mentions.kt: -------------------------------------------------------------------------------- 1 | package io.github.srgaabriel.deck.core.entity 2 | 3 | import io.github.srgaabriel.deck.common.entity.RawMessageMentions 4 | import io.github.srgaabriel.deck.common.util.GenericId 5 | import io.github.srgaabriel.deck.common.util.IntGenericId 6 | import io.github.srgaabriel.deck.common.util.asNullable 7 | import java.util.* 8 | 9 | public data class Mentions( 10 | val users: List, 11 | val channels: List, 12 | val roles: List, 13 | val here: Boolean, 14 | val everyone: Boolean, 15 | ) { 16 | public fun isEmpty(): Boolean = 17 | !everyone && !here && users.isEmpty() && channels.isEmpty() && roles.isEmpty() 18 | 19 | public companion object { 20 | public fun from(raw: RawMessageMentions): Mentions = Mentions( 21 | users = raw.users.asNullable().orEmpty().map { it.id }, 22 | channels = raw.channels.asNullable().orEmpty().map { it.id }, 23 | roles = raw.roles.asNullable().orEmpty().map { it.id }, 24 | here = raw.here, 25 | everyone = raw.everyone, 26 | ) 27 | } 28 | } -------------------------------------------------------------------------------- /deck-core/src/main/kotlin/entity/Server.kt: -------------------------------------------------------------------------------- 1 | package io.github.srgaabriel.deck.core.entity 2 | 3 | import io.github.srgaabriel.deck.common.entity.ServerType 4 | import io.github.srgaabriel.deck.common.util.GenericId 5 | import io.github.srgaabriel.deck.core.stateless.StatelessServer 6 | import io.github.srgaabriel.deck.core.stateless.StatelessUser 7 | import io.github.srgaabriel.deck.core.util.BlankStatelessUser 8 | import kotlinx.datetime.Instant 9 | import java.util.* 10 | 11 | /** 12 | * Symbolizes a server (not a group) in Guilded 13 | */ 14 | public interface Server: StatelessServer { 15 | /** Server owner's id */ 16 | public val ownerId: GenericId 17 | public val owner: StatelessUser get() = BlankStatelessUser(client, ownerId) 18 | 19 | /** Server type, null if not defined */ 20 | public val type: ServerType? 21 | /** Server name */ 22 | public val name: String 23 | 24 | /** Server about/description */ 25 | public val about: String? 26 | 27 | /** Server avatar, null if default */ 28 | public val avatar: String? 29 | /** Server banner, null if none */ 30 | public val banner: String? 31 | 32 | /** Server timezone, null if not defined */ 33 | public val timezone: String? 34 | /** Server default channel id (used for welcome messages), null if none */ 35 | public val defaultChannelId: UUID? 36 | 37 | /** Instant the server was created */ 38 | public val createdAt: Instant 39 | } -------------------------------------------------------------------------------- /deck-core/src/main/kotlin/entity/SocialLink.kt: -------------------------------------------------------------------------------- 1 | package io.github.srgaabriel.deck.core.entity 2 | 3 | import io.github.srgaabriel.deck.common.entity.RawUserSocialLink 4 | import io.github.srgaabriel.deck.common.entity.SocialLinkType 5 | import io.github.srgaabriel.deck.common.util.GenericId 6 | import io.github.srgaabriel.deck.common.util.asNullable 7 | import io.github.srgaabriel.deck.core.DeckClient 8 | import io.github.srgaabriel.deck.core.stateless.StatelessUser 9 | import io.github.srgaabriel.deck.core.util.BlankStatelessUser 10 | import kotlinx.datetime.Instant 11 | 12 | public data class SocialLink( 13 | val client: DeckClient, 14 | val type: SocialLinkType, 15 | val userId: GenericId, 16 | val handle: String?, 17 | val serviceId: String?, 18 | val createdAt: Instant 19 | ) { 20 | val user: StatelessUser get() = BlankStatelessUser(client, userId) 21 | 22 | public companion object { 23 | public fun from(client: DeckClient, raw: RawUserSocialLink): SocialLink = SocialLink( 24 | client = client, 25 | type = raw.type, 26 | userId = raw.userId, 27 | handle = raw.handle.asNullable(), 28 | serviceId = raw.serviceId.asNullable(), 29 | createdAt = raw.createdAt 30 | ) 31 | } 32 | } -------------------------------------------------------------------------------- /deck-core/src/main/kotlin/entity/User.kt: -------------------------------------------------------------------------------- 1 | package io.github.srgaabriel.deck.core.entity 2 | 3 | import io.github.srgaabriel.deck.core.stateless.StatelessUser 4 | import kotlinx.datetime.Instant 5 | 6 | public interface User: StatelessUser { 7 | public val name: String 8 | 9 | public val avatar: String? 10 | public val banner: String? 11 | 12 | public val isBot: Boolean 13 | public val createdAt: Instant 14 | } -------------------------------------------------------------------------------- /deck-core/src/main/kotlin/entity/Webhook.kt: -------------------------------------------------------------------------------- 1 | package io.github.srgaabriel.deck.core.entity 2 | 3 | import io.github.srgaabriel.deck.common.util.GenericId 4 | import io.github.srgaabriel.deck.core.stateless.StatelessUser 5 | import io.github.srgaabriel.deck.core.stateless.StatelessWebhook 6 | import io.github.srgaabriel.deck.core.stateless.channel.StatelessServerChannel 7 | import io.github.srgaabriel.deck.core.util.BlankStatelessServerChannel 8 | import io.github.srgaabriel.deck.core.util.BlankStatelessUser 9 | import io.github.srgaabriel.deck.rest.builder.ExecuteWebhookRequestBuilder 10 | import io.github.srgaabriel.deck.rest.builder.UpdateWebhookRequestBuilder 11 | import io.github.srgaabriel.deck.rest.request.ExecuteWebhookResponse 12 | import kotlinx.datetime.Instant 13 | import java.util.* 14 | 15 | /** 16 | * Represents a Webhook from a Guilded server channel 17 | */ 18 | public interface Webhook: StatelessWebhook { 19 | /** The webhook's name */ 20 | public val name: String 21 | /** The id of the channel this webhook was created in */ 22 | public val channelId: UUID 23 | public val channel: StatelessServerChannel get() = BlankStatelessServerChannel(client, id, serverId) 24 | 25 | /** The instant this webhook was created */ 26 | public val createdAt: Instant 27 | /** The instant this webhook was deleted, null by default */ 28 | public val deletedAt: Instant? 29 | 30 | /** The id of the user who created this webhook */ 31 | public val creatorId: GenericId 32 | public val creator: StatelessUser get() = BlankStatelessUser(client, creatorId) 33 | 34 | /** This webhook's token */ 35 | public val token: String? 36 | 37 | /** 38 | * Patches **(NOT UPDATES)** this webhook 39 | * 40 | * @param builder patch builder 41 | * 42 | * @return the updated webhook 43 | */ 44 | public suspend fun patch(builder: UpdateWebhookRequestBuilder.() -> Unit): Webhook = update { 45 | name = this@Webhook.name 46 | channelId = this@Webhook.channelId 47 | } 48 | 49 | /** 50 | * Executes this webhook using its known [token], sending a message with the details provided in the [builder] 51 | * 52 | * @param builder message builder 53 | * @return response, null if token not known 54 | */ 55 | public suspend fun execute(builder: ExecuteWebhookRequestBuilder.() -> Unit): ExecuteWebhookResponse? = 56 | token?.let { execute(it, builder) } 57 | } -------------------------------------------------------------------------------- /deck-core/src/main/kotlin/entity/channel/CalendarChannel.kt: -------------------------------------------------------------------------------- 1 | package io.github.srgaabriel.deck.core.entity.channel 2 | 3 | import io.github.srgaabriel.deck.core.stateless.channel.StatelessCalendarChannel 4 | 5 | public interface CalendarChannel: ServerChannel, StatelessCalendarChannel -------------------------------------------------------------------------------- /deck-core/src/main/kotlin/entity/channel/Channel.kt: -------------------------------------------------------------------------------- 1 | package io.github.srgaabriel.deck.core.entity.channel 2 | 3 | import io.github.srgaabriel.deck.common.util.GenericId 4 | import io.github.srgaabriel.deck.core.stateless.StatelessUser 5 | import io.github.srgaabriel.deck.core.stateless.channel.StatelessChannel 6 | import io.github.srgaabriel.deck.core.util.BlankStatelessUser 7 | import kotlinx.datetime.Instant 8 | 9 | public interface Channel: StatelessChannel { 10 | public val name: String 11 | public val topic: String? 12 | 13 | public val isPublic: Boolean 14 | 15 | public val createdAt: Instant 16 | public val archivedAt: Instant? 17 | 18 | public val creatorId: GenericId 19 | public val creator: StatelessUser get() = BlankStatelessUser(client, creatorId) 20 | 21 | public val archiverId: GenericId? 22 | public val archiver: StatelessUser? get() = archiverId?.let { BlankStatelessUser(client, it) } 23 | 24 | public val updatedAt: Instant? 25 | } -------------------------------------------------------------------------------- /deck-core/src/main/kotlin/entity/channel/DocumentationChannel.kt: -------------------------------------------------------------------------------- 1 | package io.github.srgaabriel.deck.core.entity.channel 2 | 3 | import io.github.srgaabriel.deck.core.stateless.channel.StatelessDocumentationChannel 4 | 5 | public interface DocumentationChannel: ServerChannel, StatelessDocumentationChannel -------------------------------------------------------------------------------- /deck-core/src/main/kotlin/entity/channel/ForumChannel.kt: -------------------------------------------------------------------------------- 1 | package io.github.srgaabriel.deck.core.entity.channel 2 | 3 | import io.github.srgaabriel.deck.core.stateless.channel.StatelessForumChannel 4 | 5 | public interface ForumChannel: ServerChannel, StatelessForumChannel -------------------------------------------------------------------------------- /deck-core/src/main/kotlin/entity/channel/ListChannel.kt: -------------------------------------------------------------------------------- 1 | package io.github.srgaabriel.deck.core.entity.channel 2 | 3 | import io.github.srgaabriel.deck.core.stateless.channel.StatelessListChannel 4 | 5 | public interface ListChannel: ServerChannel, StatelessListChannel -------------------------------------------------------------------------------- /deck-core/src/main/kotlin/entity/channel/MessageChannel.kt: -------------------------------------------------------------------------------- 1 | package io.github.srgaabriel.deck.core.entity.channel 2 | 3 | import io.github.srgaabriel.deck.common.util.GenericId 4 | import io.github.srgaabriel.deck.core.stateless.StatelessServer 5 | import io.github.srgaabriel.deck.core.stateless.channel.StatelessMessageChannel 6 | 7 | public interface MessageChannel: Channel, StatelessMessageChannel 8 | 9 | public interface DmChannel: Channel, StatelessMessageChannel { 10 | override val serverId: GenericId? get() = null 11 | override val server: StatelessServer? get() = null 12 | } 13 | 14 | public interface ServerMessageChannel: ServerChannel, StatelessMessageChannel -------------------------------------------------------------------------------- /deck-core/src/main/kotlin/entity/channel/ServerChannel.kt: -------------------------------------------------------------------------------- 1 | package io.github.srgaabriel.deck.core.entity.channel 2 | 3 | import io.github.srgaabriel.deck.common.util.GenericId 4 | import io.github.srgaabriel.deck.core.stateless.StatelessServer 5 | import io.github.srgaabriel.deck.core.stateless.channel.StatelessServerChannel 6 | 7 | public interface ServerChannel: Channel, StatelessServerChannel { 8 | override val serverId: GenericId 9 | override val server: StatelessServer get() = super.server 10 | 11 | public val groupId: GenericId 12 | } -------------------------------------------------------------------------------- /deck-core/src/main/kotlin/entity/impl/DeckCalendarEvent.kt: -------------------------------------------------------------------------------- 1 | package io.github.srgaabriel.deck.core.entity.impl 2 | 3 | import io.github.srgaabriel.deck.common.entity.RawCalendarEvent 4 | import io.github.srgaabriel.deck.common.util.GenericId 5 | import io.github.srgaabriel.deck.common.util.IntGenericId 6 | import io.github.srgaabriel.deck.common.util.asNullable 7 | import io.github.srgaabriel.deck.core.DeckClient 8 | import io.github.srgaabriel.deck.core.entity.CalendarEvent 9 | import kotlinx.datetime.Instant 10 | import java.util.* 11 | 12 | public data class DeckCalendarEvent( 13 | override val client: DeckClient, 14 | override val id: IntGenericId, 15 | override val channelId: UUID, 16 | override val serverId: GenericId, 17 | override val name: String, 18 | override val description: String?, 19 | override val location: String?, 20 | override val url: String?, 21 | override val rsvpLimit: Int?, 22 | override val color: Int?, 23 | override val seriesId: UUID?, 24 | override val lastsAllDay: Boolean, 25 | override val roleIds: List, 26 | override val repeats: Boolean, 27 | override val durationInMinutes: Int?, 28 | override val startsAt: Instant, 29 | override val isPrivate: Boolean, 30 | override val createdAt: Instant, 31 | override val createdBy: GenericId, 32 | override val cancellationDescription: String?, 33 | override val cancelledBy: GenericId?, 34 | ): CalendarEvent { 35 | public companion object { 36 | public fun from(client: DeckClient, raw: RawCalendarEvent): DeckCalendarEvent = DeckCalendarEvent( 37 | client = client, 38 | id = raw.id, 39 | channelId = raw.channelId, 40 | serverId = raw.serverId, 41 | name = raw.name, 42 | description = raw.description.asNullable(), 43 | location = raw.location.asNullable(), 44 | url = raw.url.asNullable(), 45 | rsvpLimit = raw.rsvpLimit.asNullable(), 46 | color = raw.color.asNullable(), 47 | seriesId = raw.seriesId.asNullable(), 48 | lastsAllDay = raw.isAllDay, 49 | roleIds = raw.roleIds.asNullable().orEmpty(), 50 | repeats = raw.repeats, 51 | durationInMinutes = raw.duration.asNullable(), 52 | startsAt = raw.startsAt, 53 | isPrivate = raw.isPrivate.asNullable() == true, 54 | createdAt = raw.createdAt, 55 | createdBy = raw.createdBy, 56 | cancellationDescription = raw.cancellation.asNullable()?.description?.asNullable(), 57 | cancelledBy = raw.cancellation.asNullable()?.createdBy 58 | ) 59 | } 60 | } -------------------------------------------------------------------------------- /deck-core/src/main/kotlin/entity/impl/DeckCalendarEventComment.kt: -------------------------------------------------------------------------------- 1 | package io.github.srgaabriel.deck.core.entity.impl 2 | 3 | import io.github.srgaabriel.deck.common.entity.RawCalendarEventComment 4 | import io.github.srgaabriel.deck.common.util.GenericId 5 | import io.github.srgaabriel.deck.common.util.IntGenericId 6 | import io.github.srgaabriel.deck.common.util.asNullable 7 | import io.github.srgaabriel.deck.core.DeckClient 8 | import io.github.srgaabriel.deck.core.entity.CalendarEventComment 9 | import io.github.srgaabriel.deck.core.entity.Mentions 10 | import kotlinx.datetime.Instant 11 | import java.util.* 12 | 13 | public class DeckCalendarEventComment( 14 | override val client: DeckClient, 15 | override val id: IntGenericId, 16 | override val serverId: GenericId, 17 | override val channelId: UUID, 18 | override val calendarEventId: IntGenericId, 19 | override val content: String, 20 | override val createdAt: Instant, 21 | override val authorId: GenericId, 22 | override val updatedAt: Instant?, 23 | override val mentions: Mentions? 24 | ): CalendarEventComment { 25 | public companion object { 26 | public fun from(client: DeckClient, serverId: GenericId, raw: RawCalendarEventComment): DeckCalendarEventComment = DeckCalendarEventComment( 27 | client = client, 28 | id = raw.id, 29 | serverId = serverId, 30 | channelId = raw.channelId, 31 | calendarEventId = raw.calendarEventId, 32 | content = raw.content, 33 | createdAt = raw.createdAt, 34 | authorId = raw.createdBy, 35 | updatedAt = raw.updatedAt.asNullable(), 36 | mentions = raw.mentions.asNullable()?.let { Mentions.from(it) } 37 | ) 38 | } 39 | } -------------------------------------------------------------------------------- /deck-core/src/main/kotlin/entity/impl/DeckCalendarEventRsvp.kt: -------------------------------------------------------------------------------- 1 | package io.github.srgaabriel.deck.core.entity.impl 2 | 3 | import io.github.srgaabriel.deck.common.entity.CalendarEventRsvpStatus 4 | import io.github.srgaabriel.deck.common.entity.RawCalendarEventRsvp 5 | import io.github.srgaabriel.deck.common.util.GenericId 6 | import io.github.srgaabriel.deck.common.util.IntGenericId 7 | import io.github.srgaabriel.deck.common.util.asNullable 8 | import io.github.srgaabriel.deck.core.DeckClient 9 | import io.github.srgaabriel.deck.core.entity.CalendarEventRsvp 10 | import kotlinx.datetime.Instant 11 | import java.util.* 12 | 13 | public class DeckCalendarEventRsvp( 14 | override val client: DeckClient, 15 | override val userId: GenericId, 16 | override val calendarEventId: IntGenericId, 17 | override val channelId: UUID, 18 | override val serverId: GenericId, 19 | override val status: CalendarEventRsvpStatus, 20 | override val creatorId: GenericId, 21 | override val editorId: GenericId?, 22 | override val createdAt: Instant, 23 | override val updatedAt: Instant? 24 | ): CalendarEventRsvp { 25 | public companion object { 26 | public fun from(client: DeckClient, raw: RawCalendarEventRsvp): DeckCalendarEventRsvp = 27 | DeckCalendarEventRsvp( 28 | client = client, 29 | userId = raw.userId, 30 | calendarEventId = raw.calendarEventId, 31 | channelId = raw.channelId, 32 | serverId = raw.serverId, 33 | status = raw.status, 34 | creatorId = raw.createdBy, 35 | editorId = raw.updatedBy.asNullable(), 36 | createdAt = raw.createdAt, 37 | updatedAt = raw.updatedAt.asNullable() 38 | ) 39 | } 40 | } -------------------------------------------------------------------------------- /deck-core/src/main/kotlin/entity/impl/DeckDocumentation.kt: -------------------------------------------------------------------------------- 1 | package io.github.srgaabriel.deck.core.entity.impl 2 | 3 | import io.github.srgaabriel.deck.common.entity.RawDocumentation 4 | import io.github.srgaabriel.deck.common.util.GenericId 5 | import io.github.srgaabriel.deck.common.util.IntGenericId 6 | import io.github.srgaabriel.deck.common.util.asNullable 7 | import io.github.srgaabriel.deck.core.DeckClient 8 | import io.github.srgaabriel.deck.core.entity.Documentation 9 | import kotlinx.datetime.Instant 10 | import java.util.* 11 | 12 | public data class DeckDocumentation( 13 | override val client: DeckClient, 14 | override val id: IntGenericId, 15 | override val title: String, 16 | override val content: String, 17 | override val serverId: GenericId, 18 | override val channelId: UUID, 19 | override val createdAt: Instant, 20 | override val updatedAt: Instant?, 21 | override val authorId: GenericId, 22 | override val editorId: GenericId? 23 | ): Documentation { 24 | public companion object { 25 | public fun from(client: DeckClient, raw: RawDocumentation): DeckDocumentation = DeckDocumentation( 26 | client = client, 27 | id = raw.id, 28 | title = raw.title, 29 | content = raw.content, 30 | serverId = raw.serverId, 31 | channelId = raw.channelId, 32 | createdAt = raw.createdAt, 33 | updatedAt = raw.updatedAt.asNullable(), 34 | authorId = raw.createdBy, 35 | editorId = raw.updatedBy.asNullable() 36 | ) 37 | } 38 | } -------------------------------------------------------------------------------- /deck-core/src/main/kotlin/entity/impl/DeckDocumentationComment.kt: -------------------------------------------------------------------------------- 1 | package io.github.srgaabriel.deck.core.entity.impl 2 | 3 | import io.github.srgaabriel.deck.common.entity.RawDocumentationComment 4 | import io.github.srgaabriel.deck.common.util.GenericId 5 | import io.github.srgaabriel.deck.common.util.IntGenericId 6 | import io.github.srgaabriel.deck.common.util.asNullable 7 | import io.github.srgaabriel.deck.core.DeckClient 8 | import io.github.srgaabriel.deck.core.entity.DocumentationComment 9 | import io.github.srgaabriel.deck.core.entity.Mentions 10 | import kotlinx.datetime.Instant 11 | import java.util.* 12 | 13 | public data class DeckDocumentationComment( 14 | override val client: DeckClient, 15 | override val id: IntGenericId, 16 | override val channelId: UUID, 17 | override val documentationId: IntGenericId, 18 | override val serverId: GenericId, 19 | override val content: String, 20 | override val authorId: GenericId, 21 | override val createdAt: Instant, 22 | override val updatedAt: Instant?, 23 | override val mentions: Mentions?, 24 | ): DocumentationComment { 25 | public companion object { 26 | public fun from(client: DeckClient, serverId: GenericId, raw: RawDocumentationComment): DeckDocumentationComment = DeckDocumentationComment( 27 | client = client, 28 | id = raw.id, 29 | channelId = raw.channelId, 30 | documentationId = raw.docId, 31 | serverId = serverId, 32 | content = raw.content, 33 | authorId = raw.createdBy, 34 | createdAt = raw.createdAt, 35 | updatedAt = raw.updatedAt.asNullable(), 36 | mentions = raw.mentions.asNullable()?.let { Mentions.from(it) } 37 | ) 38 | } 39 | } -------------------------------------------------------------------------------- /deck-core/src/main/kotlin/entity/impl/DeckForumTopic.kt: -------------------------------------------------------------------------------- 1 | package io.github.srgaabriel.deck.core.entity.impl 2 | 3 | import io.github.srgaabriel.deck.common.entity.RawForumTopic 4 | import io.github.srgaabriel.deck.common.util.GenericId 5 | import io.github.srgaabriel.deck.common.util.asNullable 6 | import io.github.srgaabriel.deck.core.DeckClient 7 | import io.github.srgaabriel.deck.core.entity.ForumTopic 8 | import io.github.srgaabriel.deck.core.entity.Mentions 9 | import kotlinx.datetime.Instant 10 | import java.util.* 11 | 12 | public data class DeckForumTopic( 13 | override val client: DeckClient, 14 | override val id: Int, 15 | override val authorId: GenericId, 16 | override val serverId: GenericId, 17 | override val channelId: UUID, 18 | override val title: String, 19 | override val content: String, 20 | override val createdAt: Instant, 21 | override val updatedAt: Instant?, 22 | override val bumpedAt: Instant?, 23 | override val mentions: Mentions? 24 | ): ForumTopic { 25 | public companion object { 26 | public fun from(client: DeckClient, raw: RawForumTopic): DeckForumTopic = DeckForumTopic( 27 | client = client, 28 | id = raw.id, 29 | authorId = raw.createdBy, 30 | serverId = raw.serverId, 31 | channelId = raw.channelId, 32 | title = raw.title, 33 | content = raw.content, 34 | createdAt = raw.createdAt, 35 | updatedAt = raw.updatedAt.asNullable(), 36 | bumpedAt = raw.bumpedAt.asNullable(), 37 | mentions = raw.mentions.asNullable()?.let { Mentions.from(it) } 38 | ) 39 | } 40 | } -------------------------------------------------------------------------------- /deck-core/src/main/kotlin/entity/impl/DeckForumTopicComment.kt: -------------------------------------------------------------------------------- 1 | package io.github.srgaabriel.deck.core.entity.impl 2 | 3 | import io.github.srgaabriel.deck.common.entity.RawForumTopicComment 4 | import io.github.srgaabriel.deck.common.util.GenericId 5 | import io.github.srgaabriel.deck.common.util.IntGenericId 6 | import io.github.srgaabriel.deck.common.util.asNullable 7 | import io.github.srgaabriel.deck.core.DeckClient 8 | import io.github.srgaabriel.deck.core.entity.ForumTopicComment 9 | import io.github.srgaabriel.deck.core.entity.Mentions 10 | import kotlinx.datetime.Instant 11 | import java.util.* 12 | 13 | public data class DeckForumTopicComment( 14 | override val client: DeckClient, 15 | override val id: IntGenericId, 16 | override val forumTopicId: IntGenericId, 17 | override val channelId: UUID, 18 | override val serverId: GenericId, 19 | override val content: String, 20 | override val mentions: Mentions?, 21 | override val createdAt: Instant, 22 | override val updatedAt: Instant?, 23 | ): ForumTopicComment { 24 | public companion object { 25 | public fun from(client: DeckClient, serverId: GenericId, raw: RawForumTopicComment): DeckForumTopicComment = 26 | DeckForumTopicComment( 27 | client, 28 | raw.id, 29 | raw.forumTopicId, 30 | raw.channelId, 31 | serverId, 32 | raw.content, 33 | raw.mentions.asNullable()?.let { Mentions.from(it) }, 34 | raw.createdAt, 35 | raw.updatedAt.asNullable() 36 | ) 37 | } 38 | } -------------------------------------------------------------------------------- /deck-core/src/main/kotlin/entity/impl/DeckListItem.kt: -------------------------------------------------------------------------------- 1 | package io.github.srgaabriel.deck.core.entity.impl 2 | 3 | import io.github.srgaabriel.deck.common.entity.RawListItem 4 | import io.github.srgaabriel.deck.common.util.GenericId 5 | import io.github.srgaabriel.deck.common.util.asNullable 6 | import io.github.srgaabriel.deck.common.util.map 7 | import io.github.srgaabriel.deck.core.DeckClient 8 | import io.github.srgaabriel.deck.core.entity.ListItem 9 | import io.github.srgaabriel.deck.core.entity.ListItemNote 10 | import kotlinx.datetime.Instant 11 | import java.util.* 12 | 13 | public data class DeckListItem( 14 | override val client: DeckClient, 15 | override val id: UUID, 16 | override val authorId: GenericId, 17 | override val serverId: GenericId, 18 | override val channelId: UUID, 19 | override val label: String, 20 | override val note: ListItemNote?, 21 | override val createdAt: Instant, 22 | override val updatedAt: Instant?, 23 | override val editorId: GenericId? 24 | ): ListItem { 25 | public companion object { 26 | public fun from(client: DeckClient, raw: RawListItem): DeckListItem = DeckListItem( 27 | client = client, 28 | id = raw.id, 29 | serverId = raw.serverId, 30 | channelId = raw.channelId, 31 | label = raw.message, 32 | note = raw.note.map { ListItemNote.from(client, it) }.asNullable(), 33 | authorId = raw.createdBy, 34 | createdAt = raw.createdAt, 35 | updatedAt = raw.updatedAt.asNullable(), 36 | editorId = raw.updatedBy.asNullable() 37 | ) 38 | } 39 | } -------------------------------------------------------------------------------- /deck-core/src/main/kotlin/entity/impl/DeckMember.kt: -------------------------------------------------------------------------------- 1 | package io.github.srgaabriel.deck.core.entity.impl 2 | 3 | import io.github.srgaabriel.deck.common.entity.RawServerMember 4 | import io.github.srgaabriel.deck.common.entity.UserType 5 | import io.github.srgaabriel.deck.common.util.GenericId 6 | import io.github.srgaabriel.deck.common.util.IntGenericId 7 | import io.github.srgaabriel.deck.common.util.asNullable 8 | import io.github.srgaabriel.deck.core.DeckClient 9 | import io.github.srgaabriel.deck.core.entity.Member 10 | import kotlinx.datetime.Instant 11 | 12 | public data class DeckMember( 13 | override val client: DeckClient, 14 | override val id: GenericId, 15 | override val name: String, 16 | override val type: UserType, 17 | override val serverId: GenericId, 18 | override val nickname: String?, 19 | override val avatar: String?, 20 | override val banner: String?, 21 | override val roleIds: List, 22 | override val isOwner: Boolean, 23 | override val createdAt: Instant, 24 | override val joinedAt: Instant, 25 | ) : Member { 26 | public companion object { 27 | public fun from(client: DeckClient, serverId: GenericId, raw: RawServerMember): DeckMember = DeckMember( 28 | client = client, 29 | id = raw.user.id, 30 | name = raw.user.name, 31 | type = raw.user.type, 32 | serverId = serverId, 33 | nickname = raw.nickname.asNullable(), 34 | avatar = raw.user.avatar.asNullable(), 35 | banner = raw.user.banner.asNullable(), 36 | roleIds = raw.roleIds, 37 | isOwner = raw.isOwner, 38 | createdAt = raw.user.createdAt, 39 | joinedAt = raw.joinedAt 40 | ) 41 | } 42 | } -------------------------------------------------------------------------------- /deck-core/src/main/kotlin/entity/impl/DeckMessage.kt: -------------------------------------------------------------------------------- 1 | package io.github.srgaabriel.deck.core.entity.impl 2 | 3 | import io.github.srgaabriel.deck.common.Embed 4 | import io.github.srgaabriel.deck.common.entity.RawMessage 5 | import io.github.srgaabriel.deck.common.from 6 | import io.github.srgaabriel.deck.common.util.GenericId 7 | import io.github.srgaabriel.deck.common.util.asNullable 8 | import io.github.srgaabriel.deck.core.DeckClient 9 | import io.github.srgaabriel.deck.core.entity.Mentions 10 | import io.github.srgaabriel.deck.core.entity.Message 11 | import kotlinx.datetime.Instant 12 | import java.util.* 13 | 14 | public data class DeckMessage( 15 | override val client: DeckClient, 16 | override val id: UUID, 17 | override val content: String, 18 | override val authorId: GenericId, 19 | override val serverId: GenericId?, 20 | override val channelId: UUID, 21 | override val embeds: List, 22 | override val createdAt: Instant, 23 | override val updatedAt: Instant?, 24 | override val mentions: Mentions?, 25 | override val repliesTo: List, 26 | override val isPrivate: Boolean, 27 | override val isSilent: Boolean, 28 | override val createdByWebhookId: UUID? 29 | ): Message { 30 | public companion object { 31 | public fun from(client: DeckClient, raw: RawMessage): DeckMessage = DeckMessage( 32 | client = client, 33 | id = raw.id, 34 | content = raw.content.asNullable().orEmpty(), 35 | authorId = raw.createdBy, 36 | serverId = raw.serverId.asNullable(), 37 | channelId = raw.channelId, 38 | embeds = raw.embeds.map { Embed.from(it) }, 39 | createdAt = raw.createdAt, 40 | updatedAt = raw.updatedAt.asNullable(), 41 | mentions = raw.mentions.asNullable()?.let { Mentions.from(it) }, 42 | repliesTo = raw.replyMessageIds.asNullable()?.map { it }.orEmpty(), 43 | isPrivate = raw.isPrivate, 44 | isSilent = raw.isSilent, 45 | createdByWebhookId = raw.createdByWebhookId.asNullable() 46 | ) 47 | } 48 | } -------------------------------------------------------------------------------- /deck-core/src/main/kotlin/entity/impl/DeckServer.kt: -------------------------------------------------------------------------------- 1 | package io.github.srgaabriel.deck.core.entity.impl 2 | 3 | import io.github.srgaabriel.deck.common.entity.RawServer 4 | import io.github.srgaabriel.deck.common.entity.ServerType 5 | import io.github.srgaabriel.deck.common.util.GenericId 6 | import io.github.srgaabriel.deck.common.util.asNullable 7 | import io.github.srgaabriel.deck.core.DeckClient 8 | import io.github.srgaabriel.deck.core.entity.Server 9 | import kotlinx.datetime.Instant 10 | import java.util.* 11 | 12 | public data class DeckServer( 13 | override val client: DeckClient, 14 | override val id: GenericId, 15 | override val ownerId: GenericId, 16 | override val type: ServerType?, 17 | override val name: String, 18 | override val about: String?, 19 | override val avatar: String?, 20 | override val banner: String?, 21 | override val timezone: String?, 22 | override val defaultChannelId: UUID?, 23 | override val createdAt: Instant, 24 | ): Server { 25 | public companion object { 26 | public fun from(client: DeckClient, raw: RawServer): DeckServer = DeckServer( 27 | client = client, 28 | id = raw.id, 29 | ownerId = raw.ownerId, 30 | type = raw.type.asNullable(), 31 | name = raw.name, 32 | about = raw.about.asNullable(), 33 | avatar = raw.avatar.asNullable(), 34 | banner = raw.banner.asNullable(), 35 | timezone = raw.timezone.asNullable(), 36 | defaultChannelId = raw.defaultChannelId.asNullable(), 37 | createdAt = raw.createdAt 38 | ) 39 | } 40 | } -------------------------------------------------------------------------------- /deck-core/src/main/kotlin/entity/impl/DeckUser.kt: -------------------------------------------------------------------------------- 1 | package io.github.srgaabriel.deck.core.entity.impl 2 | 3 | import io.github.srgaabriel.deck.common.entity.RawUser 4 | import io.github.srgaabriel.deck.common.entity.UserType 5 | import io.github.srgaabriel.deck.common.util.GenericId 6 | import io.github.srgaabriel.deck.common.util.asNullable 7 | import io.github.srgaabriel.deck.core.DeckClient 8 | import io.github.srgaabriel.deck.core.entity.User 9 | import kotlinx.datetime.Instant 10 | 11 | public class DeckUser( 12 | override val client: DeckClient, 13 | override val id: GenericId, 14 | override val name: String, 15 | override val avatar: String?, 16 | override val banner: String?, 17 | override val isBot: Boolean, 18 | override val createdAt: Instant, 19 | ): User { 20 | public companion object { 21 | public fun from(client: DeckClient, raw: RawUser): DeckUser = DeckUser( 22 | client = client, 23 | id = raw.id, 24 | name = raw.name, 25 | avatar = raw.avatar.asNullable(), 26 | banner = raw.banner.asNullable(), 27 | isBot = raw.type == UserType.BOT, 28 | createdAt = raw.createdAt 29 | ) 30 | } 31 | } -------------------------------------------------------------------------------- /deck-core/src/main/kotlin/entity/impl/DeckWebhook.kt: -------------------------------------------------------------------------------- 1 | package io.github.srgaabriel.deck.core.entity.impl 2 | 3 | import io.github.srgaabriel.deck.common.entity.RawWebhook 4 | import io.github.srgaabriel.deck.common.util.GenericId 5 | import io.github.srgaabriel.deck.common.util.asNullable 6 | import io.github.srgaabriel.deck.core.DeckClient 7 | import io.github.srgaabriel.deck.core.entity.Webhook 8 | import kotlinx.datetime.Instant 9 | import java.util.* 10 | 11 | public data class DeckWebhook( 12 | override val client: DeckClient, 13 | override val id: UUID, 14 | override val serverId: GenericId, 15 | override val name: String, 16 | override val channelId: UUID, 17 | override val createdAt: Instant, 18 | override val deletedAt: Instant?, 19 | override val creatorId: GenericId, 20 | override val token: String? 21 | ) : Webhook { 22 | public companion object { 23 | public fun from(client: DeckClient, raw: RawWebhook): DeckWebhook = DeckWebhook( 24 | client = client, 25 | id = raw.id, 26 | serverId = raw.serverId, 27 | name = raw.name, 28 | channelId = raw.channelId, 29 | createdAt = raw.createdAt, 30 | deletedAt = raw.deletedAt.asNullable(), 31 | creatorId = raw.createdBy, 32 | token = raw.token.asNullable() 33 | ) 34 | } 35 | } -------------------------------------------------------------------------------- /deck-core/src/main/kotlin/event/calendar/CalendarEventCreate.kt: -------------------------------------------------------------------------------- 1 | package io.github.srgaabriel.deck.core.event.calendar 2 | 3 | import io.github.srgaabriel.deck.core.DeckClient 4 | import io.github.srgaabriel.deck.core.entity.CalendarEvent 5 | import io.github.srgaabriel.deck.core.entity.impl.DeckCalendarEvent 6 | import io.github.srgaabriel.deck.core.event.DeckEvent 7 | import io.github.srgaabriel.deck.core.event.EventMapper 8 | import io.github.srgaabriel.deck.core.event.EventService 9 | import io.github.srgaabriel.deck.core.event.mapper 10 | import io.github.srgaabriel.deck.core.stateless.StatelessServer 11 | import io.github.srgaabriel.deck.core.stateless.channel.StatelessCalendarChannel 12 | import io.github.srgaabriel.deck.gateway.event.GatewayEvent 13 | import io.github.srgaabriel.deck.gateway.event.type.GatewayCalendarEventCreatedEvent 14 | 15 | /** 16 | * Called when a [CalendarEvent] is created 17 | */ 18 | public data class CalendarEventCreateEvent( 19 | override val client: DeckClient, 20 | override val barebones: GatewayEvent, 21 | val calendarEvent: CalendarEvent, 22 | ): DeckEvent { 23 | val server: StatelessServer by lazy { calendarEvent.server } 24 | val channel: StatelessCalendarChannel by lazy { calendarEvent.channel } 25 | } 26 | 27 | internal val EventService.calendarEventCreate: EventMapper get() = mapper { client, event -> 28 | CalendarEventCreateEvent( 29 | client = client, 30 | barebones = event, 31 | calendarEvent = DeckCalendarEvent.from(client, event.calendarEvent) 32 | ) 33 | } -------------------------------------------------------------------------------- /deck-core/src/main/kotlin/event/calendar/CalendarEventDelete.kt: -------------------------------------------------------------------------------- 1 | package io.github.srgaabriel.deck.core.event.calendar 2 | 3 | import io.github.srgaabriel.deck.core.DeckClient 4 | import io.github.srgaabriel.deck.core.entity.CalendarEvent 5 | import io.github.srgaabriel.deck.core.entity.impl.DeckCalendarEvent 6 | import io.github.srgaabriel.deck.core.event.DeckEvent 7 | import io.github.srgaabriel.deck.core.event.EventMapper 8 | import io.github.srgaabriel.deck.core.event.EventService 9 | import io.github.srgaabriel.deck.core.event.mapper 10 | import io.github.srgaabriel.deck.core.stateless.StatelessServer 11 | import io.github.srgaabriel.deck.core.stateless.channel.StatelessCalendarChannel 12 | import io.github.srgaabriel.deck.gateway.event.GatewayEvent 13 | import io.github.srgaabriel.deck.gateway.event.type.GatewayCalendarEventDeletedEvent 14 | 15 | /** 16 | * Called when a [CalendarEvent] is deleted 17 | */ 18 | public data class CalendarEventDeleteEvent( 19 | override val client: DeckClient, 20 | override val barebones: GatewayEvent, 21 | val calendarEvent: CalendarEvent, 22 | ): DeckEvent { 23 | val server: StatelessServer by lazy { calendarEvent.server } 24 | val channel: StatelessCalendarChannel by lazy { calendarEvent.channel } 25 | } 26 | 27 | internal val EventService.calendarEventDelete: EventMapper get() = mapper { client, event -> 28 | CalendarEventDeleteEvent( 29 | client = client, 30 | barebones = event, 31 | calendarEvent = DeckCalendarEvent.from(client, event.calendarEvent) 32 | ) 33 | } -------------------------------------------------------------------------------- /deck-core/src/main/kotlin/event/calendar/CalendarEventRsvpBulkUpdate.kt: -------------------------------------------------------------------------------- 1 | package io.github.srgaabriel.deck.core.event.calendar 2 | 3 | import io.github.srgaabriel.deck.common.util.GenericId 4 | import io.github.srgaabriel.deck.core.DeckClient 5 | import io.github.srgaabriel.deck.core.entity.CalendarEvent 6 | import io.github.srgaabriel.deck.core.entity.CalendarEventRsvp 7 | import io.github.srgaabriel.deck.core.entity.impl.DeckCalendarEventRsvp 8 | import io.github.srgaabriel.deck.core.event.DeckEvent 9 | import io.github.srgaabriel.deck.core.event.EventMapper 10 | import io.github.srgaabriel.deck.core.event.EventService 11 | import io.github.srgaabriel.deck.core.event.mapper 12 | import io.github.srgaabriel.deck.core.stateless.StatelessServer 13 | import io.github.srgaabriel.deck.core.util.BlankStatelessServer 14 | import io.github.srgaabriel.deck.gateway.event.GatewayEvent 15 | import io.github.srgaabriel.deck.gateway.event.type.GatewayCalendarEventRsvpManyUpdatedEvent 16 | 17 | /** 18 | * Called when multiple RSVPs are updated/created at the same time in a single [CalendarEvent] 19 | */ 20 | public data class CalendarEventRsvpBulkUpdateEvent( 21 | override val client: DeckClient, 22 | override val barebones: GatewayEvent, 23 | val serverId: GenericId, 24 | val calendarEventRsvps: List, 25 | ): DeckEvent { 26 | val server: StatelessServer get() = BlankStatelessServer(client, serverId) 27 | } 28 | 29 | internal val EventService.calendarEventRsvpBulkUpdate: EventMapper 30 | get() = mapper { client, event -> 31 | CalendarEventRsvpBulkUpdateEvent( 32 | client = client, 33 | barebones = event, 34 | serverId = event.serverId, 35 | calendarEventRsvps = event.calendarEventRsvps.map { DeckCalendarEventRsvp.from(client, it) } 36 | ) 37 | } -------------------------------------------------------------------------------- /deck-core/src/main/kotlin/event/calendar/CalendarEventRsvpDelete.kt: -------------------------------------------------------------------------------- 1 | package io.github.srgaabriel.deck.core.event.calendar 2 | 3 | import io.github.srgaabriel.deck.core.DeckClient 4 | import io.github.srgaabriel.deck.core.entity.CalendarEventRsvp 5 | import io.github.srgaabriel.deck.core.entity.impl.DeckCalendarEventRsvp 6 | import io.github.srgaabriel.deck.core.event.DeckEvent 7 | import io.github.srgaabriel.deck.core.event.EventMapper 8 | import io.github.srgaabriel.deck.core.event.EventService 9 | import io.github.srgaabriel.deck.core.event.mapper 10 | import io.github.srgaabriel.deck.core.stateless.StatelessServer 11 | import io.github.srgaabriel.deck.core.stateless.channel.StatelessCalendarChannel 12 | import io.github.srgaabriel.deck.core.stateless.channel.content.StatelessCalendarEvent 13 | import io.github.srgaabriel.deck.gateway.event.GatewayEvent 14 | import io.github.srgaabriel.deck.gateway.event.type.GatewayCalendarEventRsvpDeletedEvent 15 | 16 | /** 17 | * Called when a [CalendarEventRsvp] RSVP is deleted 18 | */ 19 | public data class CalendarEventRsvpDeleteEvent( 20 | override val client: DeckClient, 21 | override val barebones: GatewayEvent, 22 | val calendarEventRsvp: CalendarEventRsvp, 23 | ): DeckEvent { 24 | val server: StatelessServer by lazy { calendarEventRsvp.server } 25 | val channel: StatelessCalendarChannel by lazy { calendarEventRsvp.channel } 26 | val calendarEvent: StatelessCalendarEvent by lazy { calendarEventRsvp.calendarEvent } 27 | } 28 | 29 | internal val EventService.calendarEventRsvpDelete: EventMapper 30 | get() = mapper { client, event -> 31 | CalendarEventRsvpDeleteEvent( 32 | client = client, 33 | barebones = event, 34 | calendarEventRsvp = DeckCalendarEventRsvp.from(client, event.calendarEventRsvp) 35 | ) 36 | } -------------------------------------------------------------------------------- /deck-core/src/main/kotlin/event/calendar/CalendarEventRsvpUpdate.kt: -------------------------------------------------------------------------------- 1 | package io.github.srgaabriel.deck.core.event.calendar 2 | 3 | import io.github.srgaabriel.deck.core.DeckClient 4 | import io.github.srgaabriel.deck.core.entity.CalendarEventRsvp 5 | import io.github.srgaabriel.deck.core.entity.impl.DeckCalendarEventRsvp 6 | import io.github.srgaabriel.deck.core.event.DeckEvent 7 | import io.github.srgaabriel.deck.core.event.EventMapper 8 | import io.github.srgaabriel.deck.core.event.EventService 9 | import io.github.srgaabriel.deck.core.event.mapper 10 | import io.github.srgaabriel.deck.core.stateless.StatelessServer 11 | import io.github.srgaabriel.deck.core.stateless.channel.StatelessCalendarChannel 12 | import io.github.srgaabriel.deck.core.stateless.channel.content.StatelessCalendarEvent 13 | import io.github.srgaabriel.deck.gateway.event.GatewayEvent 14 | import io.github.srgaabriel.deck.gateway.event.type.GatewayCalendarEventRsvpUpdatedEvent 15 | 16 | /** 17 | * Called when a single [CalendarEventRsvp] RSVP is updated 18 | * 19 | * @see CalendarEventRsvpBulkUpdateEvent 20 | */ 21 | public data class CalendarEventRsvpUpdateEvent( 22 | override val client: DeckClient, 23 | override val barebones: GatewayEvent, 24 | val calendarEventRsvp: CalendarEventRsvp, 25 | ): DeckEvent { 26 | val server: StatelessServer by lazy { calendarEventRsvp.server } 27 | val channel: StatelessCalendarChannel by lazy { calendarEventRsvp.channel } 28 | val calendarEvent: StatelessCalendarEvent by lazy { calendarEventRsvp.calendarEvent } 29 | } 30 | 31 | internal val EventService.calendarEventRsvpUpdate: EventMapper 32 | get() = mapper { client, event -> 33 | CalendarEventRsvpUpdateEvent( 34 | client = client, 35 | barebones = event, 36 | calendarEventRsvp = DeckCalendarEventRsvp.from(client, event.calendarEventRsvp) 37 | ) 38 | } -------------------------------------------------------------------------------- /deck-core/src/main/kotlin/event/calendar/CalendarEventUpdate.kt: -------------------------------------------------------------------------------- 1 | package io.github.srgaabriel.deck.core.event.calendar 2 | 3 | import io.github.srgaabriel.deck.core.DeckClient 4 | import io.github.srgaabriel.deck.core.entity.CalendarEvent 5 | import io.github.srgaabriel.deck.core.entity.impl.DeckCalendarEvent 6 | import io.github.srgaabriel.deck.core.event.DeckEvent 7 | import io.github.srgaabriel.deck.core.event.EventMapper 8 | import io.github.srgaabriel.deck.core.event.EventService 9 | import io.github.srgaabriel.deck.core.event.mapper 10 | import io.github.srgaabriel.deck.core.stateless.StatelessServer 11 | import io.github.srgaabriel.deck.core.stateless.channel.StatelessCalendarChannel 12 | import io.github.srgaabriel.deck.gateway.event.GatewayEvent 13 | import io.github.srgaabriel.deck.gateway.event.type.GatewayCalendarEventUpdatedEvent 14 | 15 | /** 16 | * Called when a [CalendarEvent] is updated 17 | */ 18 | public data class CalendarEventUpdateEvent( 19 | override val client: DeckClient, 20 | override val barebones: GatewayEvent, 21 | val calendarEvent: CalendarEvent, 22 | ): DeckEvent { 23 | val server: StatelessServer by lazy { calendarEvent.server } 24 | val channel: StatelessCalendarChannel by lazy { calendarEvent.channel } 25 | } 26 | 27 | internal val EventService.calendarEventUpdate: EventMapper get() = mapper { client, event -> 28 | CalendarEventUpdateEvent( 29 | client = client, 30 | barebones = event, 31 | calendarEvent = DeckCalendarEvent.from(client, event.calendarEvent) 32 | ) 33 | } -------------------------------------------------------------------------------- /deck-core/src/main/kotlin/event/channel/ServerChannelCreate.kt: -------------------------------------------------------------------------------- 1 | package io.github.srgaabriel.deck.core.event.channel 2 | 3 | import io.github.srgaabriel.deck.common.util.GenericId 4 | import io.github.srgaabriel.deck.core.DeckClient 5 | import io.github.srgaabriel.deck.core.entity.channel.ServerChannel 6 | import io.github.srgaabriel.deck.core.entity.impl.DeckServerChannel 7 | import io.github.srgaabriel.deck.core.event.DeckEvent 8 | import io.github.srgaabriel.deck.core.event.EventMapper 9 | import io.github.srgaabriel.deck.core.event.EventService 10 | import io.github.srgaabriel.deck.core.event.mapper 11 | import io.github.srgaabriel.deck.core.stateless.StatelessServer 12 | import io.github.srgaabriel.deck.core.util.BlankStatelessServer 13 | import io.github.srgaabriel.deck.gateway.event.GatewayEvent 14 | import io.github.srgaabriel.deck.gateway.event.type.GatewayServerChannelCreatedEvent 15 | 16 | /** 17 | * Called when a [ServerChannel] is created 18 | */ 19 | public data class ServerChannelCreateEvent( 20 | override val client: DeckClient, 21 | override val barebones: GatewayEvent, 22 | val serverId: GenericId, 23 | val channel: ServerChannel 24 | ): DeckEvent { 25 | public val server: StatelessServer by lazy { BlankStatelessServer(client, serverId) } 26 | } 27 | 28 | internal val EventService.serverChannelCreate: EventMapper get() = mapper { client, event -> 29 | ServerChannelCreateEvent( 30 | client = client, 31 | barebones = event, 32 | serverId = event.serverId, 33 | channel = DeckServerChannel.from(client, event.channel) 34 | ) 35 | } -------------------------------------------------------------------------------- /deck-core/src/main/kotlin/event/channel/ServerChannelDelete.kt: -------------------------------------------------------------------------------- 1 | package io.github.srgaabriel.deck.core.event.channel 2 | 3 | import io.github.srgaabriel.deck.common.util.GenericId 4 | import io.github.srgaabriel.deck.core.DeckClient 5 | import io.github.srgaabriel.deck.core.entity.channel.ServerChannel 6 | import io.github.srgaabriel.deck.core.entity.impl.DeckServerChannel 7 | import io.github.srgaabriel.deck.core.event.DeckEvent 8 | import io.github.srgaabriel.deck.core.event.EventMapper 9 | import io.github.srgaabriel.deck.core.event.EventService 10 | import io.github.srgaabriel.deck.core.event.mapper 11 | import io.github.srgaabriel.deck.core.stateless.StatelessServer 12 | import io.github.srgaabriel.deck.core.util.BlankStatelessServer 13 | import io.github.srgaabriel.deck.gateway.event.GatewayEvent 14 | import io.github.srgaabriel.deck.gateway.event.type.GatewayServerChannelDeletedEvent 15 | 16 | /** 17 | * Called when a [ServerChannel] is deleted 18 | */ 19 | public data class ServerChannelDeleteEvent( 20 | override val client: DeckClient, 21 | override val barebones: GatewayEvent, 22 | val serverId: GenericId, 23 | val channel: ServerChannel 24 | ): DeckEvent { 25 | public val server: StatelessServer by lazy { BlankStatelessServer(client, serverId) } 26 | } 27 | 28 | internal val EventService.serverChannelDelete: EventMapper get() = mapper { client, event -> 29 | ServerChannelDeleteEvent( 30 | client = client, 31 | barebones = event, 32 | serverId = event.serverId, 33 | channel = DeckServerChannel.from(client, event.channel) 34 | ) 35 | } -------------------------------------------------------------------------------- /deck-core/src/main/kotlin/event/channel/ServerChannelUpdate.kt: -------------------------------------------------------------------------------- 1 | package io.github.srgaabriel.deck.core.event.channel 2 | 3 | import io.github.srgaabriel.deck.common.util.GenericId 4 | import io.github.srgaabriel.deck.core.DeckClient 5 | import io.github.srgaabriel.deck.core.entity.channel.ServerChannel 6 | import io.github.srgaabriel.deck.core.entity.impl.DeckServerChannel 7 | import io.github.srgaabriel.deck.core.event.DeckEvent 8 | import io.github.srgaabriel.deck.core.event.EventMapper 9 | import io.github.srgaabriel.deck.core.event.EventService 10 | import io.github.srgaabriel.deck.core.event.mapper 11 | import io.github.srgaabriel.deck.core.stateless.StatelessServer 12 | import io.github.srgaabriel.deck.core.util.BlankStatelessServer 13 | import io.github.srgaabriel.deck.gateway.event.GatewayEvent 14 | import io.github.srgaabriel.deck.gateway.event.type.GatewayServerChannelUpdatedEvent 15 | 16 | /** 17 | * Called when a [ServerChannel] is edited 18 | */ 19 | public data class ServerChannelUpdateEvent( 20 | override val client: DeckClient, 21 | override val barebones: GatewayEvent, 22 | val serverId: GenericId, 23 | val channel: ServerChannel 24 | ): DeckEvent { 25 | public val server: StatelessServer by lazy { BlankStatelessServer(client, serverId) } 26 | } 27 | 28 | internal val EventService.serverChannelUpdate: EventMapper get() = mapper { client, event -> 29 | ServerChannelUpdateEvent( 30 | client = client, 31 | barebones = event, 32 | serverId = event.serverId, 33 | channel = DeckServerChannel.from(client, event.channel) 34 | ) 35 | } -------------------------------------------------------------------------------- /deck-core/src/main/kotlin/event/documentation/DocumentationCreate.kt: -------------------------------------------------------------------------------- 1 | package io.github.srgaabriel.deck.core.event.documentation 2 | 3 | import io.github.srgaabriel.deck.core.DeckClient 4 | import io.github.srgaabriel.deck.core.entity.Documentation 5 | import io.github.srgaabriel.deck.core.entity.impl.DeckDocumentation 6 | import io.github.srgaabriel.deck.core.event.DeckEvent 7 | import io.github.srgaabriel.deck.core.event.EventMapper 8 | import io.github.srgaabriel.deck.core.event.EventService 9 | import io.github.srgaabriel.deck.core.event.mapper 10 | import io.github.srgaabriel.deck.core.stateless.StatelessServer 11 | import io.github.srgaabriel.deck.core.stateless.channel.StatelessDocumentationChannel 12 | import io.github.srgaabriel.deck.gateway.event.GatewayEvent 13 | import io.github.srgaabriel.deck.gateway.event.type.GatewayDocumentationCreatedEvent 14 | 15 | /** 16 | * Called when a [Documentation] is created in a server channel 17 | */ 18 | public data class DocumentationCreateEvent( 19 | override val client: DeckClient, 20 | override val barebones: GatewayEvent, 21 | val documentation: Documentation 22 | ): DeckEvent { 23 | val server: StatelessServer by lazy { documentation.server } 24 | val channel: StatelessDocumentationChannel by lazy { documentation.channel } 25 | } 26 | 27 | internal val EventService.documentationCreate: EventMapper 28 | get() = mapper { client, event -> 29 | DocumentationCreateEvent( 30 | client = client, 31 | barebones = event, 32 | documentation = DeckDocumentation.from(client, event.documentation) 33 | ) 34 | } -------------------------------------------------------------------------------- /deck-core/src/main/kotlin/event/documentation/DocumentationDelete.kt: -------------------------------------------------------------------------------- 1 | package io.github.srgaabriel.deck.core.event.documentation 2 | 3 | import io.github.srgaabriel.deck.core.DeckClient 4 | import io.github.srgaabriel.deck.core.entity.Documentation 5 | import io.github.srgaabriel.deck.core.entity.impl.DeckDocumentation 6 | import io.github.srgaabriel.deck.core.event.DeckEvent 7 | import io.github.srgaabriel.deck.core.event.EventMapper 8 | import io.github.srgaabriel.deck.core.event.EventService 9 | import io.github.srgaabriel.deck.core.event.mapper 10 | import io.github.srgaabriel.deck.core.stateless.StatelessServer 11 | import io.github.srgaabriel.deck.core.stateless.channel.StatelessDocumentationChannel 12 | import io.github.srgaabriel.deck.gateway.event.GatewayEvent 13 | import io.github.srgaabriel.deck.gateway.event.type.GatewayDocumentationDeletedEvent 14 | 15 | /** 16 | * Called when a [Documentation] is deleted in a server channel 17 | */ 18 | public data class DocumentationDeleteEvent( 19 | override val client: DeckClient, 20 | override val barebones: GatewayEvent, 21 | val documentation: Documentation 22 | ): DeckEvent { 23 | val server: StatelessServer by lazy { documentation.server } 24 | val channel: StatelessDocumentationChannel by lazy { documentation.channel } 25 | } 26 | 27 | internal val EventService.documentationDelete: EventMapper 28 | get() = mapper { client, event -> 29 | DocumentationDeleteEvent( 30 | client = client, 31 | barebones = event, 32 | documentation = DeckDocumentation.from(client, event.documentation) 33 | ) 34 | } -------------------------------------------------------------------------------- /deck-core/src/main/kotlin/event/documentation/DocumentationUpdate.kt: -------------------------------------------------------------------------------- 1 | package io.github.srgaabriel.deck.core.event.documentation 2 | 3 | import io.github.srgaabriel.deck.core.DeckClient 4 | import io.github.srgaabriel.deck.core.entity.Documentation 5 | import io.github.srgaabriel.deck.core.entity.impl.DeckDocumentation 6 | import io.github.srgaabriel.deck.core.event.DeckEvent 7 | import io.github.srgaabriel.deck.core.event.EventMapper 8 | import io.github.srgaabriel.deck.core.event.EventService 9 | import io.github.srgaabriel.deck.core.event.mapper 10 | import io.github.srgaabriel.deck.core.stateless.StatelessServer 11 | import io.github.srgaabriel.deck.core.stateless.channel.StatelessDocumentationChannel 12 | import io.github.srgaabriel.deck.gateway.event.GatewayEvent 13 | import io.github.srgaabriel.deck.gateway.event.type.GatewayDocumentationUpdatedEvent 14 | 15 | /** 16 | * Called when a [Documentation] is edited in a server channel 17 | */ 18 | public data class DocumentationUpdateEvent( 19 | override val client: DeckClient, 20 | override val barebones: GatewayEvent, 21 | val documentation: Documentation 22 | ): DeckEvent { 23 | val server: StatelessServer by lazy { documentation.server } 24 | val channel: StatelessDocumentationChannel by lazy { documentation.channel } 25 | } 26 | 27 | internal val EventService.documentationUpdate: EventMapper 28 | get() = mapper { client, event -> 29 | DocumentationUpdateEvent( 30 | client = client, 31 | barebones = event, 32 | documentation = DeckDocumentation.from(client, event.documentation) 33 | ) 34 | } -------------------------------------------------------------------------------- /deck-core/src/main/kotlin/event/forum/ForumTopicCommentCreate.kt: -------------------------------------------------------------------------------- 1 | package io.github.srgaabriel.deck.core.event.forum 2 | 3 | import io.github.srgaabriel.deck.core.DeckClient 4 | import io.github.srgaabriel.deck.core.entity.ForumTopicComment 5 | import io.github.srgaabriel.deck.core.entity.impl.DeckForumTopicComment 6 | import io.github.srgaabriel.deck.core.event.DeckEvent 7 | import io.github.srgaabriel.deck.core.event.EventMapper 8 | import io.github.srgaabriel.deck.core.event.EventService 9 | import io.github.srgaabriel.deck.core.event.mapper 10 | import io.github.srgaabriel.deck.core.stateless.StatelessServer 11 | import io.github.srgaabriel.deck.core.stateless.channel.StatelessForumChannel 12 | import io.github.srgaabriel.deck.core.stateless.channel.content.StatelessForumTopic 13 | import io.github.srgaabriel.deck.gateway.event.GatewayEvent 14 | import io.github.srgaabriel.deck.gateway.event.type.GatewayForumTopicCommentCreatedEvent 15 | 16 | /** 17 | * Called when a new [ForumTopicComment] is posted 18 | */ 19 | public data class ForumTopicCommentCreateEvent( 20 | override val client: DeckClient, 21 | override val barebones: GatewayEvent, 22 | val forumTopicComment: ForumTopicComment 23 | ): DeckEvent { 24 | public val server: StatelessServer by lazy { forumTopicComment.server } 25 | public val channel: StatelessForumChannel by lazy { forumTopicComment.channel } 26 | public val topic: StatelessForumTopic by lazy { forumTopicComment.forumTopic } 27 | } 28 | 29 | internal val EventService.forumTopicCommentCreate: EventMapper 30 | get() = mapper { client, event -> 31 | ForumTopicCommentCreateEvent( 32 | client = client, 33 | barebones = event, 34 | forumTopicComment = DeckForumTopicComment.from(client, event.serverId, event.forumTopicComment) 35 | ) 36 | } -------------------------------------------------------------------------------- /deck-core/src/main/kotlin/event/forum/ForumTopicCommentDelete.kt: -------------------------------------------------------------------------------- 1 | package io.github.srgaabriel.deck.core.event.forum 2 | 3 | import io.github.srgaabriel.deck.core.DeckClient 4 | import io.github.srgaabriel.deck.core.entity.ForumTopicComment 5 | import io.github.srgaabriel.deck.core.entity.impl.DeckForumTopicComment 6 | import io.github.srgaabriel.deck.core.event.DeckEvent 7 | import io.github.srgaabriel.deck.core.event.EventMapper 8 | import io.github.srgaabriel.deck.core.event.EventService 9 | import io.github.srgaabriel.deck.core.event.mapper 10 | import io.github.srgaabriel.deck.core.stateless.StatelessServer 11 | import io.github.srgaabriel.deck.core.stateless.channel.StatelessForumChannel 12 | import io.github.srgaabriel.deck.core.stateless.channel.content.StatelessForumTopic 13 | import io.github.srgaabriel.deck.gateway.event.GatewayEvent 14 | import io.github.srgaabriel.deck.gateway.event.type.GatewayForumTopicCommentDeletedEvent 15 | 16 | /** 17 | * Called when a new [ForumTopicComment] is posted 18 | */ 19 | public data class ForumTopicCommentDeleteEvent( 20 | override val client: DeckClient, 21 | override val barebones: GatewayEvent, 22 | val forumTopicComment: ForumTopicComment 23 | ): DeckEvent { 24 | public val server: StatelessServer by lazy { forumTopicComment.server } 25 | public val channel: StatelessForumChannel by lazy { forumTopicComment.channel } 26 | public val topic: StatelessForumTopic by lazy { forumTopicComment.forumTopic } 27 | } 28 | 29 | internal val EventService.forumTopicCommentDelete: EventMapper 30 | get() = mapper { client, event -> 31 | ForumTopicCommentDeleteEvent( 32 | client = client, 33 | barebones = event, 34 | forumTopicComment = DeckForumTopicComment.from(client, event.serverId, event.forumTopicComment) 35 | ) 36 | } -------------------------------------------------------------------------------- /deck-core/src/main/kotlin/event/forum/ForumTopicCommentUpdate.kt: -------------------------------------------------------------------------------- 1 | package io.github.srgaabriel.deck.core.event.forum 2 | 3 | import io.github.srgaabriel.deck.core.DeckClient 4 | import io.github.srgaabriel.deck.core.entity.ForumTopicComment 5 | import io.github.srgaabriel.deck.core.entity.impl.DeckForumTopicComment 6 | import io.github.srgaabriel.deck.core.event.DeckEvent 7 | import io.github.srgaabriel.deck.core.event.EventMapper 8 | import io.github.srgaabriel.deck.core.event.EventService 9 | import io.github.srgaabriel.deck.core.event.mapper 10 | import io.github.srgaabriel.deck.core.stateless.StatelessServer 11 | import io.github.srgaabriel.deck.core.stateless.channel.StatelessForumChannel 12 | import io.github.srgaabriel.deck.core.stateless.channel.content.StatelessForumTopic 13 | import io.github.srgaabriel.deck.gateway.event.GatewayEvent 14 | import io.github.srgaabriel.deck.gateway.event.type.GatewayForumTopicCommentUpdatedEvent 15 | 16 | /** 17 | * Called when a new [ForumTopicComment] is posted 18 | */ 19 | public data class ForumTopicCommentUpdateEvent( 20 | override val client: DeckClient, 21 | override val barebones: GatewayEvent, 22 | val forumTopicComment: ForumTopicComment 23 | ): DeckEvent { 24 | public val server: StatelessServer by lazy { forumTopicComment.server } 25 | public val channel: StatelessForumChannel by lazy { forumTopicComment.channel } 26 | public val topic: StatelessForumTopic by lazy { forumTopicComment.forumTopic } 27 | } 28 | 29 | internal val EventService.forumTopicCommentUpdate: EventMapper 30 | get() = mapper { client, event -> 31 | ForumTopicCommentUpdateEvent( 32 | client = client, 33 | barebones = event, 34 | forumTopicComment = DeckForumTopicComment.from(client, event.serverId, event.forumTopicComment) 35 | ) 36 | } -------------------------------------------------------------------------------- /deck-core/src/main/kotlin/event/forum/ForumTopicCreate.kt: -------------------------------------------------------------------------------- 1 | package io.github.srgaabriel.deck.core.event.forum 2 | 3 | import io.github.srgaabriel.deck.core.DeckClient 4 | import io.github.srgaabriel.deck.core.entity.ForumTopic 5 | import io.github.srgaabriel.deck.core.entity.impl.DeckForumTopic 6 | import io.github.srgaabriel.deck.core.event.DeckEvent 7 | import io.github.srgaabriel.deck.core.event.EventMapper 8 | import io.github.srgaabriel.deck.core.event.EventService 9 | import io.github.srgaabriel.deck.core.event.mapper 10 | import io.github.srgaabriel.deck.core.stateless.StatelessServer 11 | import io.github.srgaabriel.deck.core.stateless.channel.StatelessForumChannel 12 | import io.github.srgaabriel.deck.gateway.event.GatewayEvent 13 | import io.github.srgaabriel.deck.gateway.event.type.GatewayForumTopicCreatedEvent 14 | 15 | /** 16 | * Called when a new [ForumTopic] is created 17 | */ 18 | public data class ForumTopicCreateEvent( 19 | override val client: DeckClient, 20 | override val barebones: GatewayEvent, 21 | val forumTopic: ForumTopic 22 | ): DeckEvent { 23 | public val server: StatelessServer by lazy { forumTopic.server } 24 | public val channel: StatelessForumChannel by lazy { forumTopic.channel } 25 | } 26 | 27 | internal val EventService.forumTopicCreate: EventMapper 28 | get() = mapper { client, event -> 29 | ForumTopicCreateEvent( 30 | client = client, 31 | barebones = event, 32 | forumTopic = DeckForumTopic.from(client, event.forumTopic) 33 | ) 34 | } -------------------------------------------------------------------------------- /deck-core/src/main/kotlin/event/forum/ForumTopicDelete.kt: -------------------------------------------------------------------------------- 1 | package io.github.srgaabriel.deck.core.event.forum 2 | 3 | import io.github.srgaabriel.deck.core.DeckClient 4 | import io.github.srgaabriel.deck.core.entity.ForumTopic 5 | import io.github.srgaabriel.deck.core.entity.impl.DeckForumTopic 6 | import io.github.srgaabriel.deck.core.event.DeckEvent 7 | import io.github.srgaabriel.deck.core.event.EventMapper 8 | import io.github.srgaabriel.deck.core.event.EventService 9 | import io.github.srgaabriel.deck.core.event.mapper 10 | import io.github.srgaabriel.deck.core.stateless.StatelessServer 11 | import io.github.srgaabriel.deck.core.stateless.channel.StatelessForumChannel 12 | import io.github.srgaabriel.deck.gateway.event.GatewayEvent 13 | import io.github.srgaabriel.deck.gateway.event.type.GatewayForumTopicDeletedEvent 14 | 15 | /** 16 | * Called when a new [ForumTopic] is deleted 17 | */ 18 | public data class ForumTopicDeleteEvent( 19 | override val client: DeckClient, 20 | override val barebones: GatewayEvent, 21 | val forumTopic: ForumTopic 22 | ): DeckEvent { 23 | public val server: StatelessServer by lazy { forumTopic.server } 24 | public val channel: StatelessForumChannel by lazy { forumTopic.channel } 25 | } 26 | 27 | internal val EventService.forumTopicDelete: EventMapper 28 | get() = mapper { client, event -> 29 | ForumTopicDeleteEvent( 30 | client = client, 31 | barebones = event, 32 | forumTopic = DeckForumTopic.from(client, event.forumTopic) 33 | ) 34 | } -------------------------------------------------------------------------------- /deck-core/src/main/kotlin/event/forum/ForumTopicLocked.kt: -------------------------------------------------------------------------------- 1 | package io.github.srgaabriel.deck.core.event.forum 2 | 3 | import io.github.srgaabriel.deck.core.DeckClient 4 | import io.github.srgaabriel.deck.core.entity.ForumTopic 5 | import io.github.srgaabriel.deck.core.entity.impl.DeckForumTopic 6 | import io.github.srgaabriel.deck.core.event.DeckEvent 7 | import io.github.srgaabriel.deck.core.event.EventMapper 8 | import io.github.srgaabriel.deck.core.event.EventService 9 | import io.github.srgaabriel.deck.core.event.mapper 10 | import io.github.srgaabriel.deck.core.stateless.StatelessServer 11 | import io.github.srgaabriel.deck.core.stateless.channel.StatelessForumChannel 12 | import io.github.srgaabriel.deck.gateway.event.GatewayEvent 13 | import io.github.srgaabriel.deck.gateway.event.type.GatewayForumTopicLockedEvent 14 | 15 | /** 16 | * Called when a new [ForumTopic] is locked 17 | */ 18 | public data class ForumTopicLockedEvent( 19 | override val client: DeckClient, 20 | override val barebones: GatewayEvent, 21 | val forumTopic: ForumTopic 22 | ): DeckEvent { 23 | public val server: StatelessServer by lazy { forumTopic.server } 24 | public val channel: StatelessForumChannel by lazy { forumTopic.channel } 25 | } 26 | 27 | internal val EventService.forumTopicLocked: EventMapper 28 | get() = mapper { client, event -> 29 | ForumTopicLockedEvent( 30 | client = client, 31 | barebones = event, 32 | forumTopic = DeckForumTopic.from(client, event.forumTopic) 33 | ) 34 | } -------------------------------------------------------------------------------- /deck-core/src/main/kotlin/event/forum/ForumTopicPin.kt: -------------------------------------------------------------------------------- 1 | package io.github.srgaabriel.deck.core.event.forum 2 | 3 | import io.github.srgaabriel.deck.core.DeckClient 4 | import io.github.srgaabriel.deck.core.entity.ForumTopic 5 | import io.github.srgaabriel.deck.core.entity.impl.DeckForumTopic 6 | import io.github.srgaabriel.deck.core.event.DeckEvent 7 | import io.github.srgaabriel.deck.core.event.EventMapper 8 | import io.github.srgaabriel.deck.core.event.EventService 9 | import io.github.srgaabriel.deck.core.event.mapper 10 | import io.github.srgaabriel.deck.core.stateless.StatelessServer 11 | import io.github.srgaabriel.deck.core.stateless.channel.StatelessForumChannel 12 | import io.github.srgaabriel.deck.gateway.event.GatewayEvent 13 | import io.github.srgaabriel.deck.gateway.event.type.GatewayForumTopicPinnedEvent 14 | 15 | /** 16 | * Called when a new [ForumTopic] is pinned 17 | */ 18 | public data class ForumTopicPinEvent( 19 | override val client: DeckClient, 20 | override val barebones: GatewayEvent, 21 | val forumTopic: ForumTopic 22 | ): DeckEvent { 23 | public val server: StatelessServer by lazy { forumTopic.server } 24 | public val channel: StatelessForumChannel by lazy { forumTopic.channel } 25 | } 26 | 27 | internal val EventService.forumTopicPin: EventMapper 28 | get() = mapper { client, event -> 29 | ForumTopicPinEvent( 30 | client = client, 31 | barebones = event, 32 | forumTopic = DeckForumTopic.from(client, event.forumTopic) 33 | ) 34 | } -------------------------------------------------------------------------------- /deck-core/src/main/kotlin/event/forum/ForumTopicReactionAdd.kt: -------------------------------------------------------------------------------- 1 | package io.github.srgaabriel.deck.core.event.forum 2 | 3 | import io.github.srgaabriel.deck.common.util.Emote 4 | import io.github.srgaabriel.deck.common.util.GenericId 5 | import io.github.srgaabriel.deck.common.util.IntGenericId 6 | import io.github.srgaabriel.deck.common.util.getValue 7 | import io.github.srgaabriel.deck.core.DeckClient 8 | import io.github.srgaabriel.deck.core.entity.ForumTopic 9 | import io.github.srgaabriel.deck.core.event.DeckEvent 10 | import io.github.srgaabriel.deck.core.event.EventMapper 11 | import io.github.srgaabriel.deck.core.event.EventService 12 | import io.github.srgaabriel.deck.core.event.mapper 13 | import io.github.srgaabriel.deck.core.stateless.StatelessServer 14 | import io.github.srgaabriel.deck.core.stateless.StatelessUser 15 | import io.github.srgaabriel.deck.core.stateless.channel.StatelessMessageChannel 16 | import io.github.srgaabriel.deck.core.stateless.channel.content.StatelessForumTopic 17 | import io.github.srgaabriel.deck.core.util.BlankStatelessForumTopic 18 | import io.github.srgaabriel.deck.core.util.BlankStatelessMessageChannel 19 | import io.github.srgaabriel.deck.core.util.BlankStatelessServer 20 | import io.github.srgaabriel.deck.core.util.BlankStatelessUser 21 | import io.github.srgaabriel.deck.gateway.event.GatewayEvent 22 | import io.github.srgaabriel.deck.gateway.event.type.GatewayForumTopicReactionCreatedEvent 23 | import java.util.* 24 | 25 | /** 26 | * Called when someone reacts to a [ForumTopic] 27 | * (not only when a new reaction emote is added to a message) 28 | */ 29 | public data class ForumTopicReactionAddEvent( 30 | override val client: DeckClient, 31 | override val barebones: GatewayEvent, 32 | val serverId: GenericId, 33 | val channelId: UUID, 34 | val forumTopicId: IntGenericId, 35 | val userId: GenericId, 36 | val emote: Emote 37 | ): DeckEvent { 38 | val server: StatelessServer? by lazy { BlankStatelessServer(client, serverId) } 39 | val channel: StatelessMessageChannel by lazy { BlankStatelessMessageChannel(client, channelId, serverId) } 40 | val forumTopic: StatelessForumTopic by lazy { BlankStatelessForumTopic(client, forumTopicId, channelId, serverId) } 41 | val user: StatelessUser by lazy { BlankStatelessUser(client, userId) } 42 | } 43 | 44 | internal val EventService.forumTopicReactionAdd: EventMapper get() = mapper { client, event -> 45 | ForumTopicReactionAddEvent( 46 | client = client, 47 | barebones = event, 48 | serverId = event.serverId.getValue(), 49 | channelId = event.reaction.channelId, 50 | forumTopicId = event.reaction.forumTopicId, 51 | userId = event.reaction.createdBy, 52 | emote = Emote.from(event.reaction.emote) 53 | ) 54 | } -------------------------------------------------------------------------------- /deck-core/src/main/kotlin/event/forum/ForumTopicReactionRemove.kt: -------------------------------------------------------------------------------- 1 | package io.github.srgaabriel.deck.core.event.forum 2 | 3 | import io.github.srgaabriel.deck.common.util.Emote 4 | import io.github.srgaabriel.deck.common.util.GenericId 5 | import io.github.srgaabriel.deck.common.util.IntGenericId 6 | import io.github.srgaabriel.deck.common.util.getValue 7 | import io.github.srgaabriel.deck.core.DeckClient 8 | import io.github.srgaabriel.deck.core.entity.ForumTopic 9 | import io.github.srgaabriel.deck.core.event.DeckEvent 10 | import io.github.srgaabriel.deck.core.event.EventMapper 11 | import io.github.srgaabriel.deck.core.event.EventService 12 | import io.github.srgaabriel.deck.core.event.mapper 13 | import io.github.srgaabriel.deck.core.stateless.StatelessServer 14 | import io.github.srgaabriel.deck.core.stateless.StatelessUser 15 | import io.github.srgaabriel.deck.core.stateless.channel.StatelessMessageChannel 16 | import io.github.srgaabriel.deck.core.stateless.channel.content.StatelessForumTopic 17 | import io.github.srgaabriel.deck.core.util.BlankStatelessForumTopic 18 | import io.github.srgaabriel.deck.core.util.BlankStatelessMessageChannel 19 | import io.github.srgaabriel.deck.core.util.BlankStatelessServer 20 | import io.github.srgaabriel.deck.core.util.BlankStatelessUser 21 | import io.github.srgaabriel.deck.gateway.event.GatewayEvent 22 | import io.github.srgaabriel.deck.gateway.event.type.GatewayForumTopicReactionDeletedEvent 23 | import java.util.* 24 | 25 | /** 26 | * Called when someone removes a reaction from a [ForumTopic] 27 | * (not only when a reaction emote is removed completely from a topic) 28 | */ 29 | public data class ForumTopicReactionRemoveEvent( 30 | override val client: DeckClient, 31 | override val barebones: GatewayEvent, 32 | val serverId: GenericId, 33 | val channelId: UUID, 34 | val forumTopicId: IntGenericId, 35 | val userId: GenericId, 36 | val emote: Emote 37 | ): DeckEvent { 38 | val server: StatelessServer? by lazy { BlankStatelessServer(client, serverId) } 39 | val channel: StatelessMessageChannel by lazy { BlankStatelessMessageChannel(client, channelId, serverId) } 40 | val forumTopic: StatelessForumTopic by lazy { BlankStatelessForumTopic(client, forumTopicId, channelId, serverId) } 41 | val user: StatelessUser by lazy { BlankStatelessUser(client, userId) } 42 | } 43 | 44 | internal val EventService.forumTopicReactionRemove: EventMapper get() = mapper { client, event -> 45 | ForumTopicReactionRemoveEvent( 46 | client = client, 47 | barebones = event, 48 | serverId = event.serverId.getValue(), 49 | channelId = event.reaction.channelId, 50 | forumTopicId = event.reaction.forumTopicId, 51 | userId = event.reaction.createdBy, 52 | emote = Emote.from(event.reaction.emote) 53 | ) 54 | } -------------------------------------------------------------------------------- /deck-core/src/main/kotlin/event/forum/ForumTopicUnlocked.kt: -------------------------------------------------------------------------------- 1 | package io.github.srgaabriel.deck.core.event.forum 2 | 3 | import io.github.srgaabriel.deck.core.DeckClient 4 | import io.github.srgaabriel.deck.core.entity.ForumTopic 5 | import io.github.srgaabriel.deck.core.entity.impl.DeckForumTopic 6 | import io.github.srgaabriel.deck.core.event.DeckEvent 7 | import io.github.srgaabriel.deck.core.event.EventMapper 8 | import io.github.srgaabriel.deck.core.event.EventService 9 | import io.github.srgaabriel.deck.core.event.mapper 10 | import io.github.srgaabriel.deck.core.stateless.StatelessServer 11 | import io.github.srgaabriel.deck.core.stateless.channel.StatelessForumChannel 12 | import io.github.srgaabriel.deck.gateway.event.GatewayEvent 13 | import io.github.srgaabriel.deck.gateway.event.type.GatewayForumTopicUnlockedEvent 14 | 15 | /** 16 | * Called when a new [ForumTopic] is unlocked 17 | */ 18 | public data class ForumTopicUnlockedEvent( 19 | override val client: DeckClient, 20 | override val barebones: GatewayEvent, 21 | val forumTopic: ForumTopic 22 | ): DeckEvent { 23 | public val server: StatelessServer by lazy { forumTopic.server } 24 | public val channel: StatelessForumChannel by lazy { forumTopic.channel } 25 | } 26 | 27 | internal val EventService.forumTopicUnlocked: EventMapper 28 | get() = mapper { client, event -> 29 | ForumTopicUnlockedEvent( 30 | client = client, 31 | barebones = event, 32 | forumTopic = DeckForumTopic.from(client, event.forumTopic) 33 | ) 34 | } -------------------------------------------------------------------------------- /deck-core/src/main/kotlin/event/forum/ForumTopicUnpin.kt: -------------------------------------------------------------------------------- 1 | package io.github.srgaabriel.deck.core.event.forum 2 | 3 | import io.github.srgaabriel.deck.core.DeckClient 4 | import io.github.srgaabriel.deck.core.entity.ForumTopic 5 | import io.github.srgaabriel.deck.core.entity.impl.DeckForumTopic 6 | import io.github.srgaabriel.deck.core.event.DeckEvent 7 | import io.github.srgaabriel.deck.core.event.EventMapper 8 | import io.github.srgaabriel.deck.core.event.EventService 9 | import io.github.srgaabriel.deck.core.event.mapper 10 | import io.github.srgaabriel.deck.core.stateless.StatelessServer 11 | import io.github.srgaabriel.deck.core.stateless.channel.StatelessForumChannel 12 | import io.github.srgaabriel.deck.gateway.event.GatewayEvent 13 | import io.github.srgaabriel.deck.gateway.event.type.GatewayForumTopicUnpinnedEvent 14 | 15 | /** 16 | * Called when a new [ForumTopic] is unpinned 17 | */ 18 | public data class ForumTopicUnpinEvent( 19 | override val client: DeckClient, 20 | override val barebones: GatewayEvent, 21 | val forumTopic: ForumTopic 22 | ): DeckEvent { 23 | public val server: StatelessServer by lazy { forumTopic.server } 24 | public val channel: StatelessForumChannel by lazy { forumTopic.channel } 25 | } 26 | 27 | internal val EventService.forumTopicUnpin: EventMapper 28 | get() = mapper { client, event -> 29 | ForumTopicUnpinEvent( 30 | client = client, 31 | barebones = event, 32 | forumTopic = DeckForumTopic.from(client, event.forumTopic) 33 | ) 34 | } -------------------------------------------------------------------------------- /deck-core/src/main/kotlin/event/forum/ForumTopicUpdate.kt: -------------------------------------------------------------------------------- 1 | package io.github.srgaabriel.deck.core.event.forum 2 | 3 | import io.github.srgaabriel.deck.core.DeckClient 4 | import io.github.srgaabriel.deck.core.entity.ForumTopic 5 | import io.github.srgaabriel.deck.core.entity.impl.DeckForumTopic 6 | import io.github.srgaabriel.deck.core.event.DeckEvent 7 | import io.github.srgaabriel.deck.core.event.EventMapper 8 | import io.github.srgaabriel.deck.core.event.EventService 9 | import io.github.srgaabriel.deck.core.event.mapper 10 | import io.github.srgaabriel.deck.core.stateless.StatelessServer 11 | import io.github.srgaabriel.deck.core.stateless.channel.StatelessForumChannel 12 | import io.github.srgaabriel.deck.gateway.event.GatewayEvent 13 | import io.github.srgaabriel.deck.gateway.event.type.GatewayForumTopicUpdatedEvent 14 | 15 | /** 16 | * Called when a new [ForumTopic] is updated 17 | */ 18 | public data class ForumTopicUpdateEvent( 19 | override val client: DeckClient, 20 | override val barebones: GatewayEvent, 21 | val forumTopic: ForumTopic 22 | ): DeckEvent { 23 | public val server: StatelessServer by lazy { forumTopic.server } 24 | public val channel: StatelessForumChannel by lazy { forumTopic.channel } 25 | } 26 | 27 | internal val EventService.forumTopicUpdate: EventMapper 28 | get() = mapper { client, event -> 29 | ForumTopicUpdateEvent( 30 | client = client, 31 | barebones = event, 32 | forumTopic = DeckForumTopic.from(client, event.forumTopic) 33 | ) 34 | } -------------------------------------------------------------------------------- /deck-core/src/main/kotlin/event/list/ListItemComplete.kt: -------------------------------------------------------------------------------- 1 | package io.github.srgaabriel.deck.core.event.list 2 | 3 | import io.github.srgaabriel.deck.core.DeckClient 4 | import io.github.srgaabriel.deck.core.entity.ListItem 5 | import io.github.srgaabriel.deck.core.entity.impl.DeckListItem 6 | import io.github.srgaabriel.deck.core.event.DeckEvent 7 | import io.github.srgaabriel.deck.core.event.EventMapper 8 | import io.github.srgaabriel.deck.core.event.EventService 9 | import io.github.srgaabriel.deck.core.event.mapper 10 | import io.github.srgaabriel.deck.core.stateless.StatelessServer 11 | import io.github.srgaabriel.deck.core.stateless.channel.StatelessListChannel 12 | import io.github.srgaabriel.deck.gateway.event.GatewayEvent 13 | import io.github.srgaabriel.deck.gateway.event.type.GatewayListItemCompletedEvent 14 | 15 | /** 16 | * Called when a [ListItem] is marked as "complete" 17 | */ 18 | public data class ListItemCompleteEvent( 19 | override val client: DeckClient, 20 | override val barebones: GatewayEvent, 21 | val listItem: ListItem 22 | ): DeckEvent { 23 | val server: StatelessServer by lazy { listItem.server } 24 | val channel: StatelessListChannel by lazy { listItem.channel } 25 | } 26 | 27 | internal val EventService.listItemComplete: EventMapper get() = mapper { client, event -> 28 | ListItemCompleteEvent( 29 | client = client, 30 | barebones = event, 31 | listItem = DeckListItem.from(client, event.listItem) 32 | ) 33 | } -------------------------------------------------------------------------------- /deck-core/src/main/kotlin/event/list/ListItemCreate.kt: -------------------------------------------------------------------------------- 1 | package io.github.srgaabriel.deck.core.event.list 2 | 3 | import io.github.srgaabriel.deck.core.DeckClient 4 | import io.github.srgaabriel.deck.core.entity.ListItem 5 | import io.github.srgaabriel.deck.core.entity.impl.DeckListItem 6 | import io.github.srgaabriel.deck.core.event.DeckEvent 7 | import io.github.srgaabriel.deck.core.event.EventMapper 8 | import io.github.srgaabriel.deck.core.event.EventService 9 | import io.github.srgaabriel.deck.core.event.mapper 10 | import io.github.srgaabriel.deck.core.stateless.StatelessServer 11 | import io.github.srgaabriel.deck.core.stateless.channel.StatelessListChannel 12 | import io.github.srgaabriel.deck.gateway.event.GatewayEvent 13 | import io.github.srgaabriel.deck.gateway.event.type.GatewayListItemCreatedEvent 14 | 15 | /** 16 | * Called when a new [ListItem] is created 17 | */ 18 | public data class ListItemCreateEvent( 19 | override val client: DeckClient, 20 | override val barebones: GatewayEvent, 21 | val listItem: ListItem 22 | ): DeckEvent { 23 | val server: StatelessServer by lazy { listItem.server } 24 | val channel: StatelessListChannel by lazy { listItem.channel } 25 | } 26 | 27 | internal val EventService.listItemCreate: EventMapper 28 | get() = mapper { client, event -> 29 | ListItemCreateEvent( 30 | client = client, 31 | barebones = event, 32 | listItem = DeckListItem.from(client, event.listItem) 33 | ) 34 | } -------------------------------------------------------------------------------- /deck-core/src/main/kotlin/event/list/ListItemDelete.kt: -------------------------------------------------------------------------------- 1 | package io.github.srgaabriel.deck.core.event.list 2 | 3 | import io.github.srgaabriel.deck.core.DeckClient 4 | import io.github.srgaabriel.deck.core.entity.ListItem 5 | import io.github.srgaabriel.deck.core.entity.impl.DeckListItem 6 | import io.github.srgaabriel.deck.core.event.DeckEvent 7 | import io.github.srgaabriel.deck.core.event.EventMapper 8 | import io.github.srgaabriel.deck.core.event.EventService 9 | import io.github.srgaabriel.deck.core.event.mapper 10 | import io.github.srgaabriel.deck.core.stateless.StatelessServer 11 | import io.github.srgaabriel.deck.core.stateless.channel.StatelessListChannel 12 | import io.github.srgaabriel.deck.gateway.event.GatewayEvent 13 | import io.github.srgaabriel.deck.gateway.event.type.GatewayListItemDeletedEvent 14 | 15 | /** 16 | * Called when a [ListItem] is deleted (not completed) 17 | */ 18 | public data class ListItemDeleteEvent( 19 | override val client: DeckClient, 20 | override val barebones: GatewayEvent, 21 | val listItem: ListItem 22 | ): DeckEvent { 23 | val server: StatelessServer by lazy { listItem.server } 24 | val channel: StatelessListChannel by lazy { listItem.channel } 25 | } 26 | 27 | internal val EventService.listItemDelete: EventMapper 28 | get() = mapper { client, event -> 29 | ListItemDeleteEvent( 30 | client = client, 31 | barebones = event, 32 | listItem = DeckListItem.from(client, event.listItem) 33 | ) 34 | } -------------------------------------------------------------------------------- /deck-core/src/main/kotlin/event/list/ListItemIncomplete.kt: -------------------------------------------------------------------------------- 1 | package io.github.srgaabriel.deck.core.event.list 2 | 3 | import io.github.srgaabriel.deck.core.DeckClient 4 | import io.github.srgaabriel.deck.core.entity.ListItem 5 | import io.github.srgaabriel.deck.core.entity.impl.DeckListItem 6 | import io.github.srgaabriel.deck.core.event.DeckEvent 7 | import io.github.srgaabriel.deck.core.event.EventMapper 8 | import io.github.srgaabriel.deck.core.event.EventService 9 | import io.github.srgaabriel.deck.core.event.mapper 10 | import io.github.srgaabriel.deck.core.stateless.StatelessServer 11 | import io.github.srgaabriel.deck.core.stateless.channel.StatelessListChannel 12 | import io.github.srgaabriel.deck.gateway.event.GatewayEvent 13 | import io.github.srgaabriel.deck.gateway.event.type.GatewayListItemUncompletedEvent 14 | 15 | /** 16 | * Called when a completed [ListItem] is marked as incomplete again 17 | */ 18 | public data class ListItemIncompleteEvent( 19 | override val client: DeckClient, 20 | override val barebones: GatewayEvent, 21 | val listItem: ListItem 22 | ): DeckEvent { 23 | val server: StatelessServer by lazy { listItem.server } 24 | val channel: StatelessListChannel by lazy { listItem.channel } 25 | } 26 | 27 | internal val EventService.listItemIncomplete: EventMapper get() = mapper { client, event -> 28 | ListItemIncompleteEvent( 29 | client = client, 30 | barebones = event, 31 | listItem = DeckListItem.from(client, event.listItem) 32 | ) 33 | } -------------------------------------------------------------------------------- /deck-core/src/main/kotlin/event/list/ListItemUpdate.kt: -------------------------------------------------------------------------------- 1 | package io.github.srgaabriel.deck.core.event.list 2 | 3 | import io.github.srgaabriel.deck.core.DeckClient 4 | import io.github.srgaabriel.deck.core.entity.ListItem 5 | import io.github.srgaabriel.deck.core.entity.impl.DeckListItem 6 | import io.github.srgaabriel.deck.core.event.DeckEvent 7 | import io.github.srgaabriel.deck.core.event.EventMapper 8 | import io.github.srgaabriel.deck.core.event.EventService 9 | import io.github.srgaabriel.deck.core.event.mapper 10 | import io.github.srgaabriel.deck.core.stateless.StatelessServer 11 | import io.github.srgaabriel.deck.core.stateless.channel.StatelessListChannel 12 | import io.github.srgaabriel.deck.gateway.event.GatewayEvent 13 | import io.github.srgaabriel.deck.gateway.event.type.GatewayListItemUpdatedEvent 14 | 15 | /** 16 | * Called when the attributes of a [ListItem] is edited 17 | * (not when it's marked as complete or incomplete) 18 | * 19 | * @see ListItemCompleteEvent 20 | * @see ListItemIncompleteEvent 21 | */ 22 | public data class ListItemUpdateEvent( 23 | override val client: DeckClient, 24 | override val barebones: GatewayEvent, 25 | val listItem: ListItem 26 | ): DeckEvent { 27 | val server: StatelessServer by lazy { listItem.server } 28 | val channel: StatelessListChannel by lazy { listItem.channel } 29 | } 30 | 31 | internal val EventService.listItemUpdate: EventMapper get() = mapper { client, event -> 32 | ListItemUpdateEvent( 33 | client = client, 34 | barebones = event, 35 | listItem = DeckListItem.from(client, event.listItem) 36 | ) 37 | } -------------------------------------------------------------------------------- /deck-core/src/main/kotlin/event/message/MessageCreate.kt: -------------------------------------------------------------------------------- 1 | package io.github.srgaabriel.deck.core.event.message 2 | 3 | import io.github.srgaabriel.deck.common.util.GenericId 4 | import io.github.srgaabriel.deck.core.DeckClient 5 | import io.github.srgaabriel.deck.core.entity.Message 6 | import io.github.srgaabriel.deck.core.entity.impl.DeckMessage 7 | import io.github.srgaabriel.deck.core.event.DeckEvent 8 | import io.github.srgaabriel.deck.core.event.EventMapper 9 | import io.github.srgaabriel.deck.core.event.EventService 10 | import io.github.srgaabriel.deck.core.event.mapper 11 | import io.github.srgaabriel.deck.core.stateless.StatelessServer 12 | import io.github.srgaabriel.deck.core.stateless.StatelessUser 13 | import io.github.srgaabriel.deck.core.stateless.channel.StatelessMessageChannel 14 | import io.github.srgaabriel.deck.gateway.event.GatewayEvent 15 | import io.github.srgaabriel.deck.gateway.event.type.GatewayChatMessageCreatedEvent 16 | import java.util.* 17 | 18 | /** 19 | * Called when a [Message] is sent, be it on a private channel (DM) 20 | * or in a server channel 21 | */ 22 | public data class MessageCreateEvent( 23 | override val client: DeckClient, 24 | override val barebones: GatewayEvent, 25 | public val message: Message 26 | ) : DeckEvent { 27 | inline val authorId: GenericId get() = message.authorId 28 | inline val channelId: UUID get() = message.channelId 29 | inline val serverId: GenericId? get() = message.serverId 30 | 31 | public val channel: StatelessMessageChannel by lazy { message.channel } 32 | public val author: StatelessUser by lazy { message.author } 33 | public val server: StatelessServer? by lazy { message.server } 34 | } 35 | 36 | internal val EventService.messageCreate: EventMapper get() = mapper { client, event -> 37 | MessageCreateEvent( 38 | client = client, 39 | barebones = event, 40 | message = DeckMessage.from(client, event.message) 41 | ) 42 | } -------------------------------------------------------------------------------- /deck-core/src/main/kotlin/event/message/MessageDelete.kt: -------------------------------------------------------------------------------- 1 | package io.github.srgaabriel.deck.core.event.message 2 | 3 | import io.github.srgaabriel.deck.common.util.GenericId 4 | import io.github.srgaabriel.deck.core.DeckClient 5 | import io.github.srgaabriel.deck.core.entity.Message 6 | import io.github.srgaabriel.deck.core.event.DeckEvent 7 | import io.github.srgaabriel.deck.core.event.EventMapper 8 | import io.github.srgaabriel.deck.core.event.EventService 9 | import io.github.srgaabriel.deck.core.event.mapper 10 | import io.github.srgaabriel.deck.core.stateless.StatelessServer 11 | import io.github.srgaabriel.deck.core.stateless.channel.StatelessMessageChannel 12 | import io.github.srgaabriel.deck.core.util.BlankStatelessMessageChannel 13 | import io.github.srgaabriel.deck.core.util.BlankStatelessServer 14 | import io.github.srgaabriel.deck.gateway.event.GatewayEvent 15 | import io.github.srgaabriel.deck.gateway.event.type.GatewayChatMessageDeletedEvent 16 | import kotlinx.datetime.Instant 17 | import java.util.* 18 | 19 | /** 20 | * Called when a [Message] is deleted, be it on a private channel (DM) 21 | * or in a server channel 22 | */ 23 | public data class MessageDeleteEvent( 24 | override val client: DeckClient, 25 | override val barebones: GatewayEvent, 26 | public val messageId: UUID, 27 | public val channelId: UUID, 28 | public val serverId: GenericId?, 29 | public val deletedAt: Instant 30 | ): DeckEvent { 31 | public val channel: StatelessMessageChannel by lazy { BlankStatelessMessageChannel(client, channelId, serverId) } 32 | public val server: StatelessServer? by lazy { serverId?.let { BlankStatelessServer(client, it) } } 33 | } 34 | 35 | internal val EventService.messageDelete: EventMapper get() = mapper { client, event -> 36 | MessageDeleteEvent( 37 | client = client, 38 | barebones = event, 39 | messageId = event.message.id, 40 | serverId = event.serverId, 41 | channelId = event.message.channelId, 42 | deletedAt = event.message.deletedAt 43 | ) 44 | } -------------------------------------------------------------------------------- /deck-core/src/main/kotlin/event/message/MessageReactionAdd.kt: -------------------------------------------------------------------------------- 1 | package io.github.srgaabriel.deck.core.event.message 2 | 3 | import io.github.srgaabriel.deck.common.util.Emote 4 | import io.github.srgaabriel.deck.common.util.GenericId 5 | import io.github.srgaabriel.deck.common.util.asNullable 6 | import io.github.srgaabriel.deck.core.DeckClient 7 | import io.github.srgaabriel.deck.core.entity.Message 8 | import io.github.srgaabriel.deck.core.event.DeckEvent 9 | import io.github.srgaabriel.deck.core.event.EventMapper 10 | import io.github.srgaabriel.deck.core.event.EventService 11 | import io.github.srgaabriel.deck.core.event.mapper 12 | import io.github.srgaabriel.deck.core.stateless.StatelessMessage 13 | import io.github.srgaabriel.deck.core.stateless.StatelessServer 14 | import io.github.srgaabriel.deck.core.stateless.StatelessUser 15 | import io.github.srgaabriel.deck.core.stateless.channel.StatelessMessageChannel 16 | import io.github.srgaabriel.deck.core.util.BlankStatelessMessage 17 | import io.github.srgaabriel.deck.core.util.BlankStatelessMessageChannel 18 | import io.github.srgaabriel.deck.core.util.BlankStatelessServer 19 | import io.github.srgaabriel.deck.core.util.BlankStatelessUser 20 | import io.github.srgaabriel.deck.gateway.event.GatewayEvent 21 | import io.github.srgaabriel.deck.gateway.event.type.GatewayChatMessageReactionCreatedEvent 22 | import java.util.* 23 | 24 | /** 25 | * Called when someone reacts to a [Message] 26 | * (not only when a new reaction emote is added to a message) 27 | */ 28 | public data class MessageReactionAddEvent( 29 | override val client: DeckClient, 30 | override val barebones: GatewayEvent, 31 | val serverId: GenericId?, 32 | val channelId: UUID, 33 | val messageId: UUID, 34 | val userId: GenericId, 35 | val emote: Emote 36 | ): DeckEvent { 37 | val server: StatelessServer? by lazy { serverId?.let { BlankStatelessServer(client, serverId) } } 38 | val channel: StatelessMessageChannel by lazy { BlankStatelessMessageChannel(client, channelId, serverId) } 39 | val message: StatelessMessage by lazy { BlankStatelessMessage(client, messageId, channelId, serverId) } 40 | val user: StatelessUser by lazy { BlankStatelessUser(client, userId) } 41 | } 42 | 43 | internal val EventService.messageReactionAdd: EventMapper get() = mapper { client, event -> 44 | MessageReactionAddEvent( 45 | client = client, 46 | barebones = event, 47 | serverId = event.serverId.asNullable(), 48 | channelId = event.reaction.channelId, 49 | messageId = event.reaction.messageId, 50 | userId = event.reaction.createdBy, 51 | emote = Emote.from(event.reaction.emote) 52 | ) 53 | } -------------------------------------------------------------------------------- /deck-core/src/main/kotlin/event/message/MessageReactionRemove.kt: -------------------------------------------------------------------------------- 1 | package io.github.srgaabriel.deck.core.event.message 2 | 3 | import io.github.srgaabriel.deck.common.util.Emote 4 | import io.github.srgaabriel.deck.common.util.GenericId 5 | import io.github.srgaabriel.deck.common.util.asNullable 6 | import io.github.srgaabriel.deck.core.DeckClient 7 | import io.github.srgaabriel.deck.core.entity.Message 8 | import io.github.srgaabriel.deck.core.event.DeckEvent 9 | import io.github.srgaabriel.deck.core.event.EventMapper 10 | import io.github.srgaabriel.deck.core.event.EventService 11 | import io.github.srgaabriel.deck.core.event.mapper 12 | import io.github.srgaabriel.deck.core.stateless.StatelessMessage 13 | import io.github.srgaabriel.deck.core.stateless.StatelessServer 14 | import io.github.srgaabriel.deck.core.stateless.StatelessUser 15 | import io.github.srgaabriel.deck.core.stateless.channel.StatelessMessageChannel 16 | import io.github.srgaabriel.deck.core.util.BlankStatelessMessage 17 | import io.github.srgaabriel.deck.core.util.BlankStatelessMessageChannel 18 | import io.github.srgaabriel.deck.core.util.BlankStatelessServer 19 | import io.github.srgaabriel.deck.core.util.BlankStatelessUser 20 | import io.github.srgaabriel.deck.gateway.event.GatewayEvent 21 | import io.github.srgaabriel.deck.gateway.event.type.GatewayChatMessageReactionDeletedEvent 22 | import java.util.* 23 | 24 | /** 25 | * Called when someone removes a reaction from a [Message] 26 | * (not only when a reaction emote is removed completely from a message) 27 | */ 28 | public data class MessageReactionRemoveEvent( 29 | override val client: DeckClient, 30 | override val barebones: GatewayEvent, 31 | val serverId: GenericId?, 32 | val channelId: UUID, 33 | val messageId: UUID, 34 | val userId: GenericId, 35 | val emote: Emote 36 | ): DeckEvent { 37 | val server: StatelessServer? by lazy { serverId?.let { BlankStatelessServer(client, serverId) } } 38 | val channel: StatelessMessageChannel by lazy { BlankStatelessMessageChannel(client, channelId, serverId) } 39 | val message: StatelessMessage by lazy { BlankStatelessMessage(client, messageId, channelId, serverId) } 40 | val user: StatelessUser by lazy { BlankStatelessUser(client, userId) } 41 | } 42 | 43 | internal val EventService.messageReactionRemove: EventMapper get() = mapper { client, event -> 44 | MessageReactionRemoveEvent( 45 | client = client, 46 | barebones = event, 47 | serverId = event.serverId.asNullable(), 48 | channelId = event.reaction.channelId, 49 | messageId = event.reaction.messageId, 50 | userId = event.reaction.createdBy, 51 | emote = Emote.from(event.reaction.emote) 52 | ) 53 | } -------------------------------------------------------------------------------- /deck-core/src/main/kotlin/event/message/MessageUpdate.kt: -------------------------------------------------------------------------------- 1 | package io.github.srgaabriel.deck.core.event.message 2 | 3 | import io.github.srgaabriel.deck.common.util.GenericId 4 | import io.github.srgaabriel.deck.core.DeckClient 5 | import io.github.srgaabriel.deck.core.entity.Message 6 | import io.github.srgaabriel.deck.core.entity.impl.DeckMessage 7 | import io.github.srgaabriel.deck.core.event.DeckEvent 8 | import io.github.srgaabriel.deck.core.event.EventMapper 9 | import io.github.srgaabriel.deck.core.event.EventService 10 | import io.github.srgaabriel.deck.core.event.mapper 11 | import io.github.srgaabriel.deck.core.stateless.StatelessServer 12 | import io.github.srgaabriel.deck.core.stateless.StatelessUser 13 | import io.github.srgaabriel.deck.core.stateless.channel.StatelessMessageChannel 14 | import io.github.srgaabriel.deck.gateway.event.GatewayEvent 15 | import io.github.srgaabriel.deck.gateway.event.type.GatewayChatMessageUpdatedEvent 16 | import java.util.* 17 | 18 | /** 19 | * Called when a [Message]'s content is edited, be it on a private channel (DM) 20 | * or in a server channel 21 | */ 22 | public data class MessageUpdateEvent( 23 | override val client: DeckClient, 24 | override val barebones: GatewayEvent, 25 | public val message: Message 26 | ) : DeckEvent { 27 | inline val authorId: GenericId get() = message.authorId 28 | inline val channelId: UUID get() = message.channelId 29 | inline val serverId: GenericId? get() = message.serverId 30 | 31 | public val channel: StatelessMessageChannel by lazy { message.channel } 32 | public val author: StatelessUser by lazy { message.author } 33 | public val server: StatelessServer? by lazy { message.server } 34 | } 35 | 36 | internal val EventService.messageUpdate: EventMapper get() = mapper { client, event -> 37 | val message = DeckMessage.from(client, event.message) 38 | MessageUpdateEvent( 39 | client = client, 40 | barebones = event, 41 | message = message 42 | ) 43 | } -------------------------------------------------------------------------------- /deck-core/src/main/kotlin/event/server/BotMembershipCreate.kt: -------------------------------------------------------------------------------- 1 | package io.github.srgaabriel.deck.core.event.server 2 | 3 | import io.github.srgaabriel.deck.common.util.GenericId 4 | import io.github.srgaabriel.deck.core.DeckClient 5 | import io.github.srgaabriel.deck.core.entity.Server 6 | import io.github.srgaabriel.deck.core.entity.impl.DeckServer 7 | import io.github.srgaabriel.deck.core.event.DeckEvent 8 | import io.github.srgaabriel.deck.core.event.EventMapper 9 | import io.github.srgaabriel.deck.core.event.EventService 10 | import io.github.srgaabriel.deck.core.event.mapper 11 | import io.github.srgaabriel.deck.core.stateless.StatelessUser 12 | import io.github.srgaabriel.deck.core.util.BlankStatelessUser 13 | import io.github.srgaabriel.deck.gateway.event.GatewayEvent 14 | import io.github.srgaabriel.deck.gateway.event.type.GatewayBotServerMembershipCreatedEvent 15 | 16 | /** 17 | * Emitted when the bot is added to a server 18 | */ 19 | public data class BotMembershipCreateEvent( 20 | override val client: DeckClient, 21 | override val barebones: GatewayEvent, 22 | val server: Server, 23 | val createdBy: GenericId 24 | ): DeckEvent { 25 | val creator: StatelessUser by lazy { BlankStatelessUser(client, createdBy) } 26 | } 27 | 28 | internal val EventService.botMembershipCreated: EventMapper get() = 29 | mapper { client, event -> 30 | BotMembershipCreateEvent( 31 | client = client, 32 | barebones = event, 33 | server = DeckServer.from(client, event.server), 34 | createdBy = event.createdBy 35 | ) 36 | } -------------------------------------------------------------------------------- /deck-core/src/main/kotlin/event/server/BotMembershipDelete.kt: -------------------------------------------------------------------------------- 1 | package io.github.srgaabriel.deck.core.event.server 2 | 3 | import io.github.srgaabriel.deck.common.util.GenericId 4 | import io.github.srgaabriel.deck.core.DeckClient 5 | import io.github.srgaabriel.deck.core.entity.Server 6 | import io.github.srgaabriel.deck.core.entity.impl.DeckServer 7 | import io.github.srgaabriel.deck.core.event.DeckEvent 8 | import io.github.srgaabriel.deck.core.event.EventMapper 9 | import io.github.srgaabriel.deck.core.event.EventService 10 | import io.github.srgaabriel.deck.core.event.mapper 11 | import io.github.srgaabriel.deck.core.stateless.StatelessUser 12 | import io.github.srgaabriel.deck.core.util.BlankStatelessUser 13 | import io.github.srgaabriel.deck.gateway.event.GatewayEvent 14 | import io.github.srgaabriel.deck.gateway.event.type.GatewayBotServerMembershipDeletedEvent 15 | 16 | /** 17 | * Emitted when the bot is removed from a server 18 | */ 19 | public data class BotMembershipDeleteEvent( 20 | override val client: DeckClient, 21 | override val barebones: GatewayEvent, 22 | val server: Server, 23 | val deletedBy: GenericId 24 | ): DeckEvent { 25 | val deleter: StatelessUser by lazy { BlankStatelessUser(client, deletedBy) } 26 | } 27 | 28 | internal val EventService.botMembershipDelete: EventMapper get() = 29 | mapper { client, event -> 30 | BotMembershipDeleteEvent( 31 | client = client, 32 | barebones = event, 33 | server = DeckServer.from(client, event.server), 34 | deletedBy = event.deletedBy 35 | ) 36 | } -------------------------------------------------------------------------------- /deck-core/src/main/kotlin/event/server/MemberBan.kt: -------------------------------------------------------------------------------- 1 | package io.github.srgaabriel.deck.core.event.server 2 | 3 | import io.github.srgaabriel.deck.common.util.GenericId 4 | import io.github.srgaabriel.deck.core.DeckClient 5 | import io.github.srgaabriel.deck.core.entity.Ban 6 | import io.github.srgaabriel.deck.core.entity.Member 7 | import io.github.srgaabriel.deck.core.event.DeckEvent 8 | import io.github.srgaabriel.deck.core.event.EventMapper 9 | import io.github.srgaabriel.deck.core.event.EventService 10 | import io.github.srgaabriel.deck.core.event.mapper 11 | import io.github.srgaabriel.deck.core.stateless.StatelessServer 12 | import io.github.srgaabriel.deck.core.stateless.StatelessUser 13 | import io.github.srgaabriel.deck.core.util.BlankStatelessServer 14 | import io.github.srgaabriel.deck.gateway.event.GatewayEvent 15 | import io.github.srgaabriel.deck.gateway.event.type.GatewayServerMemberBannedEvent 16 | 17 | /** 18 | * Called when a [Member] is banned from a server 19 | */ 20 | public data class MemberBanEvent( 21 | override val client: DeckClient, 22 | override val barebones: GatewayEvent, 23 | public val serverId: GenericId, 24 | public val ban: Ban 25 | ): DeckEvent { 26 | public val server: StatelessServer by lazy { BlankStatelessServer(client, serverId) } 27 | public val user: StatelessUser by lazy { ban.user } 28 | public val author: StatelessUser by lazy { ban.author } 29 | } 30 | 31 | internal val EventService.memberBan: EventMapper get() = mapper { client, event -> 32 | MemberBanEvent( 33 | client = client, 34 | barebones = event, 35 | serverId = event.serverId, 36 | ban = Ban.from(client, event.serverMemberBan) 37 | ) 38 | } -------------------------------------------------------------------------------- /deck-core/src/main/kotlin/event/server/MemberJoin.kt: -------------------------------------------------------------------------------- 1 | package io.github.srgaabriel.deck.core.event.server 2 | 3 | import io.github.srgaabriel.deck.core.DeckClient 4 | import io.github.srgaabriel.deck.core.entity.Member 5 | import io.github.srgaabriel.deck.core.entity.impl.DeckMember 6 | import io.github.srgaabriel.deck.core.event.DeckEvent 7 | import io.github.srgaabriel.deck.core.event.EventMapper 8 | import io.github.srgaabriel.deck.core.event.EventService 9 | import io.github.srgaabriel.deck.core.event.mapper 10 | import io.github.srgaabriel.deck.core.stateless.StatelessServer 11 | import io.github.srgaabriel.deck.gateway.event.GatewayEvent 12 | import io.github.srgaabriel.deck.gateway.event.type.GatewayServerMemberJoinedEvent 13 | 14 | /** 15 | * Called when a new [Member] joins a server 16 | */ 17 | public data class MemberJoinEvent( 18 | override val client: DeckClient, 19 | override val barebones: GatewayEvent, 20 | public val member: Member 21 | ): DeckEvent { 22 | public val server: StatelessServer by lazy { member.server } 23 | } 24 | 25 | internal val EventService.memberJoin: EventMapper get() = mapper { client, event -> 26 | MemberJoinEvent( 27 | client = client, 28 | barebones = event, 29 | member = DeckMember.from(client, event.serverId, event.member) 30 | ) 31 | } -------------------------------------------------------------------------------- /deck-core/src/main/kotlin/event/server/MemberLeave.kt: -------------------------------------------------------------------------------- 1 | package io.github.srgaabriel.deck.core.event.server 2 | 3 | import io.github.srgaabriel.deck.common.util.GenericId 4 | import io.github.srgaabriel.deck.core.DeckClient 5 | import io.github.srgaabriel.deck.core.entity.Member 6 | import io.github.srgaabriel.deck.core.event.DeckEvent 7 | import io.github.srgaabriel.deck.core.event.EventMapper 8 | import io.github.srgaabriel.deck.core.event.EventService 9 | import io.github.srgaabriel.deck.core.event.mapper 10 | import io.github.srgaabriel.deck.core.stateless.StatelessServer 11 | import io.github.srgaabriel.deck.core.stateless.StatelessUser 12 | import io.github.srgaabriel.deck.core.util.BlankStatelessServer 13 | import io.github.srgaabriel.deck.core.util.BlankStatelessUser 14 | import io.github.srgaabriel.deck.gateway.event.GatewayEvent 15 | import io.github.srgaabriel.deck.gateway.event.type.GatewayServerMemberRemovedEvent 16 | 17 | /** 18 | * Called when a [Member] leaves a server 19 | * (even if it's because of a kick or a ban) 20 | */ 21 | public data class MemberLeaveEvent( 22 | override val client: DeckClient, 23 | override val barebones: GatewayEvent, 24 | public val serverId: GenericId, 25 | public val userId: GenericId, 26 | public val isKick: Boolean, 27 | public val isBan: Boolean 28 | ): DeckEvent { 29 | public val server: StatelessServer by lazy { BlankStatelessServer(client, serverId) } 30 | public val user: StatelessUser by lazy { BlankStatelessUser(client, userId) } 31 | } 32 | 33 | internal val EventService.memberLeave: EventMapper get() = mapper { client, event -> 34 | MemberLeaveEvent( 35 | client = client, 36 | barebones = event, 37 | serverId = event.serverId, 38 | userId = event.userId, 39 | isKick = event.isKick, 40 | isBan = event.isBan 41 | ) 42 | } -------------------------------------------------------------------------------- /deck-core/src/main/kotlin/event/server/MemberSocialLinkCreate.kt: -------------------------------------------------------------------------------- 1 | package io.github.srgaabriel.deck.core.event.server 2 | 3 | import io.github.srgaabriel.deck.common.util.GenericId 4 | import io.github.srgaabriel.deck.core.DeckClient 5 | import io.github.srgaabriel.deck.core.entity.SocialLink 6 | import io.github.srgaabriel.deck.core.event.DeckEvent 7 | import io.github.srgaabriel.deck.core.event.EventMapper 8 | import io.github.srgaabriel.deck.core.event.EventService 9 | import io.github.srgaabriel.deck.core.event.mapper 10 | import io.github.srgaabriel.deck.core.stateless.StatelessMember 11 | import io.github.srgaabriel.deck.core.stateless.StatelessServer 12 | import io.github.srgaabriel.deck.core.stateless.StatelessUser 13 | import io.github.srgaabriel.deck.core.util.BlankStatelessMember 14 | import io.github.srgaabriel.deck.core.util.BlankStatelessServer 15 | import io.github.srgaabriel.deck.core.util.BlankStatelessUser 16 | import io.github.srgaabriel.deck.gateway.event.GatewayEvent 17 | import io.github.srgaabriel.deck.gateway.event.type.GatewayServerMemberSocialLinkCreatedEvent 18 | 19 | public data class MemberSocialLinkCreateEvent( 20 | override val client: DeckClient, 21 | override val barebones: GatewayEvent, 22 | val serverId: GenericId, 23 | val socialLink: SocialLink 24 | ): DeckEvent { 25 | val server: StatelessServer by lazy { BlankStatelessServer(client, serverId) } 26 | val user: StatelessUser by lazy { BlankStatelessUser(client, socialLink.userId) } 27 | val member: StatelessMember by lazy { BlankStatelessMember(client, socialLink.userId, serverId) } 28 | } 29 | 30 | internal val EventService.memberSocialLinkCreate: EventMapper 31 | get() = mapper { client, event -> 32 | MemberSocialLinkCreateEvent( 33 | client = client, 34 | barebones = event, 35 | serverId = event.serverId, 36 | socialLink = SocialLink.from(client, event.socialLink) 37 | ) 38 | } -------------------------------------------------------------------------------- /deck-core/src/main/kotlin/event/server/MemberSocialLinkDelete.kt: -------------------------------------------------------------------------------- 1 | package io.github.srgaabriel.deck.core.event.server 2 | 3 | import io.github.srgaabriel.deck.common.util.GenericId 4 | import io.github.srgaabriel.deck.core.DeckClient 5 | import io.github.srgaabriel.deck.core.entity.SocialLink 6 | import io.github.srgaabriel.deck.core.event.DeckEvent 7 | import io.github.srgaabriel.deck.core.event.EventMapper 8 | import io.github.srgaabriel.deck.core.event.EventService 9 | import io.github.srgaabriel.deck.core.event.mapper 10 | import io.github.srgaabriel.deck.core.stateless.StatelessMember 11 | import io.github.srgaabriel.deck.core.stateless.StatelessServer 12 | import io.github.srgaabriel.deck.core.stateless.StatelessUser 13 | import io.github.srgaabriel.deck.core.util.BlankStatelessMember 14 | import io.github.srgaabriel.deck.core.util.BlankStatelessServer 15 | import io.github.srgaabriel.deck.core.util.BlankStatelessUser 16 | import io.github.srgaabriel.deck.gateway.event.GatewayEvent 17 | import io.github.srgaabriel.deck.gateway.event.type.GatewayServerMemberSocialLinkDeletedEvent 18 | 19 | public data class MemberSocialLinkDeleteEvent( 20 | override val client: DeckClient, 21 | override val barebones: GatewayEvent, 22 | val serverId: GenericId, 23 | val socialLink: SocialLink 24 | ): DeckEvent { 25 | val server: StatelessServer by lazy { BlankStatelessServer(client, serverId) } 26 | val user: StatelessUser by lazy { BlankStatelessUser(client, socialLink.userId) } 27 | val member: StatelessMember by lazy { BlankStatelessMember(client, socialLink.userId, serverId) } 28 | } 29 | 30 | internal val EventService.memberSocialLinkDelete: EventMapper 31 | get() = mapper { client, event -> 32 | MemberSocialLinkDeleteEvent( 33 | client = client, 34 | barebones = event, 35 | serverId = event.serverId, 36 | socialLink = SocialLink.from(client, event.socialLink) 37 | ) 38 | } -------------------------------------------------------------------------------- /deck-core/src/main/kotlin/event/server/MemberSocialLinkUpdate.kt: -------------------------------------------------------------------------------- 1 | package io.github.srgaabriel.deck.core.event.server 2 | 3 | import io.github.srgaabriel.deck.common.util.GenericId 4 | import io.github.srgaabriel.deck.core.DeckClient 5 | import io.github.srgaabriel.deck.core.entity.SocialLink 6 | import io.github.srgaabriel.deck.core.event.DeckEvent 7 | import io.github.srgaabriel.deck.core.event.EventMapper 8 | import io.github.srgaabriel.deck.core.event.EventService 9 | import io.github.srgaabriel.deck.core.event.mapper 10 | import io.github.srgaabriel.deck.core.stateless.StatelessMember 11 | import io.github.srgaabriel.deck.core.stateless.StatelessServer 12 | import io.github.srgaabriel.deck.core.stateless.StatelessUser 13 | import io.github.srgaabriel.deck.core.util.BlankStatelessMember 14 | import io.github.srgaabriel.deck.core.util.BlankStatelessServer 15 | import io.github.srgaabriel.deck.core.util.BlankStatelessUser 16 | import io.github.srgaabriel.deck.gateway.event.GatewayEvent 17 | import io.github.srgaabriel.deck.gateway.event.type.GatewayServerMemberSocialLinkUpdatedEvent 18 | 19 | public data class MemberSocialLinkUpdateEvent( 20 | override val client: DeckClient, 21 | override val barebones: GatewayEvent, 22 | val serverId: GenericId, 23 | val socialLink: SocialLink 24 | ): DeckEvent { 25 | val server: StatelessServer by lazy { BlankStatelessServer(client, serverId) } 26 | val user: StatelessUser by lazy { BlankStatelessUser(client, socialLink.userId) } 27 | val member: StatelessMember by lazy { BlankStatelessMember(client, socialLink.userId, serverId) } 28 | } 29 | 30 | internal val EventService.memberSocialLinkUpdate: EventMapper 31 | get() = mapper { client, event -> 32 | MemberSocialLinkUpdateEvent( 33 | client = client, 34 | barebones = event, 35 | serverId = event.serverId, 36 | socialLink = SocialLink.from(client, event.socialLink) 37 | ) 38 | } -------------------------------------------------------------------------------- /deck-core/src/main/kotlin/event/server/MemberUnban.kt: -------------------------------------------------------------------------------- 1 | package io.github.srgaabriel.deck.core.event.server 2 | 3 | import io.github.srgaabriel.deck.common.util.GenericId 4 | import io.github.srgaabriel.deck.core.DeckClient 5 | import io.github.srgaabriel.deck.core.entity.Ban 6 | import io.github.srgaabriel.deck.core.entity.Member 7 | import io.github.srgaabriel.deck.core.event.DeckEvent 8 | import io.github.srgaabriel.deck.core.event.EventMapper 9 | import io.github.srgaabriel.deck.core.event.EventService 10 | import io.github.srgaabriel.deck.core.event.mapper 11 | import io.github.srgaabriel.deck.core.stateless.StatelessServer 12 | import io.github.srgaabriel.deck.core.stateless.StatelessUser 13 | import io.github.srgaabriel.deck.core.util.BlankStatelessServer 14 | import io.github.srgaabriel.deck.gateway.event.GatewayEvent 15 | import io.github.srgaabriel.deck.gateway.event.type.GatewayServerMemberUnbannedEvent 16 | 17 | /** 18 | * Called when a [Member] is pardoned (unbanned) 19 | */ 20 | public data class MemberUnbanEvent( 21 | override val client: DeckClient, 22 | override val barebones: GatewayEvent, 23 | public val serverId: GenericId, 24 | public val ban: Ban 25 | ): DeckEvent { 26 | public val server: StatelessServer by lazy { BlankStatelessServer(client, serverId) } 27 | public val user: StatelessUser by lazy { ban.user } 28 | } 29 | 30 | internal val EventService.memberUnban: EventMapper get() = mapper { client, event -> 31 | MemberUnbanEvent( 32 | client = client, 33 | barebones = event, 34 | serverId = event.serverId, 35 | ban = Ban.from(client, event.serverMemberBan) 36 | ) 37 | } -------------------------------------------------------------------------------- /deck-core/src/main/kotlin/event/server/MemberUpdate.kt: -------------------------------------------------------------------------------- 1 | package io.github.srgaabriel.deck.core.event.server 2 | 3 | import io.github.srgaabriel.deck.common.util.GenericId 4 | import io.github.srgaabriel.deck.core.DeckClient 5 | import io.github.srgaabriel.deck.core.entity.Member 6 | import io.github.srgaabriel.deck.core.event.DeckEvent 7 | import io.github.srgaabriel.deck.core.event.EventMapper 8 | import io.github.srgaabriel.deck.core.event.EventService 9 | import io.github.srgaabriel.deck.core.event.mapper 10 | import io.github.srgaabriel.deck.core.stateless.StatelessServer 11 | import io.github.srgaabriel.deck.core.stateless.StatelessUser 12 | import io.github.srgaabriel.deck.core.util.BlankStatelessServer 13 | import io.github.srgaabriel.deck.core.util.BlankStatelessUser 14 | import io.github.srgaabriel.deck.core.util.Patch 15 | import io.github.srgaabriel.deck.core.util.asPatch 16 | import io.github.srgaabriel.deck.gateway.event.GatewayEvent 17 | import io.github.srgaabriel.deck.gateway.event.type.GatewayServerMemberUpdatedEvent 18 | 19 | /** 20 | * Called when a [Member]'s attributes are updated 21 | */ 22 | public data class MemberUpdateEvent( 23 | override val client: DeckClient, 24 | override val barebones: GatewayEvent, 25 | val serverId: GenericId, 26 | val userId: GenericId, 27 | val memberData: MemberData 28 | ): DeckEvent { 29 | public val user: StatelessUser by lazy { BlankStatelessUser(client, userId) } 30 | public val server: StatelessServer by lazy { BlankStatelessServer(client, serverId) } 31 | 32 | public data class MemberData( 33 | val nickname: Patch 34 | ) 35 | } 36 | 37 | internal val EventService.memberUpdate: EventMapper get() = mapper { client, event -> 38 | MemberUpdateEvent( 39 | client = client, 40 | barebones = event, 41 | serverId = event.serverId, 42 | userId = event.userInfo.id, 43 | memberData = MemberUpdateEvent.MemberData( 44 | nickname = event.userInfo.nickname.asPatch() 45 | ) 46 | ) 47 | } -------------------------------------------------------------------------------- /deck-core/src/main/kotlin/event/server/ServerRolesUpdate.kt: -------------------------------------------------------------------------------- 1 | package io.github.srgaabriel.deck.core.event.server 2 | 3 | import io.github.srgaabriel.deck.common.util.GenericId 4 | import io.github.srgaabriel.deck.common.util.IntGenericId 5 | import io.github.srgaabriel.deck.core.DeckClient 6 | import io.github.srgaabriel.deck.core.event.DeckEvent 7 | import io.github.srgaabriel.deck.core.event.EventMapper 8 | import io.github.srgaabriel.deck.core.event.EventService 9 | import io.github.srgaabriel.deck.core.event.mapper 10 | import io.github.srgaabriel.deck.gateway.event.GatewayEvent 11 | import io.github.srgaabriel.deck.gateway.event.type.GatewayServerRolesUpdatedEvent 12 | 13 | public data class ServerRolesUpdateEvent( 14 | override val client: DeckClient, 15 | override val barebones: GatewayEvent, 16 | val serverId: GenericId, 17 | val memberRoles: Map> 18 | ): DeckEvent 19 | 20 | internal val EventService.serverRolesUpdate: EventMapper 21 | get() = mapper { client, event -> 22 | ServerRolesUpdateEvent( 23 | client = client, 24 | barebones = event, 25 | serverId = event.serverId, 26 | memberRoles = event.memberRoleIds.associate { it.userId to it.roleIds } 27 | ) 28 | } -------------------------------------------------------------------------------- /deck-core/src/main/kotlin/event/user/Hello.kt: -------------------------------------------------------------------------------- 1 | package io.github.srgaabriel.deck.core.event.user 2 | 3 | import io.github.srgaabriel.deck.core.DeckClient 4 | import io.github.srgaabriel.deck.core.event.DeckEvent 5 | import io.github.srgaabriel.deck.core.event.EventMapper 6 | import io.github.srgaabriel.deck.core.event.EventService 7 | import io.github.srgaabriel.deck.core.event.mapper 8 | import io.github.srgaabriel.deck.gateway.event.GatewayEvent 9 | import io.github.srgaabriel.deck.gateway.event.type.GatewayHelloEvent 10 | 11 | /** 12 | * Called when a gateway connects to guilded 13 | */ 14 | public data class HelloEvent( 15 | override val client: DeckClient, 16 | override val barebones: GatewayEvent, 17 | public val heartbeatInterval: Long, 18 | public val lastMessageId: String 19 | ) : DeckEvent 20 | 21 | internal val EventService.hello: EventMapper get() = mapper { client, event -> 22 | HelloEvent( 23 | client = client, 24 | barebones = event, 25 | heartbeatInterval = event.heartbeatIntervalMs, 26 | lastMessageId = event.lastMessageId 27 | ) 28 | } -------------------------------------------------------------------------------- /deck-core/src/main/kotlin/event/webhook/WebhookCreate.kt: -------------------------------------------------------------------------------- 1 | package io.github.srgaabriel.deck.core.event.webhook 2 | 3 | import io.github.srgaabriel.deck.core.DeckClient 4 | import io.github.srgaabriel.deck.core.entity.Webhook 5 | import io.github.srgaabriel.deck.core.entity.impl.DeckWebhook 6 | import io.github.srgaabriel.deck.core.event.DeckEvent 7 | import io.github.srgaabriel.deck.core.event.EventMapper 8 | import io.github.srgaabriel.deck.core.event.EventService 9 | import io.github.srgaabriel.deck.core.event.mapper 10 | import io.github.srgaabriel.deck.core.stateless.StatelessServer 11 | import io.github.srgaabriel.deck.gateway.event.GatewayEvent 12 | import io.github.srgaabriel.deck.gateway.event.type.GatewayServerWebhookCreatedEvent 13 | 14 | /** 15 | * Called when a [Webhook] is created 16 | */ 17 | public data class WebhookCreateEvent( 18 | override val client: DeckClient, 19 | override val barebones: GatewayEvent, 20 | val webhook: Webhook 21 | ) : DeckEvent { 22 | public val server: StatelessServer by lazy { webhook.server } 23 | } 24 | 25 | internal val EventService.webhookCreate: EventMapper get() = mapper { client, event -> 26 | WebhookCreateEvent( 27 | client = client, 28 | barebones = event, 29 | webhook = DeckWebhook.from(client, event.webhook) 30 | ) 31 | } -------------------------------------------------------------------------------- /deck-core/src/main/kotlin/event/webhook/WebhookUpdate.kt: -------------------------------------------------------------------------------- 1 | package io.github.srgaabriel.deck.core.event.webhook 2 | 3 | import io.github.srgaabriel.deck.core.DeckClient 4 | import io.github.srgaabriel.deck.core.entity.Webhook 5 | import io.github.srgaabriel.deck.core.entity.impl.DeckWebhook 6 | import io.github.srgaabriel.deck.core.event.DeckEvent 7 | import io.github.srgaabriel.deck.core.event.EventMapper 8 | import io.github.srgaabriel.deck.core.event.EventService 9 | import io.github.srgaabriel.deck.core.event.mapper 10 | import io.github.srgaabriel.deck.core.stateless.StatelessServer 11 | import io.github.srgaabriel.deck.gateway.event.GatewayEvent 12 | import io.github.srgaabriel.deck.gateway.event.type.GatewayServerWebhookUpdatedEvent 13 | 14 | /** 15 | * Called when a [Webhook] is updated 16 | */ 17 | public data class WebhookUpdateEvent( 18 | override val client: DeckClient, 19 | override val barebones: GatewayEvent, 20 | val webhook: Webhook 21 | ) : DeckEvent { 22 | public val server: StatelessServer by lazy { webhook.server } 23 | } 24 | 25 | internal val EventService.webhookUpdate: EventMapper get() = mapper { client, event -> 26 | WebhookUpdateEvent( 27 | client = client, 28 | barebones = event, 29 | webhook = DeckWebhook.from(client, event.webhook) 30 | ) 31 | } -------------------------------------------------------------------------------- /deck-core/src/main/kotlin/stateless/StatelessEntity.kt: -------------------------------------------------------------------------------- 1 | package io.github.srgaabriel.deck.core.stateless 2 | 3 | import io.github.srgaabriel.deck.core.DeckClient 4 | 5 | public interface StatelessEntity { 6 | public val client: DeckClient 7 | } -------------------------------------------------------------------------------- /deck-core/src/main/kotlin/stateless/StatelessGroup.kt: -------------------------------------------------------------------------------- 1 | package io.github.srgaabriel.deck.core.stateless 2 | 3 | import io.github.srgaabriel.deck.common.util.GenericId 4 | 5 | public interface StatelessGroup: StatelessEntity { 6 | public val id: GenericId 7 | 8 | /** 9 | * Adds the specified member to this group 10 | * 11 | * @param memberId member's id 12 | */ 13 | public suspend fun addMember(memberId: GenericId): Unit = 14 | client.rest.group.addMember(memberId, id) 15 | 16 | /** 17 | * Adds the specified member to this group 18 | * 19 | * @param memberId member's id 20 | */ 21 | public suspend fun removeMember(memberId: GenericId): Unit = 22 | client.rest.group.removeMember(memberId, id) 23 | } -------------------------------------------------------------------------------- /deck-core/src/main/kotlin/stateless/StatelessRole.kt: -------------------------------------------------------------------------------- 1 | package io.github.srgaabriel.deck.core.stateless 2 | 3 | import io.github.srgaabriel.deck.common.util.GenericId 4 | import io.github.srgaabriel.deck.common.util.IntGenericId 5 | import io.github.srgaabriel.deck.core.util.BlankStatelessServer 6 | 7 | public interface StatelessRole: StatelessEntity { 8 | public val id: IntGenericId 9 | public val serverId: GenericId 10 | 11 | public val server: StatelessServer get() = BlankStatelessServer(client, serverId) 12 | 13 | public suspend fun awardXp(amount: Int): Unit = 14 | client.rest.server.awardXpToRole(id, serverId, amount) 15 | } -------------------------------------------------------------------------------- /deck-core/src/main/kotlin/stateless/StatelessUser.kt: -------------------------------------------------------------------------------- 1 | package io.github.srgaabriel.deck.core.stateless 2 | 3 | import io.github.srgaabriel.deck.common.util.DeckUnsupported 4 | import io.github.srgaabriel.deck.common.util.GenericId 5 | import io.github.srgaabriel.deck.core.entity.User 6 | 7 | public interface StatelessUser: StatelessEntity { 8 | public val id: GenericId 9 | 10 | @DeckUnsupported 11 | public suspend fun fetch(): User = 12 | client.getUser(id) 13 | } -------------------------------------------------------------------------------- /deck-core/src/main/kotlin/stateless/StatelessWebhook.kt: -------------------------------------------------------------------------------- 1 | package io.github.srgaabriel.deck.core.stateless 2 | 3 | import io.github.srgaabriel.deck.common.util.GenericId 4 | import io.github.srgaabriel.deck.core.entity.Webhook 5 | import io.github.srgaabriel.deck.core.entity.impl.DeckWebhook 6 | import io.github.srgaabriel.deck.core.util.BlankStatelessServer 7 | import io.github.srgaabriel.deck.rest.builder.ExecuteWebhookRequestBuilder 8 | import io.github.srgaabriel.deck.rest.builder.UpdateWebhookRequestBuilder 9 | import io.github.srgaabriel.deck.rest.request.ExecuteWebhookResponse 10 | import java.util.* 11 | 12 | public interface StatelessWebhook: StatelessEntity { 13 | public val id: UUID 14 | public val serverId: GenericId 15 | 16 | public val server: StatelessServer get() = BlankStatelessServer(client, serverId) 17 | 18 | /** 19 | * Executes this webhook using the provided webhook [token], sending a message with the details provided in the [builder] 20 | * 21 | * @param token webhook's token 22 | * @param builder message builder 23 | * 24 | * @return response 25 | */ 26 | public suspend fun execute(token: String, builder: ExecuteWebhookRequestBuilder.() -> Unit): ExecuteWebhookResponse = 27 | client.executeWebhook(id, token, builder) 28 | 29 | /** 30 | * Overwrites this webhook with the new data provided 31 | * inside the [builder]. It's not a [PATCH](https://tools.ietf.org/html/rfc5789) operation but instead a [PUT](https://tools.ietf.org/html/rfc7231#section-4.3.4) one. 32 | * 33 | * @param builder update builder 34 | * @return updated webhook containing new data 35 | */ 36 | public suspend fun update(builder: UpdateWebhookRequestBuilder.() -> Unit): Webhook = 37 | DeckWebhook.from(client, client.rest.webhook.updateWebhook(serverId, id, builder)) 38 | 39 | /** 40 | * Deletes this webhook 41 | */ 42 | public suspend fun delete(): Unit = 43 | client.rest.webhook.deleteWebhook(serverId, id) 44 | 45 | public suspend fun getWebhook(): Webhook = 46 | DeckWebhook.from(client, client.rest.webhook.getWebhook(serverId, id)) 47 | } -------------------------------------------------------------------------------- /deck-core/src/main/kotlin/stateless/channel/StatelessChannel.kt: -------------------------------------------------------------------------------- 1 | package io.github.srgaabriel.deck.core.stateless.channel 2 | 3 | import io.github.srgaabriel.deck.common.entity.ServerChannelType 4 | import io.github.srgaabriel.deck.common.util.GenericId 5 | import io.github.srgaabriel.deck.core.entity.channel.Channel 6 | import io.github.srgaabriel.deck.core.entity.impl.DeckServerChannel 7 | import io.github.srgaabriel.deck.core.stateless.StatelessEntity 8 | import io.github.srgaabriel.deck.core.stateless.StatelessServer 9 | import io.github.srgaabriel.deck.core.util.BlankStatelessServer 10 | import java.util.* 11 | 12 | public interface StatelessChannel: StatelessEntity { 13 | public val id: UUID 14 | public val serverId: GenericId? 15 | 16 | public val server: StatelessServer? get() = serverId?.let { BlankStatelessServer(client, it) } 17 | public val type: ServerChannelType 18 | 19 | /** 20 | * Retrieves a [Channel] that the bot has access to 21 | * 22 | * @return the [Channel] matching this channel's id 23 | */ 24 | public suspend fun getChannel(): Channel = 25 | DeckServerChannel.from(client, client.rest.channel.getChannel(id)) 26 | } -------------------------------------------------------------------------------- /deck-core/src/main/kotlin/stateless/channel/StatelessDocumentationChannel.kt: -------------------------------------------------------------------------------- 1 | package io.github.srgaabriel.deck.core.stateless.channel 2 | 3 | import io.github.srgaabriel.deck.common.entity.ServerChannelType 4 | import io.github.srgaabriel.deck.common.util.IntGenericId 5 | import io.github.srgaabriel.deck.core.entity.Documentation 6 | import io.github.srgaabriel.deck.core.entity.channel.DocumentationChannel 7 | import io.github.srgaabriel.deck.core.entity.impl.DeckDocumentation 8 | import io.github.srgaabriel.deck.rest.builder.CreateDocumentationRequestBuilder 9 | 10 | public interface StatelessDocumentationChannel: StatelessServerChannel { 11 | override val type: ServerChannelType get() = ServerChannelType.Documentation 12 | 13 | /** 14 | * Creates a [Documentation] within this documentation channel. 15 | * 16 | * @param builder documentation builder 17 | * @return the created documentation 18 | */ 19 | public suspend fun createDocumentation(builder: CreateDocumentationRequestBuilder.() -> Unit): Documentation = 20 | DeckDocumentation.from(client, client.rest.channel.createDocumentation(id, builder)) 21 | 22 | /** 23 | * Retrieves the [Documentation] associated with the specified [documentationId] 24 | * 25 | * @param documentationId documentation's id 26 | * @return found documentation 27 | */ 28 | public suspend fun getDocumentation(documentationId: IntGenericId): Documentation = 29 | DeckDocumentation.from(client, client.rest.channel.getDocumentation(id, documentationId)) 30 | 31 | /** 32 | * Retrieves all [Documentation]s within this documentation channel 33 | * 34 | * @return list of [Documentation] 35 | */ 36 | public suspend fun getDocumentations(): List = 37 | client.rest.channel.getDocumentations(id).map { DeckDocumentation.from(client, it) } 38 | 39 | /** 40 | * Updates **(NOT PATCHES)** the documentation associated with the provided [documentationId] 41 | * 42 | * @param documentationId documentation's id 43 | * @param builder update builder 44 | * 45 | * @return updated documentation 46 | */ 47 | public suspend fun updateDocumentation(documentationId: IntGenericId, builder: CreateDocumentationRequestBuilder.() -> Unit): Documentation = 48 | DeckDocumentation.from(client, client.rest.channel.updateDocumentation(id, documentationId, builder)) 49 | 50 | /** 51 | * Deletes the documentation associated with the provided [documentationId] 52 | * 53 | * @param documentationId documentation's id 54 | */ 55 | public suspend fun deleteDocumentation(documentationId: IntGenericId): Unit = 56 | client.rest.channel.deleteDocumentation(id, documentationId) 57 | 58 | override suspend fun getChannel(): DocumentationChannel = 59 | client.getChannelOf(id) 60 | } -------------------------------------------------------------------------------- /deck-core/src/main/kotlin/stateless/channel/StatelessServerChannel.kt: -------------------------------------------------------------------------------- 1 | package io.github.srgaabriel.deck.core.stateless.channel 2 | 3 | import io.github.srgaabriel.deck.common.util.GenericId 4 | import io.github.srgaabriel.deck.core.entity.channel.ServerChannel 5 | import io.github.srgaabriel.deck.core.entity.impl.DeckServerChannel 6 | import io.github.srgaabriel.deck.core.stateless.StatelessServer 7 | import io.github.srgaabriel.deck.core.util.BlankStatelessServer 8 | 9 | public interface StatelessServerChannel: StatelessChannel { 10 | override val serverId: GenericId 11 | 12 | override val server: StatelessServer get() = BlankStatelessServer(client, serverId) 13 | 14 | /** 15 | * Deletes this channel 16 | */ 17 | public suspend fun delete(): Unit = 18 | client.rest.channel.deleteChannel(id) 19 | 20 | /** 21 | * Retrieves a [ServerChannel] that the bot has access to 22 | * 23 | * @return the [ServerChannel] matching this channel's id 24 | */ 25 | override suspend fun getChannel(): ServerChannel = 26 | DeckServerChannel.from(client, client.rest.channel.getChannel(id)) 27 | } -------------------------------------------------------------------------------- /deck-core/src/main/kotlin/stateless/channel/content/StatelessCalendarEventRsvp.kt: -------------------------------------------------------------------------------- 1 | package io.github.srgaabriel.deck.core.stateless.channel.content 2 | 3 | import io.github.srgaabriel.deck.common.entity.CalendarEventRsvpStatus 4 | import io.github.srgaabriel.deck.common.util.GenericId 5 | import io.github.srgaabriel.deck.common.util.IntGenericId 6 | import io.github.srgaabriel.deck.core.entity.CalendarEventRsvp 7 | import io.github.srgaabriel.deck.core.entity.impl.DeckCalendarEventRsvp 8 | import io.github.srgaabriel.deck.core.stateless.StatelessEntity 9 | import io.github.srgaabriel.deck.core.stateless.StatelessServer 10 | import io.github.srgaabriel.deck.core.stateless.StatelessUser 11 | import io.github.srgaabriel.deck.core.stateless.channel.StatelessCalendarChannel 12 | import io.github.srgaabriel.deck.core.util.BlankStatelessCalendarChannel 13 | import io.github.srgaabriel.deck.core.util.BlankStatelessCalendarEvent 14 | import io.github.srgaabriel.deck.core.util.BlankStatelessServer 15 | import io.github.srgaabriel.deck.core.util.BlankStatelessUser 16 | import java.util.* 17 | 18 | public interface StatelessCalendarEventRsvp: StatelessEntity { 19 | public val userId: GenericId 20 | public val serverId: GenericId 21 | public val channelId: UUID 22 | public val calendarEventId: IntGenericId 23 | 24 | public val user: StatelessUser get() = BlankStatelessUser(client, userId) 25 | public val channel: StatelessCalendarChannel get() = BlankStatelessCalendarChannel(client, channelId, serverId) 26 | public val server: StatelessServer get() = BlankStatelessServer(client, serverId) 27 | public val calendarEvent: StatelessCalendarEvent get() = BlankStatelessCalendarEvent(client, calendarEventId, channelId, serverId) 28 | 29 | /** 30 | * Sets this RSVP status to [status]. If this RSVP does not exist, it will be created with the provided [status]. 31 | * 32 | * @param status New RSVP status 33 | * 34 | * @return updated RSVP 35 | */ 36 | public suspend fun update(status: CalendarEventRsvpStatus): CalendarEventRsvp = 37 | DeckCalendarEventRsvp.from(client, client.rest.channel.putCalendarEventRsvp(channelId, calendarEventId, userId, status)) 38 | 39 | /** 40 | * Deletes this RSVP 41 | */ 42 | public suspend fun delete(): Unit = 43 | client.rest.channel.deleteCalendarEventRsvp(channelId, calendarEventId, userId) 44 | 45 | public suspend fun getCalendarEvent(): CalendarEventRsvp = 46 | DeckCalendarEventRsvp.from(client, client.rest.channel.getCalendarEventRsvp(channelId, calendarEventId, userId)) 47 | } -------------------------------------------------------------------------------- /deck-core/src/main/kotlin/stateless/channel/content/StatelessCalendarEventSeries.kt: -------------------------------------------------------------------------------- 1 | package io.github.srgaabriel.deck.core.stateless.channel.content 2 | 3 | import io.github.srgaabriel.deck.common.util.GenericId 4 | import io.github.srgaabriel.deck.core.stateless.StatelessEntity 5 | import io.github.srgaabriel.deck.core.stateless.channel.StatelessCalendarChannel 6 | import io.github.srgaabriel.deck.core.util.BlankStatelessCalendarChannel 7 | import io.github.srgaabriel.deck.rest.builder.UpdateCalendarEventRequestBuilder 8 | import java.util.* 9 | 10 | public interface StatelessCalendarEventSeries: StatelessEntity { 11 | public val id: UUID 12 | public val serverId: GenericId 13 | public val channelId: UUID 14 | 15 | public val channel: StatelessCalendarChannel get() = BlankStatelessCalendarChannel(client, id, serverId) 16 | 17 | /** 18 | * **Patches** all events within this series with the data provided in the [builder] 19 | * 20 | * @param builder patch builder 21 | */ 22 | public suspend fun update(builder: UpdateCalendarEventRequestBuilder.() -> Unit): Unit = 23 | client.rest.channel.updateCalendarEventSeries(channelId, id, builder) 24 | 25 | /** Deletes this series and all events within it */ 26 | public suspend fun delete(): Unit = 27 | client.rest.channel.deleteCalendarEventSeries(channelId, id) 28 | } -------------------------------------------------------------------------------- /deck-core/src/main/kotlin/stateless/channel/content/StatelessChannelContent.kt: -------------------------------------------------------------------------------- 1 | package io.github.srgaabriel.deck.core.stateless.channel.content 2 | 3 | import io.github.srgaabriel.deck.common.entity.ServerChannelType 4 | import io.github.srgaabriel.deck.common.util.DeckDelicateApi 5 | import io.github.srgaabriel.deck.common.util.Emote 6 | import io.github.srgaabriel.deck.common.util.IntGenericId 7 | import io.github.srgaabriel.deck.core.stateless.StatelessEntity 8 | import io.github.srgaabriel.deck.core.util.ReactionHolder 9 | import java.util.* 10 | 11 | public interface StatelessChannelContent: StatelessEntity, ReactionHolder { 12 | public val id: IntGenericId 13 | public val channelId: UUID 14 | public val channelType: ServerChannelType 15 | 16 | @DeckDelicateApi 17 | override suspend fun addReaction(reactionId: IntGenericId): Unit = 18 | client.rest.channel.addReactionToContent( 19 | channelId, 20 | ServerChannelType.Calendar, 21 | id, 22 | reactionId 23 | ) 24 | 25 | @DeckDelicateApi 26 | override suspend fun removeReaction(reactionId: IntGenericId): Unit = 27 | client.rest.channel.removeReactionFromContent( 28 | channelId, 29 | ServerChannelType.Calendar, 30 | id, 31 | reactionId 32 | ) 33 | 34 | @DeckDelicateApi 35 | public suspend fun addReactionToComment(commentId: IntGenericId, reactionId: IntGenericId): Unit = 36 | client.rest.channel.addReactionToComment( 37 | channelId, 38 | ServerChannelType.Calendar, 39 | id, 40 | commentId, 41 | reactionId 42 | ) 43 | 44 | @DeckDelicateApi 45 | public suspend fun removeReactionFromComment(commentId: IntGenericId, reactionId: IntGenericId): Unit = 46 | client.rest.channel.removeReactionFromComment( 47 | channelId, 48 | ServerChannelType.Calendar, 49 | id, 50 | commentId, 51 | reactionId 52 | ) 53 | 54 | @DeckDelicateApi 55 | public suspend fun addReactionToComment(commentId: IntGenericId, emote: Emote): Unit = 56 | addReactionToComment(commentId, emote.id) 57 | 58 | @DeckDelicateApi 59 | public suspend fun removeReactionFromComment(commentId: IntGenericId, emote: Emote): Unit = 60 | addReactionToComment(commentId, emote.id) 61 | } -------------------------------------------------------------------------------- /deck-core/src/main/kotlin/stateless/channel/content/StatelessListItem.kt: -------------------------------------------------------------------------------- 1 | package io.github.srgaabriel.deck.core.stateless.channel.content 2 | 3 | import io.github.srgaabriel.deck.common.util.GenericId 4 | import io.github.srgaabriel.deck.core.entity.ListItem 5 | import io.github.srgaabriel.deck.core.entity.impl.DeckListItem 6 | import io.github.srgaabriel.deck.core.stateless.StatelessEntity 7 | import io.github.srgaabriel.deck.core.stateless.StatelessServer 8 | import io.github.srgaabriel.deck.core.stateless.channel.StatelessListChannel 9 | import io.github.srgaabriel.deck.core.util.BlankStatelessListChannel 10 | import io.github.srgaabriel.deck.core.util.BlankStatelessServer 11 | import io.github.srgaabriel.deck.rest.builder.CreateListItemRequestBuilder 12 | import io.github.srgaabriel.deck.rest.builder.UpdateListItemRequestBuilder 13 | import java.util.* 14 | 15 | public interface StatelessListItem: StatelessEntity { 16 | public val id: UUID 17 | public val serverId: GenericId 18 | public val channelId: UUID 19 | 20 | public val server: StatelessServer get() = BlankStatelessServer(client, serverId) 21 | public val channel: StatelessListChannel get() = BlankStatelessListChannel(client, id, serverId) 22 | 23 | /** 24 | * Overwrites this list item with the new data provided in the [builder]. 25 | * 26 | * @param builder item builder, requires a [CreateListItemRequestBuilder.label] and a [CreateListItemRequestBuilder.note] 27 | * @return updated item containing new data 28 | */ 29 | public suspend fun update(builder: UpdateListItemRequestBuilder.() -> Unit): ListItem = 30 | DeckListItem.from(client, client.rest.channel.updateListItem(channelId, id, builder)) 31 | 32 | /** 33 | * Marks this list item as 'completed' within this channel. _(not to be confused with [delete])_ 34 | */ 35 | public suspend fun complete(): Unit = 36 | client.rest.channel.completeListItem(channelId, id) 37 | 38 | /** 39 | * Marks this list item as 'uncompleted' within this channel. 40 | */ 41 | public suspend fun uncomplete(): Unit = 42 | client.rest.channel.uncompleteListItem(channelId, id) 43 | 44 | /** 45 | * Deletes this list item. _(not to be confused with [complete])_ 46 | */ 47 | public suspend fun delete(): Unit = 48 | client.rest.channel.deleteListItem(channelId, id) 49 | 50 | public suspend fun getListItem(): ListItem = 51 | DeckListItem.from(client, client.rest.channel.getListItem(channelId, id)) 52 | } -------------------------------------------------------------------------------- /deck-core/src/main/kotlin/util/Client.kt: -------------------------------------------------------------------------------- 1 | package io.github.srgaabriel.deck.core.util 2 | 3 | import io.github.srgaabriel.deck.core.DeckClient 4 | import io.github.srgaabriel.deck.gateway.GatewayOrchestrator 5 | import io.github.srgaabriel.deck.rest.RestClient 6 | 7 | /** 8 | * A builder for a [DeckClient] 9 | */ 10 | public class ClientBuilder(token: String) { 11 | public var rest: RestClient = RestClient(token) 12 | public var gateway: GatewayOrchestrator = GatewayOrchestrator(token) 13 | 14 | public var logRequests: Boolean by rest::logRequests 15 | public var logEventPayloads: Boolean by gateway::logEventPayloads 16 | 17 | public var enableEventReplaying: Boolean by gateway::enableEventReplaying 18 | public var automaticPrivateRepliesToPrivateMessages: Boolean? = null 19 | 20 | /** 21 | * Enables request (including responses) and event payloads logging 22 | */ 23 | public fun debugMode() { 24 | logRequests = true 25 | logEventPayloads = true 26 | } 27 | 28 | public fun build(): DeckClient { 29 | val client = DeckClient(rest, gateway) 30 | if (automaticPrivateRepliesToPrivateMessages != null) 31 | client.privateRepliesToPrivateMessagesByDefault = automaticPrivateRepliesToPrivateMessages!! 32 | return client 33 | } 34 | } -------------------------------------------------------------------------------- /deck-core/src/main/kotlin/util/Events.kt: -------------------------------------------------------------------------------- 1 | package io.github.srgaabriel.deck.core.util 2 | 3 | import io.github.srgaabriel.deck.core.event.DeckEvent 4 | import io.github.srgaabriel.deck.gateway.util.onEachHandlingErrors 5 | import kotlinx.coroutines.* 6 | import kotlinx.coroutines.channels.Channel 7 | import kotlinx.coroutines.flow.* 8 | 9 | public inline fun on( 10 | gatewayId: Int?, 11 | scope: CoroutineScope, 12 | eventsFlow: SharedFlow, 13 | noinline callback: suspend T.() -> Unit 14 | ): Job = eventsFlow.buffer(Channel.UNLIMITED).filterIsInstance() 15 | .filter { it.barebones.info.gatewayId == (gatewayId ?: return@filter true) } 16 | .onEachHandlingErrors(callback) 17 | .launchIn(scope) 18 | 19 | @OptIn(ExperimentalCoroutinesApi::class) 20 | public suspend inline fun await( 21 | timeout: Long, 22 | gatewayId: Int?, 23 | scope: CoroutineScope, 24 | eventsFlow: SharedFlow, 25 | ): T? = withTimeoutOrNull(timeout) { 26 | suspendCancellableCoroutine { continuation -> 27 | scope.launch { 28 | val event = eventsFlow.buffer(Channel.UNLIMITED).filterIsInstance() 29 | .filter { it.barebones.info.gatewayId == (gatewayId ?: return@filter true) }.first() 30 | continuation.resume(event) {} 31 | } 32 | } 33 | } -------------------------------------------------------------------------------- /deck-core/src/main/kotlin/util/Reactions.kt: -------------------------------------------------------------------------------- 1 | package io.github.srgaabriel.deck.core.util 2 | 3 | import io.github.srgaabriel.deck.common.util.Emote 4 | import io.github.srgaabriel.deck.common.util.IntGenericId 5 | 6 | /** 7 | * Represents an entity who can have reactions 8 | */ 9 | public interface ReactionHolder { 10 | /** 11 | * Makes the bot add a reaction to this entity 12 | * 13 | * @param reactionId reaction emote id 14 | */ 15 | public suspend fun addReaction(reactionId: IntGenericId) 16 | 17 | /** 18 | * Removes the bot's reaction from this entity 19 | * 20 | * @param reactionId reaction emote id 21 | */ 22 | public suspend fun removeReaction(reactionId: IntGenericId) 23 | } 24 | 25 | /** 26 | * Makes the bot add a reaction to this entity 27 | * 28 | * @param emote reaction emote 29 | */ 30 | public suspend fun ReactionHolder.addReaction(emote: Emote): Unit = addReaction(emote.id) 31 | 32 | /** 33 | * Removes the bot's reaction from this entity 34 | * 35 | * @param emote reaction emote 36 | */ 37 | public suspend fun ReactionHolder.removeReaction(emote: Emote): Unit = removeReaction(emote.id) -------------------------------------------------------------------------------- /deck-core/src/main/resources/logback.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | [%d{HH:mm:ss}] %-5level %msg%n 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /deck-extras/build.gradle.kts: -------------------------------------------------------------------------------- 1 | plugins { 2 | `deck-publishing` 3 | } 4 | 5 | repositories { 6 | mavenCentral() 7 | } 8 | 9 | dependencies { 10 | implementation(kotlin("stdlib")) 11 | implementation(project(":deck-core")) 12 | implementation(libs.mordant) 13 | } -------------------------------------------------------------------------------- /deck-extras/src/main/kotlin/content/Util.kt: -------------------------------------------------------------------------------- 1 | package io.github.srgaabriel.deck.extras.content 2 | 3 | import io.github.srgaabriel.deck.core.entity.Message 4 | import io.github.srgaabriel.deck.core.stateless.StatelessMessage 5 | import io.github.srgaabriel.deck.core.stateless.channel.StatelessMessageChannel 6 | import io.github.srgaabriel.deck.extras.content.node.encode 7 | import io.github.srgaabriel.deck.rest.builder.SendMessageRequestBuilder 8 | import kotlinx.serialization.json.Json 9 | import kotlinx.serialization.json.encodeToJsonElement 10 | 11 | // workaround, TODO fix 12 | private val ENCODING_JSON = Json { encodeDefaults = false } 13 | 14 | public fun SendMessageRequestBuilder.content(builder: ContentBuilder.() -> Unit) { 15 | contentElement = ENCODING_JSON.encodeToJsonElement(ContentBuilder().apply(builder).build().encode()) 16 | } 17 | 18 | public suspend fun StatelessMessageChannel.sendContent(builder: ContentBuilder.() -> Unit): Message = 19 | sendMessage { content(builder) } 20 | 21 | public suspend fun StatelessMessage.sendReplyOfContent(builder: ContentBuilder.() -> Unit): Message = 22 | sendReply { content(builder) } -------------------------------------------------------------------------------- /deck-extras/src/main/kotlin/conversation/AbstractMessageChannelConversation.kt: -------------------------------------------------------------------------------- 1 | package io.github.srgaabriel.deck.extras.conversation 2 | 3 | import io.github.srgaabriel.deck.common.util.DeckExperimental 4 | import io.github.srgaabriel.deck.core.entity.Message 5 | import io.github.srgaabriel.deck.core.stateless.channel.StatelessMessageChannel 6 | import io.github.srgaabriel.deck.core.util.sendMessage 7 | import io.github.srgaabriel.deck.rest.builder.SendMessageRequestBuilder 8 | import kotlinx.coroutines.Dispatchers 9 | import kotlinx.coroutines.flow.MutableSharedFlow 10 | import kotlin.coroutines.CoroutineContext 11 | 12 | @DeckExperimental 13 | public abstract class AbstractMessageChannelConversation: Conversation { 14 | override val coroutineContext: CoroutineContext = Dispatchers.Unconfined 15 | override val responseFlow: MutableSharedFlow = MutableSharedFlow() 16 | public abstract val messageChannel: StatelessMessageChannel 17 | 18 | public open var abortMessage: String = "abort" 19 | public open var onTimeout: suspend () -> Unit = { messageChannel.sendMessage("You were too late to answer, so this operation was aborted.") } 20 | 21 | override suspend fun ask(message: SendMessageRequestBuilder.() -> Unit): ConversationMessage = 22 | ask(messageChannel.sendMessage(message)) 23 | 24 | override suspend fun ask(message: Message): ConversationMessage { 25 | if (!active) error("You need to init the conversation before asking something.") 26 | return ConversationMessage( 27 | conversation = this, 28 | replyingTo = message 29 | ) 30 | } 31 | 32 | public open suspend fun ask(content: String): ConversationMessage = 33 | ask(messageChannel.sendMessage(content)) 34 | 35 | public fun onTimeout(callback: suspend () -> Unit) { 36 | this.onTimeout = callback 37 | } 38 | 39 | public suspend fun timeout(): Unit = onTimeout() 40 | } -------------------------------------------------------------------------------- /deck-extras/src/main/kotlin/conversation/Conversation.kt: -------------------------------------------------------------------------------- 1 | package io.github.srgaabriel.deck.extras.conversation 2 | 3 | import io.github.srgaabriel.deck.common.util.DeckExperimental 4 | import io.github.srgaabriel.deck.core.entity.Message 5 | import io.github.srgaabriel.deck.core.stateless.StatelessUser 6 | import io.github.srgaabriel.deck.rest.builder.SendMessageRequestBuilder 7 | import kotlinx.coroutines.CoroutineScope 8 | import kotlinx.coroutines.Job 9 | import kotlinx.coroutines.flow.Flow 10 | 11 | @DeckExperimental 12 | public interface Conversation: CoroutineScope { 13 | public val active: Boolean 14 | public val listeningJob: Job 15 | public val responseFlow: Flow 16 | 17 | public val user: StatelessUser 18 | 19 | public fun init() 20 | 21 | public fun end() 22 | 23 | public suspend fun ask(message: Message): ConversationMessage 24 | 25 | public suspend fun ask(message: SendMessageRequestBuilder.() -> Unit): ConversationMessage 26 | } -------------------------------------------------------------------------------- /deck-extras/src/main/kotlin/conversation/ConversationMessage.kt: -------------------------------------------------------------------------------- 1 | package io.github.srgaabriel.deck.extras.conversation 2 | 3 | import io.github.srgaabriel.deck.common.util.DeckExperimental 4 | import io.github.srgaabriel.deck.core.entity.Message 5 | import kotlinx.coroutines.* 6 | import kotlinx.coroutines.channels.Channel 7 | import kotlinx.coroutines.flow.buffer 8 | import kotlinx.coroutines.flow.first 9 | import kotlinx.coroutines.flow.launchIn 10 | import kotlinx.coroutines.flow.onEach 11 | 12 | @DeckExperimental 13 | public class ConversationMessage( 14 | public val conversation: Conversation, 15 | public val replyingTo: Message 16 | ) { 17 | @OptIn(ExperimentalCoroutinesApi::class) 18 | public suspend fun awaitReply(timeout: Long): Message? = withTimeoutOrNull(timeout) { 19 | suspendCancellableCoroutine { continuation -> 20 | conversation.launch { 21 | val message = conversation.responseFlow.buffer(Channel.UNLIMITED).first { conversation.active } 22 | continuation.resume(message) {} 23 | } 24 | } 25 | } 26 | 27 | public fun onReply(callback: suspend (Message) -> Unit): Job = 28 | conversation.responseFlow.buffer(Channel.UNLIMITED).onEach(callback).launchIn(conversation) 29 | } -------------------------------------------------------------------------------- /deck-extras/src/main/kotlin/misc/Logging.kt: -------------------------------------------------------------------------------- 1 | package io.github.srgaabriel.deck.extras.misc 2 | 3 | import com.github.ajalt.mordant.rendering.AnsiLevel 4 | import com.github.ajalt.mordant.rendering.TextColors 5 | import com.github.ajalt.mordant.terminal.Terminal 6 | import io.github.srgaabriel.deck.common.log.DeckLogger 7 | import io.github.srgaabriel.deck.common.log.LoggingLevel 8 | import io.github.srgaabriel.deck.common.log.LoggingMessage 9 | import io.github.srgaabriel.deck.core.util.ClientBuilder 10 | 11 | /** 12 | * Enables colored logging 13 | */ 14 | public fun ClientBuilder.coloredLogging() { 15 | val logger = MordantLogger() 16 | rest.logger = logger 17 | gateway.logger = logger 18 | } 19 | 20 | public class MordantLogger: DeckLogger { 21 | private val terminal = Terminal(tabWidth = 4, ansiLevel = AnsiLevel.TRUECOLOR) 22 | 23 | override fun log(level: LoggingLevel, message: LoggingMessage, exception: Throwable?) { 24 | val (prefix, color) = when(level) { 25 | LoggingLevel.Debug -> "\uD83E\uDDEA debug" to TextColors.brightBlue 26 | LoggingLevel.Info -> "\uD83D\uDCE8 info" to TextColors.brightGreen 27 | LoggingLevel.Warning -> "⚠ warning" to TextColors.brightYellow 28 | LoggingLevel.Error -> "❌ error" to TextColors.brightRed 29 | } 30 | fun String.asFormattedText() = replace("\n", "\n${" ".repeat(prefix.length)} ") 31 | 32 | val text = buildString { 33 | append(color(prefix)) 34 | append(": ") 35 | val message = message() 36 | append( 37 | (if (message is Throwable) 38 | message.stackTraceToString() 39 | else 40 | terminal.render(message)) 41 | .asFormattedText() 42 | ) 43 | if (exception != null) { 44 | append(exception.stackTraceToString().asFormattedText()) 45 | } 46 | } 47 | terminal.println(text) 48 | } 49 | } -------------------------------------------------------------------------------- /deck-extras/src/main/kotlin/misc/Reactions.kt: -------------------------------------------------------------------------------- 1 | package io.github.srgaabriel.deck.extras.misc 2 | 3 | import io.github.srgaabriel.deck.common.util.GenericId 4 | import io.github.srgaabriel.deck.common.util.IntGenericId 5 | import io.github.srgaabriel.deck.core.event.message.MessageReactionAddEvent 6 | import io.github.srgaabriel.deck.core.stateless.StatelessMessage 7 | import kotlinx.coroutines.Job 8 | 9 | /** 10 | * @param scope Where you'll handle the reaction event, return true to continue listening 11 | * to [MessageReactionAddEvent] or false to cancel the job. 12 | */ 13 | 14 | public suspend fun StatelessMessage.onReaction(scope: suspend MessageReactionAddEvent.() -> Boolean): Job { 15 | var job: Job? = null 16 | job = client.on { 17 | if (messageId != this@onReaction.id) 18 | return@on 19 | if (!scope()) 20 | job?.cancel() 21 | } 22 | return job 23 | } 24 | 25 | /** 26 | * @param userId The user you are expecting to react, leave null if there's 27 | * none particularly. If this user is defined and someone else reacts to the message besides him, it'll be simply ignored. 28 | * 29 | * @param reactionId The reaction you are expecting to get on your message, leave null if there's 30 | * none particularly. If this reaction is defined and the user reacts with another emote besides it, it'll be simply ignored. 31 | * 32 | * @param scope Where you'll handle the event when it's already known that both the provided [userId] and 33 | * [reactionId] are expected and correct. 34 | */ 35 | public suspend fun StatelessMessage.onReaction( 36 | userId: GenericId? = null, 37 | reactionId: IntGenericId? = null, 38 | scope: suspend MessageReactionAddEvent.() -> Boolean 39 | ): Job = onReaction onUncheckedReaction@ { 40 | if (userId != null && userId != this.userId) 41 | return@onUncheckedReaction true 42 | else if (reactionId != null && reactionId != emote.id) 43 | return@onUncheckedReaction true 44 | scope() 45 | } -------------------------------------------------------------------------------- /deck-gateway/build.gradle.kts: -------------------------------------------------------------------------------- 1 | plugins { 2 | `deck-publishing` 3 | } 4 | 5 | repositories { 6 | mavenCentral() 7 | } 8 | 9 | dependencies { 10 | implementation(kotlin("stdlib")) 11 | api(project(":deck-common")) 12 | implementation(libs.bundles.ktor.client.essentials) 13 | implementation(libs.ktor.client.websockets) 14 | implementation(libs.kotlin.logging.jvm) 15 | } -------------------------------------------------------------------------------- /deck-gateway/src/main/kotlin/Gateway.kt: -------------------------------------------------------------------------------- 1 | package io.github.srgaabriel.deck.gateway 2 | 3 | import io.github.srgaabriel.deck.gateway.event.GatewayEvent 4 | import kotlinx.coroutines.CoroutineScope 5 | import kotlinx.coroutines.Job 6 | import kotlinx.coroutines.flow.SharedFlow 7 | import kotlinx.coroutines.flow.StateFlow 8 | import java.util.concurrent.atomic.AtomicInteger 9 | 10 | /** 11 | * Base gateway interface 12 | */ 13 | public interface Gateway { 14 | public val id: Int 15 | 16 | public val state: StateFlow 17 | public val scope: CoroutineScope 18 | public val eventFlow: SharedFlow 19 | 20 | public var maxRetries: Int 21 | public val retryCounter: AtomicInteger 22 | // Null if not yet received 23 | public var lastMessageId: String? 24 | 25 | /** 26 | * Connects to the gateway, starts listening to its events and then starts to send pings to it. 27 | * 28 | * Calls [Gateway.connect], [Gateway.startListening], [Gateway.startPinging] respectively. 29 | */ 30 | public suspend fun start() 31 | 32 | /** 33 | * Connects to the gateway, but doesn't start listening yet 34 | * 35 | * @see start 36 | * @see startListening 37 | * @see startPinging 38 | */ 39 | public suspend fun connect() 40 | 41 | /** 42 | * Awaits for the Hello event and then starts sending heartbeats (pings) 43 | * accordingly 44 | */ 45 | public suspend fun startPinging(): Job 46 | 47 | /** 48 | * Starts listening to the websocket events 49 | */ 50 | public suspend fun startListening(): Job 51 | 52 | /** 53 | * Disconnects from the gateway. Set [expectingReconnect] to true to send 54 | * close reason of `SERVICE_RESTART` 55 | */ 56 | public suspend fun disconnect(expectingReconnect: Boolean = false) 57 | } -------------------------------------------------------------------------------- /deck-gateway/src/main/kotlin/GatewayOrchestrator.kt: -------------------------------------------------------------------------------- 1 | package io.github.srgaabriel.deck.gateway 2 | 3 | import io.github.srgaabriel.deck.common.log.DeckLogger 4 | import io.github.srgaabriel.deck.common.log.MicroutilsLogger 5 | import io.github.srgaabriel.deck.gateway.event.GatewayEvent 6 | import io.ktor.client.* 7 | import io.ktor.client.engine.cio.* 8 | import io.ktor.client.plugins.websocket.* 9 | import kotlinx.coroutines.CoroutineScope 10 | import kotlinx.coroutines.asCoroutineDispatcher 11 | import kotlinx.coroutines.flow.MutableSharedFlow 12 | import java.util.concurrent.Executors 13 | import java.util.concurrent.atomic.AtomicInteger 14 | import kotlin.coroutines.CoroutineContext 15 | 16 | public class GatewayOrchestrator(internal val token: String): CoroutineScope { 17 | override val coroutineContext: CoroutineContext = Executors 18 | .newFixedThreadPool(8) 19 | .asCoroutineDispatcher() 20 | internal val httpClient = HttpClient(CIO) { 21 | install(WebSockets) 22 | } 23 | public val globalEventsFlow: MutableSharedFlow = MutableSharedFlow() 24 | public var logger: DeckLogger = MicroutilsLogger("Gateway Logger") 25 | 26 | public var logEventPayloads: Boolean = false 27 | public val gateways: MutableMap = mutableMapOf() 28 | 29 | public var enableEventReplaying: Boolean = true 30 | 31 | private var gatewayIds = AtomicInteger(0) 32 | 33 | /** 34 | * Creates and returns a gateway without starting it 35 | * 36 | * @return the created gateway 37 | */ 38 | public fun createGateway(): Gateway { 39 | val gateway = DefaultGateway( 40 | id = gatewayIds.incrementAndGet(), 41 | orchestrator = this 42 | ) 43 | gateways[gateway.id] = gateway 44 | return gateway 45 | } 46 | 47 | /** 48 | * Starts the gateway 49 | * 50 | * @param id gateway id 51 | */ 52 | public suspend fun startGateway(id: Int) { 53 | gateways[id]?.start() 54 | } 55 | 56 | /** 57 | * Disconnects from the gateway without ditching it. 58 | * 59 | * @param id gateway id 60 | * @param expectingReconnect set to true to disconnect with `SERVICE_RESTART` code 61 | */ 62 | public suspend fun disconnectGateway(id: Int, expectingReconnect: Boolean = false) { 63 | val gateway = gateways[id] ?: return 64 | gateway.disconnect(expectingReconnect) 65 | } 66 | 67 | /** 68 | * Disconnects from the gateway and ditches it. 69 | * 70 | * @param id gateway id 71 | */ 72 | public suspend fun ditchGateway(id: Int) { 73 | disconnectGateway(id) 74 | gateways.remove(id) 75 | } 76 | } -------------------------------------------------------------------------------- /deck-gateway/src/main/kotlin/GatewayState.kt: -------------------------------------------------------------------------------- 1 | package io.github.srgaabriel.deck.gateway 2 | 3 | public enum class GatewayState { 4 | Active, 5 | Retrying, 6 | Replaying, 7 | Closed 8 | } -------------------------------------------------------------------------------- /deck-gateway/src/main/kotlin/entity/Messages.kt: -------------------------------------------------------------------------------- 1 | @file:UseSerializers(UUIDSerializer::class) 2 | 3 | package io.github.srgaabriel.deck.gateway.entity 4 | 5 | import io.github.srgaabriel.deck.common.util.GenericId 6 | import io.github.srgaabriel.deck.common.util.UUIDSerializer 7 | import kotlinx.datetime.Instant 8 | import kotlinx.serialization.Serializable 9 | import kotlinx.serialization.UseSerializers 10 | import java.util.* 11 | 12 | @Serializable 13 | public data class RawPartialDeletedMessage( 14 | public val id: UUID, 15 | public val serverId: GenericId, 16 | public val channelId: UUID, 17 | public val deletedAt: Instant 18 | ) -------------------------------------------------------------------------------- /deck-gateway/src/main/kotlin/entity/Reactions.kt: -------------------------------------------------------------------------------- 1 | @file:UseSerializers(UUIDSerializer::class) 2 | 3 | package io.github.srgaabriel.deck.gateway.entity 4 | 5 | import io.github.srgaabriel.deck.common.entity.RawEmote 6 | import io.github.srgaabriel.deck.common.util.GenericId 7 | import io.github.srgaabriel.deck.common.util.IntGenericId 8 | import io.github.srgaabriel.deck.common.util.UUIDSerializer 9 | import kotlinx.serialization.Serializable 10 | import kotlinx.serialization.UseSerializers 11 | import java.util.* 12 | 13 | @Serializable 14 | public data class RawMessageReaction( 15 | val channelId: UUID, 16 | val messageId: UUID, 17 | val createdBy: GenericId, 18 | val emote: RawEmote 19 | ) 20 | 21 | @Serializable 22 | public data class RawForumTopicReaction( 23 | val channelId: UUID, 24 | val createdBy: GenericId, 25 | val emote: RawEmote, 26 | val forumTopicId: IntGenericId 27 | ) 28 | 29 | @Serializable 30 | public data class RawForumTopicCommentReaction( 31 | val channelId: UUID, 32 | val createdBy: GenericId, 33 | val emote: RawEmote, 34 | val forumTopicId: IntGenericId, 35 | val forumTopicCommentId: IntGenericId 36 | ) 37 | 38 | @Serializable 39 | public data class RawCalendarEventReaction( 40 | val channelId: UUID, 41 | val createdBy: GenericId, 42 | val emote: RawEmote, 43 | val calendarEventId: IntGenericId 44 | ) 45 | 46 | @Serializable 47 | public data class RawCalendarEventCommentReaction( 48 | val channelId: UUID, 49 | val createdBy: GenericId, 50 | val emote: RawEmote, 51 | val calendarEventId: IntGenericId, 52 | val calendarEventCommentId: IntGenericId 53 | ) 54 | 55 | @Serializable 56 | public data class RawDocumentationReaction( 57 | val channelId: UUID, 58 | val createdBy: GenericId, 59 | val emote: RawEmote, 60 | val docId: IntGenericId 61 | ) 62 | 63 | @Serializable 64 | public data class RawDocumentationCommentReaction( 65 | val channelId: UUID, 66 | val createdBy: GenericId, 67 | val emote: RawEmote, 68 | val docId: IntGenericId, 69 | val docCommentId: IntGenericId 70 | ) -------------------------------------------------------------------------------- /deck-gateway/src/main/kotlin/entity/User.kt: -------------------------------------------------------------------------------- 1 | @file:UseSerializers(UUIDSerializer::class) 2 | 3 | package io.github.srgaabriel.deck.gateway.entity 4 | 5 | import io.github.srgaabriel.deck.common.entity.UserType 6 | import io.github.srgaabriel.deck.common.util.GenericId 7 | import io.github.srgaabriel.deck.common.util.IntGenericId 8 | import io.github.srgaabriel.deck.common.util.OptionalProperty 9 | import io.github.srgaabriel.deck.common.util.UUIDSerializer 10 | import kotlinx.datetime.Instant 11 | import kotlinx.serialization.Serializable 12 | import kotlinx.serialization.UseSerializers 13 | import java.util.* 14 | 15 | @Serializable 16 | public data class RawBot( 17 | val id: GenericId, 18 | val type: UserType = UserType.USER, 19 | val avatar: OptionalProperty = OptionalProperty.NotPresent, 20 | val banner: OptionalProperty = OptionalProperty.NotPresent, 21 | val botId: UUID, 22 | val name: String, 23 | val createdAt: Instant, 24 | val createdBy: GenericId 25 | ) 26 | 27 | @Serializable 28 | public data class RawServerMemberInfo( 29 | val id: GenericId, 30 | val nickname: OptionalProperty = OptionalProperty.NotPresent 31 | ) 32 | 33 | @Serializable 34 | public data class RawServerRoleUpdate( 35 | val userId: GenericId, 36 | val roleIds: List 37 | ) -------------------------------------------------------------------------------- /deck-gateway/src/main/kotlin/event/type/GeneralEvents.kt: -------------------------------------------------------------------------------- 1 | package io.github.srgaabriel.deck.gateway.event.type 2 | 3 | import io.github.srgaabriel.deck.gateway.entity.RawBot 4 | import io.github.srgaabriel.deck.gateway.event.GatewayEvent 5 | import kotlinx.serialization.SerialName 6 | import kotlinx.serialization.Serializable 7 | 8 | @Serializable 9 | @SerialName("HelloEvent") 10 | public data class GatewayHelloEvent( 11 | val heartbeatIntervalMs: Long, 12 | val lastMessageId: String, 13 | @SerialName("user") 14 | val self: RawBot 15 | ) : GatewayEvent() 16 | 17 | @Serializable 18 | @SerialName("ResumeEvent") 19 | public data class GatewayResumeEvent( 20 | @SerialName("s") 21 | val messageId: String 22 | ) : GatewayEvent() -------------------------------------------------------------------------------- /deck-gateway/src/main/kotlin/event/type/MessageEvents.kt: -------------------------------------------------------------------------------- 1 | package io.github.srgaabriel.deck.gateway.event.type 2 | 3 | import io.github.srgaabriel.deck.common.entity.RawMessage 4 | import io.github.srgaabriel.deck.common.util.GenericId 5 | import io.github.srgaabriel.deck.gateway.entity.RawPartialDeletedMessage 6 | import io.github.srgaabriel.deck.gateway.event.GatewayEvent 7 | import kotlinx.serialization.SerialName 8 | import kotlinx.serialization.Serializable 9 | 10 | @Serializable 11 | @SerialName("ChatMessageCreated") 12 | public data class GatewayChatMessageCreatedEvent( 13 | public val serverId: GenericId, 14 | public val message: RawMessage 15 | ): GatewayEvent() 16 | 17 | @Serializable 18 | @SerialName("ChatMessageUpdated") 19 | public data class GatewayChatMessageUpdatedEvent( 20 | public val serverId: GenericId, 21 | public val message: RawMessage 22 | ): GatewayEvent() 23 | 24 | @Serializable 25 | @SerialName("ChatMessageDeleted") 26 | public data class GatewayChatMessageDeletedEvent( 27 | public val serverId: GenericId, 28 | public val message: RawPartialDeletedMessage 29 | ): GatewayEvent() -------------------------------------------------------------------------------- /deck-gateway/src/main/kotlin/event/type/ServerEvents.kt: -------------------------------------------------------------------------------- 1 | package io.github.srgaabriel.deck.gateway.event.type 2 | 3 | import io.github.srgaabriel.deck.common.entity.RawWebhook 4 | import io.github.srgaabriel.deck.common.util.GenericId 5 | import io.github.srgaabriel.deck.gateway.entity.RawServerRoleUpdate 6 | import io.github.srgaabriel.deck.gateway.event.GatewayEvent 7 | import kotlinx.serialization.SerialName 8 | import kotlinx.serialization.Serializable 9 | 10 | @Serializable 11 | @SerialName("ServerRolesUpdated") 12 | public data class GatewayServerRolesUpdatedEvent( 13 | val serverId: GenericId, 14 | val memberRoleIds: List 15 | ): GatewayEvent() 16 | 17 | @Serializable 18 | @SerialName("ServerWebhookCreated") 19 | public data class GatewayServerWebhookCreatedEvent( 20 | val serverId: GenericId, 21 | val webhook: RawWebhook 22 | ): GatewayEvent() 23 | 24 | @Serializable 25 | @SerialName("ServerWebhookUpdated") 26 | public data class GatewayServerWebhookUpdatedEvent( 27 | val serverId: GenericId, 28 | val webhook: RawWebhook 29 | ): GatewayEvent() -------------------------------------------------------------------------------- /deck-gateway/src/main/kotlin/util/Events.kt: -------------------------------------------------------------------------------- 1 | package io.github.srgaabriel.deck.gateway.util 2 | 3 | import io.github.srgaabriel.deck.gateway.Gateway 4 | import io.github.srgaabriel.deck.gateway.GatewayOrchestrator 5 | import io.github.srgaabriel.deck.gateway.event.GatewayEvent 6 | import kotlinx.coroutines.* 7 | import kotlinx.coroutines.channels.Channel 8 | import kotlinx.coroutines.flow.* 9 | 10 | public inline fun Gateway.on( 11 | scope: CoroutineScope = this.scope, 12 | noinline callback: suspend T.() -> Unit 13 | ): Job = on(id, scope, eventFlow, callback) 14 | 15 | public suspend inline fun Gateway.await( 16 | timeout: Long, 17 | scope: CoroutineScope = this.scope, 18 | ): T? = await(id, scope, eventFlow, timeout) 19 | 20 | public inline fun GatewayOrchestrator.on( 21 | scope: CoroutineScope = this, 22 | gatewayId: Int? = null, 23 | noinline callback: suspend T.() -> Unit 24 | ): Job = on(gatewayId, scope, globalEventsFlow, callback) 25 | 26 | public suspend inline fun GatewayOrchestrator.await( 27 | timeout: Long, 28 | scope: CoroutineScope = this, 29 | gatewayId: Int? = null 30 | ): T? = await(gatewayId, scope, globalEventsFlow, timeout) 31 | 32 | public inline fun on( 33 | gatewayId: Int?, 34 | scope: CoroutineScope, 35 | eventsFlow: SharedFlow, 36 | noinline callback: suspend T.() -> Unit 37 | ): Job = eventsFlow.buffer(Channel.UNLIMITED).filterIsInstance() 38 | .filter { it.info.gatewayId == (gatewayId ?: return@filter true) } 39 | .onEachHandlingErrors(callback) 40 | .launchIn(scope) 41 | 42 | @OptIn(ExperimentalCoroutinesApi::class) 43 | public suspend inline fun await( 44 | gatewayId: Int?, 45 | scope: CoroutineScope, 46 | eventsFlow: SharedFlow, 47 | timeout: Long 48 | ): T? = withTimeoutOrNull(timeout) { 49 | suspendCancellableCoroutine { continuation -> 50 | scope.launch { 51 | val event = eventsFlow.buffer(Channel.UNLIMITED).filterIsInstance() 52 | .filter { it.info.gatewayId == (gatewayId ?: return@filter true) }.first() 53 | continuation.resume(event) {} 54 | } 55 | } 56 | } 57 | 58 | public inline fun Flow.onEachHandlingErrors(crossinline callback: suspend T.() -> Unit): Flow = 59 | onEach { 60 | try { 61 | callback(it) 62 | } catch (exception: CancellationException) { 63 | throw exception 64 | } catch (throwable: Throwable) { 65 | throwable.printStackTrace() 66 | } 67 | } -------------------------------------------------------------------------------- /deck-gateway/src/main/kotlin/util/GatewayConstants.kt: -------------------------------------------------------------------------------- 1 | package io.github.srgaabriel.deck.gateway.util 2 | 3 | public object GatewayConstants { 4 | // According to RFC 6455 5 | public const val GatewayPing: String = "9" 6 | public const val GatewayPong: String = "10" 7 | } -------------------------------------------------------------------------------- /deck-gateway/src/main/kotlin/util/GatewayOpcode.kt: -------------------------------------------------------------------------------- 1 | package io.github.srgaabriel.deck.gateway.util 2 | 3 | public object GatewayOpcode { 4 | public const val Dispatch: Int = 0 5 | public const val Hello: Int = 1 6 | public const val Resume: Int = 2 7 | public const val Error: Int = 8 8 | public const val InternalError: Int = 9 9 | } -------------------------------------------------------------------------------- /deck-rest/build.gradle.kts: -------------------------------------------------------------------------------- 1 | plugins { 2 | `deck-publishing` 3 | } 4 | 5 | repositories { 6 | mavenCentral() 7 | } 8 | 9 | dependencies { 10 | implementation(kotlin("stdlib")) 11 | api(project(":deck-common")) 12 | implementation(libs.bundles.ktor.client.essentials) 13 | implementation(libs.ktor.client.logging) 14 | implementation(libs.ktor.client.content.negotation) 15 | implementation(libs.kotlin.logging.jvm) 16 | } -------------------------------------------------------------------------------- /deck-rest/src/main/kotlin/RestClient.kt: -------------------------------------------------------------------------------- 1 | package io.github.srgaabriel.deck.rest 2 | 3 | import io.github.srgaabriel.deck.common.log.DeckLogger 4 | import io.github.srgaabriel.deck.common.log.MicroutilsLogger 5 | import io.github.srgaabriel.deck.rest.route.* 6 | import io.github.srgaabriel.deck.rest.util.RequestService 7 | import io.github.srgaabriel.deck.rest.util.createHttpClient 8 | import io.ktor.client.* 9 | import io.ktor.client.plugins.* 10 | import io.ktor.client.plugins.logging.* 11 | 12 | public class RestClient(public val token: String) { 13 | public var logger: DeckLogger = MicroutilsLogger("Rest Client Logger") 14 | 15 | public var httpClient: HttpClient = createHttpClient() 16 | public val requestService: RequestService = RequestService(httpClient, this) 17 | 18 | // ALL by default 19 | public var logLevel: LogLevel 20 | get() = httpClient.plugin(Logging).level 21 | set(value) { httpClient.plugin(Logging).level = value } 22 | 23 | public var logRequests: Boolean = false 24 | 25 | public val channel: ChannelRoutes = ChannelRoutes(this) 26 | public val group: GroupRoutes = GroupRoutes(this) 27 | public val server: ServerRoutes = ServerRoutes(this) 28 | public val user: UserRoutes = UserRoutes(this) 29 | public val webhook: WebhookRoutes = WebhookRoutes(this) 30 | } -------------------------------------------------------------------------------- /deck-rest/src/main/kotlin/builder/RequestBuilder.kt: -------------------------------------------------------------------------------- 1 | package io.github.srgaabriel.deck.rest.builder 2 | 3 | /** 4 | * Structures heavily inspired on the discord Kotlin 5 | * library Kord (see README.md) 6 | */ 7 | public interface RequestBuilder { 8 | public fun toRequest(): T 9 | } -------------------------------------------------------------------------------- /deck-rest/src/main/kotlin/builder/WebhookBuilders.kt: -------------------------------------------------------------------------------- 1 | package io.github.srgaabriel.deck.rest.builder 2 | 3 | import io.github.srgaabriel.deck.common.Embed 4 | import io.github.srgaabriel.deck.common.EmbedBuilder 5 | import io.github.srgaabriel.deck.common.util.nullableOptional 6 | import io.github.srgaabriel.deck.rest.request.CreateWebhookRequest 7 | import io.github.srgaabriel.deck.rest.request.ExecuteWebhookRequest 8 | import io.github.srgaabriel.deck.rest.request.UpdateWebhookRequest 9 | import io.github.srgaabriel.deck.rest.util.required 10 | import kotlinx.serialization.json.JsonElement 11 | import kotlinx.serialization.json.JsonPrimitive 12 | import kotlinx.serialization.json.jsonPrimitive 13 | import java.util.* 14 | 15 | public class CreateWebhookRequestBuilder: RequestBuilder { 16 | public var name: String by required() 17 | public var channelId: UUID by required() 18 | 19 | override fun toRequest(): CreateWebhookRequest = CreateWebhookRequest( 20 | name = name, 21 | channelId = channelId 22 | ) 23 | } 24 | 25 | public class UpdateWebhookRequestBuilder: RequestBuilder { 26 | public var name: String by required() 27 | public var channelId: UUID? = null 28 | 29 | override fun toRequest(): UpdateWebhookRequest = UpdateWebhookRequest( 30 | name = name, 31 | channelId = channelId.nullableOptional() 32 | ) 33 | } 34 | 35 | public class ExecuteWebhookRequestBuilder: RequestBuilder { 36 | public var isPrivate: Boolean = false 37 | public val repliesTo: MutableList = mutableListOf() 38 | 39 | public var content: String? 40 | set(value) { 41 | contentElement = if (value == null) null else JsonPrimitive(value) 42 | } 43 | get() = contentElement?.jsonPrimitive?.content 44 | public var contentElement: JsonElement? = null 45 | 46 | public var embeds: List = listOf() 47 | public val silent: Boolean = false 48 | 49 | public var username: String? = null 50 | public var avatar: String? = null 51 | 52 | public fun replyTo(vararg messageIds: UUID): Unit = 53 | repliesTo.addAll(messageIds).let {} 54 | 55 | public fun embed(builder: EmbedBuilder.() -> Unit) { 56 | embeds = embeds + EmbedBuilder().apply(builder).build() 57 | } 58 | 59 | override fun toRequest(): ExecuteWebhookRequest = ExecuteWebhookRequest( 60 | content = contentElement, 61 | embeds = embeds.map { it.toSerializable() }, 62 | isPrivate = isPrivate, 63 | isSilent = silent, 64 | replyMessageIds = repliesTo, 65 | username = username, 66 | avatarUrl = avatar 67 | ) 68 | } -------------------------------------------------------------------------------- /deck-rest/src/main/kotlin/request/MemberRequests.kt: -------------------------------------------------------------------------------- 1 | package io.github.srgaabriel.deck.rest.request 2 | 3 | import io.github.srgaabriel.deck.common.entity.RawServerBan 4 | import io.github.srgaabriel.deck.common.entity.RawUserSocialLink 5 | import kotlinx.serialization.Serializable 6 | 7 | @Serializable 8 | public data class UpdateMemberNicknameRequest( 9 | val nickname: String 10 | ) 11 | 12 | @Serializable 13 | public data class GetMemberRolesResponse( 14 | val roleIds: List 15 | ) 16 | 17 | @Serializable 18 | public data class GetMemberSocialLinkResponse( 19 | val socialLink: RawUserSocialLink 20 | ) 21 | 22 | @Serializable 23 | public data class GetServerMemberBanResponse( 24 | val serverMemberBan: RawServerBan 25 | ) 26 | 27 | @Serializable 28 | public data class MemberModifyXpAmountDAO constructor( 29 | val amount: Int 30 | ) 31 | 32 | @Serializable 33 | public data class MemberModifyXpTotalDAO( 34 | val total: Int 35 | ) -------------------------------------------------------------------------------- /deck-rest/src/main/kotlin/request/ServerRequests.kt: -------------------------------------------------------------------------------- 1 | package io.github.srgaabriel.deck.rest.request 2 | 3 | import io.github.srgaabriel.deck.common.entity.RawServer 4 | import io.github.srgaabriel.deck.common.entity.RawServerBan 5 | import io.github.srgaabriel.deck.common.entity.RawServerMember 6 | import io.github.srgaabriel.deck.common.entity.RawServerMemberSummary 7 | import kotlinx.serialization.Serializable 8 | 9 | @Serializable 10 | public data class GetServerResponse( 11 | val server: RawServer, 12 | ) 13 | 14 | @Serializable 15 | public data class GetServerMemberResponse( 16 | val member: RawServerMember 17 | ) 18 | 19 | @Serializable 20 | public data class GetServerMembersResponse( 21 | val members: List 22 | ) 23 | 24 | @Serializable 25 | public data class GetServerBansResponse( 26 | val serverMemberBans: List 27 | ) -------------------------------------------------------------------------------- /deck-rest/src/main/kotlin/request/WebhookRequests.kt: -------------------------------------------------------------------------------- 1 | @file:UseSerializers(UUIDSerializer::class) 2 | 3 | package io.github.srgaabriel.deck.rest.request 4 | 5 | import io.github.srgaabriel.deck.common.entity.RawEmbed 6 | import io.github.srgaabriel.deck.common.entity.RawWebhook 7 | import io.github.srgaabriel.deck.common.util.GenericId 8 | import io.github.srgaabriel.deck.common.util.OptionalProperty 9 | import io.github.srgaabriel.deck.common.util.UUIDSerializer 10 | import kotlinx.datetime.Instant 11 | import kotlinx.serialization.SerialName 12 | import kotlinx.serialization.Serializable 13 | import kotlinx.serialization.UseSerializers 14 | import kotlinx.serialization.json.JsonElement 15 | import kotlinx.serialization.json.JsonObject 16 | import java.util.* 17 | 18 | @Serializable 19 | public data class CreateWebhookRequest( 20 | public val name: String, 21 | public val channelId: UUID 22 | ) 23 | 24 | @Serializable 25 | public data class CreateWebhookResponse( 26 | public val webhook: RawWebhook 27 | ) 28 | 29 | @Serializable 30 | public data class UpdateWebhookRequest( 31 | public val name: String, 32 | public val channelId: OptionalProperty 33 | ) 34 | 35 | @Serializable 36 | public data class GetServerWebhooksResponse( 37 | public val webhooks: List 38 | ) 39 | 40 | @Serializable 41 | public data class ExecuteWebhookRequest( 42 | public val content: JsonElement? = null, 43 | public val embeds: List = emptyList(), 44 | public val isPrivate: Boolean, 45 | public val isSilent: Boolean, 46 | public val replyMessageIds: List = emptyList(), 47 | public val username: String? = null, 48 | @SerialName("avatar_url") 49 | public val avatarUrl: String? = null 50 | ) 51 | 52 | @Serializable 53 | public data class ExecuteWebhookResponse( 54 | public val id: UUID, 55 | public val channelId: UUID, 56 | public val content: OptionalProperty = OptionalProperty.NotPresent, 57 | public val embeds: OptionalProperty> = OptionalProperty.NotPresent, 58 | public val type: String, 59 | public val createdBy: GenericId, 60 | public val createdAt: Instant, 61 | public val webhookId: UUID 62 | ) -------------------------------------------------------------------------------- /deck-rest/src/main/kotlin/route/GroupRoutes.kt: -------------------------------------------------------------------------------- 1 | package io.github.srgaabriel.deck.rest.route 2 | 3 | import io.github.srgaabriel.deck.common.util.GenericId 4 | import io.github.srgaabriel.deck.rest.RestClient 5 | import io.github.srgaabriel.deck.rest.util.sendRequest 6 | import io.ktor.http.* 7 | 8 | public class GroupRoutes(private val client: RestClient) { 9 | public suspend fun addMember( 10 | userId: GenericId, 11 | groupId: GenericId 12 | ): Unit = client.sendRequest( 13 | endpoint = "/groups/$groupId/members/$userId", 14 | method = HttpMethod.Put 15 | ) 16 | 17 | public suspend fun removeMember( 18 | userId: GenericId, 19 | groupId: GenericId 20 | ): Unit = client.sendRequest( 21 | endpoint = "/groups/$groupId/members/$userId", 22 | method = HttpMethod.Delete 23 | ) 24 | } -------------------------------------------------------------------------------- /deck-rest/src/main/kotlin/route/UserRoutes.kt: -------------------------------------------------------------------------------- 1 | package io.github.srgaabriel.deck.rest.route 2 | 3 | import io.github.srgaabriel.deck.common.entity.RawUser 4 | import io.github.srgaabriel.deck.common.util.GenericId 5 | import io.github.srgaabriel.deck.rest.RestClient 6 | import io.github.srgaabriel.deck.rest.util.sendRequest 7 | import io.ktor.http.* 8 | 9 | public class UserRoutes(private val client: RestClient) { 10 | public suspend fun getSelf(): RawUser = getUser("@me") 11 | 12 | public suspend fun getUser(userId: GenericId): RawUser = client.sendRequest( 13 | endpoint = "/users/${userId}", 14 | method = HttpMethod.Get 15 | ) 16 | } -------------------------------------------------------------------------------- /deck-rest/src/main/kotlin/util/Exceptions.kt: -------------------------------------------------------------------------------- 1 | package io.github.srgaabriel.deck.rest.util 2 | 3 | import kotlinx.serialization.Serializable 4 | 5 | public class GuildedRequestException( 6 | code: String, 7 | message: String 8 | ) : RuntimeException("[$code] $message") 9 | 10 | @Serializable 11 | public data class RawGuildedRequestException( 12 | val code: String, 13 | val message: String 14 | ) 15 | 16 | // We inline the function, so it doesn't appear in stack traces. 17 | @Suppress("NOTHING_TO_INLINE") 18 | public inline fun RawGuildedRequestException.toException(): GuildedRequestException = 19 | GuildedRequestException(code, message) -------------------------------------------------------------------------------- /deck-rest/src/main/kotlin/util/Logging.kt: -------------------------------------------------------------------------------- 1 | package io.github.srgaabriel.deck.rest.util 2 | 3 | import io.github.srgaabriel.deck.common.log.debug 4 | import io.github.srgaabriel.deck.rest.RestClient 5 | import io.ktor.client.plugins.logging.* 6 | 7 | public class KtorDeckLoggerWrapper(public val client: RestClient): Logger { 8 | override fun log(message: String) { 9 | if (!client.logRequests) 10 | return 11 | val messageToBeLogged = message 12 | .replace(client.token, "") // Hide token 13 | .replace(client.token.drop(5), "") // Hide token in case it is logged without the default prefix (`gapi_`) 14 | client.logger.debug { messageToBeLogged } 15 | } 16 | } -------------------------------------------------------------------------------- /deck-rest/src/main/kotlin/util/Properties.kt: -------------------------------------------------------------------------------- 1 | package io.github.srgaabriel.deck.rest.util 2 | 3 | import io.github.srgaabriel.deck.common.util.OptionalProperty 4 | import io.github.srgaabriel.deck.rest.builder.RequestBuilder 5 | import kotlin.contracts.ExperimentalContracts 6 | import kotlin.contracts.InvocationKind 7 | import kotlin.contracts.contract 8 | import kotlin.reflect.KProperty 9 | 10 | public class RequiredRequestField { 11 | private var value: OptionalProperty = OptionalProperty.NotPresent 12 | 13 | public operator fun getValue(thisRef: Any, property: KProperty<*>): A = 14 | if (value is OptionalProperty.Present) (value as OptionalProperty.Present).value else error("You must provide a value to the ${property.name} field!") 15 | 16 | public operator fun setValue(thisRef: Any, property: KProperty<*>, value: A) { 17 | this.value = OptionalProperty.Present(value) 18 | } 19 | } 20 | 21 | @Suppress("unused") 22 | public fun RequestBuilder<*>.required(): RequiredRequestField = RequiredRequestField() 23 | 24 | @OptIn(ExperimentalContracts::class) 25 | internal fun String.plusIf(condition: Boolean, text: () -> String): String { 26 | contract { 27 | callsInPlace(text, InvocationKind.AT_MOST_ONCE) 28 | } 29 | return if (condition) this + text() else this 30 | } -------------------------------------------------------------------------------- /deck-rest/src/main/kotlin/util/Requests.kt: -------------------------------------------------------------------------------- 1 | package io.github.srgaabriel.deck.rest.util 2 | 3 | import io.github.srgaabriel.deck.common.util.Constants 4 | import io.github.srgaabriel.deck.common.util.DeckInternalApi 5 | import io.github.srgaabriel.deck.rest.RestClient 6 | import io.ktor.client.* 7 | import io.ktor.client.call.* 8 | import io.ktor.client.request.* 9 | import io.ktor.client.statement.* 10 | import io.ktor.http.* 11 | 12 | public data class Request( 13 | val method: HttpMethod, 14 | val api: String = Constants.GuildedRestApi, 15 | val endpoint: String, 16 | val body: S? = null, 17 | val token: String? = null, 18 | val address: GuildedAddress = GuildedAddress.API 19 | ) 20 | 21 | public class RequestService( 22 | public val client: HttpClient, 23 | public val rest: RestClient 24 | ) { 25 | @OptIn(DeckInternalApi::class) 26 | public suspend inline fun superviseRequest( 27 | request: Request, 28 | failureHandler: FailureHandler = FailureHandler 29 | ): G { 30 | val response = scheduleRequest(request) 31 | return if (!response.status.isSuccess()) { 32 | failureHandler.onFailure(response) 33 | } else { 34 | response.body() 35 | } 36 | } 37 | 38 | @DeckInternalApi 39 | public suspend inline fun scheduleRequest(request: Request): HttpResponse = client.request(request.address.uri + request.endpoint) { 40 | if (request.body != null) 41 | setBody(request.body) 42 | method = request.method 43 | 44 | header(HttpHeaders.ContentType, ContentType.Application.Json) 45 | if (request.token != null) 46 | header(HttpHeaders.Authorization, "Bearer ${request.token}") 47 | } 48 | } 49 | 50 | public interface FailureHandler { 51 | public suspend fun onFailure(response: HttpResponse): G 52 | 53 | public companion object Default: FailureHandler { 54 | override suspend fun onFailure(response: HttpResponse): G { 55 | throw response.body().toException() 56 | } 57 | } 58 | } 59 | 60 | public enum class GuildedAddress(public val uri: String) { 61 | MEDIA(Constants.GuildedMedia), 62 | API(Constants.GuildedRestApi) 63 | } -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | kotlin.code.style=official 2 | org.gradle.jvmargs=-Dkotlin.daemon.jvm.options=--illegal-access=permit 3 | systemProp.org.gradle.internal.publish.checksums.insecure=true -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SrGaabriel/deck/1d55bdcd6576ee671b842f635631a920ffba5a41/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-7.6-all.zip 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SrGaabriel/deck/1d55bdcd6576ee671b842f635631a920ffba5a41/gradlew -------------------------------------------------------------------------------- /libs.versions.toml: -------------------------------------------------------------------------------- 1 | [versions] 2 | kotlin = "1.7.10" 3 | 4 | kotlinx-datetime = "0.3.2" 5 | kotlinx-coroutines = "1.6.4" 6 | kotlinx-serialization = "1.3.3" 7 | 8 | ktor = "2.1.0" 9 | kotlinx-logging = "2.1.23" 10 | 11 | mordant = "2.0.0-beta6" 12 | logback = "1.2.11" 13 | 14 | mockk = "1.12.5" 15 | valiktor = "0.12.0" 16 | 17 | [libraries] 18 | ktor-client-core = { module = "io.ktor:ktor-client-core", version.ref = "ktor" } 19 | ktor-client-cio = { module = "io.ktor:ktor-client-cio", version.ref = "ktor" } 20 | ktor-client-logging = { module = "io.ktor:ktor-client-logging", version.ref = "ktor" } 21 | ktor-client-websockets = { module = "io.ktor:ktor-client-websockets", version.ref = "ktor" } 22 | ktor-client-serialization = { module = "io.ktor:ktor-client-serialization", version.ref = "ktor" } 23 | ktor-client-content-negotation = { module = "io.ktor:ktor-client-content-negotiation", version.ref = "ktor" } 24 | 25 | ktor-serialization-json = { module = "io.ktor:ktor-serialization-kotlinx-json", version.ref = "ktor" } 26 | 27 | kotlinx-coroutines = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-core", version.ref = "kotlinx-coroutines" } 28 | kotlinx-datetime = { module = "org.jetbrains.kotlinx:kotlinx-datetime", version.ref = "kotlinx-datetime" } 29 | kotlinx-serialization-json = { module = "org.jetbrains.kotlinx:kotlinx-serialization-json", version.ref = "kotlinx-serialization" } 30 | 31 | kotlin-logging-jvm = { module = "io.github.microutils:kotlin-logging-jvm", version.ref = "kotlinx-logging" } 32 | 33 | mordant = { module = "com.github.ajalt.mordant:mordant", version.ref = "mordant" } 34 | logback = { module = "ch.qos.logback:logback-classic", version.ref = "logback" } 35 | 36 | mockk = { module = "io.mockk:mockk", version.ref = "mockk" } 37 | valiktor-core = { module = "org.valiktor:valiktor-core", version.ref = "valiktor" } 38 | 39 | [bundles] 40 | ktor-client-essentials = ["ktor-client-core", "ktor-client-cio", "ktor-serialization-json"] 41 | 42 | [plugins] 43 | kotlin-jvm = { id = "org.jetbrains.kotlin.jvm", version.ref = "kotlin" } 44 | kotlinx-serialization = { id = "org.jetbrains.kotlin.plugin.serialization", version.ref = "kotlin" } 45 | dokka = { id = "org.jetbrains.dokka", version.ref = "kotlin" } -------------------------------------------------------------------------------- /settings.gradle.kts: -------------------------------------------------------------------------------- 1 | rootProject.name = "deck" 2 | 3 | enableFeaturePreview("VERSION_CATALOGS") 4 | 5 | dependencyResolutionManagement { 6 | versionCatalogs { 7 | create("libs") { 8 | from(files("libs.versions.toml")) 9 | } 10 | } 11 | } 12 | 13 | include("deck-common") 14 | include("deck-rest") 15 | include("deck-gateway") 16 | include("deck-core") 17 | include("deck-extras") --------------------------------------------------------------------------------