1
0
mirror of https://github.com/InsanusMokrassar/TelegramBotAPI.git synced 2024-11-22 16:23:48 +00:00

Compare commits

...

11 Commits

Author SHA1 Message Date
ddf34aad3f
Merge pull request #921 from InsanusMokrassar/20.0.1
20.0.1
2024-11-11 14:11:51 +06:00
c818a44044 fill changelog 2024-11-11 13:52:31 +06:00
d578f6af90 jvmApiDump 2024-11-11 13:38:09 +06:00
5ce4e4cbc0 fix of modifyRow 2024-11-11 13:37:20 +06:00
41e369cea5 fix of #761 2024-11-11 13:35:46 +06:00
f85d4a36e1 fix of #860 2024-11-11 13:14:28 +06:00
fb3b8a7415 fix of #917 2024-11-11 13:03:46 +06:00
609c2b5fad fix of #919 2024-11-11 12:39:42 +06:00
2c602e4434
Merge pull request #920 from byteduck-exploit/patch-1
Use correct method name for createInvoiceLink.
2024-11-11 12:38:01 +06:00
1a3c9bca1d start 20.0.1 2024-11-11 12:36:30 +06:00
Alex
43496505a7
Use correct method name for createInvoiceLink. 2024-11-11 05:14:07 +01:00
13 changed files with 139 additions and 17 deletions

View File

