Skip to content

Commit

Permalink
code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
vendelieu committed Nov 26, 2024
1 parent fafc6e6 commit b196e79
Show file tree
Hide file tree
Showing 10 changed files with 31 additions and 21 deletions.
10 changes: 10 additions & 0 deletions .github/workflows/gradle-wrapper-validation.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
name: "Validate Gradle Wrapper"
on: [push, pull_request]

jobs:
validation:
name: "Validation"
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3.3.0
- uses: gradle/wrapper-validation-action@v1
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ internal fun collectInputChains(
}.arguments
.firstOrNull()
?.value
?.cast<Boolean>() ?: false
?.cast<Boolean>() == true

val links = chain.declarations
.filter { i ->
Expand Down
2 changes: 1 addition & 1 deletion ksp/src/jvmMain/kotlin/eu/vendeli/ksp/utils/ParseUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ internal fun List<KSValueArgument>.parseAsCommandHandler(isCallbackQ: Boolean) =
scope = parseScopes() ?: if (isCallbackQ) callbackQueryList else messageList,
guardClass = parseGuard(),
argParserClass = parseArgParser(),
isAutoAnswer = firstOrNull { it.name?.asString() == "autoAnswer" }?.value?.safeCast<Boolean>() ?: false,
isAutoAnswer = firstOrNull { it.name?.asString() == "autoAnswer" }?.value?.safeCast<Boolean>() == true,
)

