Compare commits

...

24 Commits
0.0.3 ... 0.1.2

Author SHA1 Message Date
03d9986fcf update tgbotapi 2021-02-17 17:34:42 +06:00
46986316c2 start 0.1.1 2021-02-17 17:33:36 +06:00
8fe6fb4bf1 Merge pull request #6 from InsanusMokrassar/0.1.0
0.1.0
2021-02-17 01:22:44 +06:00
2baed760f7 inluding sdi 2021-02-17 01:21:41 +06:00
a2b3fe57ac update publication scripts 2021-02-17 00:31:50 +06:00
6dec930a9d Merge pull request #4 from InsanusMokrassar/0.1.0
0.1.0
2021-02-17 00:06:58 +06:00
01aa098125 update changelog and gradle.properties 2021-02-16 23:42:25 +06:00
fc9d668e31 add build workflow 2021-02-16 23:37:42 +06:00
96f1ff56c0 update gradle wrapper version 2021-02-16 23:35:25 +06:00
f3c3640421 update publishing scripts 2021-02-16 23:34:47 +06:00
158b03a9ca update dependencies 2021-02-16 23:32:19 +06:00
7258275d0e start 0.1.1 2021-02-16 23:29:41 +06:00
595102fede BehaviourContext.invoke 2021-01-10 15:21:31 +06:00
bc5737d435 update dependencies 2021-01-10 15:04:45 +06:00
79f3962c65 start 0.1.0 2021-01-10 15:01:52 +06:00
41dade823b Merge pull request #3 from InsanusMokrassar/0.0.5
0.0.5
2020-12-08 15:03:59 +06:00
c5c64bcd2d update publication scripts 2020-12-08 15:00:54 +06:00
95f7f93c20 update dependencies 2020-12-08 14:50:11 +06:00
49c90d2a0d start 0.0.5 2020-12-08 14:35:38 +06:00
2a54ff38f8 Update .travis.yml 2020-11-17 21:46:19 +06:00
5d221435fe Create .travis.yml 2020-11-17 21:45:42 +06:00
d7d8eb8faf Merge pull request #2 from InsanusMokrassar/0.0.4
0.0.4
2020-11-17 21:40:55 +06:00
fdee11d637 start 0.0.4 2020-11-17 21:38:45 +06:00
5376afecc2 Merge pull request #1 from InsanusMokrassar/0.0.3
0.0.3
2020-11-13 11:32:37 +06:00
18 changed files with 265 additions and 216 deletions

16
.github/workflows/build.yml vendored Normal file
View File

@@ -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

11
.travis.yml Normal file
View File

@@ -0,0 +1,11 @@
language: java
install: true
os: linux
dist: trusty
jdk: oraclejdk8
jobs:
include:
- stage: build
script: ./gradlew build -s

View File

@@ -1,5 +1,40 @@
# Changelog
## 0.1.1
* `Versions`
* `tgbotapi`: `0.32.5` -> `0.32.6`
## 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`
* `Bot`
* New dependency `sdi`
* Now it is possible to pass `Module` to configuration for providing a global plugins parameters like different
common database or tools
* `Plugin`
* Two new methods `BehaviourContext#invoke`
* Old method `invoke` has been deprecated
## 0.0.5
* `Versions`
* `kotlin`: `1.4.10` -> `1.4.21`
* `kotlin coroutines`: `1.4.1` -> `1.4.2`
* `tgbotapi`: `0.30.7` -> `0.30.10`
* `microutils`: `0.4.1` -> `0.4.11`
## 0.0.4
* `Versions`
* `tgbotapi`: `0.30.4` -> `0.30.7`
* `microutils`: `0.3.4` -> `0.4.1`
## 0.0.3
* `Bot`:

View File

