mirror of
https://github.com/InsanusMokrassar/TelegramBotAPI-examples.git
synced 2025-12-17 11:45:36 +00:00
Compare commits
1 Commits
3.1.1
...
5fb1239d63
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5fb1239d63 |
@@ -1,6 +1,5 @@
|
|||||||
import dev.inmo.micro_utils.coroutines.AccumulatorFlow
|
import dev.inmo.micro_utils.coroutines.AccumulatorFlow
|
||||||
import dev.inmo.micro_utils.fsm.common.State
|
import dev.inmo.micro_utils.fsm.common.State
|
||||||
import dev.inmo.tgbotapi.extensions.api.send.send
|
|
||||||
import dev.inmo.tgbotapi.extensions.api.send.sendMessage
|
import dev.inmo.tgbotapi.extensions.api.send.sendMessage
|
||||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.*
|
import dev.inmo.tgbotapi.extensions.behaviour_builder.*
|
||||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.expectations.*
|
import dev.inmo.tgbotapi.extensions.behaviour_builder.expectations.*
|
||||||
@@ -56,7 +55,7 @@ suspend fun main(args: Array<String>) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
strictlyOn<StopState> {
|
strictlyOn<StopState> {
|
||||||
send(it.context, "You have stopped sending of content")
|
sendMessage(it.context, "You have stopped sending of content")
|
||||||
|
|
||||||
null
|
null
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,19 +14,17 @@ import java.io.File
|
|||||||
*/
|
*/
|
||||||
suspend fun main(args: Array<String>) {
|
suspend fun main(args: Array<String>) {
|
||||||
val botToken = args.first()
|
val botToken = args.first()
|
||||||
val directoryOrFile = args.getOrNull(1) ?.let { File(it) } ?: File("/tmp/")
|
val directoryOrFile = args.getOrNull(1) ?.let { File(it) } ?: File("")
|
||||||
directoryOrFile.mkdirs()
|
directoryOrFile.mkdirs()
|
||||||
|
|
||||||
telegramBotWithBehaviourAndLongPolling(botToken, CoroutineScope(Dispatchers.IO)) {
|
telegramBotWithBehaviourAndLongPolling(botToken, CoroutineScope(Dispatchers.IO)) {
|
||||||
onMedia(initialFilter = null) {
|
onMedia(initialFilter = null) {
|
||||||
val pathedFile = bot.getFileAdditionalInfo(it.content.media)
|
val pathedFile = bot.getFileAdditionalInfo(it.content.media)
|
||||||
val outFile = File(directoryOrFile, pathedFile.filePath.filenameFromUrl)
|
val file = File(directoryOrFile, pathedFile.filePath.filenameFromUrl).apply {
|
||||||
runCatching {
|
createNewFile()
|
||||||
bot.downloadFile(it.content.media, outFile)
|
writeBytes(bot.downloadFile(pathedFile))
|
||||||
}.onFailure {
|
|
||||||
it.printStackTrace()
|
|
||||||
}
|
}
|
||||||
reply(it, "Saved to ${outFile.absolutePath}")
|
reply(it, "Saved to ${file.absolutePath}")
|
||||||
}
|
}
|
||||||
onContentMessage { println(it) }
|
onContentMessage { println(it) }
|
||||||
}.second.join()
|
}.second.join()
|
||||||
|
|||||||
@@ -16,30 +16,23 @@ suspend fun main(vararg args: String) {
|
|||||||
val botToken = args.first()
|
val botToken = args.first()
|
||||||
|
|
||||||
telegramBotWithBehaviourAndLongPolling(botToken, CoroutineScope(Dispatchers.IO)) {
|
telegramBotWithBehaviourAndLongPolling(botToken, CoroutineScope(Dispatchers.IO)) {
|
||||||
onContentMessage {
|
onContentMessage(subcontextUpdatesFilter = { _, _ -> true }) {
|
||||||
val toAnswer = buildEntities {
|
val toAnswer = buildEntities {
|
||||||
when (val forwardInfo = it.forwardInfo) {
|
when (val forwardInfo = it.forwardInfo) {
|
||||||
null -> +"There is no forward info"
|
null -> +"There is no forward info"
|
||||||
is ForwardInfo.ByAnonymous -> {
|
is AnonymousForwardInfo -> {
|
||||||
regular("Anonymous user which signed as \"") + code(forwardInfo.senderName) + "\""
|
regular("Anonymous user which signed as \"") + code(forwardInfo.senderName) + "\""
|
||||||
}
|
}
|
||||||
is ForwardInfo.ByUser -> {
|
is UserForwardInfo -> {
|
||||||
val user = forwardInfo.from
|
val user = forwardInfo.from
|
||||||
when (user) {
|
when (user) {
|
||||||
is CommonUser -> {
|
is CommonUser -> regular("User ")
|
||||||
if (user.isPremium) {
|
|
||||||
regular("Premium user ")
|
|
||||||
} else {
|
|
||||||
regular("User ")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
is CommonBot,
|
is CommonBot,
|
||||||
is ExtendedBot -> regular("Bot ")
|
is ExtendedBot -> regular("Bot ")
|
||||||
} + code(user.id.chatId.toString()) + " (${user.firstName} ${user.lastName}: ${user.username ?.username ?: "Without username"})"
|
} + code(user.id.chatId.toString()) + " (${user.firstName} ${user.lastName}: ${user.username ?.username ?: "Without username"})"
|
||||||
}
|
}
|
||||||
is ForwardInfo.PublicChat.FromChannel -> regular("Channel (") + code(forwardInfo.channelChat.title) + ")"
|
is ForwardFromChannelInfo -> regular("Channel (") + code((forwardInfo.channelChat).title) + ")"
|
||||||
is ForwardInfo.PublicChat.FromSupergroup -> regular("Supergroup (") + code(forwardInfo.group.title) + ")"
|
is ForwardFromSupergroupInfo -> regular("Supergroup (") + code((forwardInfo.group).title) + ")"
|
||||||
is ForwardInfo.PublicChat.SentByChannel -> regular("Sent by channel (") + code(forwardInfo.channelChat.title) + ")"
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
reply(it, toAnswer)
|
reply(it, toAnswer)
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import dev.inmo.micro_utils.coroutines.subscribeSafelyWithoutExceptions
|
import dev.inmo.micro_utils.coroutines.subscribeSafelyWithoutExceptions
|
||||||
import dev.inmo.tgbotapi.extensions.api.chat.get.getChat
|
import dev.inmo.tgbotapi.extensions.api.chat.get.getChat
|
||||||
import dev.inmo.tgbotapi.extensions.api.send.*
|
import dev.inmo.tgbotapi.extensions.api.send.reply
|
||||||
|
import dev.inmo.tgbotapi.extensions.api.send.sendTextMessage
|
||||||
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.onContentMessage
|
import dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling.onContentMessage
|
||||||
import dev.inmo.tgbotapi.extensions.utils.formatting.linkMarkdownV2
|
import dev.inmo.tgbotapi.extensions.utils.formatting.linkMarkdownV2
|
||||||
@@ -26,7 +27,7 @@ suspend fun main(vararg args: String) {
|
|||||||
val chat = message.chat
|
val chat = message.chat
|
||||||
if (chat is ChannelChat) {
|
if (chat is ChannelChat) {
|
||||||
val answer = "Hi everybody in this channel \"${chat.title}\""
|
val answer = "Hi everybody in this channel \"${chat.title}\""
|
||||||
send(chat, answer, MarkdownV2)
|
sendTextMessage(chat, answer, MarkdownV2)
|
||||||
return@onContentMessage
|
return@onContentMessage
|
||||||
}
|
}
|
||||||
val answerText = "Oh, hi, " + when (chat) {
|
val answerText = "Oh, hi, " + when (chat) {
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ import dev.inmo.tgbotapi.extensions.api.bot.getMe
|
|||||||
import dev.inmo.tgbotapi.bot.ktor.telegramBot
|
import dev.inmo.tgbotapi.bot.ktor.telegramBot
|
||||||
import dev.inmo.tgbotapi.extensions.api.answers.answer
|
import dev.inmo.tgbotapi.extensions.api.answers.answer
|
||||||
import dev.inmo.tgbotapi.extensions.api.bot.setMyCommands
|
import dev.inmo.tgbotapi.extensions.api.bot.setMyCommands
|
||||||
import dev.inmo.tgbotapi.extensions.api.edit.edit
|
import dev.inmo.tgbotapi.extensions.api.edit.text.editMessageText
|
||||||
import dev.inmo.tgbotapi.extensions.api.send.*
|
import dev.inmo.tgbotapi.extensions.api.send.*
|
||||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.*
|
import dev.inmo.tgbotapi.extensions.behaviour_builder.*
|
||||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling.*
|
import dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling.*
|
||||||
@@ -88,7 +88,7 @@ suspend fun activateKeyboardsBot(
|
|||||||
|
|
||||||
val text = "This is $page of $count"
|
val text = "This is $page of $count"
|
||||||
|
|
||||||
edit(
|
editMessageText(
|
||||||
it.message.withContent<TextContent>() ?: it.let {
|
it.message.withContent<TextContent>() ?: it.let {
|
||||||
answer(it, "Unsupported message type :(")
|
answer(it, "Unsupported message type :(")
|
||||||
return@onMessageDataCallbackQuery
|
return@onMessageDataCallbackQuery
|
||||||
@@ -100,7 +100,6 @@ suspend fun activateKeyboardsBot(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
answer(it)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
onUnhandledCommand {
|
onUnhandledCommand {
|
||||||
|
|||||||
@@ -3,15 +3,15 @@ import dev.inmo.tgbotapi.bot.ktor.telegramBot
|
|||||||
import dev.inmo.tgbotapi.bot.TelegramBot
|
import dev.inmo.tgbotapi.bot.TelegramBot
|
||||||
import dev.inmo.tgbotapi.extensions.api.bot.getMe
|
import dev.inmo.tgbotapi.extensions.api.bot.getMe
|
||||||
import dev.inmo.tgbotapi.extensions.api.bot.setMyCommands
|
import dev.inmo.tgbotapi.extensions.api.bot.setMyCommands
|
||||||
import dev.inmo.tgbotapi.extensions.api.send.*
|
|
||||||
import dev.inmo.tgbotapi.extensions.api.send.media.sendDocument
|
import dev.inmo.tgbotapi.extensions.api.send.media.sendDocument
|
||||||
import dev.inmo.tgbotapi.extensions.api.send.media.sendDocumentsGroup
|
import dev.inmo.tgbotapi.extensions.api.send.media.sendDocumentsGroup
|
||||||
|
import dev.inmo.tgbotapi.extensions.api.send.reply
|
||||||
|
import dev.inmo.tgbotapi.extensions.api.send.withUploadDocumentAction
|
||||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.buildBehaviourWithLongPolling
|
import dev.inmo.tgbotapi.extensions.behaviour_builder.buildBehaviourWithLongPolling
|
||||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling.onCommandWithArgs
|
import dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling.onCommandWithArgs
|
||||||
import dev.inmo.tgbotapi.requests.abstracts.asMultipartFile
|
import dev.inmo.tgbotapi.requests.abstracts.asMultipartFile
|
||||||
import dev.inmo.tgbotapi.types.BotCommand
|
import dev.inmo.tgbotapi.types.BotCommand
|
||||||
import dev.inmo.tgbotapi.types.chat.Chat
|
import dev.inmo.tgbotapi.types.chat.Chat
|
||||||
import dev.inmo.tgbotapi.types.files.DocumentFile
|
|
||||||
import dev.inmo.tgbotapi.types.media.TelegramMediaDocument
|
import dev.inmo.tgbotapi.types.media.TelegramMediaDocument
|
||||||
import dev.inmo.tgbotapi.types.mediaCountInMediaGroup
|
import dev.inmo.tgbotapi.types.mediaCountInMediaGroup
|
||||||
import java.io.File
|
import java.io.File
|
||||||
@@ -81,7 +81,7 @@ suspend fun main(args: Array<String>) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!sent) {
|
if (!sent) {
|
||||||
reply(message, "Nothing selected :(")
|
bot.reply(message, "Nothing selected :(")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,27 +25,25 @@ suspend fun activateResenderBot(
|
|||||||
) {
|
) {
|
||||||
val chat = it.chat
|
val chat = it.chat
|
||||||
withTypingAction(chat) {
|
withTypingAction(chat) {
|
||||||
executeUnsafe(it.content.createResend(chat.id, replyToMessageId = it.messageId)) {
|
executeUnsafe(it.content.createResend(chat.id, replyToMessageId = it.messageId))
|
||||||
it.forEach(print)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
onVisualGallery {
|
onVisualGallery {
|
||||||
val chat = it.chat ?: return@onVisualGallery
|
val chat = it.chat ?: return@onVisualGallery
|
||||||
withUploadPhotoAction(chat) {
|
withUploadPhotoAction(chat) {
|
||||||
send(chat, it.map { it.content.toMediaGroupMemberTelegramMedia() })
|
sendVisualMediaGroup(chat, it.map { it.content.toMediaGroupMemberTelegramMedia() })
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
onPlaylist {
|
onPlaylist {
|
||||||
val chat = it.chat ?: return@onPlaylist
|
val chat = it.chat ?: return@onPlaylist
|
||||||
withUploadDocumentAction(chat) {
|
withUploadDocumentAction(chat) {
|
||||||
send(chat, it.map { it.content.toMediaGroupMemberTelegramMedia() })
|
sendPlaylist(chat, it.map { it.content.toMediaGroupMemberTelegramMedia() })
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
onDocumentsGroup {
|
onDocumentsGroup {
|
||||||
val chat = it.chat ?: return@onDocumentsGroup
|
val chat = it.chat ?: return@onDocumentsGroup
|
||||||
withUploadDocumentAction(chat) {
|
withUploadDocumentAction(chat) {
|
||||||
send(chat, it.map { it.content.toMediaGroupMemberTelegramMedia() })
|
sendDocumentsGroup(chat, it.map { it.content.toMediaGroupMemberTelegramMedia() })
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -17,9 +17,9 @@ suspend fun main(args: Array<String>) {
|
|||||||
|
|
||||||
if (diceType == SlotMachineDiceAnimationType) {
|
if (diceType == SlotMachineDiceAnimationType) {
|
||||||
val result = dice.calculateSlotMachineResult() ?: return@onDice
|
val result = dice.calculateSlotMachineResult() ?: return@onDice
|
||||||
reply(it, "${result.leftReel}|${result.centerReel}|${result.rightReel}")
|
bot.reply(it, "${result.leftReel}|${result.centerReel}|${result.rightReel}")
|
||||||
} else {
|
} else {
|
||||||
reply(it, "There is no slot machine dice in message")
|
bot.reply(it, "There is no slot machine dice in message")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}.join()
|
}.join()
|
||||||
|
|||||||
@@ -1,33 +0,0 @@
|
|||||||
buildscript {
|
|
||||||
repositories {
|
|
||||||
mavenCentral()
|
|
||||||
}
|
|
||||||
|
|
||||||
dependencies {
|
|
||||||
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
plugins {
|
|
||||||
id "org.jetbrains.kotlin.multiplatform"
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
kotlin {
|
|
||||||
jvm()
|
|
||||||
// js(LEGACY) {
|
|
||||||
js(IR) {
|
|
||||||
browser()
|
|
||||||
binaries.executable()
|
|
||||||
}
|
|
||||||
|
|
||||||
sourceSets {
|
|
||||||
commonMain {
|
|
||||||
dependencies {
|
|
||||||
implementation kotlin('stdlib')
|
|
||||||
|
|
||||||
api "dev.inmo:tgbotapi:$telegram_bot_api_version"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,71 +0,0 @@
|
|||||||
import dev.inmo.micro_utils.coroutines.defaultSafelyWithoutExceptionHandler
|
|
||||||
import dev.inmo.micro_utils.coroutines.subscribeSafelyWithoutExceptions
|
|
||||||
import dev.inmo.tgbotapi.extensions.api.bot.getMe
|
|
||||||
import dev.inmo.tgbotapi.bot.ktor.telegramBot
|
|
||||||
import dev.inmo.tgbotapi.extensions.api.get.getCustomEmojiStickerOrNull
|
|
||||||
import dev.inmo.tgbotapi.extensions.api.get.getStickerSet
|
|
||||||
import dev.inmo.tgbotapi.extensions.api.send.*
|
|
||||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.*
|
|
||||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling.*
|
|
||||||
import dev.inmo.tgbotapi.extensions.utils.formatting.*
|
|
||||||
import dev.inmo.tgbotapi.types.StickerType
|
|
||||||
import dev.inmo.tgbotapi.types.message.textsources.*
|
|
||||||
import dev.inmo.tgbotapi.types.stickers.StickerSet
|
|
||||||
import kotlinx.coroutines.*
|
|
||||||
|
|
||||||
fun StickerSet.buildInfo() = buildEntities {
|
|
||||||
bold("StickerSet name: ") + "${name}\n"
|
|
||||||
bold("StickerSet title: ") + "${title}\n"
|
|
||||||
bold(
|
|
||||||
when (stickerType) {
|
|
||||||
StickerType.CustomEmoji -> "Custom emoji"
|
|
||||||
StickerType.Mask -> "Mask"
|
|
||||||
StickerType.Regular -> "Regular"
|
|
||||||
is StickerType.Unknown -> "Unknown type \"${stickerType.type}\""
|
|
||||||
}
|
|
||||||
) + " sticker set with title " + bold(title) + " and name " + bold(name)
|
|
||||||
}
|
|
||||||
|
|
||||||
suspend fun activateStickerInfoBot(
|
|
||||||
token: String,
|
|
||||||
print: (Any) -> Unit
|
|
||||||
) {
|
|
||||||
val bot = telegramBot(token)
|
|
||||||
|
|
||||||
print(bot.getMe())
|
|
||||||
|
|
||||||
defaultSafelyWithoutExceptionHandler = {
|
|
||||||
it.printStackTrace()
|
|
||||||
}
|
|
||||||
|
|
||||||
bot.buildBehaviourWithLongPolling(CoroutineScope(currentCoroutineContext() + SupervisorJob())) {
|
|
||||||
onText {
|
|
||||||
withTypingAction(it.chat) {
|
|
||||||
it.content.textSources.mapNotNull {
|
|
||||||
if (it is CustomEmojiTextSource) {
|
|
||||||
getCustomEmojiStickerOrNull(it.customEmojiId) ?.stickerSetName
|
|
||||||
} else {
|
|
||||||
null
|
|
||||||
}
|
|
||||||
}.distinct().map {
|
|
||||||
getStickerSet(it)
|
|
||||||
}.distinct().flatMap {
|
|
||||||
it.buildInfo() + regular("\n")
|
|
||||||
}.separateForText().map { entities ->
|
|
||||||
reply(it, entities)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
onSticker {
|
|
||||||
val stickerSetInfo = getStickerSet(it.content.media)
|
|
||||||
reply(
|
|
||||||
it,
|
|
||||||
stickerSetInfo.buildInfo()
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
allUpdatesFlow.subscribeSafelyWithoutExceptions(this) {
|
|
||||||
println(it)
|
|
||||||
}
|
|
||||||
}.join()
|
|
||||||
}
|
|
||||||
@@ -1,32 +0,0 @@
|
|||||||
import kotlinx.browser.document
|
|
||||||
import kotlinx.coroutines.*
|
|
||||||
import org.w3c.dom.*
|
|
||||||
|
|
||||||
private val scope = CoroutineScope(Dispatchers.Default)
|
|
||||||
|
|
||||||
fun main() {
|
|
||||||
document.addEventListener(
|
|
||||||
"DOMContentLoaded",
|
|
||||||
{
|
|
||||||
val botsContainer = document.getElementById("bots_container") ?: return@addEventListener
|
|
||||||
|
|
||||||
(document.getElementById("bot_token_form") as? HTMLFormElement) ?.onsubmit = {
|
|
||||||
(document.getElementById("bot_token") as? HTMLInputElement) ?.value ?.let { token ->
|
|
||||||
val botContainer = document.createElement("div") as HTMLDivElement
|
|
||||||
botsContainer.append(botContainer)
|
|
||||||
|
|
||||||
val infoDiv = document.createElement("div") as HTMLDivElement
|
|
||||||
botContainer.append(infoDiv)
|
|
||||||
|
|
||||||
scope.launch {
|
|
||||||
activateStickerInfoBot(token) {
|
|
||||||
infoDiv.innerHTML = it.toString()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
)
|
|
||||||
}
|
|
||||||
@@ -1,16 +0,0 @@
|
|||||||
<!DOCTYPE html>
|
|
||||||
<html lang="en">
|
|
||||||
<head>
|
|
||||||
<meta charset="UTF-8">
|
|
||||||
<title>Resender bot</title>
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
<form id="bot_token_form">
|
|
||||||
<input type="text" id="bot_token">
|
|
||||||
<input type="submit" value="Start bot">
|
|
||||||
</form>
|
|
||||||
<div id="start_offer">Type your bot token to the input above to start its work</div>
|
|
||||||
<script type="text/javascript" src="StickerInfoBotLib.js"></script>
|
|
||||||
<div id="bots_container"></div>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
@@ -1,21 +0,0 @@
|
|||||||
buildscript {
|
|
||||||
repositories {
|
|
||||||
mavenCentral()
|
|
||||||
}
|
|
||||||
|
|
||||||
dependencies {
|
|
||||||
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
apply plugin: 'kotlin'
|
|
||||||
apply plugin: 'application'
|
|
||||||
|
|
||||||
mainClassName="StickerInfoBotJvmKt"
|
|
||||||
|
|
||||||
|
|
||||||
dependencies {
|
|
||||||
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
|
|
||||||
|
|
||||||
implementation project(":StickerInfoBot:StickerInfoBotLib")
|
|
||||||
}
|
|
||||||
@@ -1,5 +0,0 @@
|
|||||||
suspend fun main(args: Array<String>) {
|
|
||||||
activateStickerInfoBot(args.first()) {
|
|
||||||
println(it)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,9 +1,6 @@
|
|||||||
import dev.inmo.micro_utils.coroutines.launchSafelyWithoutExceptions
|
import dev.inmo.micro_utils.coroutines.launchSafelyWithoutExceptions
|
||||||
import dev.inmo.tgbotapi.types.webAppQueryIdField
|
import dev.inmo.tgbotapi.types.webAppQueryIdField
|
||||||
import dev.inmo.tgbotapi.webapps.*
|
import dev.inmo.tgbotapi.webapps.*
|
||||||
import dev.inmo.tgbotapi.webapps.haptic.HapticFeedbackStyle
|
|
||||||
import dev.inmo.tgbotapi.webapps.haptic.HapticFeedbackType
|
|
||||||
import dev.inmo.tgbotapi.webapps.popup.*
|
|
||||||
import io.ktor.client.HttpClient
|
import io.ktor.client.HttpClient
|
||||||
import io.ktor.client.request.*
|
import io.ktor.client.request.*
|
||||||
import io.ktor.client.statement.bodyAsText
|
import io.ktor.client.statement.bodyAsText
|
||||||
@@ -18,8 +15,8 @@ import kotlinx.serialization.json.Json
|
|||||||
import org.w3c.dom.HTMLElement
|
import org.w3c.dom.HTMLElement
|
||||||
|
|
||||||
fun HTMLElement.log(text: String) {
|
fun HTMLElement.log(text: String) {
|
||||||
appendText(text)
|
|
||||||
appendElement("p", {})
|
appendElement("p", {})
|
||||||
|
appendText(text)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun main() {
|
fun main() {
|
||||||
@@ -42,17 +39,13 @@ fun main() {
|
|||||||
}
|
}
|
||||||
val dataIsSafe = response.bodyAsText().toBoolean()
|
val dataIsSafe = response.bodyAsText().toBoolean()
|
||||||
|
|
||||||
document.body ?.log(
|
document.body ?.appendElement("div") {
|
||||||
if (dataIsSafe) {
|
textContent = if (dataIsSafe) {
|
||||||
"Data is safe"
|
"Data is safe"
|
||||||
} else {
|
} else {
|
||||||
"Data is unsafe"
|
"Data is unsafe"
|
||||||
}
|
}
|
||||||
)
|
}
|
||||||
|
|
||||||
document.body ?.log(
|
|
||||||
webApp.initDataUnsafe.chat.toString()
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
document.body ?.appendElement("button") {
|
document.body ?.appendElement("button") {
|
||||||
@@ -69,79 +62,6 @@ fun main() {
|
|||||||
})
|
})
|
||||||
appendText("Example button")
|
appendText("Example button")
|
||||||
} ?: window.alert("Unable to load body")
|
} ?: window.alert("Unable to load body")
|
||||||
|
|
||||||
document.body ?.appendElement("p", {})
|
|
||||||
document.body ?.appendText("Alerts:")
|
|
||||||
|
|
||||||
document.body ?.appendElement("button") {
|
|
||||||
addEventListener("click", {
|
|
||||||
webApp.showPopup(
|
|
||||||
PopupParams(
|
|
||||||
"It is sample title of default button",
|
|
||||||
"It is sample message of default button",
|
|
||||||
DefaultPopupButton("default", "Default button"),
|
|
||||||
OkPopupButton("ok"),
|
|
||||||
DestructivePopupButton("destructive", "Destructive button")
|
|
||||||
)
|
|
||||||
) {
|
|
||||||
document.body ?.log(
|
|
||||||
when (it) {
|
|
||||||
"default" -> "You have clicked default button in popup"
|
|
||||||
"ok" -> "You have clicked ok button in popup"
|
|
||||||
"destructive" -> "You have clicked destructive button in popup"
|
|
||||||
else -> "I can't imagine where you take button with id $it"
|
|
||||||
}
|
|
||||||
)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
appendText("Popup")
|
|
||||||
} ?: window.alert("Unable to load body")
|
|
||||||
|
|
||||||
document.body ?.appendElement("button") {
|
|
||||||
addEventListener("click", {
|
|
||||||
webApp.showAlert(
|
|
||||||
"This is alert message"
|
|
||||||
) {
|
|
||||||
document.body ?.log(
|
|
||||||
"You have closed alert"
|
|
||||||
)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
appendText("Alert")
|
|
||||||
} ?: window.alert("Unable to load body")
|
|
||||||
|
|
||||||
document.body ?.appendElement("button") {
|
|
||||||
addEventListener("click", {
|
|
||||||
webApp.showConfirm(
|
|
||||||
"This is confirm message"
|
|
||||||
) {
|
|
||||||
document.body ?.log(
|
|
||||||
"You have pressed \"${if (it) "Ok" else "Cancel"}\" in confirm"
|
|
||||||
)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
appendText("Confirm")
|
|
||||||
} ?: window.alert("Unable to load body")
|
|
||||||
|
|
||||||
document.body ?.appendElement("p", {})
|
|
||||||
|
|
||||||
document.body ?.appendElement("button") {
|
|
||||||
fun updateText() {
|
|
||||||
textContent = if (webApp.isClosingConfirmationEnabled) {
|
|
||||||
"Disable closing confirmation"
|
|
||||||
} else {
|
|
||||||
"Enable closing confirmation"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
addEventListener("click", {
|
|
||||||
webApp.toggleClosingConfirmation()
|
|
||||||
updateText()
|
|
||||||
})
|
|
||||||
updateText()
|
|
||||||
} ?: window.alert("Unable to load body")
|
|
||||||
|
|
||||||
document.body ?.appendElement("p", {})
|
|
||||||
|
|
||||||
webApp.apply {
|
webApp.apply {
|
||||||
onThemeChanged {
|
onThemeChanged {
|
||||||
document.body ?.log("Theme changed: ${webApp.themeParams}")
|
document.body ?.log("Theme changed: ${webApp.themeParams}")
|
||||||
@@ -149,28 +69,6 @@ fun main() {
|
|||||||
onViewportChanged {
|
onViewportChanged {
|
||||||
document.body ?.log("Viewport changed: ${it.isStateStable}")
|
document.body ?.log("Viewport changed: ${it.isStateStable}")
|
||||||
}
|
}
|
||||||
backButton.apply {
|
|
||||||
onClick {
|
|
||||||
document.body ?.log("Back button clicked")
|
|
||||||
hapticFeedback.impactOccurred(
|
|
||||||
HapticFeedbackStyle.Heavy
|
|
||||||
)
|
|
||||||
}
|
|
||||||
show()
|
|
||||||
}
|
|
||||||
mainButton.apply {
|
|
||||||
setText("Main button")
|
|
||||||
onClick {
|
|
||||||
document.body ?.log("Main button clicked")
|
|
||||||
hapticFeedback.notificationOccurred(
|
|
||||||
HapticFeedbackType.Success
|
|
||||||
)
|
|
||||||
}
|
|
||||||
show()
|
|
||||||
}
|
|
||||||
onSettingsButtonClicked {
|
|
||||||
document.body ?.log("Settings button clicked")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
webApp.ready()
|
webApp.ready()
|
||||||
}.onFailure {
|
}.onFailure {
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import dev.inmo.micro_utils.coroutines.subscribeSafelyWithoutExceptions
|
import dev.inmo.micro_utils.coroutines.subscribeSafelyWithoutExceptions
|
||||||
|
import dev.inmo.micro_utils.crypto.hmacSha256
|
||||||
import dev.inmo.micro_utils.ktor.server.createKtorServer
|
import dev.inmo.micro_utils.ktor.server.createKtorServer
|
||||||
import dev.inmo.tgbotapi.extensions.api.answers.answer
|
import dev.inmo.tgbotapi.extensions.api.answers.answer
|
||||||
import dev.inmo.tgbotapi.extensions.api.bot.getMe
|
import dev.inmo.tgbotapi.extensions.api.bot.getMe
|
||||||
|
|||||||
@@ -4,8 +4,8 @@ org.gradle.parallel=true
|
|||||||
org.gradle.jvmargs=-Xmx768m
|
org.gradle.jvmargs=-Xmx768m
|
||||||
|
|
||||||
|
|
||||||
kotlin_version=1.7.10
|
kotlin_version=1.7.0
|
||||||
telegram_bot_api_version=3.1.1
|
telegram_bot_api_version=2.0.3
|
||||||
micro_utils_version=0.12.1
|
micro_utils_version=0.11.0
|
||||||
serialization_version=1.4.0-RC
|
serialization_version=1.3.3
|
||||||
ktor_version=2.1.0
|
ktor_version=2.0.2
|
||||||
|
|||||||
2
gradle/wrapper/gradle-wrapper.properties
vendored
2
gradle/wrapper/gradle-wrapper.properties
vendored
@@ -2,4 +2,4 @@ distributionBase=GRADLE_USER_HOME
|
|||||||
distributionPath=wrapper/dists
|
distributionPath=wrapper/dists
|
||||||
zipStoreBase=GRADLE_USER_HOME
|
zipStoreBase=GRADLE_USER_HOME
|
||||||
zipStorePath=wrapper/dists
|
zipStorePath=wrapper/dists
|
||||||
distributionUrl=https\://services.gradle.org/distributions/gradle-7.5.1-bin.zip
|
distributionUrl=https\://services.gradle.org/distributions/gradle-7.4.2-bin.zip
|
||||||
|
|||||||
@@ -14,9 +14,6 @@ include ":ResenderBot:jvm_launcher"
|
|||||||
include ":KeyboardsBot:KeyboardsBotLib"
|
include ":KeyboardsBot:KeyboardsBotLib"
|
||||||
include ":KeyboardsBot:jvm_launcher"
|
include ":KeyboardsBot:jvm_launcher"
|
||||||
|
|
||||||
include ":StickerInfoBot:StickerInfoBotLib"
|
|
||||||
include ":StickerInfoBot:jvm_launcher"
|
|
||||||
|
|
||||||
include ":SlotMachineDetectorBot"
|
include ":SlotMachineDetectorBot"
|
||||||
|
|
||||||
include ":WebApp"
|
include ":WebApp"
|
||||||
|
|||||||
Reference in New Issue
Block a user