From ab362e8c3b12a915e725f9703a9fb4e9136cc248 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Sat, 7 Sep 2024 02:43:05 +0600 Subject: [PATCH 1/5] start updating up to 18.2.0 --- .../src/main/kotlin/StarTransactionsBot.kt | 6 +-- WebApp/src/jsMain/kotlin/main.kt | 44 ++++++++++++++++++- gradle.properties | 2 +- 3 files changed, 46 insertions(+), 6 deletions(-) diff --git a/StarTransactionsBot/src/main/kotlin/StarTransactionsBot.kt b/StarTransactionsBot/src/main/kotlin/StarTransactionsBot.kt index 1a5f7c2..e964cc3 100644 --- a/StarTransactionsBot/src/main/kotlin/StarTransactionsBot.kt +++ b/StarTransactionsBot/src/main/kotlin/StarTransactionsBot.kt @@ -12,10 +12,7 @@ import dev.inmo.tgbotapi.extensions.api.send.send import dev.inmo.tgbotapi.extensions.behaviour_builder.telegramBotWithBehaviourAndLongPolling import dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling.* import dev.inmo.tgbotapi.extensions.utils.extensions.sameChat -import dev.inmo.tgbotapi.extensions.utils.types.buttons.dataButton -import dev.inmo.tgbotapi.extensions.utils.types.buttons.flatInlineKeyboard -import dev.inmo.tgbotapi.extensions.utils.types.buttons.inlineKeyboard -import dev.inmo.tgbotapi.extensions.utils.types.buttons.payButton +import dev.inmo.tgbotapi.extensions.utils.types.buttons.* import dev.inmo.tgbotapi.extensions.utils.withContentOrNull import dev.inmo.tgbotapi.requests.abstracts.asMultipartFile import dev.inmo.tgbotapi.types.RawChatId @@ -30,6 +27,7 @@ import dev.inmo.tgbotapi.types.message.content.TextContent import dev.inmo.tgbotapi.types.message.textsources.TextSourcesList import dev.inmo.tgbotapi.types.payments.LabeledPrice import dev.inmo.tgbotapi.types.payments.stars.StarTransaction +import dev.inmo.tgbotapi.types.request.RequestId import dev.inmo.tgbotapi.utils.bold import dev.inmo.tgbotapi.utils.buildEntities import dev.inmo.tgbotapi.utils.regular diff --git a/WebApp/src/jsMain/kotlin/main.kt b/WebApp/src/jsMain/kotlin/main.kt index 17aed8e..6802855 100644 --- a/WebApp/src/jsMain/kotlin/main.kt +++ b/WebApp/src/jsMain/kotlin/main.kt @@ -182,7 +182,7 @@ fun main() { val hex = Color.Hex(r, g, b) webApp.setHeaderColor(hex) (this as? HTMLButtonElement) ?.style ?.backgroundColor = hex.value - textContent = "Header color: ${hex.value.uppercase()} (click to change)" + textContent = "Header color: ${webApp.headerColor ?.uppercase()} (click to change)" } addEventListener("click", { updateHeaderColor() @@ -192,6 +192,38 @@ fun main() { document.body ?.appendElement("p", {}) + document.body ?.appendElement("button") { + fun updateBackgroundColor() { + val (r, g, b) = Random.nextUBytes(3) + val hex = Color.Hex(r, g, b) + webApp.setBackgroundColor(hex) + (this as? HTMLButtonElement) ?.style ?.backgroundColor = hex.value + textContent = "Background color: ${webApp.backgroundColor ?.uppercase()} (click to change)" + } + addEventListener("click", { + updateBackgroundColor() + }) + updateBackgroundColor() + } ?: window.alert("Unable to load body") + + document.body ?.appendElement("p", {}) + + document.body ?.appendElement("button") { + fun updateBottomBarColor() { + val (r, g, b) = Random.nextUBytes(3) + val hex = Color.Hex(r, g, b) + webApp.setBottomBarColor(hex) + (this as? HTMLButtonElement) ?.style ?.backgroundColor = hex.value + textContent = "Bottom bar color: ${webApp.bottomBarColor ?.uppercase()} (click to change)" + } + addEventListener("click", { + updateBottomBarColor() + }) + updateBottomBarColor() + } ?: window.alert("Unable to load body") + + document.body ?.appendElement("p", {}) + fun Element.updateCloudStorageContent() { clear() webApp.cloudStorage.getAll { @@ -287,6 +319,16 @@ fun main() { } show() } + secondaryButton.apply { + setText("Secondary button") + onClick { + document.body ?.log("Secondary button clicked") + hapticFeedback.notificationOccurred( + HapticFeedbackType.Warning + ) + } + show() + } onSettingsButtonClicked { document.body ?.log("Settings button clicked") } diff --git a/gradle.properties b/gradle.properties index e408ba2..33e7e83 100644 --- a/gradle.properties +++ b/gradle.properties @@ -6,7 +6,7 @@ kotlin.daemon.jvmargs=-Xmx3g -Xms500m kotlin_version=2.0.20 -telegram_bot_api_version=18.1.0 +telegram_bot_api_version=18.2.0 micro_utils_version=0.22.2 serialization_version=1.7.2 ktor_version=2.3.12 From 21ec50c7733bc324be2fd8fc79d4a0fdb4e416d9 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Sun, 8 Sep 2024 15:53:46 +0600 Subject: [PATCH 2/5] add opportunity to use test server in custom bot --- CustomBot/src/main/kotlin/CustomBot.kt | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/CustomBot/src/main/kotlin/CustomBot.kt b/CustomBot/src/main/kotlin/CustomBot.kt index dc7d7b2..b82582c 100644 --- a/CustomBot/src/main/kotlin/CustomBot.kt +++ b/CustomBot/src/main/kotlin/CustomBot.kt @@ -15,6 +15,7 @@ suspend fun main(vararg args: String) { val botToken = args.first() val isDebug = args.any { it == "debug" } + val isTestServer = args.any { it == "testServer" } if (isDebug) { setDefaultKSLog( @@ -24,11 +25,13 @@ suspend fun main(vararg args: String) { ) } - telegramBotWithBehaviourAndLongPolling(botToken, CoroutineScope(Dispatchers.IO)) { + telegramBotWithBehaviourAndLongPolling(botToken, CoroutineScope(Dispatchers.IO), testServer = isTestServer) { // start here!! val me = getMe() println(me) - allUpdatesFlow.subscribeSafelyWithoutExceptions(this) { println(it) } + allUpdatesFlow.subscribeSafelyWithoutExceptions(this) { + println(it) + } }.second.join() } From ed2922045cd8548ec1676fbb8d80c28c382583ad Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Sun, 8 Sep 2024 19:33:43 +0600 Subject: [PATCH 3/5] add giveaways bot --- GiveawaysBot/README.md | 9 ++++ GiveawaysBot/build.gradle | 21 ++++++++ GiveawaysBot/src/main/kotlin/GiveawaysBot.kt | 55 ++++++++++++++++++++ settings.gradle | 2 + 4 files changed, 87 insertions(+) create mode 100644 GiveawaysBot/README.md create mode 100644 GiveawaysBot/build.gradle create mode 100644 GiveawaysBot/src/main/kotlin/GiveawaysBot.kt diff --git a/GiveawaysBot/README.md b/GiveawaysBot/README.md new file mode 100644 index 0000000..edc7264 --- /dev/null +++ b/GiveawaysBot/README.md @@ -0,0 +1,9 @@ +# CustomBot + +Printing giveaways + +## Launch + +```bash +../gradlew run --args="BOT_TOKEN" +``` diff --git a/GiveawaysBot/build.gradle b/GiveawaysBot/build.gradle new file mode 100644 index 0000000..d78aa5d --- /dev/null +++ b/GiveawaysBot/build.gradle @@ -0,0 +1,21 @@ +buildscript { + repositories { + mavenCentral() + } + + dependencies { + classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" + } +} + +apply plugin: 'kotlin' +apply plugin: 'application' + +mainClassName="GiveawaysBotKt" + + +dependencies { + implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version" + + implementation "dev.inmo:tgbotapi:$telegram_bot_api_version" +} diff --git a/GiveawaysBot/src/main/kotlin/GiveawaysBot.kt b/GiveawaysBot/src/main/kotlin/GiveawaysBot.kt new file mode 100644 index 0000000..7912879 --- /dev/null +++ b/GiveawaysBot/src/main/kotlin/GiveawaysBot.kt @@ -0,0 +1,55 @@ +import dev.inmo.kslog.common.KSLog +import dev.inmo.kslog.common.LogLevel +import dev.inmo.kslog.common.defaultMessageFormatter +import dev.inmo.kslog.common.setDefaultKSLog +import dev.inmo.micro_utils.coroutines.subscribeSafelyWithoutExceptions +import dev.inmo.tgbotapi.extensions.api.bot.getMe +import dev.inmo.tgbotapi.extensions.behaviour_builder.telegramBotWithBehaviourAndLongPolling +import dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling.onGiveawayCompleted +import dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling.onGiveawayContent +import dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling.onGiveawayCreated +import dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling.onGiveawayWinners +import kotlinx.coroutines.CoroutineScope +import kotlinx.coroutines.Dispatchers + +/** + * This place can be the playground for your code. + */ +suspend fun main(vararg args: String) { + val botToken = args.first() + + val isDebug = args.any { it == "debug" } + val isTestServer = args.any { it == "testServer" } + + if (isDebug) { + setDefaultKSLog( + KSLog { level: LogLevel, tag: String?, message: Any, throwable: Throwable? -> + println(defaultMessageFormatter(level, tag, message, throwable)) + } + ) + } + + telegramBotWithBehaviourAndLongPolling(botToken, CoroutineScope(Dispatchers.IO), testServer = isTestServer) { + // start here!! + val me = getMe() + println(me) + + onGiveawayCreated { + println(it) + } + + onGiveawayCompleted { + println(it) + } + + onGiveawayWinners { + println(it) + } + + onGiveawayContent { } + + allUpdatesFlow.subscribeSafelyWithoutExceptions(this) { + println(it) + } + }.second.join() +} diff --git a/settings.gradle b/settings.gradle index 698fbac..69b62eb 100644 --- a/settings.gradle +++ b/settings.gradle @@ -52,6 +52,8 @@ include ":BusinessConnectionsBot" include ":StarTransactionsBot" +include ":GiveawaysBot" + include ":CustomBot" include ":MemberUpdatedWatcherBot" From 6eafd89542afb1ba95699872f82c819a06ba25e9 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Sun, 8 Sep 2024 19:44:51 +0600 Subject: [PATCH 4/5] add println of giveaway content --- GiveawaysBot/src/main/kotlin/GiveawaysBot.kt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/GiveawaysBot/src/main/kotlin/GiveawaysBot.kt b/GiveawaysBot/src/main/kotlin/GiveawaysBot.kt index 7912879..ec2928a 100644 --- a/GiveawaysBot/src/main/kotlin/GiveawaysBot.kt +++ b/GiveawaysBot/src/main/kotlin/GiveawaysBot.kt @@ -46,7 +46,9 @@ suspend fun main(vararg args: String) { println(it) } - onGiveawayContent { } + onGiveawayContent { + println(it) + } allUpdatesFlow.subscribeSafelyWithoutExceptions(this) { println(it) From 14235e7bd4b58e13e22bee7738865576700c0481 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Sun, 8 Sep 2024 23:38:19 +0600 Subject: [PATCH 5/5] update GiveawaysBot --- GiveawaysBot/src/main/kotlin/GiveawaysBot.kt | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/GiveawaysBot/src/main/kotlin/GiveawaysBot.kt b/GiveawaysBot/src/main/kotlin/GiveawaysBot.kt index ec2928a..e00fe9e 100644 --- a/GiveawaysBot/src/main/kotlin/GiveawaysBot.kt +++ b/GiveawaysBot/src/main/kotlin/GiveawaysBot.kt @@ -29,7 +29,7 @@ suspend fun main(vararg args: String) { ) } - telegramBotWithBehaviourAndLongPolling(botToken, CoroutineScope(Dispatchers.IO), testServer = isTestServer) { + telegramBotWithBehaviourAndLongPolling(botToken, testServer = isTestServer) { // start here!! val me = getMe() println(me) @@ -50,8 +50,8 @@ suspend fun main(vararg args: String) { println(it) } - allUpdatesFlow.subscribeSafelyWithoutExceptions(this) { - println(it) - } +// allUpdatesFlow.subscribeSafelyWithoutExceptions(this) { +// println(it) +// } }.second.join() }