@@ -18,6 +18,7 @@ dependencies {
api "org.jetbrains.exposed:exposed-jdbc:$kotlin_exposed_version"
api "dev.inmo:tgbotapi:$tgbotapi_version"
api "dev.inmo:sdi:$sdi_version"
api "dev.inmo:micro_utils.repos.exposed:$microutils_version"
api "com.github.matfax.klassindex:library:$klassindex_version"
@@ -34,6 +35,7 @@ application {
kapt {
arguments {
arg("com.github.matfax.klassindex.IndexSubclasses", "dev.inmo.plagubot.Plugin")
arg("com.github.matfax.klassindex.IndexAnnotated", "dev.inmo.sdi.SDIIncluded")
}
}

View File

@@ -1,54 +0,0 @@
apply plugin: 'maven-publish'
task sourcesJar(type: Jar) {
from sourceSets.main.allSource
classifier = 'sources'
}
task javadocJar(type: Jar) {
from javadoc
classifier = 'javadoc'
}
publishing {
publications {
maven(MavenPublication) {
from components.java
artifact sourcesJar
artifact javadocJar
pom {
resolveStrategy = Closure.DELEGATE_FIRST
description = ""
name = "PlaguBot ${project.name}"
url = "https://github.com/InsanusMokrassar/PlaguBot"
scm {
developerConnection = "scm:git:[fetch=]ssh://git@github.com/InsanusMokrassar/PlaguBot.git[push=]ssh://git@github.com/InsanusMokrassar/PlaguBot.git"
url = "ssh://git@github.com/InsanusMokrassar/PlaguBot.git"
}
developers {
developer {
id = "InsanusMokrassar"
name = "Aleksei Ovsiannikov"
email = "ovsyannikov.alexey95@gmail.com"
}
}
licenses {
license {
name = "Apache Software License 2.0"
url = "https://github.com/InsanusMokrassar/PlaguBot/LICENSE"
}
}
}
}
}
}

View File

@@ -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"}
{"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"}

View File

@@ -1,43 +1,82 @@
apply plugin: 'com.jfrog.bintray'
apply plugin: 'maven-publish'
apply plugin: 'signing'
ext {
projectBintrayDir = "${project.group}/".replace(".", "/") + "${project.name}/${project.version}"
task javadocJar(type: Jar) {
from javadoc
classifier = 'javadoc'
}
task sourcesJar(type: Jar) {
from sourceSets.main.allSource
classifier = 'sources'
}
bintray {
user = project.hasProperty('BINTRAY_USER') ? project.property('BINTRAY_USER') : System.getenv('BINTRAY_USER')
key = project.hasProperty('BINTRAY_KEY') ? project.property('BINTRAY_KEY') : System.getenv('BINTRAY_KEY')
publications = ["maven"]
filesSpec {
into "$projectBintrayDir"
from("build/libs") {
include "**/*.asc"
}
from("build/publications/maven") {
rename 'pom-default.xml(.*)', "${project.name}-${project.version}.pom\$1"
}
}
publish = true
override = true
pkg {
repo = "PlaguBot"
name = "${project.name}"
vcsUrl = "https://github.com/InsanusMokrassar/PlaguBot"
licenses = ["Apache-2.0"]
version {
name = "${project.version}"
released = new Date()
vcsTag = "${project.version}"
gpg {
sign = true
passphrase = project.hasProperty('signing.gnupg.passphrase') ? project.property('signing.gnupg.passphrase') : System.getenv('signing.gnupg.passphrase')
publishing {
publications {
maven(MavenPublication) {
from components.java
artifact javadocJar
artifact sourcesJar
pom {
resolveStrategy = Closure.DELEGATE_FIRST
description = "Base PlaguBot project"
name = "PlaguBot Bot"
url = "https://github.com/InsanusMokrassar/PlaguBot"
scm {
developerConnection = "scm:git:[fetch=]ssh://git@github.com/InsanusMokrassar/PlaguBot.git[push=]ssh://git@github.com/InsanusMokrassar/PlaguBot.git"
url = "ssh://git@github.com/InsanusMokrassar/PlaguBot.git"
}
developers {
developer {
id = "InsanusMokrassar"
name = "Aleksei Ovsiannikov"
email = "ovsyannikov.alexey95@gmail.com"
}
}
licenses {
license {
name = "Apache Software License 2.0"
url = "https://github.com/InsanusMokrassar/PlaguBot/LICENSE"
}
}
}
repositories {
maven {
name = "bintray"
url = uri("https://api.bintray.com/maven/${project.hasProperty('BINTRAY_USER') ? project.property('BINTRAY_USER') : System.getenv('BINTRAY_USER')}/PlaguBot/${project.name}/;publish=1;override=1")
credentials {
username = project.hasProperty('BINTRAY_USER') ? project.property('BINTRAY_USER') : System.getenv('BINTRAY_USER')
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')
}
}
}
}
}
}
apply from: "maven.publish.gradle"
bintrayUpload.dependsOn publishToMavenLocal
signing {
useGpgCmd()
sign publishing.publications
}

View File

@@ -1,11 +1,12 @@
package dev.inmo.plagubot
import dev.inmo.micro_utils.coroutines.safelyWithoutExceptions
import dev.inmo.plagubot.config.Config
import dev.inmo.plagubot.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,11 @@ suspend inline fun initPlaguBot(
) {
val bot = telegramBot(config.botToken)
bot.startGettingFlowsUpdatesByLongPolling(scope = scope) {
val paramsMap = config.params ?.toMap() ?: emptyMap()
val database = config.params ?.database ?: config.database.database
bot.buildBehaviour(scope) {
val commands = config.plugins.flatMap {
it.invoke(bot, config.database.database, this, scope)
it.apply { invoke(database, paramsMap) }
it.getCommands()
}.let {
val futureUnavailable = it.drop(botCommandsLimit.last)
@@ -28,11 +31,7 @@ suspend inline fun initPlaguBot(
}
it.take(botCommandsLimit.last)
}
scope.launch {
safelyWithoutExceptions {
bot.setMyCommands(commands)
}
}
safelyWithoutExceptions { setMyCommands(commands) }
}
}

View File

@@ -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)
}
}

View File

@@ -2,6 +2,7 @@ package dev.inmo.plagubot.config
import com.github.matfax.klassindex.KlassIndex
import dev.inmo.plagubot.Plugin
import dev.inmo.sdi.Module
import kotlinx.serialization.*
import kotlinx.serialization.json.Json
import kotlinx.serialization.modules.*
@@ -37,6 +38,7 @@ internal val configSerialFormat: StringFormat
@Serializable
data class Config(
val plugins: List<Plugin>,
val database: DatabaseConfig,
val botToken: String
val database: DatabaseConfig = DatabaseConfig(),
val botToken: String,
val params: Module? = null
)

View File

@@ -1,5 +1,6 @@
package dev.inmo.plagubot.config
import dev.inmo.sdi.SDIIncluded
import kotlinx.serialization.Serializable
import kotlinx.serialization.Transient
import org.jetbrains.exposed.sql.Database
@@ -7,7 +8,12 @@ import org.jetbrains.exposed.sql.transactions.transactionManager
import org.sqlite.JDBC
import java.sql.Connection
const val defaultDatabaseParamsName = "defaultDatabase"
inline val Map<String, Any>.database: Database?
get() = (get(defaultDatabaseParamsName) as? DatabaseConfig) ?.database
@Serializable
@SDIIncluded
data class DatabaseConfig(
val url: String = "jdbc:sqlite:file:test?mode=memory&cache=shared",
val driver: String = JDBC::class.qualifiedName!!,

View File

@@ -7,15 +7,14 @@ buildscript {
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath "org.jetbrains.kotlin:kotlin-serialization:$kotlin_version"
classpath "com.jfrog.bintray.gradle:gradle-bintray-plugin:$gradle_bintray_plugin_version"
classpath "com.github.breadmoirai:github-release:$github_release_plugin_version"
}
}
allprojects {
repositories {
jcenter()
mavenCentral()
jcenter()
mavenLocal()
maven { url 'https://jitpack.io' }
}

View File

@@ -4,17 +4,19 @@ org.gradle.parallel=true
kotlin.js.generate.externals=true
kotlin.incremental=true
kotlin_version=1.4.10
kotlin_coroutines_version=1.4.1
kotlin_serialisation_runtime_version=1.0.1
kotlin_exposed_version=0.28.1
tgbotapi_version=0.30.4
microutils_version=0.3.3
kotlin_version=1.4.30
kotlin_coroutines_version=1.4.2
kotlin_serialisation_runtime_version=1.1.0-RC
kotlin_exposed_version=0.29.1
sdi_version=0.4.0-rc2
tgbotapi_version=0.32.6
microutils_version=0.4.25
klassindex_version=4.1.0-rc.1
sqlite_version=3.30.1
gradle_bintray_plugin_version=1.8.5
github_release_plugin_version=2.2.12
group=dev.inmo
version=0.0.3
version=0.1.1

View File

@@ -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

View File

@@ -1,54 +0,0 @@
apply plugin: 'maven-publish'
task sourcesJar(type: Jar) {
from sourceSets.main.allSource
classifier = 'sources'
}
task javadocJar(type: Jar) {
from javadoc
classifier = 'javadoc'
}
publishing {
publications {
maven(MavenPublication) {
from components.java
artifact sourcesJar
artifact javadocJar
pom {
resolveStrategy = Closure.DELEGATE_FIRST
description = ""
name = "PlaguBot ${project.name}"
url = "https://github.com/InsanusMokrassar/PlaguBot"
scm {
developerConnection = "scm:git:[fetch=]ssh://git@github.com/InsanusMokrassar/PlaguBot.git[push=]ssh://git@github.com/InsanusMokrassar/PlaguBot.git"
url = "ssh://git@github.com/InsanusMokrassar/PlaguBot.git"
}
developers {
developer {
id = "InsanusMokrassar"
name = "Aleksei Ovsiannikov"
email = "ovsyannikov.alexey95@gmail.com"
}
}
licenses {
license {
name = "Apache Software License 2.0"
url = "https://github.com/InsanusMokrassar/PlaguBot/LICENSE"
}
}
}
}
}
}

View File

@@ -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"}
{"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"}

View File

@@ -1,43 +1,82 @@
apply plugin: 'com.jfrog.bintray'
apply plugin: 'maven-publish'
apply plugin: 'signing'
ext {
projectBintrayDir = "${project.group}/".replace(".", "/") + "${project.name}/${project.version}"
task javadocJar(type: Jar) {
from javadoc
classifier = 'javadoc'
}
task sourcesJar(type: Jar) {
from sourceSets.main.allSource
classifier = 'sources'
}
bintray {
user = project.hasProperty('BINTRAY_USER') ? project.property('BINTRAY_USER') : System.getenv('BINTRAY_USER')
key = project.hasProperty('BINTRAY_KEY') ? project.property('BINTRAY_KEY') : System.getenv('BINTRAY_KEY')
publications = ["maven"]
filesSpec {
into "$projectBintrayDir"
from("build/libs") {
include "**/*.asc"
}
from("build/publications/maven") {
rename 'pom-default.xml(.*)', "${project.name}-${project.version}.pom\$1"
}
}
publish = true
override = true
pkg {
repo = "PlaguBot"
name = "${project.name}"
vcsUrl = "https://github.com/InsanusMokrassar/PlaguBot"
licenses = ["Apache-2.0"]
version {
name = "${project.version}"
released = new Date()
vcsTag = "${project.version}"
gpg {
sign = true
passphrase = project.hasProperty('signing.gnupg.passphrase') ? project.property('signing.gnupg.passphrase') : System.getenv('signing.gnupg.passphrase')
publishing {
publications {
maven(MavenPublication) {
from components.java
artifact javadocJar
artifact sourcesJar
pom {
resolveStrategy = Closure.DELEGATE_FIRST
description = "Base dependency for whole PlaguBot project"
name = "PlaguBot Plugin"
url = "https://github.com/InsanusMokrassar/PlaguBot"
scm {
developerConnection = "scm:git:[fetch=]ssh://git@github.com/InsanusMokrassar/PlaguBot.git[push=]ssh://git@github.com/InsanusMokrassar/PlaguBot.git"
url = "ssh://git@github.com/InsanusMokrassar/PlaguBot.git"
}
developers {
developer {
id = "InsanusMokrassar"
name = "Aleksei Ovsiannikov"
email = "ovsyannikov.alexey95@gmail.com"
}
}
licenses {
license {
name = "Apache Software License 2.0"
url = "https://github.com/InsanusMokrassar/PlaguBot/LICENSE"
}
}
}
repositories {
maven {
name = "bintray"
url = uri("https://api.bintray.com/maven/${project.hasProperty('BINTRAY_USER') ? project.property('BINTRAY_USER') : System.getenv('BINTRAY_USER')}/PlaguBot/${project.name}/;publish=1;override=1")
credentials {
username = project.hasProperty('BINTRAY_USER') ? project.property('BINTRAY_USER') : System.getenv('BINTRAY_USER')
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')
}
}
}
}
}
}
apply from: "maven.publish.gradle"
bintrayUpload.dependsOn publishToMavenLocal
signing {
useGpgCmd()
sign publishing.publications
}

View File

@@ -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,26 @@ interface Plugin {
*/
suspend fun getCommands(): List<BotCommand> = 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)
/**
* This method (usually) will be invoked just one time in the whole application.
*/
suspend operator fun BehaviourContext.invoke(
database: Database,
params: Map<String, Any>
) = invoke(database)
}