@ -1,5 +1,14 @@
# TelegramBotAPI changelog # TelegramBotAPI changelog
## 20.0.1
* `Core`:
* Fix of logger propagation (fix of [#860](https://github.com/InsanusMokrassar/ktgbotapi/issues/860))
* Add opportunity to modify keyboards (fix of [#761](https://github.com/InsanusMokrassar/ktgbotapi/issues/761))
* Fields of `OrderInfo` became nullable (fix of [#917](https://github.com/InsanusMokrassar/ktgbotapi/issues/917))
* Add default `toString` to `ChatType` (fix of [#919](https://github.com/InsanusMokrassar/ktgbotapi/issues/919))
* Fix of method in `CreateInvoiceLink` (merging of [#920](https://github.com/InsanusMokrassar/ktgbotapi/issues/920), made by [byteduck-exploit](https://github.com/byteduck-exploit))
## 20.0.0 ## 20.0.0
**THIS UPDATE CONTAINS SUPPORT OF [BOTS API 7.11](https://core.telegram.org/bots/api-changelog#october-31-2024)** **THIS UPDATE CONTAINS SUPPORT OF [BOTS API 7.11](https://core.telegram.org/bots/api-changelog#october-31-2024)**

View File

@ -6,4 +6,4 @@ kotlin.incremental=true
kotlin.incremental.js=true kotlin.incremental.js=true
library_group=dev.inmo library_group=dev.inmo
library_version=20.0.0 library_version=20.0.1

View File

@ -13558,6 +13558,8 @@ public final class dev/inmo/tgbotapi/types/buttons/InlineKeyboardMarkup : dev/in
public fun equals (Ljava/lang/Object;)Z public fun equals (Ljava/lang/Object;)Z
public final fun getKeyboard ()Ljava/util/List; public final fun getKeyboard ()Ljava/util/List;
public fun hashCode ()I public fun hashCode ()I
public final fun minus (Ldev/inmo/tgbotapi/types/buttons/InlineKeyboardMarkup;)Ldev/inmo/tgbotapi/types/buttons/InlineKeyboardMarkup;
public final fun plus (Ldev/inmo/tgbotapi/types/buttons/InlineKeyboardMarkup;)Ldev/inmo/tgbotapi/types/buttons/InlineKeyboardMarkup;
public fun toString ()Ljava/lang/String; public fun toString ()Ljava/lang/String;
} }
@ -13872,6 +13874,8 @@ public final class dev/inmo/tgbotapi/types/buttons/ReplyKeyboardMarkup : dev/inm
public static final field Companion Ldev/inmo/tgbotapi/types/buttons/ReplyKeyboardMarkup$Companion; public static final field Companion Ldev/inmo/tgbotapi/types/buttons/ReplyKeyboardMarkup$Companion;
public fun <init> (Ljava/util/List;Ljava/lang/Boolean;Ljava/lang/Boolean;Ljava/lang/String;Ljava/lang/Boolean;Ljava/lang/Boolean;)V public fun <init> (Ljava/util/List;Ljava/lang/Boolean;Ljava/lang/Boolean;Ljava/lang/String;Ljava/lang/Boolean;Ljava/lang/Boolean;)V
public synthetic fun <init> (Ljava/util/List;Ljava/lang/Boolean;Ljava/lang/Boolean;Ljava/lang/String;Ljava/lang/Boolean;Ljava/lang/Boolean;ILkotlin/jvm/internal/DefaultConstructorMarker;)V public synthetic fun <init> (Ljava/util/List;Ljava/lang/Boolean;Ljava/lang/Boolean;Ljava/lang/String;Ljava/lang/Boolean;Ljava/lang/Boolean;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
public final fun add (Ldev/inmo/tgbotapi/types/buttons/ReplyKeyboardMarkup;Ljava/lang/String;)Ldev/inmo/tgbotapi/types/buttons/ReplyKeyboardMarkup;
public static synthetic fun add$default (Ldev/inmo/tgbotapi/types/buttons/ReplyKeyboardMarkup;Ldev/inmo/tgbotapi/types/buttons/ReplyKeyboardMarkup;Ljava/lang/String;ILjava/lang/Object;)Ldev/inmo/tgbotapi/types/buttons/ReplyKeyboardMarkup;
public final fun component1 ()Ljava/util/List; public final fun component1 ()Ljava/util/List;
public final fun component2 ()Ljava/lang/Boolean; public final fun component2 ()Ljava/lang/Boolean;
public final fun component3 ()Ljava/lang/Boolean; public final fun component3 ()Ljava/lang/Boolean;
@ -13888,6 +13892,8 @@ public final class dev/inmo/tgbotapi/types/buttons/ReplyKeyboardMarkup : dev/inm
public final fun getResizeKeyboard ()Ljava/lang/Boolean; public final fun getResizeKeyboard ()Ljava/lang/Boolean;
public final fun getSelective ()Ljava/lang/Boolean; public final fun getSelective ()Ljava/lang/Boolean;
public fun hashCode ()I public fun hashCode ()I
public final fun minus (Ldev/inmo/tgbotapi/types/buttons/ReplyKeyboardMarkup;)Ldev/inmo/tgbotapi/types/buttons/ReplyKeyboardMarkup;
public final fun plus (Ldev/inmo/tgbotapi/types/buttons/ReplyKeyboardMarkup;)Ldev/inmo/tgbotapi/types/buttons/ReplyKeyboardMarkup;
public fun toString ()Ljava/lang/String; public fun toString ()Ljava/lang/String;
} }
@ -14752,6 +14758,7 @@ public final class dev/inmo/tgbotapi/types/chat/ChatSerializersKt {
public abstract class dev/inmo/tgbotapi/types/chat/ChatType { public abstract class dev/inmo/tgbotapi/types/chat/ChatType {
public static final field Companion Ldev/inmo/tgbotapi/types/chat/ChatType$Companion; public static final field Companion Ldev/inmo/tgbotapi/types/chat/ChatType$Companion;
public abstract fun getStringified ()Ljava/lang/String; public abstract fun getStringified ()Ljava/lang/String;
public fun toString ()Ljava/lang/String;
} }
public final class dev/inmo/tgbotapi/types/chat/ChatType$Channel : dev/inmo/tgbotapi/types/chat/ChatType { public final class dev/inmo/tgbotapi/types/chat/ChatType$Channel : dev/inmo/tgbotapi/types/chat/ChatType {
@ -27066,7 +27073,10 @@ public class dev/inmo/tgbotapi/utils/MatrixBuilder {
public fun <init> ()V public fun <init> ()V
public final fun add (Ljava/util/List;)Z public final fun add (Ljava/util/List;)Z
public final fun getMatrix ()Ljava/util/List; public final fun getMatrix ()Ljava/util/List;
public final fun modifyRow (ILkotlin/jvm/functions/Function1;)V
public final fun modifyRow (Ljava/util/List;Lkotlin/jvm/functions/Function1;)Z
public final fun plus (Ljava/util/List;)Z public final fun plus (Ljava/util/List;)Z
public final fun remove (I)Ljava/util/List;
public final fun unaryPlus (Ljava/lang/Object;)Z public final fun unaryPlus (Ljava/lang/Object;)Z
} }
@ -27149,6 +27159,9 @@ public class dev/inmo/tgbotapi/utils/RowBuilder {
public fun <init> ()V public fun <init> ()V
public final fun add (Ljava/lang/Object;)Z public final fun add (Ljava/lang/Object;)Z
public final fun getRow ()Ljava/util/List; public final fun getRow ()Ljava/util/List;
public final fun remove (I)Ljava/lang/Object;
public final fun replace (ILjava/lang/Object;)V
public final fun replace (Ljava/lang/Object;Ljava/lang/Object;)Z
public final fun unaryPlus (Ljava/lang/Object;)Z public final fun unaryPlus (Ljava/lang/Object;)Z
} }

View File

@ -34,14 +34,14 @@ class KtorRequestsExecutorBuilder(
} }
fun build() = KtorRequestsExecutor( fun build() = KtorRequestsExecutor(
telegramAPIUrlsKeeper, telegramAPIUrlsKeeper = telegramAPIUrlsKeeper,
client, client = client,
callsFactories, callsFactories = callsFactories,
excludeDefaultFactories, excludeDefaultFactories = excludeDefaultFactories,
requestsLimiter, requestsLimiter = requestsLimiter,
jsonFormatter, jsonFormatter = jsonFormatter,
pipelineStepsHolder, pipelineStepsHolder = pipelineStepsHolder,
logger logger = logger
) )
} }

View File

@ -32,10 +32,10 @@ class DefaultKtorRequestsExecutor internal constructor(
) : BaseRequestsExecutor(telegramAPIUrlsKeeper) { ) : BaseRequestsExecutor(telegramAPIUrlsKeeper) {
private val callsFactories: List<KtorCallFactory> = callsFactories.run { private val callsFactories: List<KtorCallFactory> = callsFactories.run {
if (!excludeDefaultFactories) { if (!excludeDefaultFactories) {
logger.v { "Installing default factories" } this@DefaultKtorRequestsExecutor.logger.v { "Installing default factories" }
this + createTelegramBotDefaultKtorCallRequestsFactories(logger) this + createTelegramBotDefaultKtorCallRequestsFactories(this@DefaultKtorRequestsExecutor.logger)
} else { } else {
logger.v { "Default factories will not be installed" } this@DefaultKtorRequestsExecutor.logger.v { "Default factories will not be installed" }
this this
} }
} }

View File

@ -54,7 +54,7 @@ data class CreateInvoiceLink(
@SerialName(priceDependOnShipAddressField) @SerialName(priceDependOnShipAddressField)
override val priceDependOnShipAddress: Boolean = false override val priceDependOnShipAddress: Boolean = false
) : CommonSendInvoiceData, SimpleRequest<String> { ) : CommonSendInvoiceData, SimpleRequest<String> {
override fun method(): String = "sendInvoice" override fun method(): String = "createInvoiceLink"
override val resultDeserializer: DeserializationStrategy<String> override val resultDeserializer: DeserializationStrategy<String>
get() = String.serializer() get() = String.serializer()
override val requestSerializer: SerializationStrategy<*> override val requestSerializer: SerializationStrategy<*>

View File

@ -25,4 +25,23 @@ data class InlineKeyboardMarkup(
} }
} }
} }
operator fun plus(other: InlineKeyboardMarkup): InlineKeyboardMarkup {
return InlineKeyboardMarkup(
keyboard + other.keyboard
)
}
operator fun minus(other: InlineKeyboardMarkup): InlineKeyboardMarkup {
val otherButtons = other.keyboard.flatten()
return InlineKeyboardMarkup(
keyboard.mapNotNull { row ->
row.filter { button ->
button !in otherButtons
}.takeIf {
it.isNotEmpty()
}
}
)
}
} }

View File

@ -22,4 +22,32 @@ data class ReplyKeyboardMarkup(
error("Field $inputFieldPlaceholderField length must be in $inputFieldPlaceholderLimit, but was ${inputFieldPlaceholder.length}") error("Field $inputFieldPlaceholderField length must be in $inputFieldPlaceholderLimit, but was ${inputFieldPlaceholder.length}")
} }
} }
fun add(other: ReplyKeyboardMarkup, placeholderDelimiter: String = "\n"): ReplyKeyboardMarkup {
return ReplyKeyboardMarkup(
keyboard = keyboard + other.keyboard,
resizeKeyboard = resizeKeyboard ?.or(other.resizeKeyboard ?: false) ?: other.resizeKeyboard,
oneTimeKeyboard = oneTimeKeyboard ?.or(other.oneTimeKeyboard ?: false) ?: other.oneTimeKeyboard,
inputFieldPlaceholder = inputFieldPlaceholder ?.plus(other.inputFieldPlaceholder ?.let { placeholderDelimiter + it } ?: "") ?: other.inputFieldPlaceholder,
selective = selective ?.or(other.selective ?: false) ?: other.selective,
persistent = persistent ?.or(other.persistent ?: false) ?: other.persistent,
)
}
operator fun plus(other: ReplyKeyboardMarkup): ReplyKeyboardMarkup {
return add(other)
}
operator fun minus(other: ReplyKeyboardMarkup): ReplyKeyboardMarkup {
val otherButtons = other.keyboard.flatten()
return copy(
keyboard.mapNotNull { row ->
row.filter { button ->
button !in otherButtons
}.takeIf {
it.isNotEmpty()
}
}
)
}
} }

