mirror of
https://github.com/InsanusMokrassar/TelegramBotAPI-examples.git
synced 2024-11-17 13:53:53 +00:00
commit
5f0f2ce76d
@ -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()
|
||||
}
|
||||
|
9
GiveawaysBot/README.md
Normal file
9
GiveawaysBot/README.md
Normal file
@ -0,0 +1,9 @@
|
||||
# CustomBot
|
||||
|
||||
Printing giveaways
|
||||
|
||||
## Launch
|
||||
|
||||
```bash
|
||||
../gradlew run --args="BOT_TOKEN"
|
||||
```
|
21
GiveawaysBot/build.gradle
Normal file
21
GiveawaysBot/build.gradle
Normal 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"
|
||||
}
|
57
GiveawaysBot/src/main/kotlin/GiveawaysBot.kt
Normal file
57
GiveawaysBot/src/main/kotlin/GiveawaysBot.kt
Normal 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()
|
||||
}
|
@ -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
|
||||
|
@ -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")
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -52,6 +52,8 @@ include ":BusinessConnectionsBot"
|
||||
|
||||
include ":StarTransactionsBot"
|
||||
|
||||
include ":GiveawaysBot"
|
||||
|
||||
include ":CustomBot"
|
||||
|
||||
include ":MemberUpdatedWatcherBot"
|
||||
|
Loading…
Reference in New Issue
Block a user