diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..ceab9f2 --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,16 @@ +name: Build + +on: [push] + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + - name: Set up JDK 1.8 + uses: actions/setup-java@v1 + with: + java-version: 1.8 + - name: Build with Gradle + run: ./gradlew build diff --git a/CHANGELOG.md b/CHANGELOG.md index d44a151..c049a90 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,17 @@ # Changelog +## 0.1.0 + +* `Versions` + * `kotlin`: `1.4.21` -> `1.4.30` + * `serialization`: `1.0.1` -> `1.1.0-RC` + * `exposed`: `0.28.1` -> `0.29.1` + * `tgbotapi`: `0.30.10` -> `0.32.5` + * `microutils`: `0.4.11` -> `0.4.25` +* `Plugin` + * New method `BehaviourContext#invoke` + * Old method `invoke` has been deprecated + ## 0.0.5 * `Versions` diff --git a/bot/pubconf.kpsb b/bot/pubconf.kpsb index d463863..aac6132 100644 --- a/bot/pubconf.kpsb +++ b/bot/pubconf.kpsb @@ -1 +1 @@ -{"bintrayConfig":{"repo":"PlaguBot","packageName":"${project.name}","packageVcs":"https://github.com/InsanusMokrassar/PlaguBot","autoPublish":true,"overridePublish":true},"licenses":[{"id":"Apache-2.0","title":"Apache Software License 2.0","url":"https://github.com/InsanusMokrassar/PlaguBot/LICENSE"}],"mavenConfig":{"name":"PlaguBot ${project.name}","description":"","url":"https://github.com/InsanusMokrassar/PlaguBot","vcsUrl":"ssh://git@github.com/InsanusMokrassar/PlaguBot.git","developers":[{"id":"InsanusMokrassar","name":"Aleksei Ovsiannikov","eMail":"ovsyannikov.alexey95@gmail.com"}]},"type":"JVM"} \ No newline at end of file +{"bintrayConfig":{"repo":"PlaguBot","packageName":"${project.name}","packageVcs":"https://github.com/InsanusMokrassar/PlaguBot","autoPublish":true,"overridePublish":true},"licenses":[{"id":"Apache-2.0","title":"Apache Software License 2.0","url":"https://github.com/InsanusMokrassar/PlaguBot/LICENSE"}],"mavenConfig":{"name":"PlaguBot Bot","description":"Base PlaguBot project","url":"https://github.com/InsanusMokrassar/PlaguBot","vcsUrl":"ssh://git@github.com/InsanusMokrassar/PlaguBot.git","includeGpgSigning":true,"publishToMavenCentral":true,"developers":[{"id":"InsanusMokrassar","name":"Aleksei Ovsiannikov","eMail":"ovsyannikov.alexey95@gmail.com"}]},"type":"JVM"} \ No newline at end of file diff --git a/bot/publish.gradle b/bot/publish.gradle index 30acc17..8bc041f 100644 --- a/bot/publish.gradle +++ b/bot/publish.gradle @@ -1,9 +1,6 @@ apply plugin: 'maven-publish' +apply plugin: 'signing' -task sourcesJar(type: Jar) { - from sourceSets.main.allSource - classifier = 'sources' -} task javadocJar(type: Jar) { from javadoc @@ -15,14 +12,13 @@ publishing { maven(MavenPublication) { from components.java - artifact sourcesJar artifact javadocJar pom { resolveStrategy = Closure.DELEGATE_FIRST - description = "" - name = "PlaguBot ${project.name}" + description = "Base PlaguBot project" + name = "PlaguBot Bot" url = "https://github.com/InsanusMokrassar/PlaguBot" scm { @@ -59,8 +55,23 @@ publishing { password = project.hasProperty('BINTRAY_KEY') ? project.property('BINTRAY_KEY') : System.getenv('BINTRAY_KEY') } } + + maven { + name = "sonatype" + url = uri("https://oss.sonatype.org/service/local/staging/deploy/maven2/") + credentials { + username = project.hasProperty('SONATYPE_USER') ? project.property('SONATYPE_USER') : System.getenv('SONATYPE_USER') + password = project.hasProperty('SONATYPE_PASSWORD') ? project.property('SONATYPE_PASSWORD') : System.getenv('SONATYPE_PASSWORD') + } + } + } } } -} \ No newline at end of file +} + +signing { + useGpgCmd() + sign publishing.publications +} diff --git a/bot/src/main/kotlin/dev/inmo/plagubot/App.kt b/bot/src/main/kotlin/dev/inmo/plagubot/App.kt index 005d811..de2672b 100644 --- a/bot/src/main/kotlin/dev/inmo/plagubot/App.kt +++ b/bot/src/main/kotlin/dev/inmo/plagubot/App.kt @@ -3,9 +3,10 @@ package dev.inmo.plagubot import dev.inmo.micro_utils.coroutines.safelyWithoutExceptions import dev.inmo.plagubot.config.Config import dev.inmo.plagubot.config.configSerialFormat +import dev.inmo.tgbotapi.bot.Ktor.telegramBot import dev.inmo.tgbotapi.extensions.api.bot.setMyCommands -import dev.inmo.tgbotapi.extensions.api.telegramBot -import dev.inmo.tgbotapi.extensions.utils.updates.retrieving.startGettingFlowsUpdatesByLongPolling +import dev.inmo.tgbotapi.extensions.behaviour_builder.buildBehaviour +import dev.inmo.tgbotapi.extensions.utils.updates.retrieving.longPolling import dev.inmo.tgbotapi.types.botCommandsLimit import kotlinx.coroutines.* import kotlinx.serialization.InternalSerializationApi @@ -17,9 +18,9 @@ suspend inline fun initPlaguBot( ) { val bot = telegramBot(config.botToken) - bot.startGettingFlowsUpdatesByLongPolling(scope = scope) { + bot.buildBehaviour(scope) { val commands = config.plugins.flatMap { - it.invoke(bot, config.database.database, this, scope) + it.apply { invoke(config.database.database) } it.getCommands() }.let { val futureUnavailable = it.drop(botCommandsLimit.last) @@ -28,11 +29,7 @@ suspend inline fun initPlaguBot( } it.take(botCommandsLimit.last) } - scope.launch { - safelyWithoutExceptions { - bot.setMyCommands(commands) - } - } + safelyWithoutExceptions { setMyCommands(commands) } } } diff --git a/bot/src/main/kotlin/dev/inmo/plagubot/HelloPlugin.kt b/bot/src/main/kotlin/dev/inmo/plagubot/HelloPlugin.kt index 19ef11e..1b66d96 100644 --- a/bot/src/main/kotlin/dev/inmo/plagubot/HelloPlugin.kt +++ b/bot/src/main/kotlin/dev/inmo/plagubot/HelloPlugin.kt @@ -1,8 +1,6 @@ package dev.inmo.plagubot -import dev.inmo.tgbotapi.bot.TelegramBot -import dev.inmo.tgbotapi.updateshandlers.FlowsUpdatesFilter -import kotlinx.coroutines.CoroutineScope +import dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContext import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable import org.jetbrains.exposed.sql.Database @@ -12,12 +10,7 @@ import org.jetbrains.exposed.sql.Database data class HelloPlugin( val parameter: String ) : Plugin { - override suspend fun invoke( - bot: TelegramBot, - database: Database, - updatesFilter: FlowsUpdatesFilter, - scope: CoroutineScope - ) { + override suspend fun BehaviourContext.invoke(database: Database) { println(parameter) } } diff --git a/gradle.properties b/gradle.properties index d2a56f9..bde1212 100644 --- a/gradle.properties +++ b/gradle.properties @@ -4,16 +4,16 @@ org.gradle.parallel=true kotlin.js.generate.externals=true kotlin.incremental=true -kotlin_version=1.4.21 +kotlin_version=1.4.30 kotlin_coroutines_version=1.4.2 -kotlin_serialisation_runtime_version=1.0.1 -kotlin_exposed_version=0.28.1 -tgbotapi_version=0.30.10 -microutils_version=0.4.11 +kotlin_serialisation_runtime_version=1.1.0-RC +kotlin_exposed_version=0.29.1 +tgbotapi_version=0.32.5 +microutils_version=0.4.25 klassindex_version=4.1.0-rc.1 sqlite_version=3.30.1 github_release_plugin_version=2.2.12 group=dev.inmo -version=0.0.5 +version=0.1.0 diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index be52383..2a56324 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-6.7-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-6.8.2-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/plugin/pubconf.kpsb b/plugin/pubconf.kpsb index d463863..433c2f0 100644 --- a/plugin/pubconf.kpsb +++ b/plugin/pubconf.kpsb @@ -1 +1 @@ -{"bintrayConfig":{"repo":"PlaguBot","packageName":"${project.name}","packageVcs":"https://github.com/InsanusMokrassar/PlaguBot","autoPublish":true,"overridePublish":true},"licenses":[{"id":"Apache-2.0","title":"Apache Software License 2.0","url":"https://github.com/InsanusMokrassar/PlaguBot/LICENSE"}],"mavenConfig":{"name":"PlaguBot ${project.name}","description":"","url":"https://github.com/InsanusMokrassar/PlaguBot","vcsUrl":"ssh://git@github.com/InsanusMokrassar/PlaguBot.git","developers":[{"id":"InsanusMokrassar","name":"Aleksei Ovsiannikov","eMail":"ovsyannikov.alexey95@gmail.com"}]},"type":"JVM"} \ No newline at end of file +{"bintrayConfig":{"repo":"PlaguBot","packageName":"${project.name}","packageVcs":"https://github.com/InsanusMokrassar/PlaguBot","autoPublish":true,"overridePublish":true},"licenses":[{"id":"Apache-2.0","title":"Apache Software License 2.0","url":"https://github.com/InsanusMokrassar/PlaguBot/LICENSE"}],"mavenConfig":{"name":"PlaguBot Plugin","description":"Base dependency for whole PlaguBot project","url":"https://github.com/InsanusMokrassar/PlaguBot","vcsUrl":"ssh://git@github.com/InsanusMokrassar/PlaguBot.git","includeGpgSigning":true,"publishToMavenCentral":true,"developers":[{"id":"InsanusMokrassar","name":"Aleksei Ovsiannikov","eMail":"ovsyannikov.alexey95@gmail.com"}]},"type":"JVM"} \ No newline at end of file diff --git a/plugin/publish.gradle b/plugin/publish.gradle index 30acc17..624cde7 100644 --- a/plugin/publish.gradle +++ b/plugin/publish.gradle @@ -1,9 +1,6 @@ apply plugin: 'maven-publish' +apply plugin: 'signing' -task sourcesJar(type: Jar) { - from sourceSets.main.allSource - classifier = 'sources' -} task javadocJar(type: Jar) { from javadoc @@ -15,14 +12,13 @@ publishing { maven(MavenPublication) { from components.java - artifact sourcesJar artifact javadocJar pom { resolveStrategy = Closure.DELEGATE_FIRST - description = "" - name = "PlaguBot ${project.name}" + description = "Base dependency for whole PlaguBot project" + name = "PlaguBot Plugin" url = "https://github.com/InsanusMokrassar/PlaguBot" scm { @@ -59,8 +55,23 @@ publishing { password = project.hasProperty('BINTRAY_KEY') ? project.property('BINTRAY_KEY') : System.getenv('BINTRAY_KEY') } } + + maven { + name = "sonatype" + url = uri("https://oss.sonatype.org/service/local/staging/deploy/maven2/") + credentials { + username = project.hasProperty('SONATYPE_USER') ? project.property('SONATYPE_USER') : System.getenv('SONATYPE_USER') + password = project.hasProperty('SONATYPE_PASSWORD') ? project.property('SONATYPE_PASSWORD') : System.getenv('SONATYPE_PASSWORD') + } + } + } } } -} \ No newline at end of file +} + +signing { + useGpgCmd() + sign publishing.publications +} diff --git a/plugin/src/main/kotlin/dev/inmo/plagubot/Plugin.kt b/plugin/src/main/kotlin/dev/inmo/plagubot/Plugin.kt index b37fb75..dbd17b1 100644 --- a/plugin/src/main/kotlin/dev/inmo/plagubot/Plugin.kt +++ b/plugin/src/main/kotlin/dev/inmo/plagubot/Plugin.kt @@ -1,6 +1,7 @@ package dev.inmo.plagubot import dev.inmo.tgbotapi.bot.TelegramBot +import dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContext import dev.inmo.tgbotapi.types.BotCommand import dev.inmo.tgbotapi.updateshandlers.FlowsUpdatesFilter import kotlinx.coroutines.CoroutineScope @@ -19,13 +20,20 @@ interface Plugin { */ suspend fun getCommands(): List = emptyList() - /** - * This method (usually) will be invoked just one time in the whole application. - */ + @Deprecated("Override other method with receiver BehaviourContext") suspend operator fun invoke( bot: TelegramBot, database: Database, updatesFilter: FlowsUpdatesFilter, scope: CoroutineScope - ) + ) {} + + /** + * This method (usually) will be invoked just one time in the whole application. + */ + suspend operator fun BehaviourContext.invoke( + database: Database + ) { + invoke(bot, database, flowsUpdatesFilter, scope) + } }