internal fun List<KSValueArgument>.parseAsInputHandler() = Triple(
Expand Down
10 changes: 5 additions & 5 deletions telegram-bot/api/telegram-bot.api
Original file line number Diff line number Diff line change
Expand Up @@ -13870,11 +13870,11 @@ public final class eu/vendeli/tgbot/utils/FunctionalDSLUtilsKt {
}

public final class eu/vendeli/tgbot/utils/LoggingUtilsKt {
public static final fun debug (Lorg/slf4j/Logger;Lkotlin/jvm/functions/Function0;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
public static final fun error (Lorg/slf4j/Logger;Ljava/lang/Throwable;Lkotlin/jvm/functions/Function0;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
public static synthetic fun error$default (Lorg/slf4j/Logger;Ljava/lang/Throwable;Lkotlin/jvm/functions/Function0;Lkotlin/coroutines/Continuation;ILjava/lang/Object;)Ljava/lang/Object;
public static final fun info (Lorg/slf4j/Logger;Lkotlin/jvm/functions/Function0;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
public static final fun warn (Lorg/slf4j/Logger;Lkotlin/jvm/functions/Function0;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
public static final fun debug (Lorg/slf4j/Logger;Lkotlin/jvm/functions/Function0;)V
public static final fun error (Lorg/slf4j/Logger;Ljava/lang/Throwable;Lkotlin/jvm/functions/Function0;)V
public static synthetic fun error$default (Lorg/slf4j/Logger;Ljava/lang/Throwable;Lkotlin/jvm/functions/Function0;ILjava/lang/Object;)V
public static final fun info (Lorg/slf4j/Logger;Lkotlin/jvm/functions/Function0;)V
public static final fun warn (Lorg/slf4j/Logger;Lkotlin/jvm/functions/Function0;)V
}

public class eu/vendeli/tgbot/utils/TgException : java/lang/RuntimeException {
Expand Down
10 changes: 5 additions & 5 deletions telegram-bot/api/telegram-bot.klib.api
Original file line number Diff line number Diff line change
Expand Up @@ -980,7 +980,7 @@ abstract class <#A: kotlin/Any?> eu.vendeli.tgbot.interfaces.action/MediaAction
abstract class <#A: kotlin/Any?> eu.vendeli.tgbot.interfaces.action/SimpleAction : eu.vendeli.tgbot.interfaces.action/TgAction<#A> { // eu.vendeli.tgbot.interfaces.action/SimpleAction|null[0]
constructor <init>() // eu.vendeli.tgbot.interfaces.action/SimpleAction.<init>|<init>(){}[0]

final suspend fun sendReturning(eu.vendeli.tgbot/TelegramBot): kotlinx.coroutines/Deferred<eu.vendeli.tgbot.types.internal/Response<out #A>> // eu.vendeli.tgbot.interfaces.action/SimpleAction.sendReturning|sendReturning(eu.vendeli.tgbot.TelegramBot){}[0]
final suspend inline fun sendReturning(eu.vendeli.tgbot/TelegramBot): kotlinx.coroutines/Deferred<eu.vendeli.tgbot.types.internal/Response<out #A>> // eu.vendeli.tgbot.interfaces.action/SimpleAction.sendReturning|sendReturning(eu.vendeli.tgbot.TelegramBot){}[0]
open suspend fun send(eu.vendeli.tgbot/TelegramBot) // eu.vendeli.tgbot.interfaces.action/SimpleAction.send|send(eu.vendeli.tgbot.TelegramBot){}[0]
open suspend fun sendAsync(eu.vendeli.tgbot/TelegramBot): kotlinx.coroutines/Deferred<eu.vendeli.tgbot.types.internal/Response<out #A>> // eu.vendeli.tgbot.interfaces.action/SimpleAction.sendAsync|sendAsync(eu.vendeli.tgbot.TelegramBot){}[0]
}
Expand Down Expand Up @@ -13433,6 +13433,10 @@ final fun eu.vendeli.tgbot.utils.builders/inlineKeyboardMarkup(kotlin/Function1<
final fun eu.vendeli.tgbot.utils.builders/replyKeyboardMarkup(kotlin/Function1<eu.vendeli.tgbot.utils.builders/ReplyKeyboardMarkupBuilder, kotlin/Unit>): eu.vendeli.tgbot.types.keyboard/ReplyKeyboardMarkup // eu.vendeli.tgbot.utils.builders/replyKeyboardMarkup|replyKeyboardMarkup(kotlin.Function1<eu.vendeli.tgbot.utils.builders.ReplyKeyboardMarkupBuilder,kotlin.Unit>){}[0]
final inline fun (eu.vendeli.tgbot.types.internal/InputFile).eu.vendeli.tgbot.utils/toImplicitFile(): eu.vendeli.tgbot.types.internal/ImplicitFile.InpFile // eu.vendeli.tgbot.utils/toImplicitFile|toImplicitFile@eu.vendeli.tgbot.types.internal.InputFile(){}[0]
final inline fun (eu.vendeli.tgbot.types.internal/ProcessedUpdate).eu.vendeli.tgbot.types.internal/getUser(): eu.vendeli.tgbot.types/User // eu.vendeli.tgbot.types.internal/getUser|getUser@eu.vendeli.tgbot.types.internal.ProcessedUpdate(){}[0]
final inline fun (io.ktor.util.logging/Logger).eu.vendeli.tgbot.utils/debug(kotlin/Function0<kotlin/String>) // eu.vendeli.tgbot.utils/debug|debug@io.ktor.util.logging.Logger(kotlin.Function0<kotlin.String>){}[0]
final inline fun (io.ktor.util.logging/Logger).eu.vendeli.tgbot.utils/error(kotlin/Throwable? = ..., kotlin/Function0<kotlin/String>) // eu.vendeli.tgbot.utils/error|error@io.ktor.util.logging.Logger(kotlin.Throwable?;kotlin.Function0<kotlin.String>){}[0]
final inline fun (io.ktor.util.logging/Logger).eu.vendeli.tgbot.utils/info(kotlin/Function0<kotlin/String>) // eu.vendeli.tgbot.utils/info|info@io.ktor.util.logging.Logger(kotlin.Function0<kotlin.String>){}[0]
final inline fun (io.ktor.util.logging/Logger).eu.vendeli.tgbot.utils/warn(kotlin/Function0<kotlin/String>) // eu.vendeli.tgbot.utils/warn|warn@io.ktor.util.logging.Logger(kotlin.Function0<kotlin.String>){}[0]
final inline fun (kotlin/String).eu.vendeli.tgbot.utils/toImplicitFile(): eu.vendeli.tgbot.types.internal/ImplicitFile.Str // eu.vendeli.tgbot.utils/toImplicitFile|toImplicitFile@kotlin.String(){}[0]
final inline fun <#A: kotlin/Any?> (eu.vendeli.tgbot.types.internal/Response<#A>).eu.vendeli.tgbot.types.internal/onFailure(kotlin/Function1<eu.vendeli.tgbot.types.internal/Response.Failure, kotlin/Unit>): #A? // eu.vendeli.tgbot.types.internal/onFailure|onFailure@eu.vendeli.tgbot.types.internal.Response<0:0>(kotlin.Function1<eu.vendeli.tgbot.types.internal.Response.Failure,kotlin.Unit>){0§<kotlin.Any?>}[0]
final inline fun <#A: reified kotlin/Any> (eu.vendeli.tgbot.interfaces.ctx/ClassManager).eu.vendeli.tgbot.utils/getInstance(kotlin/Array<out kotlin/Any?>...): #A? // eu.vendeli.tgbot.utils/getInstance|getInstance@eu.vendeli.tgbot.interfaces.ctx.ClassManager(kotlin.Array<out|kotlin.Any?>...){0§<kotlin.Any>}[0]
Expand Down Expand Up @@ -13685,10 +13689,6 @@ final inline fun eu.vendeli.tgbot.api/stopMessageLiveLocation(kotlin/Long): eu.v
final inline fun eu.vendeli.tgbot.api/stopPoll(kotlin/Long): eu.vendeli.tgbot.api/StopPollAction // eu.vendeli.tgbot.api/stopPoll|stopPoll(kotlin.Long){}[0]
final inline fun eu.vendeli.tgbot.api/venue(kotlin/Float, kotlin/Float, kotlin/String, kotlin/String): eu.vendeli.tgbot.api/SendVenueAction // eu.vendeli.tgbot.api/venue|venue(kotlin.Float;kotlin.Float;kotlin.String;kotlin.String){}[0]
final suspend fun (eu.vendeli.tgbot.core/TgUpdateHandler).eu.vendeli.tgbot.utils/runExceptionHandler(kotlinx.coroutines/CoroutineDispatcher = ..., kotlin/Long = ..., eu.vendeli.tgbot.interfaces.helper/ExceptionHandler): kotlinx.coroutines/Job // eu.vendeli.tgbot.utils/runExceptionHandler|runExceptionHandler@eu.vendeli.tgbot.core.TgUpdateHandler(kotlinx.coroutines.CoroutineDispatcher;kotlin.Long;eu.vendeli.tgbot.interfaces.helper.ExceptionHandler){}[0]
final suspend inline fun (io.ktor.util.logging/Logger).eu.vendeli.tgbot.utils/debug(kotlin/Function0<kotlin/String>) // eu.vendeli.tgbot.utils/debug|debug@io.ktor.util.logging.Logger(kotlin.Function0<kotlin.String>){}[0]
final suspend inline fun (io.ktor.util.logging/Logger).eu.vendeli.tgbot.utils/error(kotlin/Throwable? = ..., kotlin/Function0<kotlin/String>) // eu.vendeli.tgbot.utils/error|error@io.ktor.util.logging.Logger(kotlin.Throwable?;kotlin.Function0<kotlin.String>){}[0]
final suspend inline fun (io.ktor.util.logging/Logger).eu.vendeli.tgbot.utils/info(kotlin/Function0<kotlin/String>) // eu.vendeli.tgbot.utils/info|info@io.ktor.util.logging.Logger(kotlin.Function0<kotlin.String>){}[0]
final suspend inline fun (io.ktor.util.logging/Logger).eu.vendeli.tgbot.utils/warn(kotlin/Function0<kotlin/String>) // eu.vendeli.tgbot.utils/warn|warn@io.ktor.util.logging.Logger(kotlin.Function0<kotlin.String>){}[0]
final suspend inline fun <#A: kotlin/Any?, #B: kotlin/Any?> (kotlinx.coroutines/Deferred<eu.vendeli.tgbot.types.internal/Response<out #A>>).eu.vendeli.tgbot.types.internal/foldResponse(kotlin/Function1<eu.vendeli.tgbot.types.internal/Response.Success<#A>, #B>, kotlin/Function1<eu.vendeli.tgbot.types.internal/Response.Failure, #B>): #B // eu.vendeli.tgbot.types.internal/foldResponse|foldResponse@kotlinx.coroutines.Deferred<eu.vendeli.tgbot.types.internal.Response<out|0:0>>(kotlin.Function1<eu.vendeli.tgbot.types.internal.Response.Success<0:0>,0:1>;kotlin.Function1<eu.vendeli.tgbot.types.internal.Response.Failure,0:1>){0§<kotlin.Any?>;1§<kotlin.Any?>}[0]
final suspend inline fun <#A: kotlin/Any?> (kotlinx.coroutines/Deferred<eu.vendeli.tgbot.types.internal/Response<out #A>>).eu.vendeli.tgbot.types.internal/getOrNull(): #A? // eu.vendeli.tgbot.types.internal/getOrNull|getOrNull@kotlinx.coroutines.Deferred<eu.vendeli.tgbot.types.internal.Response<out|0:0>>(){0§<kotlin.Any?>}[0]
final suspend inline fun <#A: kotlin/Any?> (kotlinx.coroutines/Deferred<eu.vendeli.tgbot.types.internal/Response<out #A>>).eu.vendeli.tgbot.types.internal/onFailure(kotlin/Function1<eu.vendeli.tgbot.types.internal/Response.Failure, kotlin/Unit>): #A? // eu.vendeli.tgbot.types.internal/onFailure|onFailure@kotlinx.coroutines.Deferred<eu.vendeli.tgbot.types.internal.Response<out|0:0>>(kotlin.Function1<eu.vendeli.tgbot.types.internal.Response.Failure,kotlin.Unit>){0§<kotlin.Any?>}[0]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,5 @@ abstract class SimpleAction<ReturnType> : TgAction<ReturnType>() {
to: TelegramBot,
): Deferred<Response<out ReturnType>> = doRequestReturning(to)

suspend fun sendReturning(to: TelegramBot): Deferred<Response<out ReturnType>> = doRequestReturning(to)
suspend inline fun sendReturning(to: TelegramBot): Deferred<Response<out ReturnType>> = doRequestReturning(to)
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ import io.ktor.util.logging.Logger
internal expect inline fun getLogger(lvl: LogLvl, tag: String): Logger

@Suppress("NOTHING_TO_INLINE")
suspend inline fun Logger.info(message: () -> String) = info(message())
inline fun Logger.info(message: () -> String) = info(message())

@Suppress("NOTHING_TO_INLINE")
suspend inline fun Logger.warn(message: () -> String) = warn(message())
inline fun Logger.warn(message: () -> String) = warn(message())

@Suppress("NOTHING_TO_INLINE")
suspend inline fun Logger.debug(message: () -> String) = debug(message())
inline fun Logger.debug(message: () -> String) = debug(message())

@Suppress("NOTHING_TO_INLINE")
suspend inline fun Logger.error(throwable: Throwable? = null, message: () -> String) =
inline fun Logger.error(throwable: Throwable? = null, message: () -> String) =
throwable?.let { error(message(), it) } ?: error(message())
Original file line number Diff line number Diff line change
Expand Up @@ -53,5 +53,5 @@ fun Update.processUpdate(): ProcessedUpdate = when {
editedBusinessMessage != null -> EditedBusinessMessageUpdate(updateId, this, editedBusinessMessage)
deletedBusinessMessages != null -> DeletedBusinessMessagesUpdate(updateId, this, deletedBusinessMessages)
purchasedPaidMedia != null -> PurchasedPaidMediaUpdate(updateId, this, purchasedPaidMedia)
else -> throw IllegalArgumentException("Unknown type of update.")
else -> throw TgException("Unknown type of update.")
}
Original file line number Diff line number Diff line change
Expand Up @@ -136,11 +136,11 @@ private suspend fun FunctionalHandlingDsl.checkMessageForActivities(update: Proc
foundChain.inputActivity.invoke(inputContext)
// invoke chain if break condition is false
} else {
prevChain?.breakPoint?.activity?.invoke(inputContext)
prevChain.breakPoint?.activity?.invoke(inputContext)
// invoke break point activity when it's a break case
}

if (isBreakCase && prevChain?.breakPoint?.repeat == true) {
if (isBreakCase && prevChain.breakPoint?.repeat == true) {
// and if we need to repeat, do set listener again
bot.inputListener.set(user.id, foundChain.id)
return true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ package eu.vendeli.tgbot.utils.serde
import kotlinx.serialization.json.JsonElement
import kotlinx.serialization.json.JsonPrimitive

public val JsonElement.primitiveOrNull: JsonPrimitive?
val JsonElement.primitiveOrNull: JsonPrimitive?
get() = this as? JsonPrimitive

0 comments on commit b196e79

Please sign in to comment.