Skip to content

Commit

Permalink
7.6.0 (#296)
Browse files Browse the repository at this point in the history
* Supported Telegram API [8.1](https://core.telegram.org/bots/api-changelog#december-4-2024).
* Fixed `InlineQueryResult` cached and usual results serde clashing issue.
* Fixed `savePreparedInlineMessage` options serde issue.
* Added option to disable automatically cleaning class data through plugin's `autoCleanClassData` parameter.
  • Loading branch information
vendelieu authored Dec 4, 2024
1 parent 1e33ced commit a2ce66f
Show file tree
Hide file tree
Showing 42 changed files with 572 additions and 96 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/[email protected]
- uses: gradle/wrapper-validation-action@v3
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# Telegram-bot (KtGram) Changelog

## 7.6.0

* Supported Telegram API [8.1](https://core.telegram.org/bots/api-changelog#december-4-2024).
* Fixed `InlineQueryResult` cached and usual results serde clashing issue.
* Fixed `savePreparedInlineMessage` options serde issue.
* Added option to disable automatically cleaning class data through plugin's `autoCleanClassData` parameter.

## 7.5.0

* Supported Telegram API [8.0](https://core.telegram.org/bots/api-changelog#november-17-2024).
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
[![Chat in Telegram](https://img.shields.io/static/v1?label=Telegram&message=Chat&color=blue&logo=telegram)](https://t.me/venny_tgbot)
[![Chat in Telegram](https://img.shields.io/static/v1?label=Telegram&message=Channel&color=blue&logo=telegram)](https://t.me/kotlingram)

[![Validate Gradle Wrapper](https://github.com/vendelieu/telegram-bot/actions/workflows/gradle-wrapper-validation.yml/badge.svg)](https://github.com/vendelieu/telegram-bot/actions/workflows/gradle-wrapper-validation.yml)

Telegram Bot Api wrapper with a user-friendly interface.

# Installation
Expand Down
117 changes: 110 additions & 7 deletions buildSrc/src/main/resources/api.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"version": "Bot API 8.0",
"release_date": "November 17, 2024",
"changelog": "https://core.telegram.org/bots/api#november-17-2024",
"version": "Bot API 8.1",
"release_date": "December 4, 2024",
"changelog": "https://core.telegram.org/bots/api#december-4-2024",
"methods": {
"getUpdates": {
"name": "getUpdates",
Expand Down Expand Up @@ -6223,7 +6223,7 @@
"String"
],
"required": false,
"description": "Unique identifier of the business connection on behalf of which the link will be created"
"description": "Unique identifier of the business connection on behalf of which the link will be created. For payments in Telegram Stars only."
},
{
"name": "title",
Expand Down Expand Up @@ -6279,7 +6279,7 @@
"Integer"
],
"required": false,
"description": "The number of seconds the subscription will be active for before the next payment. The currency must be set to \"XTR\" (Telegram Stars) if the parameter is used. Currently, it must always be 2592000 (30 days) if specified."
"description": "The number of seconds the subscription will be active for before the next payment. The currency must be set to \"XTR\" (Telegram Stars) if the parameter is used. Currently, it must always be 2592000 (30 days) if specified. Any number of subscriptions can be active for a given bot at the same time, including multiple concurrent subscriptions from the same user. Subscription price must no exceed 2500 Telegram Stars."
},
{
"name": "max_tip_amount",
Expand Down Expand Up @@ -18032,19 +18032,70 @@
"RevenueWithdrawalState"
]
},
"AffiliateInfo": {
"name": "AffiliateInfo",
"href": "https://core.telegram.org/bots/api#affiliateinfo",
"description": [
"Contains information about the affiliate that received a commission via this transaction."
],
"fields": [
{
"name": "affiliate_user",
"types": [
"User"
],
"required": false,
"description": "Optional. The bot or the user that received an affiliate commission if it was received by a bot or a user"
},
{
"name": "affiliate_chat",
"types": [
"Chat"
],
"required": false,
"description": "Optional. The chat that received an affiliate commission if it was received by a chat"
},
{
"name": "commission_per_mille",
"types": [
"Integer"
],
"required": true,
"description": "The number of Telegram Stars received by the affiliate for each 1000 Telegram Stars received by the bot from referred users"
},
{
"name": "amount",
"types": [
"Integer"
],
"required": true,
"description": "Integer amount of Telegram Stars received by the affiliate from the transaction, rounded to 0; can be negative for refunds"
},
{
"name": "nanostar_amount",
"types": [
"Integer"
],
"required": false,
"description": "Optional. The number of 1/1000000000 shares of Telegram Stars received by the affiliate; from -999999999 to 999999999; can be negative for refunds"
}
]
},
"TransactionPartner": {
"name": "TransactionPartner",
"href": "https://core.telegram.org/bots/api#transactionpartner",
"description": [
"This object describes the source of a transaction, or its recipient for outgoing transactions. Currently, it can be one of",
"- TransactionPartnerUser",
"- TransactionPartnerAffiliateProgram",
"- TransactionPartnerFragment",
"- TransactionPartnerTelegramAds",
"- TransactionPartnerTelegramApi",
"- TransactionPartnerOther"
],
"subtypes": [
"TransactionPartnerUser",
"TransactionPartnerAffiliateProgram",
"TransactionPartnerFragment",
"TransactionPartnerTelegramAds",
"TransactionPartnerTelegramApi",
Expand Down Expand Up @@ -18074,6 +18125,14 @@
"required": true,
"description": "Information about the user"
},
{
"name": "affiliate",
"types": [
"AffiliateInfo"
],
"required": false,
"description": "Optional. Information about the affiliate that received a commission via this transaction"
},
{
"name": "invoice_payload",
"types": [
Expand Down Expand Up @@ -18109,7 +18168,7 @@
{
"name": "gift",
"types": [
"String"
"Gift"
],
"required": false,
"description": "Optional. The gift sent to the user by the bot"
Expand All @@ -18119,6 +18178,42 @@
"TransactionPartner"
]
},
"TransactionPartnerAffiliateProgram": {
"name": "TransactionPartnerAffiliateProgram",
"href": "https://core.telegram.org/bots/api#transactionpartneraffiliateprogram",
"description": [
"Describes the affiliate program that issued the affiliate commission received via this transaction."
],
"fields": [
{
"name": "type",
"types": [
"String"
],
"required": true,
"description": "Type of the transaction partner, always \"affiliate_program\""
},
{
"name": "sponsor_user",
"types": [
"User"
],
"required": false,
"description": "Optional. Information about the bot that sponsored the affiliate program"
},
{
"name": "commission_per_mille",
"types": [
"Integer"
],
"required": true,
"description": "The number of Telegram Stars received by the bot for each 1000 Telegram Stars received by the affiliate program sponsor from referred users"
}
],
"subtype_of": [
"TransactionPartner"
]
},
"TransactionPartnerFragment": {
"name": "TransactionPartnerFragment",
"href": "https://core.telegram.org/bots/api#transactionpartnerfragment",
Expand Down Expand Up @@ -18236,7 +18331,15 @@
"Integer"
],
"required": true,
"description": "Number of Telegram Stars transferred by the transaction"
"description": "Integer amount of Telegram Stars transferred by the transaction"
},
{
"name": "nanostar_amount",
"types": [
"Integer"
],
"required": false,
"description": "Optional. The number of 1/1000000000 shares of Telegram Stars transferred by the transaction; from 0 to 999999999"
},
{
"name": "date",
Expand Down
6 changes: 3 additions & 3 deletions buildSrc/src/main/resources/scrape.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,9 +143,9 @@ def get_fields(curr_name: str, curr_type: str, x: Tag, items: dict, url: str):

def get_method_return_type(curr_name: str, curr_type: str, description_items: list[str], items: dict):
description = "\n".join(description_items)
ret_search = re.search("(?:on success,)([^.]*)", description, re.IGNORECASE)
ret_search2 = re.search("(?:returns)([^.]*)(?:on success)?", description, re.IGNORECASE)
ret_search3 = re.search("([^.]*)(?:is returned)", description, re.IGNORECASE)
ret_search = re.search(".*(?:on success,)([^.]*)", description, re.IGNORECASE)
ret_search2 = re.search(".*(?:returns)([^.]*)(?:on success)?", description, re.IGNORECASE)
ret_search3 = re.search(".*([^.]*)(?:is returned)", description, re.IGNORECASE)
if ret_search:
extract_return_type(curr_type, curr_name, ret_search.group(1).strip(), items)
elif ret_search2:
Expand Down
6 changes: 3 additions & 3 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ datetime = "0.6.0"
serialization = "1.7.3"
stately = "2.1.0"

kotlin = "2.0.21"
kotlin = "2.1.0"
coroutines = "1.9.0"
dokka = "1.9.20"
kotlinter = "4.5.0"
Expand All @@ -20,9 +20,9 @@ kover = "0.8.3"
krypto = "4.0.10"
urlencoder = "1.6.0"
sslcontext = "8.3.7"
spring = "3.3.5"
spring = "3.4.0"

ksp = "2.0.21-1.0.28"
ksp = "2.1.0-1.0.29"
poet = "2.0.0"

binvalid = "0.16.3"
Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.11-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.11.1-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
Expand Down
6 changes: 3 additions & 3 deletions ksp/src/jvmMain/kotlin/eu/vendeli/ksp/ActivityCollectors.kt
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ internal fun collectCommandActivities(
activitiesFile.buildInvocationLambdaCodeBlock(
function,
injectableTypes,
pkg,
ctx,
buildMeta(
qualifier = function.qualifiedName!!.getQualifier(),
function = function.simpleName.asString(),
Expand Down Expand Up @@ -124,7 +124,7 @@ internal fun collectInputActivities(
activitiesFile.buildInvocationLambdaCodeBlock(
function,
injectableTypes,
pkg,
ctx,
buildMeta(
qualifier = function.qualifiedName!!.getQualifier(),
function = function.simpleName.asString(),
Expand Down Expand Up @@ -198,7 +198,7 @@ internal fun collectCommonActivities(
activitiesFile.buildInvocationLambdaCodeBlock(
commonAnnotationData.funDeclaration,
injectableTypes,
pkg,
ctx,
buildMeta(
qualifier = commonAnnotationData.funQualifier,
function = commonAnnotationData.funSimpleName,
Expand Down
2 changes: 2 additions & 0 deletions ksp/src/jvmMain/kotlin/eu/vendeli/ksp/ActivityProcessor.kt
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ class ActivityProcessor(
private val codeGenerator: CodeGenerator,
) : SymbolProcessor {
private val targetPackage = options["package"]?.split(';')
private val autoCleanClassData = options["autoCleanClassData"]?.toBooleanStrictOrNull() != false

override fun process(resolver: Resolver): List<KSAnnotated> {
val fileSpec = FileSpec.builder("eu.vendeli.tgbot.generated", "ActivitiesData").apply {
Expand Down Expand Up @@ -144,6 +145,7 @@ class ActivityProcessor(
logger = logger,
idxPostfix = idxPostfix,
pkg = filePkg,
autoCleanClassData = autoCleanClassData
)

collectCommandActivities(commandHandlerSymbols, context)
Expand Down
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
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import com.squareup.kotlinpoet.STRING
import com.squareup.kotlinpoet.TypeName
import com.squareup.kotlinpoet.buildCodeBlock
import com.squareup.kotlinpoet.ksp.toTypeName
import eu.vendeli.ksp.dto.CollectorsContext
import eu.vendeli.ksp.dto.CommandHandlerParams
import eu.vendeli.ksp.dto.LambdaParameters
import eu.vendeli.ksp.utils.FileBuilder
Expand Down Expand Up @@ -78,7 +79,7 @@ import kotlin.reflect.KClass
internal fun FileBuilder.buildInvocationLambdaCodeBlock(
function: KSFunctionDeclaration,
injectableTypes: Map<TypeName, ClassName>,
pkg: String? = null,
ctx: CollectorsContext? = null,
meta: Pair<String, Array<Any?>>? = null,
parameters: List<LambdaParameters> = emptyList(),
) = buildCodeBlock {
Expand Down Expand Up @@ -176,12 +177,12 @@ internal fun FileBuilder.buildInvocationLambdaCodeBlock(
if (index < function.parameters.lastIndex) parametersEnumeration += ", "
}

if (pkg != null) add(
if (ctx?.autoCleanClassData == true && ctx.pkg != null) add(
"\nif (\n\t" +
(if (isUserNullable) "user != null\n && " else "") +
"bot.update.userClassSteps[user.id] != %S\n) %L.____clearClassData(user.id)\n",
funQualifier,
pkg,
ctx.pkg,
)

if (parameters.contains(CommandHandlerParams.CallbackQueryAutoAnswer)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@ data class CollectorsContext(
val logger: KSPLogger,
val idxPostfix: String,
val pkg: String? = null,
val autoCleanClassData: Boolean = true,
)
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
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@ abstract class KtGramExt
val packages = factory.listProperty<String>()
val addSnapshotRepo = factory.property<Boolean>()
val forceVersion = factory.property<String>()
val autoCleanClassData = factory.property<Boolean>()
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ abstract class KtGramPlugin : Plugin<Project> {
pluginExtension.packages.orNull?.takeIf { it.isNotEmpty() }?.joinToString(";")?.let {
arg("package", it)
}
pluginExtension.autoCleanClassData.getOrElse(true).takeIf { !it }?.let {
arg("autoCleanClassData", "false")
}
}

if (!kspPluginPresent) log.error(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -473,6 +473,9 @@ public inline fun TelegramBot.refundStarPayment(telegramPaymentChargeId: String,
@Suppress("NOTHING_TO_INLINE")
public inline fun TelegramBot.savePreparedInlineMessage(userId: Long, result: InlineQueryResult): SavePreparedInlineMessageAction = eu.vendeli.tgbot.api.botactions.savePreparedInlineMessage(userId, result)

@Suppress("NOTHING_TO_INLINE")
public inline fun TelegramBot.savePreparedInlineMessage(userId: Long, noinline result: () -> InlineQueryResult): SavePreparedInlineMessageAction = eu.vendeli.tgbot.api.botactions.savePreparedInlineMessage(userId, result)

@Suppress("NOTHING_TO_INLINE")
public inline fun TelegramBot.sendGift(
userId: Long,
Expand Down
2 changes: 1 addition & 1 deletion settings.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
plugins {
id("org.gradle.toolchains.foojay-resolver-convention") version "0.8.0"
id("org.gradle.toolchains.foojay-resolver-convention") version "0.9.0"
}
rootProject.name = "ktgram"

Expand Down
Loading

0 comments on commit a2ce66f

Please sign in to comment.