View File

@ -29,6 +29,10 @@ sealed class ChatType {
object Channel : ChatType() { override val stringified = "channel" } object Channel : ChatType() { override val stringified = "channel" }
@Serializable(ChatTypeSerializer::class) @Serializable(ChatTypeSerializer::class)
class Unknown(override val stringified: String) : ChatType() class Unknown(override val stringified: String) : ChatType()
override fun toString(): String {
return stringified
}
} }
val String.asChatType val String.asChatType
get() = when (this) { get() = when (this) {

View File

@ -4,14 +4,21 @@ import dev.inmo.tgbotapi.types.*
import kotlinx.serialization.SerialName import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable import kotlinx.serialization.Serializable
/**
* All the field of this class are nullable due to specific of [OrderInfo](https://core.telegram.org/bots/api#orderinfo)
* from official bots api
*
* @see dev.inmo.tgbotapi.abstracts.CommonSendInvoiceData
* @see dev.inmo.tgbotapi.requests.send.payments.SendInvoice
*/
@Serializable @Serializable
data class OrderInfo( data class OrderInfo(
@SerialName(nameField) @SerialName(nameField)
val name: String, val name: String?,
@SerialName(phoneNumberField) @SerialName(phoneNumberField)
val phoneNumber: String, val phoneNumber: String?,
@SerialName(emailField) @SerialName(emailField)
val email: String, val email: String?,
@SerialName(shippingAddressField) @SerialName(shippingAddressField)
val shippingAddress: ShippingAddress val shippingAddress: ShippingAddress?
) )

View File

@ -1,5 +1,6 @@
package dev.inmo.tgbotapi.utils package dev.inmo.tgbotapi.utils
import dev.inmo.micro_utils.common.withReplaced
import dev.inmo.tgbotapi.types.buttons.Matrix import dev.inmo.tgbotapi.types.buttons.Matrix
/** /**
@ -67,6 +68,18 @@ open class RowBuilder<T> {
fun add(t: T) = mutRow.add(t) fun add(t: T) = mutRow.add(t)
operator fun T.unaryPlus() = add(this) operator fun T.unaryPlus() = add(this)
fun replace(i: Int, new: T) {
mutRow[i] = new
}
fun replace(old: T, new: T): Boolean {
val i = mutRow.indexOf(old).takeIf { it > -1 } ?: return false
replace(i, new)
return mutRow[i] == new
}
fun remove(i: Int): T {
return mutRow.removeAt(i)
}
} }
open class MatrixBuilder<T> { open class MatrixBuilder<T> {
@ -77,4 +90,19 @@ open class MatrixBuilder<T> {
fun add(t: List<T>) = mutMatrix.add(t) fun add(t: List<T>) = mutMatrix.add(t)
operator fun plus(t: List<T>) = add(t) operator fun plus(t: List<T>) = add(t)
operator fun T.unaryPlus() = add(listOf(this)) operator fun T.unaryPlus() = add(listOf(this))
fun modifyRow(i: Int, block: RowBuilder<T>.() -> Unit) {
val exists = matrix[i]
val rowBuilder = RowBuilder<T>()
exists.forEach { rowBuilder.add(it) }
mutMatrix[i] = rowBuilder.apply(block).row
}
fun modifyRow(row: List<T>, block: RowBuilder<T>.() -> Unit): Boolean {
val i = mutMatrix.indexOf(row).takeIf { it > -1 } ?: return false
modifyRow(i, block)
return true
}
fun remove(i: Int): List<T> {
return mutMatrix.removeAt(i)
}
} }

View File

@ -3390,6 +3390,7 @@ public final class dev/inmo/tgbotapi/extensions/utils/types/buttons/InlineKeyboa
public static synthetic fun inlineQueryInChosenChatButton$default (Ldev/inmo/tgbotapi/utils/RowBuilder;Ljava/lang/String;Ljava/lang/String;ZZZZILjava/lang/Object;)Z public static synthetic fun inlineQueryInChosenChatButton$default (Ldev/inmo/tgbotapi/utils/RowBuilder;Ljava/lang/String;Ljava/lang/String;ZZZZILjava/lang/Object;)Z
public static final fun inlineQueryInCurrentChatButton (Ldev/inmo/tgbotapi/utils/RowBuilder;Ljava/lang/String;Ljava/lang/String;)Z public static final fun inlineQueryInCurrentChatButton (Ldev/inmo/tgbotapi/utils/RowBuilder;Ljava/lang/String;Ljava/lang/String;)Z
public static final fun loginButton (Ldev/inmo/tgbotapi/utils/RowBuilder;Ljava/lang/String;Ldev/inmo/tgbotapi/types/LoginURL;)Z public static final fun loginButton (Ldev/inmo/tgbotapi/utils/RowBuilder;Ljava/lang/String;Ldev/inmo/tgbotapi/types/LoginURL;)Z
public static final fun modified (Ldev/inmo/tgbotapi/types/buttons/InlineKeyboardMarkup;Lkotlin/jvm/functions/Function1;)Ldev/inmo/tgbotapi/types/buttons/InlineKeyboardMarkup;
public static final fun payButton (Ldev/inmo/tgbotapi/utils/RowBuilder;Ljava/lang/String;)Z public static final fun payButton (Ldev/inmo/tgbotapi/utils/RowBuilder;Ljava/lang/String;)Z
public static final fun urlButton (Ldev/inmo/tgbotapi/utils/RowBuilder;Ljava/lang/String;Ljava/lang/String;)Z public static final fun urlButton (Ldev/inmo/tgbotapi/utils/RowBuilder;Ljava/lang/String;Ljava/lang/String;)Z
public static final fun webAppButton (Ldev/inmo/tgbotapi/utils/RowBuilder;Ljava/lang/String;Ldev/inmo/tgbotapi/types/webapps/WebAppInfo;)Z public static final fun webAppButton (Ldev/inmo/tgbotapi/utils/RowBuilder;Ljava/lang/String;Ldev/inmo/tgbotapi/types/webapps/WebAppInfo;)Z

View File

@ -49,6 +49,19 @@ inline fun flatInlineKeyboard(
block: InlineKeyboardRowBuilder.() -> Unit block: InlineKeyboardRowBuilder.() -> Unit
) = inlineKeyboard { row<InlineKeyboardButton>(block) } ) = inlineKeyboard { row<InlineKeyboardButton>(block) }
/**
* Factory-function for [InlineKeyboardBuilder]. It will [apply] [block] to internally created [InlineKeyboardMarkup]
* and [InlineKeyboardBuilder.build] [InlineKeyboardMarkup] then
*
* @see InlineKeyboardBuilder.row
*/
inline fun InlineKeyboardMarkup.modified(
block: InlineKeyboardBuilder.() -> Unit
) = InlineKeyboardBuilder().apply {
keyboard.forEach { add(it) }
block()
}.build()
/** /**
* Creates and put [PayInlineKeyboardButton] * Creates and put [PayInlineKeyboardButton]