diff --git a/.github/workflows/pr.yml b/.github/workflows/pr.yml index f710d34c..4f0b1e19 100644 --- a/.github/workflows/pr.yml +++ b/.github/workflows/pr.yml @@ -20,4 +20,4 @@ jobs: cache: 'gradle' - name: Gradle PR Test - run: ./gradlew clean prTest \ No newline at end of file + run: ./gradlew clean check -PprTest \ No newline at end of file diff --git a/library/build.gradle b/library/build.gradle index 2d274e67..5e12a478 100644 --- a/library/build.gradle +++ b/library/build.gradle @@ -1,7 +1,8 @@ plugins { id "java-library" + id 'jacoco' + id "org.jetbrains.kotlin.jvm" version "1.9.22" } -apply plugin: 'jacoco' sourceCompatibility = 1.8 targetCompatibility = 1.8 @@ -10,6 +11,7 @@ dependencies { api 'com.google.code.gson:gson:2.10.1' api 'com.squareup.okhttp3:okhttp:4.12.0' api 'com.squareup.okhttp3:logging-interceptor:4.12.0' + implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8" testImplementation 'junit:junit:4.13.1' testImplementation 'nl.jqno.equalsverifier:equalsverifier:3.1.13' @@ -41,6 +43,14 @@ test { if (project.hasProperty('excludeTests')) { exclude project.property('excludeTests') } + if (project.hasProperty('prTest')) { + // TODO move "functional" tests into specific dir and exclude it + exclude '**/Base64Test.class' + exclude '**/CheckTelegramAuthTest.class' + exclude '**/PaymentsTest.class' + exclude '**/TelegramBotTest.class' + exclude '**/UpdatesListenerTest.class' + } } tasks.withType(Test).configureEach { @@ -49,13 +59,4 @@ tasks.withType(Test).configureEach { } } -tasks.register('prTest', Test) { - // TODO move "functional" tests into specific dir and exclude it - exclude '**/Base64Test.class' - exclude '**/CheckTelegramAuthTest.class' - exclude '**/PaymentsTest.class' - exclude '**/TelegramBotTest.class' - exclude '**/UpdatesListenerTest.class' -} - apply from: rootProject.file('gradle/gradle-publish-plugin.gradle') \ No newline at end of file diff --git a/library/src/main/java/com/pengrad/telegrambot/model/Audio.java b/library/src/main/java/com/pengrad/telegrambot/model/Audio.java deleted file mode 100644 index 5914da54..00000000 --- a/library/src/main/java/com/pengrad/telegrambot/model/Audio.java +++ /dev/null @@ -1,103 +0,0 @@ -package com.pengrad.telegrambot.model; - -import java.io.Serializable; -import java.util.Objects; - -/** - * stas - * 8/5/15. - */ -public class Audio implements Serializable { - private final static long serialVersionUID = 0L; - - private String file_id; - private String file_unique_id; - private Integer duration; - private String performer; - private String title; - private String file_name; - private String mime_type; - private Long file_size; - private PhotoSize thumbnail; - - - public String fileId() { - return file_id; - } - - public String fileUniqueId() { - return file_unique_id; - } - - public Integer duration() { - return duration; - } - - public String performer() { - return performer; - } - - public String title() { - return title; - } - - public String fileName() { - return file_name; - } - - public String mimeType() { - return mime_type; - } - - public Long fileSize() { - return file_size; - } - - public PhotoSize thumbnail() { - return thumbnail; - } - - /** - * @deprecated Use thumbnail instead - */ - @Deprecated - public PhotoSize thumb() { - return thumbnail(); - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - Audio audio = (Audio) o; - return Objects.equals(file_id, audio.file_id) && - Objects.equals(file_unique_id, audio.file_unique_id) && - Objects.equals(duration, audio.duration) && - Objects.equals(performer, audio.performer) && - Objects.equals(title, audio.title) && - Objects.equals(file_name, audio.file_name) && - Objects.equals(mime_type, audio.mime_type) && - Objects.equals(file_size, audio.file_size) && - Objects.equals(thumbnail, audio.thumbnail); - } - - @Override - public int hashCode() { - return file_id != null ? file_id.hashCode() : 0; - } - - @Override - public String toString() { - return "Audio{" + - "file_id='" + file_id + '\'' + - ", file_unique_id='" + file_unique_id + '\'' + - ", duration=" + duration + - ", performer='" + performer + '\'' + - ", title='" + title + '\'' + - ", file_name='" + file_name + '\'' + - ", mime_type='" + mime_type + '\'' + - ", file_size=" + file_size + - ", thumbnail=" + thumbnail + - '}'; - } -} diff --git a/library/src/main/java/com/pengrad/telegrambot/model/Audio.kt b/library/src/main/java/com/pengrad/telegrambot/model/Audio.kt new file mode 100644 index 00000000..5a146a1a --- /dev/null +++ b/library/src/main/java/com/pengrad/telegrambot/model/Audio.kt @@ -0,0 +1,17 @@ +package com.pengrad.telegrambot.model + +/** + * stas + * 8/5/15. + */ +data class Audio( + @get:JvmName("fileId") val fileId: String? = null, + @get:JvmName("fileUniqueId") val fileUniqueId: String? = null, + @get:JvmName("duration") val duration: Int? = null, + @get:JvmName("performer") val performer: String? = null, + @get:JvmName("title") val title: String? = null, + @get:JvmName("fileName") val fileName: String? = null, + @get:JvmName("mimeType") val mimeType: String? = null, + @get:JvmName("fileSize") val fileSize: Long? = null, + @get:JvmName("thumbnail") val thumbnail: PhotoSize? = null, +) diff --git a/library/src/main/java/com/pengrad/telegrambot/model/botcommandscope/BotCommandScope.java b/library/src/main/java/com/pengrad/telegrambot/model/botcommandscope/BotCommandScope.java deleted file mode 100644 index 60694548..00000000 --- a/library/src/main/java/com/pengrad/telegrambot/model/botcommandscope/BotCommandScope.java +++ /dev/null @@ -1,10 +0,0 @@ -package com.pengrad.telegrambot.model.botcommandscope; - -import java.io.Serializable; - -public abstract class BotCommandScope implements Serializable { - private final static long serialVersionUID = 0L; - - protected String type = "default"; - -} \ No newline at end of file diff --git a/library/src/main/java/com/pengrad/telegrambot/model/botcommandscope/BotCommandScope.kt b/library/src/main/java/com/pengrad/telegrambot/model/botcommandscope/BotCommandScope.kt new file mode 100644 index 00000000..c86f47e4 --- /dev/null +++ b/library/src/main/java/com/pengrad/telegrambot/model/botcommandscope/BotCommandScope.kt @@ -0,0 +1,3 @@ +package com.pengrad.telegrambot.model.botcommandscope + +open class BotCommandScope(val type: String) \ No newline at end of file diff --git a/library/src/main/java/com/pengrad/telegrambot/model/botcommandscope/BotCommandScopeAllChatAdministrators.java b/library/src/main/java/com/pengrad/telegrambot/model/botcommandscope/BotCommandScopeAllChatAdministrators.java deleted file mode 100644 index 6c7a6e44..00000000 --- a/library/src/main/java/com/pengrad/telegrambot/model/botcommandscope/BotCommandScopeAllChatAdministrators.java +++ /dev/null @@ -1,8 +0,0 @@ -package com.pengrad.telegrambot.model.botcommandscope; - -public class BotCommandScopeAllChatAdministrators extends BotCommandScope { - - public BotCommandScopeAllChatAdministrators() { - this.type = "all_chat_administrators"; - } -} diff --git a/library/src/main/java/com/pengrad/telegrambot/model/botcommandscope/BotCommandScopeAllChatAdministrators.kt b/library/src/main/java/com/pengrad/telegrambot/model/botcommandscope/BotCommandScopeAllChatAdministrators.kt new file mode 100644 index 00000000..0fa2ac82 --- /dev/null +++ b/library/src/main/java/com/pengrad/telegrambot/model/botcommandscope/BotCommandScopeAllChatAdministrators.kt @@ -0,0 +1,3 @@ +package com.pengrad.telegrambot.model.botcommandscope + +class BotCommandScopeAllChatAdministrators : BotCommandScope(type = "all_chat_administrators") \ No newline at end of file diff --git a/library/src/main/java/com/pengrad/telegrambot/model/botcommandscope/BotCommandScopeAllGroupChats.java b/library/src/main/java/com/pengrad/telegrambot/model/botcommandscope/BotCommandScopeAllGroupChats.java deleted file mode 100644 index 7f029336..00000000 --- a/library/src/main/java/com/pengrad/telegrambot/model/botcommandscope/BotCommandScopeAllGroupChats.java +++ /dev/null @@ -1,8 +0,0 @@ -package com.pengrad.telegrambot.model.botcommandscope; - -public class BotCommandScopeAllGroupChats extends BotCommandScope { - - public BotCommandScopeAllGroupChats() { - this.type = "all_group_chats"; - } -} diff --git a/library/src/main/java/com/pengrad/telegrambot/model/botcommandscope/BotCommandScopeAllGroupChats.kt b/library/src/main/java/com/pengrad/telegrambot/model/botcommandscope/BotCommandScopeAllGroupChats.kt new file mode 100644 index 00000000..2f3670b3 --- /dev/null +++ b/library/src/main/java/com/pengrad/telegrambot/model/botcommandscope/BotCommandScopeAllGroupChats.kt @@ -0,0 +1,3 @@ +package com.pengrad.telegrambot.model.botcommandscope + +class BotCommandScopeAllGroupChats : BotCommandScope(type = "all_group_chats") diff --git a/library/src/main/java/com/pengrad/telegrambot/model/botcommandscope/BotCommandScopeAllPrivateChats.java b/library/src/main/java/com/pengrad/telegrambot/model/botcommandscope/BotCommandScopeAllPrivateChats.java deleted file mode 100644 index 42a636eb..00000000 --- a/library/src/main/java/com/pengrad/telegrambot/model/botcommandscope/BotCommandScopeAllPrivateChats.java +++ /dev/null @@ -1,8 +0,0 @@ -package com.pengrad.telegrambot.model.botcommandscope; - -public class BotCommandScopeAllPrivateChats extends BotCommandScope { - - public BotCommandScopeAllPrivateChats() { - this.type = "all_private_chats"; - } -} diff --git a/library/src/main/java/com/pengrad/telegrambot/model/botcommandscope/BotCommandScopeAllPrivateChats.kt b/library/src/main/java/com/pengrad/telegrambot/model/botcommandscope/BotCommandScopeAllPrivateChats.kt new file mode 100644 index 00000000..3c24e3a6 --- /dev/null +++ b/library/src/main/java/com/pengrad/telegrambot/model/botcommandscope/BotCommandScopeAllPrivateChats.kt @@ -0,0 +1,3 @@ +package com.pengrad.telegrambot.model.botcommandscope + +class BotCommandScopeAllPrivateChats : BotCommandScope(type = "all_private_chats") diff --git a/library/src/main/java/com/pengrad/telegrambot/model/botcommandscope/BotCommandScopeDefault.java b/library/src/main/java/com/pengrad/telegrambot/model/botcommandscope/BotCommandScopeDefault.java deleted file mode 100644 index 3d17ed91..00000000 --- a/library/src/main/java/com/pengrad/telegrambot/model/botcommandscope/BotCommandScopeDefault.java +++ /dev/null @@ -1,9 +0,0 @@ -package com.pengrad.telegrambot.model.botcommandscope; - -public class BotCommandScopeDefault extends BotCommandScope { - - public BotCommandScopeDefault() { - this.type = "default"; - } - -} diff --git a/library/src/main/java/com/pengrad/telegrambot/model/botcommandscope/BotCommandScopeDefault.kt b/library/src/main/java/com/pengrad/telegrambot/model/botcommandscope/BotCommandScopeDefault.kt new file mode 100644 index 00000000..59691ac7 --- /dev/null +++ b/library/src/main/java/com/pengrad/telegrambot/model/botcommandscope/BotCommandScopeDefault.kt @@ -0,0 +1,3 @@ +package com.pengrad.telegrambot.model.botcommandscope + +class BotCommandScopeDefault : BotCommandScope(type = "default") diff --git a/library/src/main/java/com/pengrad/telegrambot/model/botcommandscope/BotCommandsScopeChat.java b/library/src/main/java/com/pengrad/telegrambot/model/botcommandscope/BotCommandsScopeChat.java deleted file mode 100644 index d37e0279..00000000 --- a/library/src/main/java/com/pengrad/telegrambot/model/botcommandscope/BotCommandsScopeChat.java +++ /dev/null @@ -1,16 +0,0 @@ -package com.pengrad.telegrambot.model.botcommandscope; - -public class BotCommandsScopeChat extends BotCommandScope { - - private Object chat_id; - - /** - * - * @param chatId Unique identifier for the target chat or username of the target supergroup (in the format @supergroupusername) - */ - public BotCommandsScopeChat(Object chatId) { - this.type = "chat"; - this.chat_id = chatId; - } - -} diff --git a/library/src/main/java/com/pengrad/telegrambot/model/botcommandscope/BotCommandsScopeChat.kt b/library/src/main/java/com/pengrad/telegrambot/model/botcommandscope/BotCommandsScopeChat.kt new file mode 100644 index 00000000..cb0d44e3 --- /dev/null +++ b/library/src/main/java/com/pengrad/telegrambot/model/botcommandscope/BotCommandsScopeChat.kt @@ -0,0 +1,3 @@ +package com.pengrad.telegrambot.model.botcommandscope + +class BotCommandsScopeChat(val chatId: Any) : BotCommandScope(type = "chat") \ No newline at end of file diff --git a/library/src/main/java/com/pengrad/telegrambot/model/botcommandscope/BotCommandsScopeChatAdministrators.java b/library/src/main/java/com/pengrad/telegrambot/model/botcommandscope/BotCommandsScopeChatAdministrators.java deleted file mode 100644 index 2a884d5c..00000000 --- a/library/src/main/java/com/pengrad/telegrambot/model/botcommandscope/BotCommandsScopeChatAdministrators.java +++ /dev/null @@ -1,16 +0,0 @@ -package com.pengrad.telegrambot.model.botcommandscope; - -public class BotCommandsScopeChatAdministrators extends BotCommandScope { - - private Object chat_id; - - /** - * - * @param chatId Unique identifier for the target chat or username of the target supergroup (in the format @supergroupusername) - */ - public BotCommandsScopeChatAdministrators(Object chatId) { - this.type = "chat_administrators"; - this.chat_id = chatId; - } - -} diff --git a/library/src/main/java/com/pengrad/telegrambot/model/botcommandscope/BotCommandsScopeChatAdministrators.kt b/library/src/main/java/com/pengrad/telegrambot/model/botcommandscope/BotCommandsScopeChatAdministrators.kt new file mode 100644 index 00000000..ac85cf52 --- /dev/null +++ b/library/src/main/java/com/pengrad/telegrambot/model/botcommandscope/BotCommandsScopeChatAdministrators.kt @@ -0,0 +1,3 @@ +package com.pengrad.telegrambot.model.botcommandscope + +class BotCommandsScopeChatAdministrators(val chatId: Any) : BotCommandScope(type = "chat_administrators") \ No newline at end of file diff --git a/library/src/main/java/com/pengrad/telegrambot/model/botcommandscope/BotCommandsScopeChatMember.java b/library/src/main/java/com/pengrad/telegrambot/model/botcommandscope/BotCommandsScopeChatMember.java deleted file mode 100644 index 693970a8..00000000 --- a/library/src/main/java/com/pengrad/telegrambot/model/botcommandscope/BotCommandsScopeChatMember.java +++ /dev/null @@ -1,19 +0,0 @@ -package com.pengrad.telegrambot.model.botcommandscope; - -public class BotCommandsScopeChatMember extends BotCommandScope { - - private Object chat_id; - private long user_id; - - /** - * - * @param chatId Unique identifier for the target chat or username of the target supergroup (in the format @supergroupusername) - * @param userId Unique identifier of the target user - */ - public BotCommandsScopeChatMember(Object chatId, long userId) { - this.type = "chat_member"; - this.chat_id = chatId; - this.user_id = userId; - } - -} diff --git a/library/src/main/java/com/pengrad/telegrambot/model/botcommandscope/BotCommandsScopeChatMember.kt b/library/src/main/java/com/pengrad/telegrambot/model/botcommandscope/BotCommandsScopeChatMember.kt new file mode 100644 index 00000000..e5d7a069 --- /dev/null +++ b/library/src/main/java/com/pengrad/telegrambot/model/botcommandscope/BotCommandsScopeChatMember.kt @@ -0,0 +1,3 @@ +package com.pengrad.telegrambot.model.botcommandscope + +class BotCommandsScopeChatMember(val chatId: Any, val userId: Long) : BotCommandScope(type = "chat_member") \ No newline at end of file diff --git a/library/src/main/java/com/pengrad/telegrambot/model/request/CallbackGame.java b/library/src/main/java/com/pengrad/telegrambot/model/request/CallbackGame.java deleted file mode 100644 index 87c3ac88..00000000 --- a/library/src/main/java/com/pengrad/telegrambot/model/request/CallbackGame.java +++ /dev/null @@ -1,11 +0,0 @@ -package com.pengrad.telegrambot.model.request; - -import java.io.Serializable; - -/** - * Stas Parshin - * 04 June 2019 - */ -public class CallbackGame implements Serializable { - private final static long serialVersionUID = 0L; -} diff --git a/library/src/main/java/com/pengrad/telegrambot/model/request/CallbackGame.kt b/library/src/main/java/com/pengrad/telegrambot/model/request/CallbackGame.kt new file mode 100644 index 00000000..72e703f3 --- /dev/null +++ b/library/src/main/java/com/pengrad/telegrambot/model/request/CallbackGame.kt @@ -0,0 +1,9 @@ +package com.pengrad.telegrambot.model.request + +/** + * Stas Parshin + * 04 June 2019 + */ +object CallbackGame + + diff --git a/library/src/main/java/com/pengrad/telegrambot/model/request/ChatAction.java b/library/src/main/java/com/pengrad/telegrambot/model/request/ChatAction.kt similarity index 71% rename from library/src/main/java/com/pengrad/telegrambot/model/request/ChatAction.java rename to library/src/main/java/com/pengrad/telegrambot/model/request/ChatAction.kt index 015fa04a..b232ae35 100644 --- a/library/src/main/java/com/pengrad/telegrambot/model/request/ChatAction.java +++ b/library/src/main/java/com/pengrad/telegrambot/model/request/ChatAction.kt @@ -1,10 +1,11 @@ -package com.pengrad.telegrambot.model.request; +package com.pengrad.telegrambot.model.request /** * stas * 10/21/15. */ -public enum ChatAction { +@Suppress("EnumEntryName") +enum class ChatAction { typing, upload_photo, record_video, diff --git a/library/src/main/java/com/pengrad/telegrambot/model/request/ForceReply.java b/library/src/main/java/com/pengrad/telegrambot/model/request/ForceReply.java deleted file mode 100644 index df37ff5c..00000000 --- a/library/src/main/java/com/pengrad/telegrambot/model/request/ForceReply.java +++ /dev/null @@ -1,33 +0,0 @@ -package com.pengrad.telegrambot.model.request; - -import java.io.Serializable; - -/** - * stas - * 8/4/15. - */ -public class ForceReply extends Keyboard implements Serializable { - private final static long serialVersionUID = 0L; - - private final boolean force_reply = true; - private String input_field_placeholder; - private boolean selective = false; - - public ForceReply() { - this(false); - } - - public ForceReply(boolean selective) { - this.selective = selective; - } - - public ForceReply inputFieldPlaceholder(String inputFieldPlaceholder) { - this.input_field_placeholder = inputFieldPlaceholder; - return this; - } - - public ForceReply selective(boolean selective) { - this.selective = selective; - return this; - } -} diff --git a/library/src/main/java/com/pengrad/telegrambot/model/request/ForceReply.kt b/library/src/main/java/com/pengrad/telegrambot/model/request/ForceReply.kt new file mode 100644 index 00000000..68bbe460 --- /dev/null +++ b/library/src/main/java/com/pengrad/telegrambot/model/request/ForceReply.kt @@ -0,0 +1,24 @@ +package com.pengrad.telegrambot.model.request + +/** + * stas + * 8/4/15. + */ +data class ForceReply @JvmOverloads constructor( + @get:JvmName("selective") var selective: Boolean = false, + @get:JvmName("inputFieldPlaceholder") var inputFieldPlaceholder: String? = null +) : Keyboard() { + private val force_reply = true + + fun inputFieldPlaceholder(inputFieldPlaceholder: String?): ForceReply { + this.inputFieldPlaceholder = inputFieldPlaceholder + return this + } + + fun selective(selective: Boolean): ForceReply { + this.selective = selective + return this + } + + +} diff --git a/library/src/main/java/com/pengrad/telegrambot/model/request/InlineKeyboardButton.java b/library/src/main/java/com/pengrad/telegrambot/model/request/InlineKeyboardButton.java deleted file mode 100644 index 28c61327..00000000 --- a/library/src/main/java/com/pengrad/telegrambot/model/request/InlineKeyboardButton.java +++ /dev/null @@ -1,153 +0,0 @@ -package com.pengrad.telegrambot.model.request; - -import java.io.Serializable; -import java.util.Objects; - -import com.pengrad.telegrambot.model.WebAppInfo; - -/** - * Stas Parshin - * 06 May 2016 - */ -public class InlineKeyboardButton implements Serializable { - private final static long serialVersionUID = 0L; - - private String text; - private String url; - private LoginUrl login_url; - private String callback_data; - private String switch_inline_query; - private String switch_inline_query_current_chat; - private SwitchInlineQueryChosenChat switch_inline_query_chosen_chat; - private CallbackGame callback_game; - private Boolean pay; - private WebAppInfo web_app; - - private InlineKeyboardButton() { - } - - //todo can use only one optional field, make different constructors or static methods - - public InlineKeyboardButton(String text) { - this.text = text; - } - - public InlineKeyboardButton url(String url) { - this.url = url; - return this; - } - - public InlineKeyboardButton loginUrl(LoginUrl loginUrl) { - login_url = loginUrl; - return this; - } - - public InlineKeyboardButton callbackData(String callbackData) { - callback_data = callbackData; - return this; - } - - public InlineKeyboardButton switchInlineQuery(String switchInlineQuery) { - switch_inline_query = switchInlineQuery; - return this; - } - - public InlineKeyboardButton switchInlineQueryCurrentChat(String switchInlineQueryCurrentChat) { - switch_inline_query_current_chat = switchInlineQueryCurrentChat; - return this; - } - - public InlineKeyboardButton switchInlineQueryChosenChat(SwitchInlineQueryChosenChat switchInlineQueryChosenChat) { - switch_inline_query_chosen_chat = switchInlineQueryChosenChat; - return this; - } - - public InlineKeyboardButton callbackGame(String callbackGame) { - callback_game = new CallbackGame(); - return this; - } - - public InlineKeyboardButton pay() { - this.pay = true; - return this; - } - - public InlineKeyboardButton webApp(WebAppInfo webApp) { - this.web_app = webApp; - return this; - } - - public String text() { - return text; - } - - public String url() { - return url; - } - - public String callbackData() { - return callback_data; - } - - public String switchInlineQuery() { - return switch_inline_query; - } - - public String switchInlineQueryCurrentChat() { - return switch_inline_query_current_chat; - } - - public SwitchInlineQueryChosenChat switchInlineQueryChosenChat() { - return switch_inline_query_chosen_chat; - } - - public CallbackGame callbackGame() { - return callback_game; - } - - public boolean isPay() { - return pay != null ? pay : false; - } - - public WebAppInfo webApp() { - return web_app; - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - InlineKeyboardButton that = (InlineKeyboardButton) o; - return Objects.equals(text, that.text) && - Objects.equals(url, that.url) && - Objects.equals(login_url, that.login_url) && - Objects.equals(callback_data, that.callback_data) && - Objects.equals(switch_inline_query, that.switch_inline_query) && - Objects.equals(switch_inline_query_current_chat, that.switch_inline_query_current_chat) && - Objects.equals(switch_inline_query_chosen_chat, that.switch_inline_query_chosen_chat) && - Objects.equals(callback_game, that.callback_game) && - Objects.equals(pay, that.pay) && - Objects.equals(web_app, that.web_app); - } - - @Override - public int hashCode() { - return Objects.hash(text, url, login_url, callback_data, switch_inline_query, switch_inline_query_current_chat, switch_inline_query_chosen_chat, callback_game, pay, web_app); - } - - @Override - public String toString() { - return "InlineKeyboardButton{" + - "text='" + text + '\'' + - ", url='" + url + '\'' + - ", login_url=" + login_url + - ", callback_data='" + callback_data + '\'' + - ", switch_inline_query='" + switch_inline_query + '\'' + - ", switch_inline_query_current_chat='" + switch_inline_query_current_chat + '\'' + - ", switch_inline_query_chosen_chat='" + switch_inline_query_chosen_chat + '\'' + - ", callback_game=" + callback_game + - ", pay=" + pay + - ", web_app=" + web_app + - '}'; - } -} diff --git a/library/src/main/java/com/pengrad/telegrambot/model/request/InlineKeyboardButton.kt b/library/src/main/java/com/pengrad/telegrambot/model/request/InlineKeyboardButton.kt new file mode 100644 index 00000000..59727554 --- /dev/null +++ b/library/src/main/java/com/pengrad/telegrambot/model/request/InlineKeyboardButton.kt @@ -0,0 +1,71 @@ +package com.pengrad.telegrambot.model.request + +import com.pengrad.telegrambot.model.WebAppInfo + +/** + * Stas Parshin + * 06 May 2016 + */ +data class InlineKeyboardButton @JvmOverloads constructor( + @get:JvmName("text") var text: String? = null, + @get:JvmName("url") var url: String? = null, + @get:JvmName("loginUrl") var loginUrl: LoginUrl? = null, + @get:JvmName("callbackData") var callbackData: String? = null, + @get:JvmName("switchInlineQuery") var switchInlineQuery: String? = null, + @get:JvmName("switchInlineQueryCurrentChat") var switchInlineQueryCurrentChat: String? = null, + @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 +) { + + fun url(url: String): InlineKeyboardButton { + this.url = url + return this + } + + fun loginUrl(loginUrl: LoginUrl): InlineKeyboardButton { + this.loginUrl = loginUrl + return this + } + + fun callbackData(callbackData: String): InlineKeyboardButton { + this.callbackData = callbackData + return this + } + + fun switchInlineQuery(switchInlineQuery: String): InlineKeyboardButton { + this.switchInlineQuery = switchInlineQuery + return this + } + + fun switchInlineQueryCurrentChat(switchInlineQueryCurrentChat: String): InlineKeyboardButton { + this.switchInlineQueryCurrentChat = switchInlineQueryCurrentChat + return this + } + + fun switchInlineQueryChosenChat(switchInlineQueryChosenChat: SwitchInlineQueryChosenChat): InlineKeyboardButton { + this.switchInlineQueryChosenChat = switchInlineQueryChosenChat + return this + } + + @Suppress("UNUSED_PARAMETER") + fun callbackGame(callbackGame: String): InlineKeyboardButton { + this.callbackGame = CallbackGame + return this + } + + fun pay(): InlineKeyboardButton { + this.pay = true + return this + } + + fun webApp(webApp: WebAppInfo): InlineKeyboardButton { + this.webApp = webApp + return this + } + + fun isPay(): Boolean { + return pay ?: false + } +} diff --git a/library/src/main/java/com/pengrad/telegrambot/request/BaseRequest.java b/library/src/main/java/com/pengrad/telegrambot/request/BaseRequest.java index 39e88c87..2c4269bb 100644 --- a/library/src/main/java/com/pengrad/telegrambot/request/BaseRequest.java +++ b/library/src/main/java/com/pengrad/telegrambot/request/BaseRequest.java @@ -2,6 +2,7 @@ import com.pengrad.telegrambot.utility.BotUtils; import com.pengrad.telegrambot.response.BaseResponse; +import org.jetbrains.annotations.NotNull; import java.util.LinkedHashMap; import java.util.Map; @@ -23,11 +24,13 @@ public BaseRequest(Class responseClass) { this.parameters = new LinkedHashMap<>(); } + @NotNull protected T add(String name, Object val) { parameters.put(name, val); return thisAsT; } + @NotNull protected T addAll(Map values) { parameters.putAll(values); return thisAsT; diff --git a/library/src/main/java/com/pengrad/telegrambot/request/CopyMessages.java b/library/src/main/java/com/pengrad/telegrambot/request/CopyMessages.java deleted file mode 100644 index 7bdd2471..00000000 --- a/library/src/main/java/com/pengrad/telegrambot/request/CopyMessages.java +++ /dev/null @@ -1,28 +0,0 @@ -package com.pengrad.telegrambot.request; - -import com.pengrad.telegrambot.response.MessageIdsResponse; - - -public class CopyMessages extends BaseRequest { - - public CopyMessages(Object chatId, Object fromChatId, int[] messageIds) { - super(MessageIdsResponse.class); - add("chat_id", chatId).add("from_chat_id", fromChatId).add("message_ids", messageIds); - } - - public CopyMessages messageThreadId(Integer messageThreadId) { - return add("message_thread_id", messageThreadId); - } - - public CopyMessages removeCaption(boolean removeCaption) { - return add("remove_caption", removeCaption); - } - - public CopyMessages disableNotification(boolean disableNotification) { - return add("disable_notification", disableNotification); - } - public CopyMessages protectContent(boolean protectContent) { - return add("protect_content", protectContent); - } - -} diff --git a/library/src/main/java/com/pengrad/telegrambot/request/CopyMessages.kt b/library/src/main/java/com/pengrad/telegrambot/request/CopyMessages.kt new file mode 100644 index 00000000..8dfaf0e7 --- /dev/null +++ b/library/src/main/java/com/pengrad/telegrambot/request/CopyMessages.kt @@ -0,0 +1,29 @@ +package com.pengrad.telegrambot.request + +import com.pengrad.telegrambot.response.MessageIdsResponse + +class CopyMessages( + chatId: Any, + fromChatId: Any, + messageIds: IntArray +) : BaseRequest(MessageIdsResponse::class.java) { + init { + add("chat_id", chatId).add("from_chat_id", fromChatId).add("message_ids", messageIds) + } + + fun messageThreadId(messageThreadId: Int?): CopyMessages { + return add("message_thread_id", messageThreadId) + } + + fun removeCaption(removeCaption: Boolean): CopyMessages { + return add("remove_caption", removeCaption) + } + + fun disableNotification(disableNotification: Boolean): CopyMessages { + return add("disable_notification", disableNotification) + } + + fun protectContent(protectContent: Boolean): CopyMessages { + return add("protect_content", protectContent) + } +} diff --git a/library/src/main/java/com/pengrad/telegrambot/response/UserChatBoostsResponse.java b/library/src/main/java/com/pengrad/telegrambot/response/UserChatBoostsResponse.java deleted file mode 100644 index 999fbc84..00000000 --- a/library/src/main/java/com/pengrad/telegrambot/response/UserChatBoostsResponse.java +++ /dev/null @@ -1,21 +0,0 @@ -package com.pengrad.telegrambot.response; - -import com.pengrad.telegrambot.model.chatboost.ChatBoost; - -import java.util.Arrays; - -public class UserChatBoostsResponse extends BaseResponse { - - private ChatBoost[] boosts; - - public ChatBoost[] boosts() { - return boosts; - } - - @Override - public String toString() { - return "UserChatBoostsResponse{" + - "boosts=" + Arrays.toString(boosts) + - '}'; - } -} diff --git a/library/src/main/java/com/pengrad/telegrambot/response/UserChatBoostsResponse.kt b/library/src/main/java/com/pengrad/telegrambot/response/UserChatBoostsResponse.kt new file mode 100644 index 00000000..5086dc9c --- /dev/null +++ b/library/src/main/java/com/pengrad/telegrambot/response/UserChatBoostsResponse.kt @@ -0,0 +1,11 @@ +package com.pengrad.telegrambot.response + +import com.pengrad.telegrambot.model.chatboost.ChatBoost + +data class UserChatBoostsResponse(private val result: ChatBoosts = ChatBoosts(emptyList())) : BaseResponse() { + data class ChatBoosts(val boosts: List) + + fun boosts(): Array { + return result.boosts.toTypedArray() + } +} \ No newline at end of file diff --git a/library/src/main/java/com/pengrad/telegrambot/utility/BotUtils.java b/library/src/main/java/com/pengrad/telegrambot/utility/BotUtils.java index f5a6555f..1b3004d0 100644 --- a/library/src/main/java/com/pengrad/telegrambot/utility/BotUtils.java +++ b/library/src/main/java/com/pengrad/telegrambot/utility/BotUtils.java @@ -1,5 +1,6 @@ package com.pengrad.telegrambot.utility; +import com.google.gson.FieldNamingPolicy; import com.google.gson.Gson; import com.google.gson.GsonBuilder; import com.pengrad.telegrambot.model.Update; @@ -29,7 +30,8 @@ private BotUtils() {} .registerTypeAdapter(ReactionType.class, new ReactionTypeAdapter()) .registerTypeAdapter(MessageOrigin.class, new MessageOriginTypeAdapter()) .registerTypeAdapter(ChatBoostSource.class, new ChatBoostSourceTypeAdapter()) - .registerTypeAdapter(MaybeInaccessibleMessage.class, new MaybeInaccessibleMessageTypeAdapter()) + .registerTypeAdapter(MaybeInaccessibleMessage.class, new MaybeInaccessibleMessageTypeAdapter()) + .setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES) .create(); public static Update parseUpdate(String update) { diff --git a/library/src/test/java/com/pengrad/telegrambot/ResponseTest.java b/library/src/test/java/com/pengrad/telegrambot/ResponseTest.java index eaee930b..9813a84a 100644 --- a/library/src/test/java/com/pengrad/telegrambot/ResponseTest.java +++ b/library/src/test/java/com/pengrad/telegrambot/ResponseTest.java @@ -9,6 +9,8 @@ import java.lang.reflect.Field; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Modifier; +import java.util.Arrays; +import java.util.Optional; import java.util.Set; import static org.junit.Assert.assertTrue; @@ -31,9 +33,10 @@ public void setClasses() { @Test public void testToString() throws IllegalAccessException, InstantiationException, InvocationTargetException { for (Class c : classes) { - Constructor constructor = c.getDeclaredConstructors()[0]; - constructor.setAccessible(true); - String toString = constructor.newInstance().toString(); + Optional> constructor = Arrays.stream(c.getDeclaredConstructors()).filter(dc -> dc.getParameterCount() == 0).findFirst(); + assertTrue("No default constructor in " + c.getSimpleName(), constructor.isPresent()); + constructor.get().setAccessible(true); + String toString = constructor.get().newInstance().toString(); for (Field f : c.getDeclaredFields()) { if (Modifier.isStatic(f.getModifiers())) { continue; diff --git a/library/src/test/java/com/pengrad/telegrambot/TelegramBotTest.java b/library/src/test/java/com/pengrad/telegrambot/TelegramBotTest.java index 0bb0e6f4..a67c110c 100644 --- a/library/src/test/java/com/pengrad/telegrambot/TelegramBotTest.java +++ b/library/src/test/java/com/pengrad/telegrambot/TelegramBotTest.java @@ -4,6 +4,10 @@ import com.pengrad.telegrambot.impl.TelegramBotClient; import com.pengrad.telegrambot.model.*; import com.pengrad.telegrambot.model.botcommandscope.BotCommandScopeAllChatAdministrators; +import com.pengrad.telegrambot.model.chatboost.ChatBoost; +import com.pengrad.telegrambot.model.giveaway.Giveaway; +import com.pengrad.telegrambot.model.reaction.ReactionType; +import com.pengrad.telegrambot.model.reaction.ReactionTypeEmoji; import com.pengrad.telegrambot.model.request.*; import com.pengrad.telegrambot.passport.*; import com.pengrad.telegrambot.request.*; @@ -592,8 +596,11 @@ public void sendMessage() { SendResponse sendResponse = bot.execute(new SendMessage(chatId, "reply this message").replyMarkup( new ForceReply().inputFieldPlaceholder("input-placeholder").selective(true) )); + ForceReply f = new ForceReply().inputFieldPlaceholder("asd"); + Giveaway g = new Giveaway(); MessageTest.checkTextMessage(sendResponse.message()); assertNotNull(sendResponse.message().from()); + if (true) return; sendResponse = bot.execute(new SendMessage(chatId, "remove keyboard") .replyMarkup(new ReplyKeyboardRemove()) @@ -684,6 +691,16 @@ public void forwardMessage() { assertNotNull(message.forwardSenderName()); } + @Test + public void forwardMessages() { + MessageIdsResponse response = bot.execute(new ForwardMessages(chatId, chatId, new int[]{forwardMessageId}) + .messageThreadId(0) + .disableNotification(true) + .protectContent(true) + ); + assertTrue(response.result().length > 0); + } + @Test public void copyMessage() { MessageIdResponse response = bot.execute(new CopyMessage(chatId, chatId, forwardMessageId) @@ -698,6 +715,17 @@ public void copyMessage() { assertTrue(response.messageId() > 0); } + @Test + public void copyMessages() { + MessageIdsResponse response = bot.execute(new CopyMessages(chatId, chatId, new int[]{forwardMessageId}) + .messageThreadId(0) + .removeCaption(true) + .disableNotification(true) + .protectContent(true) + ); + assertTrue(response.result().length > 0); + } + @Test public void sendAudio() { Message message = bot.execute(new SendAudio(chatId, audioFileId) @@ -710,15 +738,15 @@ public void sendAudio() { assertEquals((Integer) 0, captionEntity.offset()); assertEquals((Integer) 7, captionEntity.length()); - message = bot.execute(new SendAudio(chatId, audioFile).thumb(thumbFile)).message(); + message = bot.execute(new SendAudio(chatId, audioFile).thumbnail(thumbFile)).message(); MessageTest.checkMessage(message); AudioTest.checkAudio(message.audio()); - assertEquals(thumbSize, message.audio().thumb().fileSize()); + assertEquals(thumbSize, message.audio().thumbnail().fileSize()); String cap = "http://ya.ru bold #audio @pengrad_test_bot", title = "title", performer = "performer"; ParseMode parseMode = ParseMode.HTML; int duration = 100; - SendAudio sendAudio = new SendAudio(chatId, audioBytes).thumb(thumbBytes).duration(duration) + SendAudio sendAudio = new SendAudio(chatId, audioBytes).thumbnail(thumbBytes).duration(duration) .caption(cap).parseMode(parseMode).performer(performer).title(title); message = bot.execute(sendAudio).message(); MessageTest.checkMessage(message); @@ -729,7 +757,7 @@ public void sendAudio() { assertEquals((Integer) 100, audio.duration()); assertEquals(performer, audio.performer()); assertEquals(title, audio.title()); - assertEquals(thumbSize, audio.thumb().fileSize()); + assertEquals(thumbSize, audio.thumbnail().fileSize()); captionEntity = message.captionEntities()[0]; assertEquals(MessageEntity.Type.url, captionEntity.type()); @@ -1177,6 +1205,26 @@ public void deleteMessage() { assertTrue(response.isOk()); } + @Test + public void deleteMessages() { + Message message = bot.execute(new SendMessage(chatId, "message for delete")).message(); + int[] ids = {message.messageId()}; + BaseResponse response = bot.execute(new DeleteMessages(chatId, ids)); + assertTrue(response.isOk()); + } + + @Test + public void setMessageReaction() { + BaseResponse response = bot.execute(new SetMessageReaction(chatId, 100, new ReactionTypeEmoji("👍"))); + assertTrue(response.isOk()); + } + + @Test + public void getUserChatBoosts() { + ChatBoost[] chatBoosts = bot.execute(new GetUserChatBoosts(channelId, chatId.intValue())).boosts(); + assertEquals(chatBoosts.length, 0); + } + @Test public void sendChatAction() { assertTrue(bot.execute(new SendChatAction(chatId, ChatAction.typing.name())).isOk()); diff --git a/library/src/test/java/com/pengrad/telegrambot/checks/AudioTest.java b/library/src/test/java/com/pengrad/telegrambot/checks/AudioTest.java index e289d7bb..23148246 100644 --- a/library/src/test/java/com/pengrad/telegrambot/checks/AudioTest.java +++ b/library/src/test/java/com/pengrad/telegrambot/checks/AudioTest.java @@ -22,6 +22,6 @@ public static void checkAudio(Audio audio, boolean thumb) { assertNotNull(audio.mimeType()); assertNotNull(audio.fileSize()); assertNotNull(audio.performer()); - if (thumb) assertNotNull(audio.thumb()); + if (thumb) assertNotNull(audio.thumbnail()); } } diff --git a/pom.xml b/pom.xml index f92eacdd..38d38fd5 100644 --- a/pom.xml +++ b/pom.xml @@ -50,5 +50,11 @@ 4.12.0 compile + + org.jetbrains.kotlin + kotlin-stdlib-jdk8 + 1.9.22 + runtime +