Merge pull request #289 from InsanusMokrassar/18.2.0

18.2.0
This commit is contained in:
InsanusMokrassar 2024-09-09 02:33:18 +06:00 committed by GitHub
commit 5f0f2ce76d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
8 changed files with 140 additions and 8 deletions

View File

@ -15,6 +15,7 @@ suspend fun main(vararg args: String) {
val botToken = args.first() val botToken = args.first()
val isDebug = args.any { it == "debug" } val isDebug = args.any { it == "debug" }
val isTestServer = args.any { it == "testServer" }
if (isDebug) { if (isDebug) {
setDefaultKSLog( 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!! // start here!!
val me = getMe() val me = getMe()
println(me) println(me)
allUpdatesFlow.subscribeSafelyWithoutExceptions(this) { println(it) } allUpdatesFlow.subscribeSafelyWithoutExceptions(this) {
println(it)
}
}.second.join() }.second.join()
} }

9
GiveawaysBot/README.md Normal file
View File

@ -0,0 +1,9 @@
# CustomBot
Printing giveaways
## Launch
```bash
../gradlew run --args="BOT_TOKEN"
```

21
GiveawaysBot/build.gradle Normal file
View File

@ -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"
}

View File

@ -0,0 +1,57 @@
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, testServer = isTestServer) {
// start here!!
val me = getMe()
println(me)
onGiveawayCreated {
println(it)
}
onGiveawayCompleted {
println(it)
}
onGiveawayWinners {
println(it)
}
onGiveawayContent {
println(it)
}
// allUpdatesFlow.subscribeSafelyWithoutExceptions(this) {
// println(it)
// }
}.second.join()
}

View File

@ -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.telegramBotWithBehaviourAndLongPolling
import dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling.* import dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling.*
import dev.inmo.tgbotapi.extensions.utils.extensions.sameChat 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.*
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.withContentOrNull import dev.inmo.tgbotapi.extensions.utils.withContentOrNull
import dev.inmo.tgbotapi.requests.abstracts.asMultipartFile import dev.inmo.tgbotapi.requests.abstracts.asMultipartFile
import dev.inmo.tgbotapi.types.RawChatId 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.message.textsources.TextSourcesList
import dev.inmo.tgbotapi.types.payments.LabeledPrice import dev.inmo.tgbotapi.types.payments.LabeledPrice
import dev.inmo.tgbotapi.types.payments.stars.StarTransaction 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.bold
import dev.inmo.tgbotapi.utils.buildEntities import dev.inmo.tgbotapi.utils.buildEntities
import dev.inmo.tgbotapi.utils.regular import dev.inmo.tgbotapi.utils.regular

View File

@ -182,7 +182,7 @@ fun main() {
val hex = Color.Hex(r, g, b) val hex = Color.Hex(r, g, b)
webApp.setHeaderColor(hex) webApp.setHeaderColor(hex)
(this as? HTMLButtonElement) ?.style ?.backgroundColor = hex.value (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", { addEventListener("click", {
updateHeaderColor() updateHeaderColor()
@ -192,6 +192,38 @@ fun main() {
document.body ?.appendElement("p", {}) 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() { fun Element.updateCloudStorageContent() {
clear() clear()
webApp.cloudStorage.getAll { webApp.cloudStorage.getAll {
@ -287,6 +319,16 @@ fun main() {
} }
show() show()
} }
secondaryButton.apply {
setText("Secondary button")
onClick {
document.body ?.log("Secondary button clicked")
hapticFeedback.notificationOccurred(
HapticFeedbackType.Warning
)
}
show()
}
onSettingsButtonClicked { onSettingsButtonClicked {
document.body ?.log("Settings button clicked") document.body ?.log("Settings button clicked")
} }

View File

@ -6,7 +6,7 @@ kotlin.daemon.jvmargs=-Xmx3g -Xms500m
kotlin_version=2.0.20 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 micro_utils_version=0.22.2
serialization_version=1.7.2 serialization_version=1.7.2
ktor_version=2.3.12 ktor_version=2.3.12

View File

@ -52,6 +52,8 @@ include ":BusinessConnectionsBot"
include ":StarTransactionsBot" include ":StarTransactionsBot"
include ":GiveawaysBot"
include ":CustomBot" include ":CustomBot"
include ":MemberUpdatedWatcherBot" include ":MemberUpdatedWatcherBot"