-
-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Move all sealed structure serialization to unified approach.
- Loading branch information
Showing
51 changed files
with
348 additions
and
179 deletions.
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
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
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 |
---|---|---|
@@ -1,7 +1,9 @@ | ||
import org.gradle.api.model.ObjectFactory | ||
import org.gradle.kotlin.dsl.property | ||
|
||
open class PublishingExtension(factory: ObjectFactory) { | ||
open class PublishingExtension( | ||
factory: ObjectFactory, | ||
) { | ||
val name = factory.property<String>() | ||
val description = factory.property<String>() | ||
} |
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 |
---|---|---|
|
@@ -21,4 +21,3 @@ detekt { | |
allRules = false | ||
config.from(files("$rootDir/detekt.yml")) | ||
} | ||
|
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 |
---|---|---|
|
@@ -25,4 +25,3 @@ detekt { | |
allRules = false | ||
config.from(files("$rootDir/detekt.yml")) | ||
} | ||
|
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
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
57 changes: 57 additions & 0 deletions
57
ktgram-utils/src/commonMain/kotlin/eu/vendeli/ktgram/extutils/CommonExtUtils.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 @@ | ||
package eu.vendeli.ktgram.extutils | ||
|
||
import eu.vendeli.tgbot.TelegramBot | ||
import eu.vendeli.tgbot.interfaces.action.Action | ||
import eu.vendeli.tgbot.types.User | ||
import eu.vendeli.tgbot.types.chat.Chat | ||
import eu.vendeli.tgbot.types.internal.Identifier | ||
import eu.vendeli.tgbot.types.internal.getOrNull | ||
import eu.vendeli.tgbot.utils.TgException | ||
|
||
private val DEFAULT_FAILURE_ACTION: suspend () -> Nothing = { throw TgException("Failed to process response") } | ||
|
||
private suspend fun <R> Action<R>.sendAnd( | ||
to: Identifier, | ||
bot: TelegramBot, | ||
onFailure: suspend () -> Nothing = DEFAULT_FAILURE_ACTION, | ||
block: suspend R.() -> Unit, | ||
) { | ||
val result = when (to) { | ||
is Identifier.String -> { | ||
sendReturning(to.get, bot).getOrNull() | ||
} | ||
|
||
is Identifier.Long -> { | ||
sendReturning(to.get, bot).getOrNull() | ||
} | ||
} ?: onFailure() | ||
block(result) | ||
} | ||
|
||
suspend fun <R> Action<R>.sendAnd( | ||
to: Long, | ||
bot: TelegramBot, | ||
onFailure: suspend () -> Nothing = DEFAULT_FAILURE_ACTION, | ||
block: suspend R.() -> Unit, | ||
) = sendAnd(Identifier.from(to), bot, onFailure, block) | ||
|
||
suspend fun <R> Action<R>.sendAnd( | ||
to: String, | ||
bot: TelegramBot, | ||
onFailure: suspend () -> Nothing = DEFAULT_FAILURE_ACTION, | ||
block: suspend R.() -> Unit, | ||
) = sendAnd(Identifier.from(to), bot, onFailure, block) | ||
|
||
suspend fun <R> Action<R>.sendAnd( | ||
to: Chat, | ||
bot: TelegramBot, | ||
onFailure: suspend () -> Nothing = DEFAULT_FAILURE_ACTION, | ||
block: suspend R.() -> Unit, | ||
) = sendAnd(Identifier.from(to), bot, onFailure, block) | ||
|
||
suspend fun <R> Action<R>.sendAnd( | ||
to: User, | ||
bot: TelegramBot, | ||
onFailure: suspend () -> Nothing = DEFAULT_FAILURE_ACTION, | ||
block: suspend R.() -> Unit, | ||
) = sendAnd(Identifier.from(to), bot, onFailure, block) |
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
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
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
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
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
Oops, something went wrong.