mirror of
https://github.com/InsanusMokrassar/TelegramBotAPI-examples.git
synced 2025-12-20 05:05:38 +00:00
Compare commits
54 Commits
9.2.0
...
0d5c0f055e
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0d5c0f055e | ||
|
|
f7e0f87e4a | ||
| 9170d30b2f | |||
| 2f3fd2e53b | |||
| 88697fb5a6 | |||
| 578d00cac6 | |||
| 13ecb3f0df | |||
| a008d861da | |||
| 6f3766dff6 | |||
| fda366d820 | |||
| 578887ac63 | |||
| 6a04b3980c | |||
| 984ffb8bae | |||
| 2bcec6487d | |||
| a5e3bfc3fe | |||
| 941afd0902 | |||
| 94c014b308 | |||
| 538cc9d44f | |||
| cb29726487 | |||
| 262ef26239 | |||
| 41efe5e141 | |||
| 05e289975a | |||
| 753d686fab | |||
| 281243c7e5 | |||
| 3609ae6bc2 | |||
| 4f128f3421 | |||
| ada6cd61d7 | |||
|
|
051d647004 | ||
|
|
d21606860a | ||
|
|
93c0fcb5bd | ||
| b1b8d0eb75 | |||
| 2ac23f70ab | |||
| e155373655 | |||
| d842dab5b8 | |||
| 7186d5e624 | |||
|
|
8fefb17599 | ||
| bcf4ae5888 | |||
| 7090db148e | |||
| 7d786f0e06 | |||
| c88f84011f | |||
| b8cc8854ea | |||
| 13470999e8 | |||
| af04a854ef | |||
| 44e86c9349 | |||
| 65c32d97d5 | |||
| 9b7605591e | |||
| 89d5a4f911 | |||
| 53cf212175 | |||
| 28301a92c9 | |||
| f814b11777 | |||
| 9773a74890 | |||
| a81cfaaba9 | |||
|
|
ee599611f3 | ||
| d3d6cd16c6 |
4
.github/workflows/build.yml
vendored
4
.github/workflows/build.yml
vendored
@@ -11,9 +11,9 @@ jobs:
|
|||||||
- name: Install dependencies
|
- name: Install dependencies
|
||||||
run: |
|
run: |
|
||||||
sudo apt install -y libcurl4-openssl-dev
|
sudo apt install -y libcurl4-openssl-dev
|
||||||
- name: Set up JDK 11
|
- name: Set up JDK 17
|
||||||
uses: actions/setup-java@v1
|
uses: actions/setup-java@v1
|
||||||
with:
|
with:
|
||||||
java-version: 11
|
java-version: 17
|
||||||
- name: Build with Gradle
|
- name: Build with Gradle
|
||||||
run: ./gradlew build
|
run: ./gradlew build
|
||||||
|
|||||||
9
BoostsInfoBot/README.md
Normal file
9
BoostsInfoBot/README.md
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
# UserChatShared
|
||||||
|
|
||||||
|
Showing info about boosts
|
||||||
|
|
||||||
|
## Launch
|
||||||
|
|
||||||
|
```bash
|
||||||
|
../gradlew run --args="BOT_TOKEN"
|
||||||
|
```
|
||||||
21
BoostsInfoBot/build.gradle
Normal file
21
BoostsInfoBot/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="BoostsInfoKt"
|
||||||
|
|
||||||
|
|
||||||
|
dependencies {
|
||||||
|
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
|
||||||
|
|
||||||
|
implementation "dev.inmo:tgbotapi:$telegram_bot_api_version"
|
||||||
|
}
|
||||||
65
BoostsInfoBot/src/main/kotlin/BoostsInfo.kt
Normal file
65
BoostsInfoBot/src/main/kotlin/BoostsInfo.kt
Normal file
@@ -0,0 +1,65 @@
|
|||||||
|
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.tgbotapi.bot.ktor.telegramBot
|
||||||
|
import dev.inmo.tgbotapi.extensions.api.get.getUserChatBoosts
|
||||||
|
import dev.inmo.tgbotapi.extensions.api.send.*
|
||||||
|
import dev.inmo.tgbotapi.extensions.behaviour_builder.buildBehaviourWithLongPolling
|
||||||
|
import dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling.onChatBoostUpdated
|
||||||
|
import dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling.onChatShared
|
||||||
|
import dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling.onCommand
|
||||||
|
import dev.inmo.tgbotapi.extensions.utils.types.buttons.*
|
||||||
|
import dev.inmo.tgbotapi.types.chat.member.ChatCommonAdministratorRights
|
||||||
|
import dev.inmo.tgbotapi.types.request.RequestId
|
||||||
|
import dev.inmo.tgbotapi.utils.regular
|
||||||
|
import korlibs.time.DateFormat
|
||||||
|
import korlibs.time.format
|
||||||
|
|
||||||
|
suspend fun main(args: Array<String>) {
|
||||||
|
val isDebug = args.getOrNull(1) == "debug"
|
||||||
|
|
||||||
|
if (isDebug) {
|
||||||
|
setDefaultKSLog(
|
||||||
|
KSLog { level: LogLevel, tag: String?, message: Any, throwable: Throwable? ->
|
||||||
|
println(defaultMessageFormatter(level, tag, message, throwable))
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
val requestChatId = RequestId(1)
|
||||||
|
|
||||||
|
val bot = telegramBot(args.first())
|
||||||
|
|
||||||
|
bot.buildBehaviourWithLongPolling (defaultExceptionsHandler = { it.printStackTrace() }) {
|
||||||
|
onChatBoostUpdated {
|
||||||
|
println(it)
|
||||||
|
}
|
||||||
|
|
||||||
|
onCommand("start") {
|
||||||
|
reply(
|
||||||
|
it,
|
||||||
|
replyMarkup = flatReplyKeyboard {
|
||||||
|
requestChannelButton(
|
||||||
|
"Click me :)",
|
||||||
|
requestChatId,
|
||||||
|
botIsMember = true
|
||||||
|
)
|
||||||
|
}
|
||||||
|
) {
|
||||||
|
regular("Select chat to get know about your boosts")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
onChatShared(initialFilter = { it.chatEvent.requestId == requestChatId }) {
|
||||||
|
val boosts = getUserChatBoosts(it.chatEvent.chatId, it.chat.id)
|
||||||
|
reply(
|
||||||
|
it
|
||||||
|
) {
|
||||||
|
boosts.boosts.forEach {
|
||||||
|
regular("Boost added: ${DateFormat.FORMAT1.format(it.addDate.asDate)}; Boost expire: ${DateFormat.FORMAT1.format(it.expirationDate.asDate)}; Unformatted: $it") + "\n"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}.join()
|
||||||
|
}
|
||||||
@@ -1,13 +1,31 @@
|
|||||||
|
import dev.inmo.kslog.common.KSLog
|
||||||
|
import dev.inmo.kslog.common.LogLevel
|
||||||
|
import dev.inmo.kslog.common.defaultMessageFormatter
|
||||||
|
import dev.inmo.kslog.common.filter.filtered
|
||||||
|
import dev.inmo.kslog.common.setDefaultKSLog
|
||||||
import dev.inmo.tgbotapi.bot.ktor.telegramBot
|
import dev.inmo.tgbotapi.bot.ktor.telegramBot
|
||||||
import dev.inmo.tgbotapi.extensions.api.bot.getMe
|
import dev.inmo.tgbotapi.extensions.api.bot.getMe
|
||||||
|
import dev.inmo.tgbotapi.extensions.api.chat.get.getChat
|
||||||
|
import dev.inmo.tgbotapi.utils.DefaultKTgBotAPIKSLog
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This is one of the most easiest bot - it will just print information about itself
|
* This is one of the most easiest bot - it will just print information about itself
|
||||||
*/
|
*/
|
||||||
suspend fun main(vararg args: String) {
|
suspend fun main(vararg args: String) {
|
||||||
val botToken = args.first()
|
val botToken = args.first()
|
||||||
|
val isDebug = args.getOrNull(1) == "debug"
|
||||||
|
|
||||||
|
if (isDebug) {
|
||||||
|
setDefaultKSLog(
|
||||||
|
KSLog { level: LogLevel, tag: String?, message: Any, throwable: Throwable? ->
|
||||||
|
println(defaultMessageFormatter(level, tag, message, throwable))
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
val bot = telegramBot(botToken)
|
val bot = telegramBot(botToken)
|
||||||
|
|
||||||
println(bot.getMe())
|
val me = bot.getMe()
|
||||||
|
println(me)
|
||||||
|
println(bot.getChat(me))
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,16 +32,16 @@ suspend fun main(vararg args: String) {
|
|||||||
val chat = message.chat
|
val chat = message.chat
|
||||||
|
|
||||||
val answerText = when (val chat = message.chat) {
|
val answerText = when (val chat = message.chat) {
|
||||||
is ChannelChat -> {
|
is PreviewChannelChat -> {
|
||||||
val answer = "Hi everybody in this channel \"${chat.title}\""
|
val answer = "Hi everybody in this channel \"${chat.title}\""
|
||||||
reply(message, answer, MarkdownV2)
|
reply(message, answer, MarkdownV2)
|
||||||
return@onMentionWithAnyContent
|
return@onMentionWithAnyContent
|
||||||
}
|
}
|
||||||
is PrivateChat -> {
|
is PreviewPrivateChat -> {
|
||||||
reply(message, "Hi, " + "${chat.firstName} ${chat.lastName}".textMentionMarkdownV2(chat.id), MarkdownV2)
|
reply(message, "Hi, " + "${chat.firstName} ${chat.lastName}".textMentionMarkdownV2(chat.id), MarkdownV2)
|
||||||
return@onMentionWithAnyContent
|
return@onMentionWithAnyContent
|
||||||
}
|
}
|
||||||
is GroupChat -> {
|
is PreviewGroupChat -> {
|
||||||
message.ifFromChannelGroupContentMessage {
|
message.ifFromChannelGroupContentMessage {
|
||||||
val answer = "Hi, ${it.senderChat.title}"
|
val answer = "Hi, ${it.senderChat.title}"
|
||||||
reply(message, answer, MarkdownV2)
|
reply(message, answer, MarkdownV2)
|
||||||
@@ -56,9 +56,7 @@ suspend fun main(vararg args: String) {
|
|||||||
} ?: chat.title
|
} ?: chat.title
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
is UnknownExtendedChat,
|
|
||||||
is UnknownChatType -> "Unknown :(".escapeMarkdownV2Common()
|
is UnknownChatType -> "Unknown :(".escapeMarkdownV2Common()
|
||||||
else -> error("Something went wrong: unknown type of chat $chat")
|
|
||||||
}
|
}
|
||||||
reply(
|
reply(
|
||||||
message,
|
message,
|
||||||
|
|||||||
@@ -16,15 +16,9 @@ apply plugin: 'application'
|
|||||||
|
|
||||||
mainClassName="InlineQueriesBotKt"
|
mainClassName="InlineQueriesBotKt"
|
||||||
|
|
||||||
|
apply from: "$nativePartTemplate"
|
||||||
|
|
||||||
kotlin {
|
kotlin {
|
||||||
def hostOs = System.getProperty("os.name")
|
|
||||||
def isMingwX64 = hostOs.startsWith("Windows")
|
|
||||||
def nativeTarget
|
|
||||||
if (hostOs == "Linux") nativeTarget = linuxX64("native") { binaries { executable() } }
|
|
||||||
else if (isMingwX64) nativeTarget = mingwX64("native") { binaries { executable() } }
|
|
||||||
else throw new GradleException("Host OS is not supported in Kotlin/Native.")
|
|
||||||
|
|
||||||
jvm()
|
jvm()
|
||||||
|
|
||||||
sourceSets {
|
sourceSets {
|
||||||
@@ -35,22 +29,10 @@ kotlin {
|
|||||||
api "dev.inmo:tgbotapi:$telegram_bot_api_version"
|
api "dev.inmo:tgbotapi:$telegram_bot_api_version"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
nativeMain {
|
|
||||||
dependencies {
|
|
||||||
def engine
|
|
||||||
|
|
||||||
if (hostOs == "Linux") engine = "curl"
|
|
||||||
else if (isMingwX64) engine = "winhttp"
|
|
||||||
else throw new GradleException("Host OS is not supported in Kotlin/Native.")
|
|
||||||
|
|
||||||
api "io.ktor:ktor-client-$engine:$ktor_version"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
implementation 'io.ktor:ktor-client-logging-jvm:2.3.0'
|
implementation 'io.ktor:ktor-client-logging-jvm:2.3.7'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
9
LinkPreviewsBot/README.md
Normal file
9
LinkPreviewsBot/README.md
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
# ReactionsInfoBot
|
||||||
|
|
||||||
|
This bot will resend messages with links with all variants of `LinkPreviewOptions`
|
||||||
|
|
||||||
|
## Launch
|
||||||
|
|
||||||
|
```bash
|
||||||
|
../gradlew run --args="BOT_TOKEN"
|
||||||
|
```
|
||||||
21
LinkPreviewsBot/build.gradle
Normal file
21
LinkPreviewsBot/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="LinkPreviewsBotKt"
|
||||||
|
|
||||||
|
|
||||||
|
dependencies {
|
||||||
|
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
|
||||||
|
|
||||||
|
implementation "dev.inmo:tgbotapi:$telegram_bot_api_version"
|
||||||
|
}
|
||||||
93
LinkPreviewsBot/src/main/kotlin/LinkPreviewsBot.kt
Normal file
93
LinkPreviewsBot/src/main/kotlin/LinkPreviewsBot.kt
Normal file
@@ -0,0 +1,93 @@
|
|||||||
|
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.tgbotapi.bot.ktor.telegramBot
|
||||||
|
import dev.inmo.tgbotapi.extensions.api.chat.get.getChat
|
||||||
|
import dev.inmo.tgbotapi.extensions.api.send.copyMessage
|
||||||
|
import dev.inmo.tgbotapi.extensions.api.send.reply
|
||||||
|
import dev.inmo.tgbotapi.extensions.api.send.send
|
||||||
|
import dev.inmo.tgbotapi.extensions.api.send.setMessageReaction
|
||||||
|
import dev.inmo.tgbotapi.extensions.behaviour_builder.buildBehaviourWithLongPolling
|
||||||
|
import dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling.onChatMessageReactionUpdatedByUser
|
||||||
|
import dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling.onChatMessageReactionsCountUpdated
|
||||||
|
import dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling.onContentMessage
|
||||||
|
import dev.inmo.tgbotapi.extensions.utils.textLinkTextSourceOrNull
|
||||||
|
import dev.inmo.tgbotapi.extensions.utils.uRLTextSourceOrNull
|
||||||
|
import dev.inmo.tgbotapi.extensions.utils.withContentOrNull
|
||||||
|
import dev.inmo.tgbotapi.types.LinkPreviewOptions
|
||||||
|
import dev.inmo.tgbotapi.types.chat.ExtendedChat
|
||||||
|
import dev.inmo.tgbotapi.types.message.content.TextContent
|
||||||
|
import dev.inmo.tgbotapi.types.message.content.TextedContent
|
||||||
|
import dev.inmo.tgbotapi.types.reactions.Reaction
|
||||||
|
import dev.inmo.tgbotapi.utils.customEmoji
|
||||||
|
import dev.inmo.tgbotapi.utils.regular
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This bot will reply with the same
|
||||||
|
*/
|
||||||
|
suspend fun main(vararg args: String) {
|
||||||
|
val botToken = args.first()
|
||||||
|
val isDebug = args.getOrNull(1) == "debug"
|
||||||
|
|
||||||
|
if (isDebug) {
|
||||||
|
setDefaultKSLog(
|
||||||
|
KSLog { level: LogLevel, tag: String?, message: Any, throwable: Throwable? ->
|
||||||
|
println(defaultMessageFormatter(level, tag, message, throwable))
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
val bot = telegramBot(botToken)
|
||||||
|
|
||||||
|
bot.buildBehaviourWithLongPolling {
|
||||||
|
onContentMessage {
|
||||||
|
val url = it.withContentOrNull<TextedContent>() ?.let {
|
||||||
|
it.content.textSources.firstNotNullOfOrNull {
|
||||||
|
it.textLinkTextSourceOrNull() ?.url ?: it.uRLTextSourceOrNull() ?.source
|
||||||
|
}
|
||||||
|
} ?: null.apply {
|
||||||
|
reply(it) {
|
||||||
|
regular("I am support only content with text contains url only")
|
||||||
|
}
|
||||||
|
} ?: return@onContentMessage
|
||||||
|
it.withContentOrNull<TextedContent>() ?.let {
|
||||||
|
send(
|
||||||
|
it.chat,
|
||||||
|
it.content.textSources,
|
||||||
|
linkPreviewOptions = LinkPreviewOptions.Disabled
|
||||||
|
)
|
||||||
|
send(
|
||||||
|
it.chat,
|
||||||
|
it.content.textSources,
|
||||||
|
linkPreviewOptions = LinkPreviewOptions.Large(url, showAboveText = true)
|
||||||
|
)
|
||||||
|
send(
|
||||||
|
it.chat,
|
||||||
|
it.content.textSources,
|
||||||
|
linkPreviewOptions = LinkPreviewOptions.Large(url, showAboveText = false)
|
||||||
|
)
|
||||||
|
send(
|
||||||
|
it.chat,
|
||||||
|
it.content.textSources,
|
||||||
|
linkPreviewOptions = LinkPreviewOptions.Small(url, showAboveText = true)
|
||||||
|
)
|
||||||
|
send(
|
||||||
|
it.chat,
|
||||||
|
it.content.textSources,
|
||||||
|
linkPreviewOptions = LinkPreviewOptions.Small(url, showAboveText = false)
|
||||||
|
)
|
||||||
|
send(
|
||||||
|
it.chat,
|
||||||
|
it.content.textSources,
|
||||||
|
linkPreviewOptions = LinkPreviewOptions.Default(url, showAboveText = true)
|
||||||
|
)
|
||||||
|
send(
|
||||||
|
it.chat,
|
||||||
|
it.content.textSources,
|
||||||
|
linkPreviewOptions = LinkPreviewOptions.Default(url, showAboveText = false)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}.join()
|
||||||
|
}
|
||||||
@@ -2,6 +2,7 @@ import dev.inmo.micro_utils.coroutines.subscribeSafelyWithoutExceptions
|
|||||||
import dev.inmo.tgbotapi.extensions.api.EditLiveLocationInfo
|
import dev.inmo.tgbotapi.extensions.api.EditLiveLocationInfo
|
||||||
import dev.inmo.tgbotapi.extensions.api.chat.get.getChat
|
import dev.inmo.tgbotapi.extensions.api.chat.get.getChat
|
||||||
import dev.inmo.tgbotapi.extensions.api.edit.edit
|
import dev.inmo.tgbotapi.extensions.api.edit.edit
|
||||||
|
import dev.inmo.tgbotapi.extensions.api.edit.location.live.stopLiveLocation
|
||||||
import dev.inmo.tgbotapi.extensions.api.handleLiveLocation
|
import dev.inmo.tgbotapi.extensions.api.handleLiveLocation
|
||||||
import dev.inmo.tgbotapi.extensions.api.send.*
|
import dev.inmo.tgbotapi.extensions.api.send.*
|
||||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.expectations.waitMessageDataCallbackQuery
|
import dev.inmo.tgbotapi.extensions.behaviour_builder.expectations.waitMessageDataCallbackQuery
|
||||||
@@ -75,7 +76,7 @@ suspend fun main(vararg args: String) {
|
|||||||
|
|
||||||
sendingJob.cancel() // ends live location
|
sendingJob.cancel() // ends live location
|
||||||
currentMessageState.value ?.let {
|
currentMessageState.value ?.let {
|
||||||
edit(it, replyMarkup = null) // removing reply keyboard
|
stopLiveLocation(it, replyMarkup = null)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
allUpdatesFlow.subscribeSafelyWithoutExceptions(this) { println(it) }
|
allUpdatesFlow.subscribeSafelyWithoutExceptions(this) { println(it) }
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ import dev.inmo.tgbotapi.extensions.utils.ifFromChannelGroupContentMessage
|
|||||||
import dev.inmo.tgbotapi.types.ChatId
|
import dev.inmo.tgbotapi.types.ChatId
|
||||||
import dev.inmo.tgbotapi.types.IdChatIdentifier
|
import dev.inmo.tgbotapi.types.IdChatIdentifier
|
||||||
import dev.inmo.tgbotapi.types.PollIdentifier
|
import dev.inmo.tgbotapi.types.PollIdentifier
|
||||||
|
import dev.inmo.tgbotapi.types.ReplyParameters
|
||||||
import dev.inmo.tgbotapi.types.chat.*
|
import dev.inmo.tgbotapi.types.chat.*
|
||||||
import dev.inmo.tgbotapi.types.chat.GroupChat
|
import dev.inmo.tgbotapi.types.chat.GroupChat
|
||||||
import dev.inmo.tgbotapi.types.chat.PrivateChat
|
import dev.inmo.tgbotapi.types.chat.PrivateChat
|
||||||
@@ -54,7 +55,7 @@ suspend fun main(vararg args: String) {
|
|||||||
it.toString()
|
it.toString()
|
||||||
},
|
},
|
||||||
isAnonymous = true,
|
isAnonymous = true,
|
||||||
replyToMessageId = it.messageId
|
replyParameters = ReplyParameters(it)
|
||||||
)
|
)
|
||||||
pollToChatMutex.withLock {
|
pollToChatMutex.withLock {
|
||||||
pollToChat[sentPoll.content.poll.id] = sentPoll.chat.id
|
pollToChat[sentPoll.content.poll.id] = sentPoll.chat.id
|
||||||
@@ -69,7 +70,7 @@ suspend fun main(vararg args: String) {
|
|||||||
it.toString()
|
it.toString()
|
||||||
},
|
},
|
||||||
isAnonymous = false,
|
isAnonymous = false,
|
||||||
replyToMessageId = it.messageId
|
replyParameters = ReplyParameters(it)
|
||||||
)
|
)
|
||||||
pollToChatMutex.withLock {
|
pollToChatMutex.withLock {
|
||||||
pollToChat[sentPoll.content.poll.id] = sentPoll.chat.id
|
pollToChat[sentPoll.content.poll.id] = sentPoll.chat.id
|
||||||
|
|||||||
@@ -16,15 +16,7 @@ apply plugin: 'application'
|
|||||||
|
|
||||||
mainClassName="RandomFileSenderBotKt"
|
mainClassName="RandomFileSenderBotKt"
|
||||||
|
|
||||||
|
|
||||||
kotlin {
|
kotlin {
|
||||||
def hostOs = System.getProperty("os.name")
|
|
||||||
def isMingwX64 = hostOs.startsWith("Windows")
|
|
||||||
def nativeTarget
|
|
||||||
if (hostOs == "Linux") nativeTarget = linuxX64("native") { binaries { executable() } }
|
|
||||||
else if (isMingwX64) nativeTarget = mingwX64("native") { binaries { executable() } }
|
|
||||||
else throw new GradleException("Host OS is not supported in Kotlin/Native.")
|
|
||||||
|
|
||||||
jvm()
|
jvm()
|
||||||
|
|
||||||
sourceSets {
|
sourceSets {
|
||||||
@@ -35,18 +27,8 @@ kotlin {
|
|||||||
api "dev.inmo:tgbotapi:$telegram_bot_api_version"
|
api "dev.inmo:tgbotapi:$telegram_bot_api_version"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
nativeMain {
|
|
||||||
dependencies {
|
|
||||||
def engine
|
|
||||||
|
|
||||||
if (hostOs == "Linux") engine = "curl"
|
|
||||||
else if (isMingwX64) engine = "winhttp"
|
|
||||||
else throw new GradleException("Host OS is not supported in Kotlin/Native.")
|
|
||||||
|
|
||||||
api "io.ktor:ktor-client-$engine:$ktor_version"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
apply from: "$nativePartTemplate"
|
||||||
|
|
||||||
|
|||||||
9
ReactionsInfoBot/README.md
Normal file
9
ReactionsInfoBot/README.md
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
# ReactionsInfoBot
|
||||||
|
|
||||||
|
This bot will send info about user reactions in his PM with reply to message user reacted to
|
||||||
|
|
||||||
|
## Launch
|
||||||
|
|
||||||
|
```bash
|
||||||
|
../gradlew run --args="BOT_TOKEN"
|
||||||
|
```
|
||||||
21
ReactionsInfoBot/build.gradle
Normal file
21
ReactionsInfoBot/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="ReactionsInfoBotKt"
|
||||||
|
|
||||||
|
|
||||||
|
dependencies {
|
||||||
|
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
|
||||||
|
|
||||||
|
implementation "dev.inmo:tgbotapi:$telegram_bot_api_version"
|
||||||
|
}
|
||||||
68
ReactionsInfoBot/src/main/kotlin/ReactionsInfoBot.kt
Normal file
68
ReactionsInfoBot/src/main/kotlin/ReactionsInfoBot.kt
Normal file
@@ -0,0 +1,68 @@
|
|||||||
|
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.tgbotapi.bot.ktor.telegramBot
|
||||||
|
import dev.inmo.tgbotapi.extensions.api.chat.get.getChat
|
||||||
|
import dev.inmo.tgbotapi.extensions.api.send.reply
|
||||||
|
import dev.inmo.tgbotapi.extensions.api.send.setMessageReaction
|
||||||
|
import dev.inmo.tgbotapi.extensions.api.send.setMessageReactions
|
||||||
|
import dev.inmo.tgbotapi.extensions.behaviour_builder.buildBehaviourWithLongPolling
|
||||||
|
import dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling.onChatMessageReactionUpdatedByUser
|
||||||
|
import dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling.onChatMessageReactionsCountUpdated
|
||||||
|
import dev.inmo.tgbotapi.types.chat.ExtendedChat
|
||||||
|
import dev.inmo.tgbotapi.types.reactions.Reaction
|
||||||
|
import dev.inmo.tgbotapi.utils.customEmoji
|
||||||
|
import dev.inmo.tgbotapi.utils.regular
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This bot will send info about user reactions in his PM with reply to message user reacted to
|
||||||
|
*/
|
||||||
|
suspend fun main(vararg args: String) {
|
||||||
|
val botToken = args.first()
|
||||||
|
val isDebug = args.getOrNull(1) == "debug"
|
||||||
|
|
||||||
|
if (isDebug) {
|
||||||
|
setDefaultKSLog(
|
||||||
|
KSLog { level: LogLevel, tag: String?, message: Any, throwable: Throwable? ->
|
||||||
|
println(defaultMessageFormatter(level, tag, message, throwable))
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
val bot = telegramBot(botToken)
|
||||||
|
|
||||||
|
bot.buildBehaviourWithLongPolling {
|
||||||
|
onChatMessageReactionUpdatedByUser {
|
||||||
|
setMessageReaction(
|
||||||
|
it.chat.id,
|
||||||
|
it.messageId,
|
||||||
|
"✍"
|
||||||
|
)
|
||||||
|
val replyResult = reply(
|
||||||
|
it.chat.id,
|
||||||
|
it.messageId,
|
||||||
|
replyInChatId = it.reactedUser.id
|
||||||
|
) {
|
||||||
|
regular("Current reactions for message in reply:\n")
|
||||||
|
it.new.forEach {
|
||||||
|
when (it) {
|
||||||
|
is Reaction.CustomEmoji -> regular("• ") + customEmoji(it.customEmojiId) + regular("(customEmojiId: ${it.customEmojiId})")
|
||||||
|
is Reaction.Emoji -> regular("• ${it.emoji}")
|
||||||
|
is Reaction.Unknown -> regular("• Unknown emoji ($it)")
|
||||||
|
}
|
||||||
|
regular("\n")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
setMessageReaction(
|
||||||
|
it.chat.id,
|
||||||
|
it.messageId,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
onChatMessageReactionsCountUpdated {
|
||||||
|
val extendedChat: ExtendedChat = getChat(it.chat)
|
||||||
|
println(extendedChat)
|
||||||
|
println(it)
|
||||||
|
}
|
||||||
|
}.join()
|
||||||
|
}
|
||||||
@@ -22,6 +22,7 @@ kotlin {
|
|||||||
}
|
}
|
||||||
linuxX64()
|
linuxX64()
|
||||||
mingwX64()
|
mingwX64()
|
||||||
|
linuxArm64()
|
||||||
|
|
||||||
sourceSets {
|
sourceSets {
|
||||||
commonMain {
|
commonMain {
|
||||||
|
|||||||
@@ -8,6 +8,10 @@ import dev.inmo.tgbotapi.extensions.behaviour_builder.filters.CommonMessageFilte
|
|||||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.filters.MessageFilterByChat
|
import dev.inmo.tgbotapi.extensions.behaviour_builder.filters.MessageFilterByChat
|
||||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling.*
|
import dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling.*
|
||||||
import dev.inmo.tgbotapi.extensions.utils.shortcuts.*
|
import dev.inmo.tgbotapi.extensions.utils.shortcuts.*
|
||||||
|
import dev.inmo.tgbotapi.extensions.utils.withContentOrNull
|
||||||
|
import dev.inmo.tgbotapi.types.ReplyParameters
|
||||||
|
import dev.inmo.tgbotapi.types.message.content.TextContent
|
||||||
|
import dev.inmo.tgbotapi.types.quoteEntitiesField
|
||||||
import dev.inmo.tgbotapi.utils.extensions.threadIdOrNull
|
import dev.inmo.tgbotapi.utils.extensions.threadIdOrNull
|
||||||
import kotlinx.coroutines.*
|
import kotlinx.coroutines.*
|
||||||
|
|
||||||
@@ -26,7 +30,14 @@ suspend fun activateResenderBot(
|
|||||||
it.content.createResend(
|
it.content.createResend(
|
||||||
chat.id,
|
chat.id,
|
||||||
messageThreadId = it.threadIdOrNull,
|
messageThreadId = it.threadIdOrNull,
|
||||||
replyToMessageId = it.messageId
|
replyParameters = it.replyInfo ?.messageMeta ?.let { meta ->
|
||||||
|
val quote = it.withContentOrNull<TextContent>() ?.content ?.quote
|
||||||
|
ReplyParameters(
|
||||||
|
meta,
|
||||||
|
entities = quote ?.textSources ?: emptyList(),
|
||||||
|
quotePosition = quote ?.position
|
||||||
|
)
|
||||||
|
}
|
||||||
)
|
)
|
||||||
) {
|
) {
|
||||||
it.forEach(print)
|
it.forEach(print)
|
||||||
|
|||||||
@@ -12,15 +12,9 @@ plugins {
|
|||||||
id "org.jetbrains.kotlin.multiplatform"
|
id "org.jetbrains.kotlin.multiplatform"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
apply from: "$nativePartTemplate"
|
||||||
|
|
||||||
kotlin {
|
kotlin {
|
||||||
def hostOs = System.getProperty("os.name")
|
|
||||||
def isMingwX64 = hostOs.startsWith("Windows")
|
|
||||||
def nativeTarget
|
|
||||||
if (hostOs == "Linux") nativeTarget = linuxX64("native") { binaries { executable() } }
|
|
||||||
else if (isMingwX64) nativeTarget = mingwX64("native") { binaries { executable() } }
|
|
||||||
else throw new GradleException("Host OS is not supported in Kotlin/Native.")
|
|
||||||
|
|
||||||
sourceSets {
|
sourceSets {
|
||||||
commonMain {
|
commonMain {
|
||||||
dependencies {
|
dependencies {
|
||||||
@@ -29,18 +23,6 @@ kotlin {
|
|||||||
api project(":ResenderBot:ResenderBotLib")
|
api project(":ResenderBot:ResenderBotLib")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
nativeMain {
|
|
||||||
dependencies {
|
|
||||||
def engine
|
|
||||||
|
|
||||||
if (hostOs == "Linux") engine = "curl"
|
|
||||||
else if (isMingwX64) engine = "winhttp"
|
|
||||||
else throw new GradleException("Host OS is not supported in Kotlin/Native.")
|
|
||||||
|
|
||||||
api "io.ktor:ktor-client-$engine:$ktor_version"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -18,5 +18,5 @@ dependencies {
|
|||||||
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
|
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
|
||||||
|
|
||||||
implementation "dev.inmo:tgbotapi:$telegram_bot_api_version"
|
implementation "dev.inmo:tgbotapi:$telegram_bot_api_version"
|
||||||
implementation 'io.ktor:ktor-client-logging-jvm:2.3.3'
|
implementation 'io.ktor:ktor-client-logging-jvm:2.3.7'
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,9 @@
|
|||||||
|
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.firstOf
|
import dev.inmo.micro_utils.coroutines.firstOf
|
||||||
|
import dev.inmo.micro_utils.coroutines.subscribeSafelyWithoutExceptions
|
||||||
import dev.inmo.micro_utils.fsm.common.State
|
import dev.inmo.micro_utils.fsm.common.State
|
||||||
import dev.inmo.tgbotapi.bot.ktor.telegramBot
|
import dev.inmo.tgbotapi.bot.ktor.telegramBot
|
||||||
import dev.inmo.tgbotapi.extensions.api.bot.setMyCommands
|
import dev.inmo.tgbotapi.extensions.api.bot.setMyCommands
|
||||||
@@ -24,6 +29,7 @@ import dev.inmo.tgbotapi.types.chat.ChatPermissions
|
|||||||
import dev.inmo.tgbotapi.types.chat.PublicChat
|
import dev.inmo.tgbotapi.types.chat.PublicChat
|
||||||
import dev.inmo.tgbotapi.types.chat.member.*
|
import dev.inmo.tgbotapi.types.chat.member.*
|
||||||
import dev.inmo.tgbotapi.types.commands.BotCommandScope
|
import dev.inmo.tgbotapi.types.commands.BotCommandScope
|
||||||
|
import dev.inmo.tgbotapi.types.message.abstracts.AccessibleMessage
|
||||||
import dev.inmo.tgbotapi.types.request.RequestId
|
import dev.inmo.tgbotapi.types.request.RequestId
|
||||||
import dev.inmo.tgbotapi.utils.*
|
import dev.inmo.tgbotapi.utils.*
|
||||||
import dev.inmo.tgbotapi.utils.mention
|
import dev.inmo.tgbotapi.utils.mention
|
||||||
@@ -49,6 +55,16 @@ sealed interface UserRetrievingStep : State {
|
|||||||
suspend fun main(args: Array<String>) {
|
suspend fun main(args: Array<String>) {
|
||||||
val botToken = args.first()
|
val botToken = args.first()
|
||||||
|
|
||||||
|
val isDebug = args.getOrNull(2) == "debug"
|
||||||
|
|
||||||
|
if (isDebug) {
|
||||||
|
setDefaultKSLog(
|
||||||
|
KSLog { level: LogLevel, tag: String?, message: Any, throwable: Throwable? ->
|
||||||
|
println(defaultMessageFormatter(level, tag, message, throwable))
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
val bot = telegramBot(botToken)
|
val bot = telegramBot(botToken)
|
||||||
|
|
||||||
val allowedAdmin = ChatId(args[1].toLong())
|
val allowedAdmin = ChatId(args[1].toLong())
|
||||||
@@ -185,14 +201,21 @@ suspend fun main(args: Array<String>) {
|
|||||||
) {
|
) {
|
||||||
onCommand(
|
onCommand(
|
||||||
"simple",
|
"simple",
|
||||||
initialFilter = { it.chat is PublicChat && it.fromUserMessageOrNull()?.user?.id == allowedAdmin }) {
|
initialFilter = { it.chat is PublicChat && it.fromUserMessageOrNull()?.user?.id == allowedAdmin }
|
||||||
|
) {
|
||||||
val replyMessage = it.replyTo
|
val replyMessage = it.replyTo
|
||||||
val userInReply = replyMessage?.fromUserMessageOrNull()?.user?.id ?: return@onCommand
|
val userInReply = replyMessage?.fromUserMessageOrNull()?.user?.id ?: return@onCommand
|
||||||
reply(
|
if (replyMessage is AccessibleMessage) {
|
||||||
replyMessage,
|
reply(
|
||||||
"Manage keyboard:",
|
replyMessage,
|
||||||
replyMarkup = buildCommonKeyboard(it.chat.id.toChatId(), userInReply) ?: return@onCommand
|
"Manage keyboard:",
|
||||||
)
|
replyMarkup = buildCommonKeyboard(it.chat.id.toChatId(), userInReply) ?: return@onCommand
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
reply(it) {
|
||||||
|
regular("Reply to somebody's message to get hist/her rights keyboard")
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
onCommand(
|
onCommand(
|
||||||
"granular",
|
"granular",
|
||||||
@@ -204,11 +227,17 @@ suspend fun main(args: Array<String>) {
|
|||||||
val usernameInText = it.content.textSources.firstNotNullOfOrNull { it.mentionTextSourceOrNull() } ?.username
|
val usernameInText = it.content.textSources.firstNotNullOfOrNull { it.mentionTextSourceOrNull() } ?.username
|
||||||
val userInReply = replyMessage?.fromUserMessageOrNull()?.user?.id ?: return@onCommand
|
val userInReply = replyMessage?.fromUserMessageOrNull()?.user?.id ?: return@onCommand
|
||||||
|
|
||||||
reply(
|
if (replyMessage is AccessibleMessage) {
|
||||||
replyMessage,
|
reply(
|
||||||
"Manage keyboard:",
|
replyMessage,
|
||||||
replyMarkup = buildGranularKeyboard(it.chat.id.toChatId(), userInReply) ?: return@onCommand
|
"Manage keyboard:",
|
||||||
)
|
replyMarkup = buildGranularKeyboard(it.chat.id.toChatId(), userInReply) ?: return@onCommand
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
reply(it) {
|
||||||
|
regular("Reply to somebody's message to get hist/her rights keyboard")
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
onMessageDataCallbackQuery(
|
onMessageDataCallbackQuery(
|
||||||
@@ -503,5 +532,9 @@ suspend fun main(args: Array<String>) {
|
|||||||
BotCommand("rights_in_channel", "Trigger granular keyboard. Use with reply to user"),
|
BotCommand("rights_in_channel", "Trigger granular keyboard. Use with reply to user"),
|
||||||
scope = BotCommandScope.AllGroupChats
|
scope = BotCommandScope.AllGroupChats
|
||||||
)
|
)
|
||||||
|
|
||||||
|
allUpdatesFlow.subscribeSafelyWithoutExceptions(this) {
|
||||||
|
println(it)
|
||||||
|
}
|
||||||
}.join()
|
}.join()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,14 +7,11 @@ import dev.inmo.tgbotapi.extensions.behaviour_builder.buildBehaviourWithLongPoll
|
|||||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling.onChatShared
|
import dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling.onChatShared
|
||||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling.onCommand
|
import dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling.onCommand
|
||||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling.onUserShared
|
import dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling.onUserShared
|
||||||
import dev.inmo.tgbotapi.extensions.utils.types.buttons.replyKeyboard
|
import dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling.onUsersShared
|
||||||
import dev.inmo.tgbotapi.extensions.utils.types.buttons.requestBotButton
|
import dev.inmo.tgbotapi.extensions.utils.types.buttons.*
|
||||||
import dev.inmo.tgbotapi.extensions.utils.types.buttons.requestChatButton
|
|
||||||
import dev.inmo.tgbotapi.extensions.utils.types.buttons.requestGroupButton
|
|
||||||
import dev.inmo.tgbotapi.extensions.utils.types.buttons.requestUserButton
|
|
||||||
import dev.inmo.tgbotapi.extensions.utils.types.buttons.requestUserOrBotButton
|
|
||||||
import dev.inmo.tgbotapi.types.BotCommand
|
import dev.inmo.tgbotapi.types.BotCommand
|
||||||
import dev.inmo.tgbotapi.types.chat.PrivateChat
|
import dev.inmo.tgbotapi.types.chat.PrivateChat
|
||||||
|
import dev.inmo.tgbotapi.types.keyboardButtonRequestUserLimit
|
||||||
import dev.inmo.tgbotapi.types.message.textsources.mention
|
import dev.inmo.tgbotapi.types.message.textsources.mention
|
||||||
import dev.inmo.tgbotapi.types.request.RequestId
|
import dev.inmo.tgbotapi.types.request.RequestId
|
||||||
import dev.inmo.tgbotapi.utils.row
|
import dev.inmo.tgbotapi.utils.row
|
||||||
@@ -30,52 +27,90 @@ suspend fun main(args: Array<String>) {
|
|||||||
val requestIdUserPremium = RequestId(3)
|
val requestIdUserPremium = RequestId(3)
|
||||||
val requestIdBot = RequestId(4)
|
val requestIdBot = RequestId(4)
|
||||||
|
|
||||||
val requestIdAnyChat = RequestId(5)
|
val requestIdUsersOrBots = RequestId(5)
|
||||||
val requestIdChannel = RequestId(6)
|
val requestIdUsersNonPremium = RequestId(6)
|
||||||
val requestIdPublicChannel = RequestId(7)
|
val requestIdUsersAny = RequestId(7)
|
||||||
val requestIdPrivateChannel = RequestId(8)
|
val requestIdUsersPremium = RequestId(8)
|
||||||
val requestIdChannelUserOwner = RequestId(9)
|
val requestIdBots = RequestId(9)
|
||||||
|
|
||||||
val requestIdGroup = RequestId(10)
|
val requestIdAnyChat = RequestId(10)
|
||||||
val requestIdPublicGroup = RequestId(11)
|
val requestIdChannel = RequestId(11)
|
||||||
val requestIdPrivateGroup = RequestId(12)
|
val requestIdPublicChannel = RequestId(12)
|
||||||
val requestIdGroupUserOwner = RequestId(13)
|
val requestIdPrivateChannel = RequestId(13)
|
||||||
|
val requestIdChannelUserOwner = RequestId(14)
|
||||||
|
|
||||||
val requestIdForum = RequestId(14)
|
val requestIdGroup = RequestId(15)
|
||||||
val requestIdPublicForum = RequestId(15)
|
val requestIdPublicGroup = RequestId(16)
|
||||||
val requestIdPrivateForum = RequestId(16)
|
val requestIdPrivateGroup = RequestId(17)
|
||||||
val requestIdForumUserOwner = RequestId(17)
|
val requestIdGroupUserOwner = RequestId(18)
|
||||||
|
|
||||||
|
val requestIdForum = RequestId(19)
|
||||||
|
val requestIdPublicForum = RequestId(20)
|
||||||
|
val requestIdPrivateForum = RequestId(21)
|
||||||
|
val requestIdForumUserOwner = RequestId(22)
|
||||||
|
|
||||||
val keyboard = replyKeyboard(
|
val keyboard = replyKeyboard(
|
||||||
resizeKeyboard = true,
|
resizeKeyboard = true,
|
||||||
) {
|
) {
|
||||||
row {
|
row {
|
||||||
requestUserOrBotButton(
|
requestUserOrBotButton(
|
||||||
"\uD83D\uDC64/\uD83E\uDD16",
|
"\uD83D\uDC64/\uD83E\uDD16 (1)",
|
||||||
requestIdUserOrBot
|
requestIdUserOrBot
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
row {
|
row {
|
||||||
requestUserButton(
|
requestUserButton(
|
||||||
"\uD83D\uDC64☆",
|
"\uD83D\uDC64☆ (1)",
|
||||||
requestIdUserNonPremium,
|
requestIdUserNonPremium,
|
||||||
premiumUser = false
|
premiumUser = false
|
||||||
)
|
)
|
||||||
requestUserButton(
|
requestUserButton(
|
||||||
"\uD83D\uDC64",
|
"\uD83D\uDC64 (1)",
|
||||||
requestIdUserAny,
|
requestIdUserAny,
|
||||||
premiumUser = null
|
premiumUser = null
|
||||||
)
|
)
|
||||||
requestUserButton(
|
requestUserButton(
|
||||||
"\uD83D\uDC64★",
|
"\uD83D\uDC64★ (1)",
|
||||||
requestIdUserPremium,
|
requestIdUserPremium,
|
||||||
premiumUser = true
|
premiumUser = true
|
||||||
)
|
)
|
||||||
requestBotButton(
|
requestBotButton(
|
||||||
"\uD83E\uDD16",
|
"\uD83E\uDD16 (1)",
|
||||||
requestIdBot
|
requestIdBot
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
row {
|
||||||
|
requestUsersOrBotsButton(
|
||||||
|
"\uD83D\uDC64/\uD83E\uDD16",
|
||||||
|
requestIdUsersOrBots,
|
||||||
|
maxCount = keyboardButtonRequestUserLimit.last
|
||||||
|
)
|
||||||
|
}
|
||||||
|
row {
|
||||||
|
requestUsersButton(
|
||||||
|
"\uD83D\uDC64☆",
|
||||||
|
requestIdUsersNonPremium,
|
||||||
|
premiumUser = false,
|
||||||
|
maxCount = keyboardButtonRequestUserLimit.last
|
||||||
|
)
|
||||||
|
requestUsersButton(
|
||||||
|
"\uD83D\uDC64",
|
||||||
|
requestIdUsersAny,
|
||||||
|
premiumUser = null,
|
||||||
|
maxCount = keyboardButtonRequestUserLimit.last
|
||||||
|
)
|
||||||
|
requestUsersButton(
|
||||||
|
"\uD83D\uDC64★",
|
||||||
|
requestIdUsersPremium,
|
||||||
|
premiumUser = true,
|
||||||
|
maxCount = keyboardButtonRequestUserLimit.last
|
||||||
|
)
|
||||||
|
requestBotsButton(
|
||||||
|
"\uD83E\uDD16",
|
||||||
|
requestIdBots,
|
||||||
|
maxCount = keyboardButtonRequestUserLimit.last
|
||||||
|
)
|
||||||
|
}
|
||||||
row {
|
row {
|
||||||
requestChatButton(
|
requestChatButton(
|
||||||
"\uD83D\uDDE3/\uD83D\uDC65",
|
"\uD83D\uDDE3/\uD83D\uDC65",
|
||||||
@@ -164,25 +199,26 @@ suspend fun main(args: Array<String>) {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
onUserShared {
|
onUsersShared {
|
||||||
val userId = it.chatEvent.userId
|
it.chatEvent.userIds.forEach { userId ->
|
||||||
val userInfo = runCatchingSafely { getChat(userId) }.getOrNull()
|
val userInfo = runCatchingSafely { getChat(userId) }.getOrNull()
|
||||||
reply(
|
reply(
|
||||||
it,
|
it,
|
||||||
) {
|
) {
|
||||||
+"You have shared "
|
+"You have shared "
|
||||||
+mention(
|
+mention(
|
||||||
when (it.chatEvent.requestId) {
|
when (it.chatEvent.requestId) {
|
||||||
requestIdUserOrBot -> "user or bot"
|
requestIdUserOrBot -> "user or bot"
|
||||||
requestIdUserNonPremium -> "non premium user"
|
requestIdUserNonPremium -> "non premium user"
|
||||||
requestIdUserAny -> "any user"
|
requestIdUserAny -> "any user"
|
||||||
requestIdUserPremium -> "premium user"
|
requestIdUserPremium -> "premium user"
|
||||||
requestIdBot -> "bot"
|
requestIdBot -> "bot"
|
||||||
else -> "somebody O.o"
|
else -> "somebody O.o"
|
||||||
},
|
},
|
||||||
userId
|
userId
|
||||||
)
|
)
|
||||||
+" (user info: $userInfo; user id: $userId)"
|
+" (user info: $userInfo; user id: $userId)"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -71,7 +71,7 @@ fun main() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
appendText("Exit button")
|
appendText("Answer in chat button")
|
||||||
} ?: window.alert("Unable to load body")
|
} ?: window.alert("Unable to load body")
|
||||||
|
|
||||||
document.body ?.appendElement("p", {})
|
document.body ?.appendElement("p", {})
|
||||||
|
|||||||
@@ -1,3 +1,7 @@
|
|||||||
|
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.micro_utils.coroutines.subscribeSafelyWithoutExceptions
|
||||||
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
|
||||||
@@ -14,6 +18,7 @@ import dev.inmo.tgbotapi.requests.answers.InlineQueryResultsButton
|
|||||||
import dev.inmo.tgbotapi.types.BotCommand
|
import dev.inmo.tgbotapi.types.BotCommand
|
||||||
import dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.InlineQueryResultArticle
|
import dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.InlineQueryResultArticle
|
||||||
import dev.inmo.tgbotapi.types.InlineQueries.InputMessageContent.InputTextMessageContent
|
import dev.inmo.tgbotapi.types.InlineQueries.InputMessageContent.InputTextMessageContent
|
||||||
|
import dev.inmo.tgbotapi.types.LinkPreviewOptions
|
||||||
import dev.inmo.tgbotapi.types.webAppQueryIdField
|
import dev.inmo.tgbotapi.types.webAppQueryIdField
|
||||||
import dev.inmo.tgbotapi.types.webapps.WebAppInfo
|
import dev.inmo.tgbotapi.types.webapps.WebAppInfo
|
||||||
import dev.inmo.tgbotapi.utils.*
|
import dev.inmo.tgbotapi.utils.*
|
||||||
@@ -43,6 +48,16 @@ suspend fun main(vararg args: String) {
|
|||||||
args.first(),
|
args.first(),
|
||||||
testServer = args.any { it == "testServer" }
|
testServer = args.any { it == "testServer" }
|
||||||
)
|
)
|
||||||
|
val isDebug = args.any { it == "debug" }
|
||||||
|
|
||||||
|
if (isDebug) {
|
||||||
|
setDefaultKSLog(
|
||||||
|
KSLog { level: LogLevel, tag: String?, message: Any, throwable: Throwable? ->
|
||||||
|
println(defaultMessageFormatter(level, tag, message, throwable))
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
val bot = telegramBot(telegramBotAPIUrlsKeeper)
|
val bot = telegramBot(telegramBotAPIUrlsKeeper)
|
||||||
createKtorServer(
|
createKtorServer(
|
||||||
"0.0.0.0",
|
"0.0.0.0",
|
||||||
@@ -52,8 +67,13 @@ suspend fun main(vararg args: String) {
|
|||||||
}
|
}
|
||||||
) {
|
) {
|
||||||
routing {
|
routing {
|
||||||
staticFiles("", File("WebApp/build/distributions")) {
|
val baseJsFolder = File("WebApp/build/dist/js/")
|
||||||
default("WebApp/build/distributions/index.html")
|
baseJsFolder.list() ?.forEach {
|
||||||
|
if (it == "productionExecutable" || it == "developmentExecutable") {
|
||||||
|
staticFiles("", File(baseJsFolder, it)) {
|
||||||
|
default("WebApp/build/dist/js/$it/index.html")
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
post("inline") {
|
post("inline") {
|
||||||
val requestBody = call.receiveText()
|
val requestBody = call.receiveText()
|
||||||
@@ -97,8 +117,11 @@ suspend fun main(vararg args: String) {
|
|||||||
row {
|
row {
|
||||||
webAppButton("Open WebApp", WebAppInfo(args[1]))
|
webAppButton("Open WebApp", WebAppInfo(args[1]))
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
|
linkPreviewOptions = LinkPreviewOptions.Small(
|
||||||
|
args[1],
|
||||||
|
showAboveText = false
|
||||||
|
)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
onCommand("attachment_menu") {
|
onCommand("attachment_menu") {
|
||||||
@@ -109,8 +132,11 @@ suspend fun main(vararg args: String) {
|
|||||||
row {
|
row {
|
||||||
webAppButton("Open WebApp", WebAppInfo(args[1]))
|
webAppButton("Open WebApp", WebAppInfo(args[1]))
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
|
linkPreviewOptions = LinkPreviewOptions.Large(
|
||||||
|
args[1],
|
||||||
|
showAboveText = true
|
||||||
|
)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
onBaseInlineQuery {
|
onBaseInlineQuery {
|
||||||
|
|||||||
@@ -10,6 +10,9 @@ buildscript {
|
|||||||
}
|
}
|
||||||
|
|
||||||
allprojects {
|
allprojects {
|
||||||
|
ext {
|
||||||
|
nativePartTemplate = "${rootProject.projectDir.absolutePath}/native_template.gradle"
|
||||||
|
}
|
||||||
repositories {
|
repositories {
|
||||||
mavenLocal()
|
mavenLocal()
|
||||||
mavenCentral()
|
mavenCentral()
|
||||||
@@ -23,6 +26,6 @@ allprojects {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
maven { url "https://git.inmo.dev/api/packages/InsanusMokrassar/maven" }
|
maven { url "https://nexus.inmo.dev/repository/maven-releases/" }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,11 +1,11 @@
|
|||||||
kotlin.code.style=official
|
kotlin.code.style=official
|
||||||
org.gradle.parallel=true
|
org.gradle.parallel=true
|
||||||
# Due to parallel compilation project require next amount of memory on full build
|
# Due to parallel compilation project require next amount of memory on full build
|
||||||
org.gradle.jvmargs=-Xmx2g
|
org.gradle.jvmargs=-Xmx2344m
|
||||||
|
|
||||||
|
|
||||||
kotlin_version=1.8.22
|
kotlin_version=1.9.22
|
||||||
telegram_bot_api_version=9.2.0
|
telegram_bot_api_version=12.0.0-branch_12.0.0-build2174
|
||||||
micro_utils_version=0.19.9
|
micro_utils_version=0.20.37
|
||||||
serialization_version=1.5.1
|
serialization_version=1.6.3
|
||||||
ktor_version=2.3.3
|
ktor_version=2.3.8
|
||||||
|
|||||||
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.6.2-bin.zip
|
distributionUrl=https\://services.gradle.org/distributions/gradle-8.6-bin.zip
|
||||||
|
|||||||
20
native_template.gradle
Normal file
20
native_template.gradle
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
kotlin {
|
||||||
|
def hostOs = System.getProperty("os.name")
|
||||||
|
def isMingwX64 = hostOs.startsWith("Windows")
|
||||||
|
def isArch64 = System.getProperty("os.arch") == "aarch64"
|
||||||
|
|
||||||
|
def nativeTarget
|
||||||
|
if (hostOs == "Linux") {
|
||||||
|
if (isArch64) {
|
||||||
|
nativeTarget = linuxArm64("native") { binaries { executable() } }
|
||||||
|
} else {
|
||||||
|
nativeTarget = linuxX64("native") { binaries { executable() } }
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (isMingwX64) {
|
||||||
|
nativeTarget = mingwX64("native") { binaries { executable() } }
|
||||||
|
} else {
|
||||||
|
throw new GradleException("Host OS is not supported in Kotlin/Native.")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -41,3 +41,9 @@ include ":LiveLocationsBot"
|
|||||||
include ":StickerSetHandler"
|
include ":StickerSetHandler"
|
||||||
|
|
||||||
include ":InlineQueriesBot"
|
include ":InlineQueriesBot"
|
||||||
|
|
||||||
|
include ":ReactionsInfoBot"
|
||||||
|
|
||||||
|
include ":LinkPreviewsBot"
|
||||||
|
|
||||||
|
include ":BoostsInfoBot"
|
||||||
|
|||||||
Reference in New Issue
Block a user