Skip to content

Commit

Permalink
Merge pull request #401 from pengrad/v7.11
Browse files Browse the repository at this point in the history
BOT API v7.11
  • Loading branch information
pengrad authored Nov 2, 2024
2 parents 1d79b77 + 00096b6 commit d860874
Show file tree
Hide file tree
Showing 9 changed files with 95 additions and 34 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.pengrad.telegrambot.model.request

data class CopyTextButton(
val text: String
)
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ data class InlineKeyboardButton @JvmOverloads constructor(
@get:JvmName("switchInlineQueryChosenChat") var switchInlineQueryChosenChat: SwitchInlineQueryChosenChat? = null,
@get:JvmName("callbackGame") var callbackGame: CallbackGame? = null,
var pay: Boolean? = null,
@get:JvmName("webApp") var webApp: WebAppInfo? = null
@get:JvmName("webApp") var webApp: WebAppInfo? = null,
@get:JvmName("copyText") var copyText: CopyTextButton? = null,
) {

fun url(url: String): InlineKeyboardButton {
Expand Down Expand Up @@ -65,6 +66,11 @@ data class InlineKeyboardButton @JvmOverloads constructor(
return this
}

fun copyText(copyText : CopyTextButton): InlineKeyboardButton {
this.copyText = copyText
return this
}

fun isPay(): Boolean {
return pay ?: false
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package com.pengrad.telegrambot.model.stars.partner;

import java.util.Objects;

public class TransactionPartnerTelegramApi extends TransactionPartner {

public final static String TYPE = "telegram_api";

private Integer request_count;

public TransactionPartnerTelegramApi() {
super(TYPE);
}

public Integer requestCount() {
return request_count;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof TransactionPartnerTelegramApi)) return false;
if (!super.equals(o)) return false;
TransactionPartnerTelegramApi that = (TransactionPartnerTelegramApi) o;
return Objects.equals(request_count, that.request_count);
}

@Override
public int hashCode() {
return Objects.hash(super.hashCode(), request_count);
}

@Override
public String toString() {
return "TransactionPartnerTelegramApi{" +
"request_count=" + request_count +
'}';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,8 @@ public T protectContent(boolean protectContent) {
return add("protect_content", protectContent);
}

public T allowPaidBroadcast(boolean allowPaidBroadcast) {
return add("allow_paid_broadcast", allowPaidBroadcast);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,8 @@ public CopyMessage protectContent(boolean protectContent) {
return add("protect_content", protectContent);
}

public CopyMessage allowPaidBroadcast(boolean allowPaidBroadcast) {
return add("allow_paid_broadcast", allowPaidBroadcast);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -85,5 +85,9 @@ public SendPaidMedia replyMarkup(ForceReply replyMarkup) {
public SendPaidMedia payload(String payload) {
return add("payload", payload);
}

public SendPaidMedia allowPaidBroadcast(boolean allowPaidBroadcast) {
return add("allow_paid_broadcast", allowPaidBroadcast);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ private BotUtils() {}
.registerTypeAdapter(BackgroundType.class, new BackgroundTypeAdapter())
.registerTypeAdapter(BackgroundFill.class, new BackgroundFillAdapter())
.registerTypeAdapter(RevenueWithdrawalState.class, new RevenueWithdrawalStateTypeAdapter())
.registerTypeAdapter(TransactionPartner.class, new TransactionPartnerTypeAdapter())
.registerTypeAdapter(TransactionPartner.class, TransactionPartnerTypeAdapter.INSTANCE)
.registerTypeAdapter(PaidMedia.class, new PaidMediaTypeAdapter())
.setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES)
.create();
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package com.pengrad.telegrambot.utility.gson

import com.google.gson.*
import com.pengrad.telegrambot.model.stars.partner.*
import java.lang.reflect.Type

object TransactionPartnerTypeAdapter : JsonDeserializer<TransactionPartner> {

private val typeMapping = mapOf(
TransactionPartnerUser.TYPE to TransactionPartnerUser::class,
TransactionPartnerFragment.TYPE to TransactionPartnerFragment::class,
TransactionPartnerTelegramAds.TYPE to TransactionPartnerTelegramAds::class,
TransactionPartnerTelegramApi.TYPE to TransactionPartnerTelegramApi::class,
TransactionPartnerOther.TYPE to TransactionPartnerOther::class
)

@Throws(JsonParseException::class)
override fun deserialize(
element: JsonElement,
type: Type,
context: JsonDeserializationContext
): TransactionPartner {
val obj = element.asJsonObject
val discriminator = obj.getAsJsonPrimitive("type")?.asString ?: "unknown"

return typeMapping[discriminator]?.let {
context.deserialize(obj, it.java)
} ?: TransactionPartner(discriminator)
}

}

0 comments on commit d860874

Please sign in to comment.