-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1050318
commit d119136
Showing
11 changed files
with
256 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
plugins { | ||
id("cloud-discord.kotlin-conventions") | ||
id("cloud-discord.publishing-conventions") | ||
} | ||
|
||
dependencies { | ||
api(projects.cloudDiscordCommon) | ||
api(libs.bundles.coroutines) | ||
|
||
implementation(libs.cloud.annotations) | ||
implementation(libs.kord) | ||
|
||
testImplementation(libs.mockito.kotlin) | ||
} |
49 changes: 49 additions & 0 deletions
49
cloud-kord/src/main/kotlin/org/incendo/cloud/discord/kord/KordCommandManager.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
// | ||
// MIT License | ||
// | ||
// Copyright (c) 2024 Incendo | ||
// | ||
// Permission is hereby granted, free of charge, to any person obtaining a copy | ||
// of this software and associated documentation files (the "Software"), to deal | ||
// in the Software without restriction, including without limitation the rights | ||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
// copies of the Software, and to permit persons to whom the Software is | ||
// furnished to do so, subject to the following conditions: | ||
// | ||
// The above copyright notice and this permission notice shall be included in all | ||
// copies or substantial portions of the Software. | ||
// | ||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
// SOFTWARE. | ||
// | ||
package org.incendo.cloud.discord.kord | ||
|
||
import cloud.commandframework.CommandManager | ||
import cloud.commandframework.execution.ExecutionCoordinator | ||
import cloud.commandframework.internal.CommandRegistrationHandler | ||
import org.apiguardian.api.API | ||
|
||
/** | ||
* Command manager for Kord. | ||
* | ||
* @param C command sender type | ||
* @since 1.0.0 | ||
*/ | ||
@API(status = API.Status.STABLE, since = "1.0.0") | ||
public class KordCommandManager<C : Any>(executionCoordinator: ExecutionCoordinator<C>) : CommandManager<C>( | ||
executionCoordinator, | ||
CommandRegistrationHandler.nullCommandRegistrationHandler() | ||
) { | ||
|
||
/** | ||
* Predicate used to evaluate sender permissions. | ||
*/ | ||
public var permissionPredicate: (C, String) -> Boolean = { _, _ -> true } | ||
|
||
override fun hasPermission(sender: C, permission: String): Boolean = permissionPredicate(sender, permission) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
plugins { | ||
id("cloud-discord.kotlin-conventions") | ||
application | ||
} | ||
|
||
indra { | ||
javaVersions { | ||
minimumToolchain(17) | ||
target(17) | ||
testWith().set(setOf(17)) | ||
} | ||
} | ||
|
||
dependencies { | ||
implementation(projects.cloudKord) | ||
implementation(libs.cloud.annotations) | ||
implementation(libs.kord) | ||
implementation(libs.kotlin.logging) | ||
implementation(libs.logback.core) | ||
implementation(libs.logback.classic) | ||
} | ||
|
||
application { | ||
mainClass = "org.incendo.cloud.discord.kord.example.ExampleBotKt" | ||
} |
49 changes: 49 additions & 0 deletions
49
...s/example-kord/src/main/kotlin/org/incendo/cloud/discord/kord/example/BotConfiguration.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
// | ||
// MIT License | ||
// | ||
// Copyright (c) 2024 Incendo | ||
// | ||
// Permission is hereby granted, free of charge, to any person obtaining a copy | ||
// of this software and associated documentation files (the "Software"), to deal | ||
// in the Software without restriction, including without limitation the rights | ||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
// copies of the Software, and to permit persons to whom the Software is | ||
// furnished to do so, subject to the following conditions: | ||
// | ||
// The above copyright notice and this permission notice shall be included in all | ||
// copies or substantial portions of the Software. | ||
// | ||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
// SOFTWARE. | ||
// | ||
package org.incendo.cloud.discord.kord.example | ||
|
||
import java.io.File | ||
import java.io.FileReader | ||
import java.util.Properties | ||
|
||
/** | ||
* Configuration for the example bot. | ||
*/ | ||
public interface BotConfiguration { | ||
|
||
/** | ||
* The bot token. | ||
*/ | ||
public val token: String | ||
} | ||
|
||
internal class PropertiesBotConfiguration private constructor(private val properties: Properties) : BotConfiguration { | ||
|
||
internal constructor(file: File) : this(Properties()) { | ||
FileReader(file).use(properties::load) | ||
} | ||
|
||
override val token: String | ||
get() = properties.getProperty("token") | ||
} |
57 changes: 57 additions & 0 deletions
57
examples/example-kord/src/main/kotlin/org/incendo/cloud/discord/kord/example/ExampleBot.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
// | ||
// MIT License | ||
// | ||
// Copyright (c) 2024 Incendo | ||
// | ||
// Permission is hereby granted, free of charge, to any person obtaining a copy | ||
// of this software and associated documentation files (the "Software"), to deal | ||
// in the Software without restriction, including without limitation the rights | ||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
// copies of the Software, and to permit persons to whom the Software is | ||
// furnished to do so, subject to the following conditions: | ||
// | ||
// The above copyright notice and this permission notice shall be included in all | ||
// copies or substantial portions of the Software. | ||
// | ||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
// SOFTWARE. | ||
// | ||
package org.incendo.cloud.discord.kord.example | ||
|
||
import cloud.commandframework.execution.ExecutionCoordinator | ||
import dev.kord.core.Kord | ||
import io.github.oshai.kotlinlogging.KotlinLogging | ||
import org.incendo.cloud.discord.kord.KordCommandManager | ||
import java.io.File | ||
|
||
private val logger = KotlinLogging.logger {} | ||
|
||
/** | ||
* Example kord bot. | ||
*/ | ||
public class ExampleBot(public val configuration: BotConfiguration) { | ||
|
||
/** | ||
* Starts the bot. | ||
*/ | ||
public suspend fun start() { | ||
logger.info { "Starting the example bot..." } | ||
val commandManager = KordCommandManager(ExecutionCoordinator.simpleCoordinator()) | ||
|
||
logger.info { "Logging into Kord..." } | ||
val kord = Kord(configuration.token) | ||
kord.login() | ||
} | ||
} | ||
|
||
/** | ||
* Main method. | ||
*/ | ||
public suspend fun main() { | ||
ExampleBot(PropertiesBotConfiguration(File("./bot.properties"))).start() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<configuration> | ||
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender"> | ||
<encoder> | ||
<pattern>[%d{HH:mm:ss}][%-5level][%-30logger{0}]: %msg%n</pattern> | ||
</encoder> | ||
</appender> | ||
<root level="debug"> | ||
<appender-ref ref="STDOUT" /> | ||
</root> | ||
</configuration> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
gradle/build-logic/src/main/kotlin/cloud-discord.kotlin-conventions.gradle.kts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import gradle.kotlin.dsl.accessors._4170a67d0be8a515d9becde6b6ee87f3.api | ||
import org.jetbrains.kotlin.gradle.dsl.KotlinJvmProjectExtension | ||
|
||
plugins { | ||
id("cloud-discord.base-conventions") | ||
id("org.jetbrains.kotlin.jvm") | ||
id("org.jetbrains.dokka") | ||
} | ||
|
||
configure<KotlinJvmProjectExtension> { | ||
explicitApi() | ||
jvmToolchain { | ||
languageVersion.set(JavaLanguageVersion.of(17)) | ||
} | ||
coreLibrariesVersion = libs.versions.kotlin.get() | ||
target { | ||
compilations.configureEach { | ||
kotlinOptions { | ||
jvmTarget = "17" | ||
languageVersion = libs.versions.kotlin.get().split(".").take(2).joinToString(".") | ||
} | ||
} | ||
} | ||
|
||
dependencies { | ||
api(kotlin("stdlib-jdk8")) | ||
} | ||
|
||
tasks.named("javadocJar", AbstractArchiveTask::class) { | ||
from(tasks.named("dokkaHtml")) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters