mirror of
https://github.com/InsanusMokrassar/TelegramBotAPI-examples.git
synced 2025-12-16 19:25:36 +00:00
Compare commits
343 Commits
0.35.1
...
c638543711
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c638543711 | ||
| 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 | |||
| 02c3d3da1a | |||
| 0ad8e61c0c | |||
| 8f80b7e066 | |||
| 48d1077ce4 | |||
| 6922a6d667 | |||
| 676ce0df80 | |||
| d97c2a0562 | |||
| 35e0cb4a46 | |||
| 30f5513f54 | |||
| fff8edde5f | |||
| e28a795796 | |||
| d289c2101d | |||
| 2ce47074d8 | |||
| 281f0840eb | |||
| 34ed962104 | |||
| aa3337bf3a | |||
| 31d29712be | |||
| 88b348376f | |||
| 0d9e295baa | |||
| ea08bac6e8 | |||
| a85fdc227e | |||
| 43482ee94e | |||
| 4addb6c755 | |||
| 7d958b6edb | |||
| 323c21f415 | |||
| 6350581739 | |||
| ea1d40fd05 | |||
| 8cee63a0fb | |||
| d42ef2c6cb | |||
| c7fe90ddd7 | |||
| acb382d3f7 | |||
| 0cfe60fd77 | |||
| 6719b9e17c | |||
| 8d33dc0ab2 | |||
| 3e2ccf9cf1 | |||
| eccbe71e68 | |||
| 24c74f3b1a | |||
| d7a7e7153e | |||
| 0b37acb7a9 | |||
| 3925ef9423 | |||
| c6019b1862 | |||
| 7b996fe1de | |||
| 4e3c186952 | |||
| 8fdf715419 | |||
| fca8704cec | |||
| bf499ee780 | |||
| 9b10749411 | |||
| d3cb8a32ef | |||
| 0f0ad5a1af | |||
| c3bc55a15c | |||
| 253328f49a | |||
| 8ef50537ae | |||
| 7e7bbfaa93 | |||
| f152ede9b5 | |||
| fcedbf30da | |||
|
|
fd030a92e3 | ||
| d54abf0b32 | |||
|
|
877a20188f | ||
| d0151ff048 | |||
| f8f517cfbb | |||
|
|
b3cbbac917 | ||
| 3e85bb4b22 | |||
| 4e0fb1c137 | |||
| d8c90ef377 | |||
| cb84fd0884 | |||
| 4379862c78 | |||
|
|
ac1d812db0 | ||
| f52590868c | |||
| 51c300c734 | |||
| f6082cff30 | |||
| a40c16fe05 | |||
| a7fe62f4af | |||
| b9c745a21e | |||
| 1c2b068a94 | |||
| 51c2cb1b0e | |||
| cfd4e2fcd5 | |||
|
|
76ceeac757 | ||
| 340de11b0a | |||
| 68a59ca5c8 | |||
|
|
cdb8581318 | ||
|
|
8b3a2ac1ed | ||
| a5b925fc59 | |||
| 9ec9f7a68c | |||
| 0f2829945f | |||
| 4eb80ea53c | |||
| 17cff21847 | |||
| 431069d190 | |||
|
|
fdbac78603 | ||
| da73acd379 | |||
|
|
6e3880f152 | ||
| 1ede6e58e6 | |||
| 0e46f176fb | |||
|
|
2bd449b8b8 | ||
| 82f9da0529 | |||
| 78b7d468f2 | |||
|
|
08059f8174 | ||
|
|
16766046d7 | ||
| 91ea20a269 | |||
| 11e280d177 | |||
| a8d4a307ef | |||
| 2bd2328a38 | |||
| 139de35db9 | |||
|
|
5dd22e1da2 | ||
| 4186ab8270 | |||
| 5aa69d7990 | |||
|
|
df952c69b2 | ||
| 9a03a02bac | |||
| 0e7c050e9e | |||
|
|
bdec902b58 | ||
|
|
cc3c87590d | ||
| 910f892b89 | |||
| 8232cb4d62 | |||
| 3b26971152 | |||
| c0019bcbf8 | |||
| c3dcb4d738 | |||
| 6a9921d4bd | |||
| 33b14f320c | |||
| 50ad281132 | |||
| 6abfc3d369 | |||
| f73620afec | |||
| a3d5112c83 | |||
|
|
23abae07b7 | ||
| c5a9f657cf | |||
|
|
51f7715915 | ||
|
|
bdfb900ce3 | ||
| 27790a2576 | |||
| e722055871 | |||
| 29e1552618 | |||
| 7ef942a2b4 | |||
| fdd4dfdbcf | |||
|
|
ba88205249 | ||
| 9a38fe51f9 | |||
|
|
c172bd1fa7 | ||
| 7392e85f1b | |||
|
|
f2c7fd79d9 | ||
| 9d77b61ea3 | |||
|
|
d567b1382b | ||
| 557d4ad3ca | |||
|
|
f070fb804b | ||
| 53de520c3a | |||
| f164ba901d | |||
|
|
2a04b4979d | ||
| 4a0279c89e | |||
|
|
fcef9f1f64 | ||
|
|
33e191816a | ||
| e0b707ceba | |||
| 115c76a9d4 | |||
| 0ebfb3c44a | |||
| 9fa3690db6 | |||
| a8c5d403c6 | |||
| 0c5186a37d | |||
| 7e9968ced9 | |||
| f1e8ed88a8 | |||
| 068dc79ac8 | |||
| 36273adfd1 | |||
| bca2ae905b | |||
| 19a713a3e3 | |||
| e039f90961 | |||
| 21692d16ca | |||
| d547dce2ab | |||
| 9bfe88a79c | |||
|
|
bfa327acf3 | ||
| 88a031b05a | |||
| 20e942b2ac | |||
|
|
3e20cbd22c | ||
| bcd35de038 | |||
|
|
2aec45d453 | ||
| ee55378e7a | |||
| b402c7b6e7 | |||
|
|
32b7c7b9a4 | ||
| 0b2d6b20de | |||
|
|
182ee7a865 | ||
| 0652a95d11 | |||
|
|
f6066c60c0 | ||
| 2fa340292c | |||
| 7d94007905 | |||
|
|
9638174d48 | ||
|
|
18bacaea2e | ||
| 0f2b3760dd | |||
| 730923f55c | |||
| 9cf8bd9f28 | |||
| 370fa45dba | |||
|
|
72e7a73e40 | ||
| 10dd9bd851 | |||
| 0217f97014 | |||
| 4ae700b58a | |||
|
|
804fb1e5ee | ||
| d443c39813 | |||
|
|
cd96547d15 | ||
| f107b4144d | |||
| 39f4196b76 | |||
|
|
22b9776c26 | ||
| 2f8f6f3169 | |||
| f2b6a50cb5 | |||
| acd602d6fa | |||
| fdb80bf471 | |||
|
|
78c58db4b7 | ||
| edd6399bcc | |||
|
|
9513e77ba3 | ||
|
|
ac75f6487e | ||
| 07750a71c0 | |||
| 0bf7e33df3 | |||
| 7fb308ea4b | |||
|
|
75b403ac98 | ||
| 5976e37046 | |||
|
|
c8a94496c7 | ||
| f6550bd401 | |||
| 389d96f323 | |||
| 803c5fd664 | |||
| b6eb4fe134 | |||
| 9a4bd55ef6 | |||
| 4dac411693 | |||
| d386d50f1c | |||
|
|
1b846a6383 | ||
| 568b845890 | |||
|
|
3ebca4a058 | ||
| 2b9af2f667 | |||
| 16410debff | |||
| a18f22fe8f | |||
| 0489f217b3 | |||
| e772cfda3b | |||
| 9d42385662 | |||
| b740203116 | |||
| 149717301d | |||
| 60e72be844 | |||
| 831b558724 | |||
| df778b4e93 | |||
| bf0c6497fe | |||
|
|
71a047f867 | ||
| 2ae3e1165d | |||
| 9a5d02512b | |||
| dd2c528006 | |||
| 1c16a9f868 | |||
| 00c3aba12b | |||
| a547bbce65 | |||
| 0b7d8c087f | |||
| 8ec282e3d5 | |||
|
|
e8433cd8ac | ||
| 222134836a | |||
| c18e02dcb3 | |||
| f9050061d1 | |||
| a3e3f6c22c | |||
| 516cc7bfcb | |||
| c707a11b66 | |||
| c6c418c393 | |||
| e0795c3c14 | |||
| dec55990dc | |||
|
|
169f3f5bd5 | ||
| e175bb6143 | |||
| 290d722ae6 | |||
| 9ee85df1ad | |||
|
|
2953c40963 | ||
| 512067b056 | |||
|
|
0cb209dc6e | ||
| 7cf6814d89 | |||
| 09e8492439 | |||
|
|
71222f42e5 | ||
| 426d649877 | |||
|
|
93faf9654a | ||
| 288386e25a | |||
| 99e83589a4 | |||
|
|
fbea95fc0a | ||
| 0edaa28151 | |||
| df874b0783 | |||
| 5f5722398d | |||
| cc29ec75ca | |||
|
|
a42173acf6 | ||
| d936bc4643 | |||
| 1b340d8db5 | |||
|
|
4cd1980778 | ||
| d89202aebb | |||
| be2de6e372 | |||
|
|
08796f18e8 | ||
| 8bd7e116e3 | |||
|
|
39d7a95c95 | ||
| 526ecac89a | |||
|
|
1e4e246fab | ||
| 6aa7fe151e | |||
| 16c27fa493 | |||
|
|
f6a811acca | ||
| 17c08fc906 | |||
| aee0943a5e | |||
| c07f4f2ed1 | |||
| 817acb8faf | |||
| 8b294a0cc0 | |||
|
|
0139cc5dcc | ||
| 6d16508277 | |||
| ce2051d32d | |||
| 1abbcc8789 | |||
| c5e05dfce1 | |||
| c1d7129af8 | |||
| 496fc45d2d | |||
| cdb634e91a | |||
| 9d17311918 | |||
| 12ef88c757 |
7
.github/workflows/build.yml
vendored
7
.github/workflows/build.yml
vendored
@@ -8,9 +8,12 @@ jobs:
|
|||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v2
|
||||||
- name: Set up JDK 1.8
|
- name: Install dependencies
|
||||||
|
run: |
|
||||||
|
sudo apt install -y libcurl4-openssl-dev
|
||||||
|
- name: Set up JDK 17
|
||||||
uses: actions/setup-java@v1
|
uses: actions/setup-java@v1
|
||||||
with:
|
with:
|
||||||
java-version: 1.8
|
java-version: 17
|
||||||
- name: Build with Gradle
|
- name: Build with Gradle
|
||||||
run: ./gradlew build
|
run: ./gradlew build
|
||||||
|
|||||||
5
.gitignore
vendored
5
.gitignore
vendored
@@ -8,3 +8,8 @@ settings.xml
|
|||||||
.gradle/
|
.gradle/
|
||||||
build/
|
build/
|
||||||
out/
|
out/
|
||||||
|
|
||||||
|
kotlin-js-store/
|
||||||
|
|
||||||
|
local.*
|
||||||
|
local.*/
|
||||||
|
|||||||
11
.travis.yml
11
.travis.yml
@@ -1,11 +0,0 @@
|
|||||||
language: java
|
|
||||||
install: true
|
|
||||||
|
|
||||||
os: linux
|
|
||||||
dist: trusty
|
|
||||||
jdk: oraclejdk8
|
|
||||||
|
|
||||||
script:
|
|
||||||
- ./gradlew build -s
|
|
||||||
|
|
||||||
|
|
||||||
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()
|
||||||
|
}
|
||||||
9
ChatAvatarSetter/README.md
Normal file
9
ChatAvatarSetter/README.md
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
# ChatAvatarSetter
|
||||||
|
|
||||||
|
This bot will set the chat avatar based on the image sent to bot
|
||||||
|
|
||||||
|
## Launch
|
||||||
|
|
||||||
|
```bash
|
||||||
|
../gradlew run --args="BOT_TOKEN"
|
||||||
|
```
|
||||||
21
ChatAvatarSetter/build.gradle
Normal file
21
ChatAvatarSetter/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="ChatAvatarSetterKt"
|
||||||
|
|
||||||
|
|
||||||
|
dependencies {
|
||||||
|
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
|
||||||
|
|
||||||
|
implementation "dev.inmo:tgbotapi:$telegram_bot_api_version"
|
||||||
|
}
|
||||||
36
ChatAvatarSetter/src/main/kotlin/ChatAvatarSetter.kt
Normal file
36
ChatAvatarSetter/src/main/kotlin/ChatAvatarSetter.kt
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
import dev.inmo.micro_utils.coroutines.runCatchingSafely
|
||||||
|
import dev.inmo.tgbotapi.bot.ktor.telegramBot
|
||||||
|
import dev.inmo.tgbotapi.extensions.api.chat.modify.setChatPhoto
|
||||||
|
import dev.inmo.tgbotapi.extensions.api.files.downloadFile
|
||||||
|
import dev.inmo.tgbotapi.extensions.api.send.reply
|
||||||
|
import dev.inmo.tgbotapi.extensions.behaviour_builder.buildBehaviourWithLongPolling
|
||||||
|
import dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling.onPhoto
|
||||||
|
import dev.inmo.tgbotapi.extensions.utils.*
|
||||||
|
import dev.inmo.tgbotapi.requests.abstracts.asMultipartFile
|
||||||
|
import kotlinx.coroutines.*
|
||||||
|
|
||||||
|
suspend fun main(args: Array<String>) {
|
||||||
|
val bot = telegramBot(args.first())
|
||||||
|
|
||||||
|
bot.buildBehaviourWithLongPolling(scope = CoroutineScope(Dispatchers.IO)) {
|
||||||
|
onPhoto {
|
||||||
|
val bytes = downloadFile(it.content)
|
||||||
|
runCatchingSafely {
|
||||||
|
setChatPhoto(
|
||||||
|
it.chat.id,
|
||||||
|
bytes.asMultipartFile("sample.jpg")
|
||||||
|
)
|
||||||
|
}.onSuccess { b ->
|
||||||
|
if (b) {
|
||||||
|
reply(it, "Done")
|
||||||
|
} else {
|
||||||
|
reply(it, "Something went wrong")
|
||||||
|
}
|
||||||
|
}.onFailure { e ->
|
||||||
|
e.printStackTrace()
|
||||||
|
|
||||||
|
reply(it, "Something went wrong (see logs)")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}.join()
|
||||||
|
}
|
||||||
9
DeepLinksBot/README.md
Normal file
9
DeepLinksBot/README.md
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
# DeepLinksBot
|
||||||
|
|
||||||
|
This bot will send you deeplink to this bot when you send some text message and react on the `start` button
|
||||||
|
|
||||||
|
## Launch
|
||||||
|
|
||||||
|
```bash
|
||||||
|
../gradlew run --args="BOT_TOKEN"
|
||||||
|
```
|
||||||
21
DeepLinksBot/build.gradle
Normal file
21
DeepLinksBot/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="DeepLinksBotKt"
|
||||||
|
|
||||||
|
|
||||||
|
dependencies {
|
||||||
|
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
|
||||||
|
|
||||||
|
implementation "dev.inmo:tgbotapi:$telegram_bot_api_version"
|
||||||
|
}
|
||||||
44
DeepLinksBot/src/main/kotlin/DeepLinksBot.kt
Normal file
44
DeepLinksBot/src/main/kotlin/DeepLinksBot.kt
Normal file
@@ -0,0 +1,44 @@
|
|||||||
|
import dev.inmo.micro_utils.coroutines.subscribeSafelySkippingExceptions
|
||||||
|
import dev.inmo.micro_utils.coroutines.subscribeSafelyWithoutExceptions
|
||||||
|
import dev.inmo.tgbotapi.bot.ktor.telegramBot
|
||||||
|
import dev.inmo.tgbotapi.extensions.api.bot.getMe
|
||||||
|
import dev.inmo.tgbotapi.extensions.api.send.reply
|
||||||
|
import dev.inmo.tgbotapi.extensions.behaviour_builder.expectations.waitDeepLinks
|
||||||
|
import dev.inmo.tgbotapi.extensions.behaviour_builder.telegramBotWithBehaviourAndLongPolling
|
||||||
|
import dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling.*
|
||||||
|
import dev.inmo.tgbotapi.extensions.utils.formatting.makeTelegramDeepLink
|
||||||
|
import dev.inmo.tgbotapi.types.message.textsources.BotCommandTextSource
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This bot will send you deeplink to this bot when you send some text message and react on the `start` button
|
||||||
|
*/
|
||||||
|
suspend fun main(vararg args: String) {
|
||||||
|
val botToken = args.first()
|
||||||
|
|
||||||
|
telegramBotWithBehaviourAndLongPolling(botToken) {
|
||||||
|
val me = bot.getMe()
|
||||||
|
val username = me.username
|
||||||
|
println(me)
|
||||||
|
|
||||||
|
if (username == null) {
|
||||||
|
error("Unable to start bot work: it have no username")
|
||||||
|
}
|
||||||
|
|
||||||
|
onText(
|
||||||
|
initialFilter = { it.content.textSources.none { it is BotCommandTextSource } } // excluding messages with commands
|
||||||
|
) {
|
||||||
|
reply(it, makeTelegramDeepLink(username, it.content.text))
|
||||||
|
}
|
||||||
|
|
||||||
|
onCommand("start", requireOnlyCommandInMessage = true) { // handling of `start` without args
|
||||||
|
reply(it, "Hi :) Send me any text and I will try hard to create deeplink for you")
|
||||||
|
}
|
||||||
|
onDeepLink { (it, deepLink) ->
|
||||||
|
reply(it, "Ok, I got deep link \"${deepLink}\" in trigger")
|
||||||
|
}
|
||||||
|
waitDeepLinks().subscribeSafelyWithoutExceptions(this) { (it, deepLink) ->
|
||||||
|
reply(it, "Ok, I got deep link \"${deepLink}\" in waiter")
|
||||||
|
println(triggersHolder.handleableCommandsHolder.handleable)
|
||||||
|
}
|
||||||
|
}.second.join()
|
||||||
|
}
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
buildscript {
|
buildscript {
|
||||||
repositories {
|
repositories {
|
||||||
jcenter()
|
mavenLocal()
|
||||||
|
mavenCentral()
|
||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
@@ -13,10 +14,13 @@ apply plugin: 'application'
|
|||||||
|
|
||||||
mainClassName="SimpleFSMBotKt"
|
mainClassName="SimpleFSMBotKt"
|
||||||
|
|
||||||
|
repositories {
|
||||||
|
mavenLocal()
|
||||||
|
mavenCentral()
|
||||||
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$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 "dev.inmo:micro_utils.fsm.common:$micro_utils_version"
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,90 +1,76 @@
|
|||||||
|
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.micro_utils.fsm.common.dsl.buildFSM
|
import dev.inmo.tgbotapi.extensions.api.send.send
|
||||||
import dev.inmo.micro_utils.fsm.common.dsl.strictlyOn
|
|
||||||
import dev.inmo.tgbotapi.extensions.api.send.media.sendMediaGroup
|
|
||||||
import dev.inmo.tgbotapi.extensions.api.send.reply
|
|
||||||
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.*
|
||||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling.command
|
import dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling.*
|
||||||
import dev.inmo.tgbotapi.extensions.utils.extensions.parseCommandsWithParams
|
import dev.inmo.tgbotapi.extensions.utils.extensions.parseCommandsWithParams
|
||||||
|
import dev.inmo.tgbotapi.extensions.utils.extensions.sameThread
|
||||||
import dev.inmo.tgbotapi.extensions.utils.formatting.*
|
import dev.inmo.tgbotapi.extensions.utils.formatting.*
|
||||||
import dev.inmo.tgbotapi.extensions.utils.shortcuts.chat
|
import dev.inmo.tgbotapi.types.IdChatIdentifier
|
||||||
import dev.inmo.tgbotapi.types.ChatId
|
import dev.inmo.tgbotapi.types.MessageThreadId
|
||||||
import dev.inmo.tgbotapi.types.message.abstracts.CommonMessage
|
import dev.inmo.tgbotapi.types.message.abstracts.CommonMessage
|
||||||
import dev.inmo.tgbotapi.types.message.content.TextContent
|
import dev.inmo.tgbotapi.types.message.content.TextContent
|
||||||
import dev.inmo.tgbotapi.types.message.content.abstracts.MediaGroupContent
|
import dev.inmo.tgbotapi.utils.botCommand
|
||||||
import dev.inmo.tgbotapi.types.message.content.abstracts.MessageContent
|
import dev.inmo.tgbotapi.utils.extensions.threadIdOrNull
|
||||||
import kotlinx.coroutines.CoroutineScope
|
import kotlinx.coroutines.*
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.flow.filter
|
||||||
|
import kotlinx.coroutines.flow.first
|
||||||
|
|
||||||
sealed interface State : State
|
sealed interface BotState : State
|
||||||
data class ExpectContentOrStopState(override val context: ChatId, val sourceMessage: CommonMessage<TextContent>) : State
|
data class ExpectContentOrStopState(override val context: IdChatIdentifier, val sourceMessage: CommonMessage<TextContent>) : BotState
|
||||||
data class StopState(override val context: ChatId) : State
|
data class StopState(override val context: IdChatIdentifier) : BotState
|
||||||
|
|
||||||
fun TextContent.containsStopCommand() = parseCommandsWithParams().keys.firstOrNull { it == "stop" } != null
|
|
||||||
|
|
||||||
suspend fun main(args: Array<String>) {
|
suspend fun main(args: Array<String>) {
|
||||||
val botToken = args.first()
|
val botToken = args.first()
|
||||||
|
|
||||||
telegramBotWithBehaviour(botToken, CoroutineScope(Dispatchers.IO)) {
|
telegramBotWithBehaviourAndFSMAndStartLongPolling<BotState>(
|
||||||
val fsm = buildFSM {
|
botToken,
|
||||||
strictlyOn<ExpectContentOrStopState> {
|
CoroutineScope(Dispatchers.IO),
|
||||||
sendMessage(
|
onStateHandlingErrorHandler = { state, e ->
|
||||||
it.context,
|
when (state) {
|
||||||
buildEntities {
|
is ExpectContentOrStopState -> {
|
||||||
+"Send me some content or "
|
println("Thrown error on ExpectContentOrStopState")
|
||||||
botCommand("stop")
|
}
|
||||||
+" if you want to stop sending"
|
is StopState -> {
|
||||||
}
|
println("Thrown error on StopState")
|
||||||
)
|
|
||||||
|
|
||||||
val content = oneOf(
|
|
||||||
parallel {
|
|
||||||
waitContentMessage(includeMediaGroups = false) { if (chat.id == it.context) content else null }.also(::println)
|
|
||||||
},
|
|
||||||
parallel {
|
|
||||||
waitMediaGroup { chat ?.id == it.context }.also(::println)
|
|
||||||
},
|
|
||||||
parallel {
|
|
||||||
waitText { if (content.containsStopCommand()) content else null }.also(::println)
|
|
||||||
}
|
|
||||||
).first()
|
|
||||||
|
|
||||||
when {
|
|
||||||
content is TextContent && content.containsStopCommand() -> StopState(it.context) // assume we got "stop" command
|
|
||||||
content is List<*> -> { // assume it is media group
|
|
||||||
val casted = (content as List<MediaGroupContent>)
|
|
||||||
|
|
||||||
reply(it.sourceMessage, "Ok, I got this media group and now will resend it to you")
|
|
||||||
sendMediaGroup(it.context, casted.map { it.toMediaGroupMemberInputMedia() })
|
|
||||||
|
|
||||||
it
|
|
||||||
}
|
|
||||||
content is MessageContent -> {
|
|
||||||
|
|
||||||
reply(it.sourceMessage, "Ok, I got this content and now will resend it to you")
|
|
||||||
execute(content.createResend(it.context))
|
|
||||||
|
|
||||||
it
|
|
||||||
}
|
|
||||||
else -> {
|
|
||||||
sendMessage(it.context, "Unknown internal error")
|
|
||||||
it
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
strictlyOn<StopState> {
|
e.printStackTrace()
|
||||||
sendMessage(it.context, "You have stopped sending of content")
|
state
|
||||||
|
}
|
||||||
|
) {
|
||||||
|
strictlyOn<ExpectContentOrStopState> {
|
||||||
|
send(
|
||||||
|
it.context,
|
||||||
|
) {
|
||||||
|
+"Send me some content or " + botCommand("stop") + " if you want to stop sending"
|
||||||
|
}
|
||||||
|
|
||||||
null
|
val contentMessage = waitAnyContentMessage().filter { message ->
|
||||||
|
message.sameThread(it.sourceMessage)
|
||||||
|
}.first()
|
||||||
|
val content = contentMessage.content
|
||||||
|
|
||||||
|
when {
|
||||||
|
content is TextContent && content.parseCommandsWithParams().keys.contains("stop") -> StopState(it.context)
|
||||||
|
else -> {
|
||||||
|
execute(content.createResend(it.context))
|
||||||
|
it
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
strictlyOn<StopState> {
|
||||||
|
send(it.context) { +"You have stopped sending of content" }
|
||||||
|
|
||||||
command("start") {
|
null
|
||||||
fsm.startChain(ExpectContentOrStopState(it.chat.id, it))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fsm.start(this)
|
command(
|
||||||
|
"start"
|
||||||
|
) {
|
||||||
|
startChain(ExpectContentOrStopState(it.chat.id, it))
|
||||||
|
}
|
||||||
}.second.join()
|
}.second.join()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
buildscript {
|
buildscript {
|
||||||
repositories {
|
repositories {
|
||||||
jcenter()
|
mavenCentral()
|
||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
@@ -14,7 +14,7 @@ apply plugin: 'application'
|
|||||||
mainClassName="FilesLoaderBotKt"
|
mainClassName="FilesLoaderBotKt"
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$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"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,9 +1,39 @@
|
|||||||
import dev.inmo.tgbotapi.extensions.api.downloadFile
|
import dev.inmo.micro_utils.coroutines.subscribeSafelyWithoutExceptions
|
||||||
|
import dev.inmo.tgbotapi.extensions.api.files.downloadFile
|
||||||
|
import dev.inmo.tgbotapi.extensions.api.files.downloadFileToTemp
|
||||||
import dev.inmo.tgbotapi.extensions.api.get.getFileAdditionalInfo
|
import dev.inmo.tgbotapi.extensions.api.get.getFileAdditionalInfo
|
||||||
import dev.inmo.tgbotapi.extensions.api.send.reply
|
import dev.inmo.tgbotapi.extensions.api.send.reply
|
||||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.telegramBotWithBehaviour
|
import dev.inmo.tgbotapi.extensions.api.send.replyWithAnimation
|
||||||
|
import dev.inmo.tgbotapi.extensions.api.send.replyWithAudio
|
||||||
|
import dev.inmo.tgbotapi.extensions.api.send.replyWithDocument
|
||||||
|
import dev.inmo.tgbotapi.extensions.api.send.replyWithMediaGroup
|
||||||
|
import dev.inmo.tgbotapi.extensions.api.send.replyWithPhoto
|
||||||
|
import dev.inmo.tgbotapi.extensions.api.send.replyWithSticker
|
||||||
|
import dev.inmo.tgbotapi.extensions.api.send.replyWithVideo
|
||||||
|
import dev.inmo.tgbotapi.extensions.api.send.replyWithVideoNote
|
||||||
|
import dev.inmo.tgbotapi.extensions.api.send.replyWithVoice
|
||||||
|
import dev.inmo.tgbotapi.extensions.api.send.withAction
|
||||||
|
import dev.inmo.tgbotapi.extensions.behaviour_builder.telegramBotWithBehaviourAndLongPolling
|
||||||
|
import dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling.onCommand
|
||||||
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.behaviour_builder.triggers_handling.onMedia
|
import dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling.onMedia
|
||||||
|
import dev.inmo.tgbotapi.requests.abstracts.asMultipartFile
|
||||||
|
import dev.inmo.tgbotapi.requests.send.SendAction
|
||||||
|
import dev.inmo.tgbotapi.types.actions.BotAction
|
||||||
|
import dev.inmo.tgbotapi.types.actions.TypingAction
|
||||||
|
import dev.inmo.tgbotapi.types.media.TelegramMediaAudio
|
||||||
|
import dev.inmo.tgbotapi.types.media.TelegramMediaDocument
|
||||||
|
import dev.inmo.tgbotapi.types.media.TelegramMediaPhoto
|
||||||
|
import dev.inmo.tgbotapi.types.media.TelegramMediaVideo
|
||||||
|
import dev.inmo.tgbotapi.types.message.content.AnimationContent
|
||||||
|
import dev.inmo.tgbotapi.types.message.content.AudioContent
|
||||||
|
import dev.inmo.tgbotapi.types.message.content.DocumentContent
|
||||||
|
import dev.inmo.tgbotapi.types.message.content.MediaGroupContent
|
||||||
|
import dev.inmo.tgbotapi.types.message.content.PhotoContent
|
||||||
|
import dev.inmo.tgbotapi.types.message.content.StickerContent
|
||||||
|
import dev.inmo.tgbotapi.types.message.content.VideoContent
|
||||||
|
import dev.inmo.tgbotapi.types.message.content.VideoNoteContent
|
||||||
|
import dev.inmo.tgbotapi.types.message.content.VoiceContent
|
||||||
import dev.inmo.tgbotapi.utils.filenameFromUrl
|
import dev.inmo.tgbotapi.utils.filenameFromUrl
|
||||||
import kotlinx.coroutines.CoroutineScope
|
import kotlinx.coroutines.CoroutineScope
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
@@ -14,18 +44,80 @@ 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("")
|
val directoryOrFile = args.getOrNull(1) ?.let { File(it) } ?: File("/tmp/")
|
||||||
directoryOrFile.mkdirs()
|
directoryOrFile.mkdirs()
|
||||||
|
|
||||||
telegramBotWithBehaviour(botToken, CoroutineScope(Dispatchers.IO)) {
|
telegramBotWithBehaviourAndLongPolling(botToken, CoroutineScope(Dispatchers.IO)) {
|
||||||
onMedia(includeMediaGroups = true) {
|
onCommand("start") {
|
||||||
val pathedFile = bot.getFileAdditionalInfo(it.content.media)
|
reply(it, "Send me any media (like photo or video) to download it")
|
||||||
val file = File(directoryOrFile, pathedFile.filePath.filenameFromUrl).apply {
|
|
||||||
createNewFile()
|
|
||||||
writeBytes(bot.downloadFile(pathedFile))
|
|
||||||
}
|
|
||||||
reply(it, "Saved to ${file.absolutePath}")
|
|
||||||
}
|
}
|
||||||
onContentMessage { println(it) }
|
onMedia(initialFilter = null) {
|
||||||
|
val content = it.content
|
||||||
|
val pathedFile = bot.getFileAdditionalInfo(content.media)
|
||||||
|
val outFile = File(directoryOrFile, pathedFile.filePath.filenameFromUrl)
|
||||||
|
runCatching {
|
||||||
|
bot.downloadFile(content.media, outFile)
|
||||||
|
}.onFailure {
|
||||||
|
it.printStackTrace()
|
||||||
|
}.onSuccess { _ ->
|
||||||
|
reply(it, "Saved to ${outFile.absolutePath}")
|
||||||
|
withAction(it.chat.id, TypingAction) {
|
||||||
|
when (content) {
|
||||||
|
is PhotoContent -> replyWithPhoto(
|
||||||
|
it,
|
||||||
|
outFile.asMultipartFile()
|
||||||
|
)
|
||||||
|
is AnimationContent -> replyWithAnimation(
|
||||||
|
it,
|
||||||
|
outFile.asMultipartFile()
|
||||||
|
)
|
||||||
|
is VideoContent -> replyWithVideo(
|
||||||
|
it,
|
||||||
|
outFile.asMultipartFile()
|
||||||
|
)
|
||||||
|
is StickerContent -> replyWithSticker(
|
||||||
|
it,
|
||||||
|
outFile.asMultipartFile()
|
||||||
|
)
|
||||||
|
is MediaGroupContent<*> -> replyWithMediaGroup(
|
||||||
|
it,
|
||||||
|
content.group.map {
|
||||||
|
when (val innerContent = it.content) {
|
||||||
|
is AudioContent -> TelegramMediaAudio(
|
||||||
|
downloadFileToTemp(innerContent.media).asMultipartFile()
|
||||||
|
)
|
||||||
|
is DocumentContent -> TelegramMediaDocument(
|
||||||
|
downloadFileToTemp(innerContent.media).asMultipartFile()
|
||||||
|
)
|
||||||
|
is PhotoContent -> TelegramMediaPhoto(
|
||||||
|
downloadFileToTemp(innerContent.media).asMultipartFile()
|
||||||
|
)
|
||||||
|
is VideoContent -> TelegramMediaVideo(
|
||||||
|
downloadFileToTemp(innerContent.media).asMultipartFile()
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
is AudioContent -> replyWithAudio(
|
||||||
|
it,
|
||||||
|
outFile.asMultipartFile()
|
||||||
|
)
|
||||||
|
is DocumentContent -> replyWithDocument(
|
||||||
|
it,
|
||||||
|
outFile.asMultipartFile()
|
||||||
|
)
|
||||||
|
is VoiceContent -> replyWithVoice(
|
||||||
|
it,
|
||||||
|
outFile.asMultipartFile()
|
||||||
|
)
|
||||||
|
is VideoNoteContent -> replyWithVideoNote(
|
||||||
|
it,
|
||||||
|
outFile.asMultipartFile()
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
allUpdatesFlow.subscribeSafelyWithoutExceptions(this) { println(it) }
|
||||||
}.second.join()
|
}.second.join()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
buildscript {
|
buildscript {
|
||||||
repositories {
|
repositories {
|
||||||
jcenter()
|
mavenCentral()
|
||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
@@ -15,7 +15,7 @@ mainClassName="ForwardInfoSenderBotKt"
|
|||||||
|
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$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"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,11 +1,15 @@
|
|||||||
import dev.inmo.micro_utils.coroutines.defaultSafelyExceptionHandler
|
|
||||||
import dev.inmo.tgbotapi.bot.Ktor.telegramBot
|
|
||||||
import dev.inmo.tgbotapi.extensions.api.send.reply
|
import dev.inmo.tgbotapi.extensions.api.send.reply
|
||||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.telegramBotWithBehaviour
|
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.*
|
import dev.inmo.tgbotapi.extensions.utils.formatting.makeLink
|
||||||
import dev.inmo.tgbotapi.types.ParseMode.MarkdownV2
|
import dev.inmo.tgbotapi.types.chat.CommonBot
|
||||||
|
import dev.inmo.tgbotapi.types.chat.CommonUser
|
||||||
|
import dev.inmo.tgbotapi.types.chat.ExtendedBot
|
||||||
import dev.inmo.tgbotapi.types.message.*
|
import dev.inmo.tgbotapi.types.message.*
|
||||||
|
import dev.inmo.tgbotapi.utils.buildEntities
|
||||||
|
import dev.inmo.tgbotapi.utils.code
|
||||||
|
import dev.inmo.tgbotapi.utils.link
|
||||||
|
import dev.inmo.tgbotapi.utils.regular
|
||||||
import kotlinx.coroutines.*
|
import kotlinx.coroutines.*
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -15,25 +19,42 @@ import kotlinx.coroutines.*
|
|||||||
suspend fun main(vararg args: String) {
|
suspend fun main(vararg args: String) {
|
||||||
val botToken = args.first()
|
val botToken = args.first()
|
||||||
|
|
||||||
telegramBotWithBehaviour(botToken, CoroutineScope(Dispatchers.IO)) {
|
telegramBotWithBehaviourAndLongPolling(botToken, CoroutineScope(Dispatchers.IO)) {
|
||||||
onContentMessage(includeMediaGroups = true) {
|
onContentMessage {
|
||||||
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 AnonymousForwardInfo -> {
|
is ForwardInfo.ByAnonymous -> {
|
||||||
regular("Anonymous user which signed as \"") + code(forwardInfo.senderName) + "\""
|
regular("Anonymous user which signed as \"") + code(forwardInfo.senderName) + "\""
|
||||||
}
|
}
|
||||||
is UserForwardInfo -> {
|
is ForwardInfo.ByUser -> {
|
||||||
val user = forwardInfo.from
|
val user = forwardInfo.from
|
||||||
regular("User ") + code(user.id.chatId.toString()) + " (${user.firstName} ${user.lastName}: ${user.username ?.username ?: "Without username"})"
|
when (user) {
|
||||||
|
is CommonUser -> {
|
||||||
|
if (user.isPremium) {
|
||||||
|
regular("Premium user ")
|
||||||
|
} else {
|
||||||
|
regular("User ")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
is CommonBot,
|
||||||
|
is ExtendedBot -> regular("Bot ")
|
||||||
|
} + code(user.id.chatId.toString()) + " (${user.firstName} ${user.lastName}: ${user.username?.username ?: "Without username"})"
|
||||||
}
|
}
|
||||||
is ForwardFromChannelInfo -> regular("Channel (") + code((forwardInfo.channelChat).title) + ")"
|
is ForwardInfo.PublicChat.FromChannel -> {
|
||||||
is ForwardFromSupergroupInfo -> regular("Supergroup (") + code((forwardInfo.group).title) + ")"
|
regular("Channel (") + (forwardInfo.channelChat.username ?.let {
|
||||||
|
link(
|
||||||
|
forwardInfo.channelChat.title,
|
||||||
|
makeLink(it)
|
||||||
|
)
|
||||||
|
} ?: code(forwardInfo.channelChat.title)) + ")"
|
||||||
|
}
|
||||||
|
is ForwardInfo.PublicChat.FromSupergroup -> regular("Supergroup (") + code(forwardInfo.group.title) + ")"
|
||||||
|
is ForwardInfo.PublicChat.SentByChannel -> regular("Sent by channel (") + code(forwardInfo.channelChat.title) + ")"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
reply(it, toAnswer)
|
reply(it, toAnswer)
|
||||||
coroutineContext.job.invokeOnCompletion { println("completance of onContentMessage") }
|
|
||||||
}
|
}
|
||||||
coroutineContext.job.invokeOnCompletion { println("Completed :)") }
|
|
||||||
}.second.join()
|
}.second.join()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
buildscript {
|
buildscript {
|
||||||
repositories {
|
repositories {
|
||||||
jcenter()
|
mavenCentral()
|
||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
@@ -11,11 +11,11 @@ buildscript {
|
|||||||
apply plugin: 'kotlin'
|
apply plugin: 'kotlin'
|
||||||
apply plugin: 'application'
|
apply plugin: 'application'
|
||||||
|
|
||||||
mainClassName="HelloBotKt"
|
mainClassName="GetMeBotKt"
|
||||||
|
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$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"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,13 +1,31 @@
|
|||||||
import dev.inmo.tgbotapi.bot.Ktor.telegramBot
|
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.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))
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
buildscript {
|
buildscript {
|
||||||
repositories {
|
repositories {
|
||||||
jcenter()
|
mavenCentral()
|
||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
@@ -15,7 +15,7 @@ mainClassName="HelloBotKt"
|
|||||||
|
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$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"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,46 +1,62 @@
|
|||||||
import dev.inmo.micro_utils.coroutines.safely
|
import dev.inmo.micro_utils.coroutines.subscribeSafelyWithoutExceptions
|
||||||
|
import dev.inmo.tgbotapi.extensions.api.bot.getMe
|
||||||
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.reply
|
import dev.inmo.tgbotapi.extensions.api.send.*
|
||||||
import dev.inmo.tgbotapi.extensions.api.send.sendTextMessage
|
import dev.inmo.tgbotapi.extensions.behaviour_builder.telegramBotWithBehaviourAndLongPolling
|
||||||
import dev.inmo.tgbotapi.bot.Ktor.telegramBot
|
|
||||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.telegramBotWithBehaviour
|
|
||||||
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.asChannelChat
|
import dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling.onMentionWithAnyContent
|
||||||
|
import dev.inmo.tgbotapi.extensions.utils.extensions.raw.sender_chat
|
||||||
import dev.inmo.tgbotapi.extensions.utils.formatting.linkMarkdownV2
|
import dev.inmo.tgbotapi.extensions.utils.formatting.linkMarkdownV2
|
||||||
import dev.inmo.tgbotapi.extensions.utils.formatting.textMentionMarkdownV2
|
import dev.inmo.tgbotapi.extensions.utils.formatting.textMentionMarkdownV2
|
||||||
import dev.inmo.tgbotapi.extensions.utils.updates.retrieving.longPolling
|
import dev.inmo.tgbotapi.extensions.utils.ifChannelChat
|
||||||
import dev.inmo.tgbotapi.types.ParseMode.MarkdownV2
|
import dev.inmo.tgbotapi.extensions.utils.ifFromChannelGroupContentMessage
|
||||||
import dev.inmo.tgbotapi.types.User
|
import dev.inmo.tgbotapi.types.chat.*
|
||||||
import dev.inmo.tgbotapi.types.chat.abstracts.*
|
import dev.inmo.tgbotapi.types.chat.GroupChat
|
||||||
|
import dev.inmo.tgbotapi.types.chat.PrivateChat
|
||||||
|
import dev.inmo.tgbotapi.types.chat.SupergroupChat
|
||||||
|
import dev.inmo.tgbotapi.types.message.MarkdownV2
|
||||||
|
import dev.inmo.tgbotapi.utils.PreviewFeature
|
||||||
import dev.inmo.tgbotapi.utils.extensions.escapeMarkdownV2Common
|
import dev.inmo.tgbotapi.utils.extensions.escapeMarkdownV2Common
|
||||||
import kotlinx.coroutines.*
|
import kotlinx.coroutines.*
|
||||||
import kotlinx.coroutines.flow.launchIn
|
|
||||||
import kotlinx.coroutines.flow.onEach
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The main purpose of this bot is just to answer "Oh, hi, " and add user mention here
|
* The main purpose of this bot is just to answer "Oh, hi, " and add user mention here
|
||||||
*/
|
*/
|
||||||
|
@OptIn(PreviewFeature::class)
|
||||||
suspend fun main(vararg args: String) {
|
suspend fun main(vararg args: String) {
|
||||||
val botToken = args.first()
|
val botToken = args.first()
|
||||||
|
|
||||||
telegramBotWithBehaviour(botToken, CoroutineScope(Dispatchers.IO)) {
|
telegramBotWithBehaviourAndLongPolling(botToken, CoroutineScope(Dispatchers.IO)) {
|
||||||
onContentMessage { message ->
|
val me = getMe()
|
||||||
|
onMentionWithAnyContent(me) { message ->
|
||||||
val chat = message.chat
|
val chat = message.chat
|
||||||
if (chat is ChannelChat) {
|
|
||||||
val answer = "Hi everybody in this channel \"${chat.title}\""
|
val answerText = when (val chat = message.chat) {
|
||||||
sendTextMessage(chat, answer, MarkdownV2)
|
is PreviewChannelChat -> {
|
||||||
return@onContentMessage
|
val answer = "Hi everybody in this channel \"${chat.title}\""
|
||||||
}
|
reply(message, answer, MarkdownV2)
|
||||||
val answerText = "Oh, hi, " + when (chat) {
|
return@onMentionWithAnyContent
|
||||||
is PrivateChat -> "${chat.firstName} ${chat.lastName}".textMentionMarkdownV2(chat.id)
|
}
|
||||||
is User -> "${chat.firstName} ${chat.lastName}".textMentionMarkdownV2(chat.id)
|
is PreviewPrivateChat -> {
|
||||||
is SupergroupChat -> (chat.username ?.username ?: getChat(chat).inviteLink) ?.let {
|
reply(message, "Hi, " + "${chat.firstName} ${chat.lastName}".textMentionMarkdownV2(chat.id), MarkdownV2)
|
||||||
chat.title.linkMarkdownV2(it)
|
return@onMentionWithAnyContent
|
||||||
} ?: chat.title
|
}
|
||||||
is GroupChat -> bot.getChat(chat).inviteLink ?.let {
|
is PreviewGroupChat -> {
|
||||||
chat.title.linkMarkdownV2(it)
|
message.ifFromChannelGroupContentMessage {
|
||||||
} ?: chat.title
|
val answer = "Hi, ${it.senderChat.title}"
|
||||||
else -> "Unknown :(".escapeMarkdownV2Common()
|
reply(message, answer, MarkdownV2)
|
||||||
|
return@onMentionWithAnyContent
|
||||||
|
}
|
||||||
|
"Oh, hi, " + when (chat) {
|
||||||
|
is SupergroupChat -> (chat.username ?.username ?: getChat(chat).inviteLink) ?.let {
|
||||||
|
chat.title.linkMarkdownV2(it)
|
||||||
|
} ?: chat.title
|
||||||
|
else -> bot.getChat(chat).inviteLink ?.let {
|
||||||
|
chat.title.linkMarkdownV2(it)
|
||||||
|
} ?: chat.title
|
||||||
|
}
|
||||||
|
}
|
||||||
|
is UnknownChatType -> "Unknown :(".escapeMarkdownV2Common()
|
||||||
}
|
}
|
||||||
reply(
|
reply(
|
||||||
message,
|
message,
|
||||||
@@ -48,5 +64,6 @@ suspend fun main(vararg args: String) {
|
|||||||
MarkdownV2
|
MarkdownV2
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
allUpdatesFlow.subscribeSafelyWithoutExceptions(this) { println(it) }
|
||||||
}.second.join()
|
}.second.join()
|
||||||
}
|
}
|
||||||
|
|||||||
9
InlineQueriesBot/README.md
Normal file
9
InlineQueriesBot/README.md
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
# InlineQueriesBot
|
||||||
|
|
||||||
|
This bot will form the inline queries for you. For that feature you should explicitly enable inline queries in bot settings
|
||||||
|
|
||||||
|
## Launch
|
||||||
|
|
||||||
|
```bash
|
||||||
|
../gradlew run --args="BOT_TOKEN"
|
||||||
|
```
|
||||||
38
InlineQueriesBot/build.gradle
Normal file
38
InlineQueriesBot/build.gradle
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
buildscript {
|
||||||
|
repositories {
|
||||||
|
mavenCentral()
|
||||||
|
}
|
||||||
|
|
||||||
|
dependencies {
|
||||||
|
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
plugins {
|
||||||
|
id "org.jetbrains.kotlin.multiplatform"
|
||||||
|
}
|
||||||
|
|
||||||
|
apply plugin: 'application'
|
||||||
|
|
||||||
|
mainClassName="InlineQueriesBotKt"
|
||||||
|
|
||||||
|
apply from: "$nativePartTemplate"
|
||||||
|
|
||||||
|
kotlin {
|
||||||
|
jvm()
|
||||||
|
|
||||||
|
sourceSets {
|
||||||
|
commonMain {
|
||||||
|
dependencies {
|
||||||
|
implementation kotlin('stdlib')
|
||||||
|
|
||||||
|
api "dev.inmo:tgbotapi:$telegram_bot_api_version"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
dependencies {
|
||||||
|
implementation 'io.ktor:ktor-client-logging-jvm:2.3.7'
|
||||||
|
}
|
||||||
|
|
||||||
67
InlineQueriesBot/src/commonMain/kotlin/Bot.kt
Normal file
67
InlineQueriesBot/src/commonMain/kotlin/Bot.kt
Normal file
@@ -0,0 +1,67 @@
|
|||||||
|
import dev.inmo.micro_utils.coroutines.subscribeSafelyWithoutExceptions
|
||||||
|
import dev.inmo.tgbotapi.extensions.api.answers.answer
|
||||||
|
import dev.inmo.tgbotapi.extensions.api.bot.getMe
|
||||||
|
import dev.inmo.tgbotapi.extensions.api.send.reply
|
||||||
|
import dev.inmo.tgbotapi.extensions.api.telegramBot
|
||||||
|
import dev.inmo.tgbotapi.extensions.behaviour_builder.buildBehaviourWithLongPolling
|
||||||
|
import dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling.onBaseInlineQuery
|
||||||
|
import dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling.onDeepLink
|
||||||
|
import dev.inmo.tgbotapi.requests.answers.InlineQueryResultsButton
|
||||||
|
import dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.InlineQueryResultArticle
|
||||||
|
import dev.inmo.tgbotapi.types.InlineQueries.InputMessageContent.InputTextMessageContent
|
||||||
|
import dev.inmo.tgbotapi.types.inlineQueryAnswerResultsLimit
|
||||||
|
import dev.inmo.tgbotapi.utils.buildEntities
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Thi bot will create inline query answers. You
|
||||||
|
* should enable inline queries in bot settings
|
||||||
|
*/
|
||||||
|
suspend fun doInlineQueriesBot(token: String) {
|
||||||
|
val bot = telegramBot(token)
|
||||||
|
|
||||||
|
bot.buildBehaviourWithLongPolling(
|
||||||
|
defaultExceptionsHandler = { it.printStackTrace() },
|
||||||
|
) {
|
||||||
|
onBaseInlineQuery {
|
||||||
|
val page = it.offset.toIntOrNull() ?: 0
|
||||||
|
val results = (0 until inlineQueryAnswerResultsLimit.last).map {
|
||||||
|
(page * inlineQueryAnswerResultsLimit.last) + it
|
||||||
|
}
|
||||||
|
|
||||||
|
answer(
|
||||||
|
it,
|
||||||
|
results = results.map { resultNumber ->
|
||||||
|
val resultAsString = resultNumber.toString()
|
||||||
|
InlineQueryResultArticle(
|
||||||
|
resultAsString,
|
||||||
|
"Title $resultNumber",
|
||||||
|
InputTextMessageContent(
|
||||||
|
buildEntities {
|
||||||
|
+"Result text of " + resultNumber.toString() + " result:\n"
|
||||||
|
+it.query
|
||||||
|
}
|
||||||
|
),
|
||||||
|
description = "Description of $resultNumber result"
|
||||||
|
)
|
||||||
|
},
|
||||||
|
cachedTime = 0,
|
||||||
|
isPersonal = true,
|
||||||
|
button = InlineQueryResultsButton.Start(
|
||||||
|
"Text of button with page $page",
|
||||||
|
"deep_link_for_page_$page"
|
||||||
|
),
|
||||||
|
nextOffset = (page + 1).toString()
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
onDeepLink { (message, deepLink) ->
|
||||||
|
reply(message, deepLink)
|
||||||
|
}
|
||||||
|
|
||||||
|
allUpdatesFlow.subscribeSafelyWithoutExceptions(this) {
|
||||||
|
println(it)
|
||||||
|
}
|
||||||
|
|
||||||
|
println(getMe())
|
||||||
|
}.join()
|
||||||
|
}
|
||||||
5
InlineQueriesBot/src/jvmMain/kotlin/InlineQueriesBot.kt
Normal file
5
InlineQueriesBot/src/jvmMain/kotlin/InlineQueriesBot.kt
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
import dev.inmo.micro_utils.common.MPPFile
|
||||||
|
|
||||||
|
suspend fun main(args: Array<String>) {
|
||||||
|
doInlineQueriesBot(args.first())
|
||||||
|
}
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
import kotlinx.coroutines.runBlocking
|
||||||
|
|
||||||
|
fun main(args: Array<String>) {
|
||||||
|
runBlocking {
|
||||||
|
doInlineQueriesBot(args.first())
|
||||||
|
}
|
||||||
|
}
|
||||||
32
KeyboardsBot/KeyboardsBotLib/build.gradle
Normal file
32
KeyboardsBot/KeyboardsBotLib/build.gradle
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
buildscript {
|
||||||
|
repositories {
|
||||||
|
mavenCentral()
|
||||||
|
}
|
||||||
|
|
||||||
|
dependencies {
|
||||||
|
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
plugins {
|
||||||
|
id "org.jetbrains.kotlin.multiplatform"
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
kotlin {
|
||||||
|
jvm()
|
||||||
|
js(IR) {
|
||||||
|
browser()
|
||||||
|
binaries.executable()
|
||||||
|
}
|
||||||
|
|
||||||
|
sourceSets {
|
||||||
|
commonMain {
|
||||||
|
dependencies {
|
||||||
|
implementation kotlin('stdlib')
|
||||||
|
|
||||||
|
api "dev.inmo:tgbotapi:$telegram_bot_api_version"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,170 @@
|
|||||||
|
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.answers.answer
|
||||||
|
import dev.inmo.tgbotapi.extensions.api.bot.setMyCommands
|
||||||
|
import dev.inmo.tgbotapi.extensions.api.edit.edit
|
||||||
|
import dev.inmo.tgbotapi.extensions.api.edit.editMessageText
|
||||||
|
import dev.inmo.tgbotapi.extensions.api.edit.reply_markup.editMessageReplyMarkup
|
||||||
|
import dev.inmo.tgbotapi.extensions.api.edit.text.editMessageText
|
||||||
|
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.types.buttons.*
|
||||||
|
import dev.inmo.tgbotapi.extensions.utils.withContent
|
||||||
|
import dev.inmo.tgbotapi.types.BotCommand
|
||||||
|
import dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.InlineQueryResultArticle
|
||||||
|
import dev.inmo.tgbotapi.types.InlineQueries.InputMessageContent.InputTextMessageContent
|
||||||
|
import dev.inmo.tgbotapi.types.message.content.TextContent
|
||||||
|
import dev.inmo.tgbotapi.utils.*
|
||||||
|
import kotlinx.coroutines.*
|
||||||
|
|
||||||
|
private const val nextPageData = "next"
|
||||||
|
private const val previousPageData = "previous"
|
||||||
|
|
||||||
|
fun String.parsePageAndCount(): Pair<Int, Int>? {
|
||||||
|
val (pageString, countString) = split(" ").takeIf { it.count() > 1 } ?: return null
|
||||||
|
return Pair(
|
||||||
|
pageString.toIntOrNull() ?: return null,
|
||||||
|
countString.toIntOrNull() ?: return null
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun InlineKeyboardBuilder.includePageButtons(page: Int, count: Int) {
|
||||||
|
val numericButtons = listOfNotNull(
|
||||||
|
page - 1,
|
||||||
|
page,
|
||||||
|
page + 1,
|
||||||
|
)
|
||||||
|
row {
|
||||||
|
val numbersRange = 1 .. count
|
||||||
|
numericButtons.forEach {
|
||||||
|
if (it in numbersRange) {
|
||||||
|
dataButton(it.toString(), "$it $count")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
row {
|
||||||
|
if (page - 1 > 2) {
|
||||||
|
dataButton("<<", "1 $count")
|
||||||
|
}
|
||||||
|
if (page - 1 > 1) {
|
||||||
|
dataButton("<", "${page - 2} $count")
|
||||||
|
}
|
||||||
|
|
||||||
|
if (page + 1 < count) {
|
||||||
|
dataButton(">", "${page + 2} $count")
|
||||||
|
}
|
||||||
|
if (page + 2 < count) {
|
||||||
|
dataButton(">>", "$count $count")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
row {
|
||||||
|
inlineQueryInChosenChatButton(
|
||||||
|
"Send somebody page",
|
||||||
|
query = "$page $count",
|
||||||
|
allowUsers = true,
|
||||||
|
allowBots = true,
|
||||||
|
allowGroups = true,
|
||||||
|
allowChannels = true,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
suspend fun activateKeyboardsBot(
|
||||||
|
token: String,
|
||||||
|
print: (Any) -> Unit
|
||||||
|
) {
|
||||||
|
val bot = telegramBot(token)
|
||||||
|
|
||||||
|
print(bot.getMe())
|
||||||
|
|
||||||
|
bot.buildBehaviourWithLongPolling(CoroutineScope(currentCoroutineContext() + SupervisorJob())) {
|
||||||
|
onCommandWithArgs("inline") { message, args ->
|
||||||
|
val numberOfPages = args.firstOrNull() ?.toIntOrNull() ?: 10
|
||||||
|
reply(
|
||||||
|
message,
|
||||||
|
replyMarkup = inlineKeyboard {
|
||||||
|
includePageButtons(1, numberOfPages)
|
||||||
|
}
|
||||||
|
) {
|
||||||
|
regular("Your inline keyboard with $numberOfPages pages")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
onMessageDataCallbackQuery {
|
||||||
|
val (page, count) = it.data.parsePageAndCount() ?: it.let {
|
||||||
|
answer(it, "Unsupported data :(")
|
||||||
|
return@onMessageDataCallbackQuery
|
||||||
|
}
|
||||||
|
|
||||||
|
edit(
|
||||||
|
it.message.withContent<TextContent>() ?: it.let {
|
||||||
|
answer(it, "Unsupported message type :(")
|
||||||
|
return@onMessageDataCallbackQuery
|
||||||
|
},
|
||||||
|
replyMarkup = inlineKeyboard {
|
||||||
|
includePageButtons(page, count)
|
||||||
|
}
|
||||||
|
) {
|
||||||
|
regular("This is $page of $count")
|
||||||
|
}
|
||||||
|
answer(it)
|
||||||
|
}
|
||||||
|
onInlineMessageIdDataCallbackQuery {
|
||||||
|
val (page, count) = it.data.parsePageAndCount() ?: it.let {
|
||||||
|
answer(it, "Unsupported data :(")
|
||||||
|
return@onInlineMessageIdDataCallbackQuery
|
||||||
|
}
|
||||||
|
|
||||||
|
editMessageText(
|
||||||
|
it.inlineMessageId,
|
||||||
|
replyMarkup = inlineKeyboard {
|
||||||
|
includePageButtons(page, count)
|
||||||
|
}
|
||||||
|
) {
|
||||||
|
regular("This is $page of $count")
|
||||||
|
}
|
||||||
|
answer(it)
|
||||||
|
}
|
||||||
|
|
||||||
|
onBaseInlineQuery {
|
||||||
|
val page = it.query.takeWhile { it.isDigit() }.toIntOrNull() ?: return@onBaseInlineQuery
|
||||||
|
val count = it.query.removePrefix(page.toString()).dropWhile { !it.isDigit() }.takeWhile { it.isDigit() }.toIntOrNull() ?: return@onBaseInlineQuery
|
||||||
|
|
||||||
|
answer(
|
||||||
|
it,
|
||||||
|
results = listOf(
|
||||||
|
InlineQueryResultArticle(
|
||||||
|
it.query,
|
||||||
|
"Send buttons",
|
||||||
|
InputTextMessageContent("It is sent via inline mode inline buttons"),
|
||||||
|
replyMarkup = inlineKeyboard {
|
||||||
|
includePageButtons(page, count)
|
||||||
|
}
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
onUnhandledCommand {
|
||||||
|
reply(
|
||||||
|
it,
|
||||||
|
replyMarkup = replyKeyboard(resizeKeyboard = true, oneTimeKeyboard = true) {
|
||||||
|
row {
|
||||||
|
simpleButton("/inline")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
) {
|
||||||
|
+"Use " + botCommand("inline") + " to get pagination inline keyboard"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
setMyCommands(BotCommand("inline", "Creates message with pagination inline keyboard"))
|
||||||
|
|
||||||
|
allUpdatesFlow.subscribeSafelyWithoutExceptions(this) {
|
||||||
|
println(it)
|
||||||
|
}
|
||||||
|
}.join()
|
||||||
|
}
|
||||||
@@ -0,0 +1,32 @@
|
|||||||
|
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 {
|
||||||
|
activateKeyboardsBot(token) {
|
||||||
|
infoDiv.innerHTML = it.toString()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
16
KeyboardsBot/KeyboardsBotLib/src/jsMain/resources/index.html
Normal file
16
KeyboardsBot/KeyboardsBotLib/src/jsMain/resources/index.html
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<title>Keyboards 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="KeyboardsBotLib.js"></script>
|
||||||
|
<div id="bots_container"></div>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
21
KeyboardsBot/jvm_launcher/build.gradle
Normal file
21
KeyboardsBot/jvm_launcher/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="KeyboardsBotJvmKt"
|
||||||
|
|
||||||
|
|
||||||
|
dependencies {
|
||||||
|
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
|
||||||
|
|
||||||
|
implementation project(":KeyboardsBot:KeyboardsBotLib")
|
||||||
|
}
|
||||||
10
KeyboardsBot/jvm_launcher/src/main/kotlin/KeyboardsBotJvm.kt
Normal file
10
KeyboardsBot/jvm_launcher/src/main/kotlin/KeyboardsBotJvm.kt
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
import kotlinx.coroutines.Dispatchers
|
||||||
|
import kotlinx.coroutines.withContext
|
||||||
|
|
||||||
|
suspend fun main(args: Array<String>) {
|
||||||
|
withContext(Dispatchers.IO) { // IO for inheriting of it in side of activateKeyboardsBot
|
||||||
|
activateKeyboardsBot(args.first()) {
|
||||||
|
println(it)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
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()
|
||||||
|
}
|
||||||
9
LiveLocationsBot/README.md
Normal file
9
LiveLocationsBot/README.md
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
# LiveLocationsBot
|
||||||
|
|
||||||
|
This bot will send you live location and update it from time to time
|
||||||
|
|
||||||
|
## Launch
|
||||||
|
|
||||||
|
```bash
|
||||||
|
../gradlew run --args="BOT_TOKEN"
|
||||||
|
```
|
||||||
21
LiveLocationsBot/build.gradle
Normal file
21
LiveLocationsBot/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="LiveLocationsBotKt"
|
||||||
|
|
||||||
|
|
||||||
|
dependencies {
|
||||||
|
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
|
||||||
|
|
||||||
|
implementation "dev.inmo:tgbotapi:$telegram_bot_api_version"
|
||||||
|
}
|
||||||
85
LiveLocationsBot/src/main/kotlin/LiveLocationsBot.kt
Normal file
85
LiveLocationsBot/src/main/kotlin/LiveLocationsBot.kt
Normal file
@@ -0,0 +1,85 @@
|
|||||||
|
import dev.inmo.micro_utils.coroutines.subscribeSafelyWithoutExceptions
|
||||||
|
import dev.inmo.tgbotapi.extensions.api.EditLiveLocationInfo
|
||||||
|
import dev.inmo.tgbotapi.extensions.api.chat.get.getChat
|
||||||
|
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.send.*
|
||||||
|
import dev.inmo.tgbotapi.extensions.behaviour_builder.expectations.waitMessageDataCallbackQuery
|
||||||
|
import dev.inmo.tgbotapi.extensions.behaviour_builder.oneOf
|
||||||
|
import dev.inmo.tgbotapi.extensions.behaviour_builder.parallel
|
||||||
|
import dev.inmo.tgbotapi.extensions.behaviour_builder.telegramBotWithBehaviourAndLongPolling
|
||||||
|
import dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling.onCommand
|
||||||
|
import dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling.onContentMessage
|
||||||
|
import dev.inmo.tgbotapi.extensions.utils.extensions.sameMessage
|
||||||
|
import dev.inmo.tgbotapi.extensions.utils.formatting.linkMarkdownV2
|
||||||
|
import dev.inmo.tgbotapi.extensions.utils.formatting.textMentionMarkdownV2
|
||||||
|
import dev.inmo.tgbotapi.extensions.utils.ifFromChannelGroupContentMessage
|
||||||
|
import dev.inmo.tgbotapi.extensions.utils.types.buttons.dataButton
|
||||||
|
import dev.inmo.tgbotapi.extensions.utils.types.buttons.flatInlineKeyboard
|
||||||
|
import dev.inmo.tgbotapi.types.chat.*
|
||||||
|
import dev.inmo.tgbotapi.types.chat.GroupChat
|
||||||
|
import dev.inmo.tgbotapi.types.chat.PrivateChat
|
||||||
|
import dev.inmo.tgbotapi.types.chat.SupergroupChat
|
||||||
|
import dev.inmo.tgbotapi.types.location.LiveLocation
|
||||||
|
import dev.inmo.tgbotapi.types.message.MarkdownV2
|
||||||
|
import dev.inmo.tgbotapi.types.message.abstracts.ContentMessage
|
||||||
|
import dev.inmo.tgbotapi.types.message.content.LiveLocationContent
|
||||||
|
import dev.inmo.tgbotapi.types.message.content.LocationContent
|
||||||
|
import dev.inmo.tgbotapi.utils.PreviewFeature
|
||||||
|
import dev.inmo.tgbotapi.utils.extensions.escapeMarkdownV2Common
|
||||||
|
import kotlinx.coroutines.*
|
||||||
|
import kotlinx.coroutines.flow.FlowCollector
|
||||||
|
import kotlinx.coroutines.flow.MutableStateFlow
|
||||||
|
import kotlinx.coroutines.flow.filter
|
||||||
|
import kotlinx.coroutines.flow.first
|
||||||
|
import kotlinx.coroutines.flow.flow
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This bot will send you live location and update it from time to time
|
||||||
|
*/
|
||||||
|
suspend fun main(vararg args: String) {
|
||||||
|
val botToken = args.first()
|
||||||
|
|
||||||
|
telegramBotWithBehaviourAndLongPolling(botToken, CoroutineScope(Dispatchers.IO)) {
|
||||||
|
val locationsFlow = flow {
|
||||||
|
var i = 0
|
||||||
|
while (isActive) {
|
||||||
|
val newInfo = EditLiveLocationInfo(
|
||||||
|
latitude = i.toDouble(),
|
||||||
|
longitude = i.toDouble(),
|
||||||
|
replyMarkup = flatInlineKeyboard {
|
||||||
|
dataButton("Cancel", "cancel")
|
||||||
|
}
|
||||||
|
)
|
||||||
|
emit(newInfo)
|
||||||
|
i++
|
||||||
|
delay(3000L) // 3 seconds
|
||||||
|
}
|
||||||
|
}
|
||||||
|
onCommand("start") {
|
||||||
|
// in this flow will be actual message with live location
|
||||||
|
val currentMessageState = MutableStateFlow<ContentMessage<LocationContent>?>(null)
|
||||||
|
val sendingJob = launch {
|
||||||
|
handleLiveLocation(
|
||||||
|
it.chat.id,
|
||||||
|
locationsFlow,
|
||||||
|
sentMessageFlow = FlowCollector { currentMessageState.emit(it) }
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
waitMessageDataCallbackQuery().filter {
|
||||||
|
it.message.sameMessage(
|
||||||
|
currentMessageState.value ?: return@filter false
|
||||||
|
) && it.data == "cancel"
|
||||||
|
}.first()
|
||||||
|
|
||||||
|
sendingJob.cancel() // ends live location
|
||||||
|
currentMessageState.value ?.let {
|
||||||
|
stopLiveLocation(it, replyMarkup = null)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
allUpdatesFlow.subscribeSafelyWithoutExceptions(this) { println(it) }
|
||||||
|
}.second.join()
|
||||||
|
}
|
||||||
|
|
||||||
11
PollsBot/README.md
Normal file
11
PollsBot/README.md
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
# PollsBot
|
||||||
|
|
||||||
|
This bot will send test poll in the chat where commands will be received. Commands:
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
## Launch
|
||||||
|
|
||||||
|
```bash
|
||||||
|
../gradlew run --args="BOT_TOKEN"
|
||||||
|
```
|
||||||
21
PollsBot/build.gradle
Normal file
21
PollsBot/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="HelloBotKt"
|
||||||
|
|
||||||
|
|
||||||
|
dependencies {
|
||||||
|
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
|
||||||
|
|
||||||
|
implementation "dev.inmo:tgbotapi:$telegram_bot_api_version"
|
||||||
|
}
|
||||||
100
PollsBot/src/main/kotlin/PollsBot.kt
Normal file
100
PollsBot/src/main/kotlin/PollsBot.kt
Normal file
@@ -0,0 +1,100 @@
|
|||||||
|
import com.benasher44.uuid.uuid4
|
||||||
|
import dev.inmo.micro_utils.coroutines.subscribeSafelyWithoutExceptions
|
||||||
|
import dev.inmo.tgbotapi.extensions.api.bot.getMe
|
||||||
|
import dev.inmo.tgbotapi.extensions.api.chat.get.getChat
|
||||||
|
import dev.inmo.tgbotapi.extensions.api.send.*
|
||||||
|
import dev.inmo.tgbotapi.extensions.api.send.polls.sendRegularPoll
|
||||||
|
import dev.inmo.tgbotapi.extensions.behaviour_builder.telegramBotWithBehaviourAndLongPolling
|
||||||
|
import dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling.*
|
||||||
|
import dev.inmo.tgbotapi.extensions.utils.extensions.raw.sender_chat
|
||||||
|
import dev.inmo.tgbotapi.extensions.utils.formatting.linkMarkdownV2
|
||||||
|
import dev.inmo.tgbotapi.extensions.utils.formatting.textMentionMarkdownV2
|
||||||
|
import dev.inmo.tgbotapi.extensions.utils.ifChannelChat
|
||||||
|
import dev.inmo.tgbotapi.extensions.utils.ifFromChannelGroupContentMessage
|
||||||
|
import dev.inmo.tgbotapi.types.ChatId
|
||||||
|
import dev.inmo.tgbotapi.types.IdChatIdentifier
|
||||||
|
import dev.inmo.tgbotapi.types.PollIdentifier
|
||||||
|
import dev.inmo.tgbotapi.types.ReplyParameters
|
||||||
|
import dev.inmo.tgbotapi.types.chat.*
|
||||||
|
import dev.inmo.tgbotapi.types.chat.GroupChat
|
||||||
|
import dev.inmo.tgbotapi.types.chat.PrivateChat
|
||||||
|
import dev.inmo.tgbotapi.types.chat.SupergroupChat
|
||||||
|
import dev.inmo.tgbotapi.types.message.MarkdownV2
|
||||||
|
import dev.inmo.tgbotapi.types.polls.Poll
|
||||||
|
import dev.inmo.tgbotapi.types.polls.PollAnswer
|
||||||
|
import dev.inmo.tgbotapi.types.polls.PollOption
|
||||||
|
import dev.inmo.tgbotapi.types.polls.RegularPoll
|
||||||
|
import dev.inmo.tgbotapi.utils.PreviewFeature
|
||||||
|
import dev.inmo.tgbotapi.utils.extensions.escapeMarkdownV2Common
|
||||||
|
import kotlinx.coroutines.*
|
||||||
|
import kotlinx.coroutines.sync.Mutex
|
||||||
|
import kotlinx.coroutines.sync.withLock
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This bot will answer with anonymous or public poll and send message on
|
||||||
|
* updates of any of it.
|
||||||
|
*
|
||||||
|
* * Use `/anonymous` to take anonymous regular poll
|
||||||
|
* * Use `/public` to take public regular poll
|
||||||
|
*/
|
||||||
|
@OptIn(PreviewFeature::class)
|
||||||
|
suspend fun main(vararg args: String) {
|
||||||
|
val botToken = args.first()
|
||||||
|
|
||||||
|
telegramBotWithBehaviourAndLongPolling(botToken, CoroutineScope(Dispatchers.IO)) {
|
||||||
|
val me = getMe()
|
||||||
|
|
||||||
|
val pollToChat = mutableMapOf<PollIdentifier, IdChatIdentifier>()
|
||||||
|
val pollToChatMutex = Mutex()
|
||||||
|
|
||||||
|
onCommand("anonymous") {
|
||||||
|
val sentPoll = sendRegularPoll(
|
||||||
|
it.chat,
|
||||||
|
"Test regular anonymous poll",
|
||||||
|
(1 .. 10).map {
|
||||||
|
it.toString()
|
||||||
|
},
|
||||||
|
isAnonymous = true,
|
||||||
|
replyParameters = ReplyParameters(it)
|
||||||
|
)
|
||||||
|
pollToChatMutex.withLock {
|
||||||
|
pollToChat[sentPoll.content.poll.id] = sentPoll.chat.id
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
onCommand("public") {
|
||||||
|
val sentPoll = sendRegularPoll(
|
||||||
|
it.chat,
|
||||||
|
"Test regular anonymous poll",
|
||||||
|
(1 .. 10).map {
|
||||||
|
it.toString()
|
||||||
|
},
|
||||||
|
isAnonymous = false,
|
||||||
|
replyParameters = ReplyParameters(it)
|
||||||
|
)
|
||||||
|
pollToChatMutex.withLock {
|
||||||
|
pollToChat[sentPoll.content.poll.id] = sentPoll.chat.id
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
onPollAnswer {
|
||||||
|
val chatId = pollToChat[it.pollId] ?: return@onPollAnswer
|
||||||
|
|
||||||
|
when(it) {
|
||||||
|
is PollAnswer.Public -> send(chatId, "[onPollAnswer] User ${it.user} have answered")
|
||||||
|
is PollAnswer.Anonymous -> send(chatId, "[onPollAnswer] Chat ${it.voterChat} have answered")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
onPollUpdates {
|
||||||
|
val chatId = pollToChat[it.id] ?: return@onPollUpdates
|
||||||
|
|
||||||
|
when(it.isAnonymous) {
|
||||||
|
false -> send(chatId, "[onPollUpdates] Public poll updated: ${it.options.joinToString()}")
|
||||||
|
true -> send(chatId, "[onPollUpdates] Anonymous poll updated: ${it.options.joinToString()}")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
allUpdatesFlow.subscribeSafelyWithoutExceptions(this) { println(it) }
|
||||||
|
}.second.join()
|
||||||
|
}
|
||||||
@@ -4,6 +4,8 @@ This repository contains several examples of simple bots which are using Telegra
|
|||||||
|
|
||||||
## How to use this repository
|
## How to use this repository
|
||||||
|
|
||||||
|
***TO RUN NATIVE TARGETS ON LINUX YOU SHOULD INSTALL CURL LIBRARY. FOR EXAMPLE: `sudo apt install libcurl4-gnutls-dev`***
|
||||||
|
|
||||||
This repository contains several important things:
|
This repository contains several important things:
|
||||||
|
|
||||||
* Example subprojects
|
* Example subprojects
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
buildscript {
|
buildscript {
|
||||||
repositories {
|
repositories {
|
||||||
jcenter()
|
mavenCentral()
|
||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
@@ -8,14 +8,27 @@ buildscript {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
apply plugin: 'kotlin'
|
plugins {
|
||||||
|
id "org.jetbrains.kotlin.multiplatform"
|
||||||
|
}
|
||||||
|
|
||||||
apply plugin: 'application'
|
apply plugin: 'application'
|
||||||
|
|
||||||
mainClassName="RandomFileSenderBotKt"
|
mainClassName="RandomFileSenderBotKt"
|
||||||
|
|
||||||
|
kotlin {
|
||||||
|
jvm()
|
||||||
|
|
||||||
dependencies {
|
sourceSets {
|
||||||
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
|
commonMain {
|
||||||
|
dependencies {
|
||||||
|
implementation kotlin('stdlib')
|
||||||
|
|
||||||
implementation "dev.inmo:tgbotapi:$telegram_bot_api_version"
|
api "dev.inmo:tgbotapi:$telegram_bot_api_version"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
apply from: "$nativePartTemplate"
|
||||||
|
|
||||||
|
|||||||
86
RandomFileSenderBot/src/commonMain/kotlin/Bot.kt
Normal file
86
RandomFileSenderBot/src/commonMain/kotlin/Bot.kt
Normal file
@@ -0,0 +1,86 @@
|
|||||||
|
import dev.inmo.micro_utils.common.MPPFile
|
||||||
|
import dev.inmo.micro_utils.common.filesize
|
||||||
|
import dev.inmo.tgbotapi.bot.TelegramBot
|
||||||
|
import dev.inmo.tgbotapi.extensions.api.bot.getMe
|
||||||
|
import dev.inmo.tgbotapi.extensions.api.bot.setMyCommands
|
||||||
|
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.reply
|
||||||
|
import dev.inmo.tgbotapi.extensions.api.send.withUploadDocumentAction
|
||||||
|
import dev.inmo.tgbotapi.extensions.api.telegramBot
|
||||||
|
import dev.inmo.tgbotapi.extensions.behaviour_builder.buildBehaviourWithLongPolling
|
||||||
|
import dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling.onCommandWithArgs
|
||||||
|
import dev.inmo.tgbotapi.requests.abstracts.asMultipartFile
|
||||||
|
import dev.inmo.tgbotapi.types.BotCommand
|
||||||
|
import dev.inmo.tgbotapi.types.chat.Chat
|
||||||
|
import dev.inmo.tgbotapi.types.media.TelegramMediaDocument
|
||||||
|
import dev.inmo.tgbotapi.types.mediaCountInMediaGroup
|
||||||
|
|
||||||
|
private const val command = "send_file"
|
||||||
|
|
||||||
|
expect fun pickFile(currentRoot: MPPFile): MPPFile?
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This bot will send files inside of working directory OR from directory in the second argument.
|
||||||
|
* You may send /send_file command to this bot to get random file from the directory OR
|
||||||
|
* `/send_file $number` when you want to receive required number of files. For example,
|
||||||
|
* /send_file and `/send_file 1` will have the same effect - bot will send one random file.
|
||||||
|
* But if you will send `/send_file 5` it will choose 5 random files and send them as group
|
||||||
|
*/
|
||||||
|
suspend fun doRandomFileSenderBot(token: String, folder: MPPFile) {
|
||||||
|
val bot = telegramBot(token)
|
||||||
|
|
||||||
|
suspend fun TelegramBot.sendFiles(chat: Chat, files: List<MPPFile>) {
|
||||||
|
when (files.size) {
|
||||||
|
1 -> sendDocument(
|
||||||
|
chat.id,
|
||||||
|
files.first().asMultipartFile(),
|
||||||
|
protectContent = true
|
||||||
|
)
|
||||||
|
else -> sendDocumentsGroup(
|
||||||
|
chat,
|
||||||
|
files.map { TelegramMediaDocument(it.asMultipartFile()) },
|
||||||
|
protectContent = true
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bot.buildBehaviourWithLongPolling (defaultExceptionsHandler = { it.printStackTrace() }) {
|
||||||
|
onCommandWithArgs(command) { message, args ->
|
||||||
|
|
||||||
|
withUploadDocumentAction(message.chat) {
|
||||||
|
val count = args.firstOrNull() ?.toIntOrNull() ?: 1
|
||||||
|
var sent = false
|
||||||
|
|
||||||
|
var left = count
|
||||||
|
val chosen = mutableListOf<MPPFile>()
|
||||||
|
|
||||||
|
while (left > 0) {
|
||||||
|
val picked = pickFile(folder) ?.takeIf { it.filesize > 0 } ?: continue
|
||||||
|
chosen.add(picked)
|
||||||
|
left--
|
||||||
|
if (chosen.size >= mediaCountInMediaGroup.last) {
|
||||||
|
sendFiles(message.chat, chosen)
|
||||||
|
chosen.clear()
|
||||||
|
sent = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (chosen.isNotEmpty()) {
|
||||||
|
sendFiles(message.chat, chosen)
|
||||||
|
sent = true
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!sent) {
|
||||||
|
reply(message, "Nothing selected :(")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
setMyCommands(
|
||||||
|
BotCommand(command, "Send some random file in picker directory")
|
||||||
|
)
|
||||||
|
|
||||||
|
println(getMe())
|
||||||
|
}.join()
|
||||||
|
}
|
||||||
10
RandomFileSenderBot/src/jvmMain/kotlin/ActualPickFile.kt
Normal file
10
RandomFileSenderBot/src/jvmMain/kotlin/ActualPickFile.kt
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
import dev.inmo.micro_utils.common.MPPFile
|
||||||
|
import java.io.File
|
||||||
|
|
||||||
|
actual fun pickFile(currentRoot: MPPFile): File? {
|
||||||
|
if (currentRoot.isFile) {
|
||||||
|
return currentRoot
|
||||||
|
} else {
|
||||||
|
return pickFile(currentRoot.listFiles() ?.takeIf { it.isNotEmpty() } ?.random() ?: return null)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
import dev.inmo.micro_utils.common.MPPFile
|
||||||
|
|
||||||
|
suspend fun main(args: Array<String>) {
|
||||||
|
doRandomFileSenderBot(args.first(), MPPFile(args.getOrNull(1) ?: ""))
|
||||||
|
}
|
||||||
@@ -1,47 +0,0 @@
|
|||||||
import dev.inmo.tgbotapi.bot.Ktor.telegramBot
|
|
||||||
import dev.inmo.tgbotapi.extensions.api.bot.getMe
|
|
||||||
import dev.inmo.tgbotapi.extensions.api.bot.setMyCommands
|
|
||||||
import dev.inmo.tgbotapi.extensions.api.send.media.sendDocument
|
|
||||||
import dev.inmo.tgbotapi.extensions.api.send.reply
|
|
||||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.buildBehaviour
|
|
||||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling.onCommand
|
|
||||||
import dev.inmo.tgbotapi.requests.abstracts.toInputFile
|
|
||||||
import dev.inmo.tgbotapi.types.BotCommand
|
|
||||||
import kotlinx.coroutines.*
|
|
||||||
import java.io.File
|
|
||||||
|
|
||||||
private const val command = "send_file"
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This bot will send files inside of working directory OR from directory in the second argument
|
|
||||||
*/
|
|
||||||
suspend fun main(args: Array<String>) {
|
|
||||||
val botToken = args.first()
|
|
||||||
val directoryOrFile = args.getOrNull(1) ?.let { File(it) } ?: File("")
|
|
||||||
|
|
||||||
fun pickFile(currentRoot: File = directoryOrFile): File? {
|
|
||||||
if (currentRoot.isFile) {
|
|
||||||
return currentRoot
|
|
||||||
} else {
|
|
||||||
return pickFile(currentRoot.listFiles() ?.random() ?: return null)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
val bot = telegramBot(botToken)
|
|
||||||
val scope = CoroutineScope(Dispatchers.Default)
|
|
||||||
|
|
||||||
bot.buildBehaviour(scope) {
|
|
||||||
onCommand(command.toRegex()) { message ->
|
|
||||||
pickFile() ?.let {
|
|
||||||
bot.sendDocument(
|
|
||||||
message.chat.id,
|
|
||||||
it.toInputFile()
|
|
||||||
)
|
|
||||||
} ?: bot.reply(message, "Nothing selected :(")
|
|
||||||
}
|
|
||||||
setMyCommands(
|
|
||||||
BotCommand(command, "Send some random file in picker directory")
|
|
||||||
)
|
|
||||||
println(getMe())
|
|
||||||
}.join()
|
|
||||||
}
|
|
||||||
10
RandomFileSenderBot/src/nativeMain/kotlin/ActualPickFile.kt
Normal file
10
RandomFileSenderBot/src/nativeMain/kotlin/ActualPickFile.kt
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
import dev.inmo.micro_utils.common.MPPFile
|
||||||
|
import okio.FileSystem
|
||||||
|
|
||||||
|
actual fun pickFile(currentRoot: MPPFile): MPPFile? {
|
||||||
|
if (FileSystem.SYSTEM.exists(currentRoot) && FileSystem.SYSTEM.listOrNull(currentRoot) == null) {
|
||||||
|
return currentRoot
|
||||||
|
} else {
|
||||||
|
return pickFile(FileSystem.SYSTEM.list(currentRoot).takeIf { it.isNotEmpty() } ?.random() ?: return null)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
import kotlinx.coroutines.runBlocking
|
||||||
|
import okio.Path.Companion.toPath
|
||||||
|
|
||||||
|
fun main(args: Array<String>) {
|
||||||
|
runBlocking {
|
||||||
|
doRandomFileSenderBot(args.first(), args.getOrNull(1) ?.toPath() ?: "".toPath())
|
||||||
|
}
|
||||||
|
}
|
||||||
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()
|
||||||
|
}
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
buildscript {
|
buildscript {
|
||||||
repositories {
|
repositories {
|
||||||
jcenter()
|
mavenCentral()
|
||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
@@ -9,7 +9,7 @@ buildscript {
|
|||||||
}
|
}
|
||||||
|
|
||||||
plugins {
|
plugins {
|
||||||
id "org.jetbrains.kotlin.multiplatform" version "$kotlin_version"
|
id "org.jetbrains.kotlin.multiplatform"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -20,6 +20,9 @@ kotlin {
|
|||||||
browser()
|
browser()
|
||||||
binaries.executable()
|
binaries.executable()
|
||||||
}
|
}
|
||||||
|
linuxX64()
|
||||||
|
mingwX64()
|
||||||
|
linuxArm64()
|
||||||
|
|
||||||
sourceSets {
|
sourceSets {
|
||||||
commonMain {
|
commonMain {
|
||||||
|
|||||||
@@ -1,35 +1,55 @@
|
|||||||
|
import dev.inmo.micro_utils.coroutines.subscribeSafelyWithoutExceptions
|
||||||
import dev.inmo.tgbotapi.extensions.api.bot.getMe
|
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.send.*
|
||||||
import dev.inmo.tgbotapi.extensions.api.send.media.*
|
import dev.inmo.tgbotapi.extensions.api.send.media.*
|
||||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.*
|
import dev.inmo.tgbotapi.extensions.behaviour_builder.*
|
||||||
|
import dev.inmo.tgbotapi.extensions.behaviour_builder.filters.CommonMessageFilterExcludeMediaGroups
|
||||||
|
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.types.message.abstracts.MediaGroupMessage
|
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 kotlinx.coroutines.*
|
import kotlinx.coroutines.*
|
||||||
import kotlin.coroutines.coroutineContext
|
|
||||||
|
|
||||||
suspend fun activateResenderBot(
|
suspend fun activateResenderBot(
|
||||||
token: String,
|
token: String,
|
||||||
print: (Any) -> Unit
|
print: (Any) -> Unit
|
||||||
) {
|
) {
|
||||||
val bot = telegramBot(token)
|
telegramBotWithBehaviourAndLongPolling(token, scope = CoroutineScope(currentCoroutineContext() + SupervisorJob())) {
|
||||||
|
|
||||||
print(bot.getMe())
|
|
||||||
|
|
||||||
bot.buildBehaviour(CoroutineScope(coroutineContext + SupervisorJob())) {
|
|
||||||
onContentMessage(
|
onContentMessage(
|
||||||
additionalFilter = { it !is MediaGroupMessage<*> }
|
subcontextUpdatesFilter = MessageFilterByChat,
|
||||||
) {
|
) {
|
||||||
executeUnsafe(it.content.createResend(it.chat.id, replyToMessageId = it.messageId))
|
val chat = it.chat
|
||||||
|
|
||||||
|
val answer = withTypingAction(chat) {
|
||||||
|
executeUnsafe(
|
||||||
|
it.content.createResend(
|
||||||
|
chat.id,
|
||||||
|
messageThreadId = it.threadIdOrNull,
|
||||||
|
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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
println("Answer info: $answer")
|
||||||
}
|
}
|
||||||
onVisualGallery {
|
|
||||||
sendVisualMediaGroup(it.chat!!, it.map { it.content.toMediaGroupMemberInputMedia() })
|
allUpdatesFlow.subscribeSafelyWithoutExceptions(this) {
|
||||||
|
println(it)
|
||||||
}
|
}
|
||||||
onPlaylist {
|
print(bot.getMe())
|
||||||
sendPlaylist(it.chat!!, it.map { it.content.toMediaGroupMemberInputMedia() })
|
}.second.join()
|
||||||
}
|
|
||||||
onDocumentsGroup {
|
|
||||||
sendDocumentsGroup(it.chat!!, it.map { it.content.toMediaGroupMemberInputMedia() })
|
|
||||||
}
|
|
||||||
}.join()
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
buildscript {
|
buildscript {
|
||||||
repositories {
|
repositories {
|
||||||
jcenter()
|
mavenCentral()
|
||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
@@ -15,7 +15,7 @@ mainClassName="ResenderBotJvmKt"
|
|||||||
|
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
|
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
|
||||||
|
|
||||||
implementation project(":ResenderBot:ResenderBotLib")
|
implementation project(":ResenderBot:ResenderBotLib")
|
||||||
}
|
}
|
||||||
|
|||||||
28
ResenderBot/native_launcher/build.gradle
Normal file
28
ResenderBot/native_launcher/build.gradle
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
buildscript {
|
||||||
|
repositories {
|
||||||
|
mavenCentral()
|
||||||
|
}
|
||||||
|
|
||||||
|
dependencies {
|
||||||
|
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
plugins {
|
||||||
|
id "org.jetbrains.kotlin.multiplatform"
|
||||||
|
}
|
||||||
|
|
||||||
|
apply from: "$nativePartTemplate"
|
||||||
|
|
||||||
|
kotlin {
|
||||||
|
sourceSets {
|
||||||
|
commonMain {
|
||||||
|
dependencies {
|
||||||
|
implementation kotlin('stdlib')
|
||||||
|
|
||||||
|
api project(":ResenderBot:ResenderBotLib")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
import kotlinx.coroutines.runBlocking
|
||||||
|
|
||||||
|
fun main(vararg args: String) {
|
||||||
|
runBlocking {
|
||||||
|
activateResenderBot(args.first()) {
|
||||||
|
println(it)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
12
RightsChangerBot/README.md
Normal file
12
RightsChangerBot/README.md
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
# RightsChanger
|
||||||
|
|
||||||
|
All the commands should be called with reply to some common user.
|
||||||
|
|
||||||
|
* Use `/simple` with bot to get request buttons for non-independent permissions change
|
||||||
|
* Use `/granular` with bot to get request buttons for independent permissions change
|
||||||
|
|
||||||
|
## Launch
|
||||||
|
|
||||||
|
```bash
|
||||||
|
../gradlew run --args="BOT_TOKEN allowed_user_id_long"
|
||||||
|
```
|
||||||
22
RightsChangerBot/build.gradle
Normal file
22
RightsChangerBot/build.gradle
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
buildscript {
|
||||||
|
repositories {
|
||||||
|
mavenCentral()
|
||||||
|
}
|
||||||
|
|
||||||
|
dependencies {
|
||||||
|
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
apply plugin: 'kotlin'
|
||||||
|
apply plugin: 'application'
|
||||||
|
|
||||||
|
mainClassName="RightsChangerKt"
|
||||||
|
|
||||||
|
|
||||||
|
dependencies {
|
||||||
|
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
|
||||||
|
|
||||||
|
implementation "dev.inmo:tgbotapi:$telegram_bot_api_version"
|
||||||
|
implementation 'io.ktor:ktor-client-logging-jvm:2.3.7'
|
||||||
|
}
|
||||||
521
RightsChangerBot/src/main/kotlin/RightsChanger.kt
Normal file
521
RightsChangerBot/src/main/kotlin/RightsChanger.kt
Normal file
@@ -0,0 +1,521 @@
|
|||||||
|
import dev.inmo.micro_utils.coroutines.firstOf
|
||||||
|
import dev.inmo.micro_utils.fsm.common.State
|
||||||
|
import dev.inmo.tgbotapi.bot.ktor.telegramBot
|
||||||
|
import dev.inmo.tgbotapi.extensions.api.bot.setMyCommands
|
||||||
|
import dev.inmo.tgbotapi.extensions.api.chat.get.getChat
|
||||||
|
import dev.inmo.tgbotapi.extensions.api.chat.members.getChatMember
|
||||||
|
import dev.inmo.tgbotapi.extensions.api.chat.members.promoteChannelAdministrator
|
||||||
|
import dev.inmo.tgbotapi.extensions.api.chat.members.restrictChatMember
|
||||||
|
import dev.inmo.tgbotapi.extensions.api.edit.edit
|
||||||
|
import dev.inmo.tgbotapi.extensions.api.send.reply
|
||||||
|
import dev.inmo.tgbotapi.extensions.api.send.send
|
||||||
|
import dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContext
|
||||||
|
import dev.inmo.tgbotapi.extensions.behaviour_builder.buildBehaviourWithFSMAndStartLongPolling
|
||||||
|
import dev.inmo.tgbotapi.extensions.behaviour_builder.expectations.*
|
||||||
|
import dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling.onCommand
|
||||||
|
import dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling.onMessageDataCallbackQuery
|
||||||
|
import dev.inmo.tgbotapi.extensions.utils.*
|
||||||
|
import dev.inmo.tgbotapi.extensions.utils.extensions.sameChat
|
||||||
|
import dev.inmo.tgbotapi.extensions.utils.types.buttons.*
|
||||||
|
import dev.inmo.tgbotapi.types.*
|
||||||
|
import dev.inmo.tgbotapi.types.buttons.InlineKeyboardMarkup
|
||||||
|
import dev.inmo.tgbotapi.types.chat.ChannelChat
|
||||||
|
import dev.inmo.tgbotapi.types.chat.ChatPermissions
|
||||||
|
import dev.inmo.tgbotapi.types.chat.PublicChat
|
||||||
|
import dev.inmo.tgbotapi.types.chat.member.*
|
||||||
|
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.utils.*
|
||||||
|
import dev.inmo.tgbotapi.utils.mention
|
||||||
|
import kotlinx.coroutines.flow.filter
|
||||||
|
import kotlinx.coroutines.flow.first
|
||||||
|
import kotlinx.coroutines.flow.mapNotNull
|
||||||
|
|
||||||
|
sealed interface UserRetrievingStep : State {
|
||||||
|
data class RetrievingChannelChatState(
|
||||||
|
override val context: ChatId
|
||||||
|
) : UserRetrievingStep
|
||||||
|
data class RetrievingUserIdChatState(
|
||||||
|
override val context: ChatId,
|
||||||
|
val channelId: ChatId
|
||||||
|
) : UserRetrievingStep
|
||||||
|
data class RetrievingChatInfoDoneState(
|
||||||
|
override val context: ChatId,
|
||||||
|
val channelId: ChatId,
|
||||||
|
val userId: UserId
|
||||||
|
) : UserRetrievingStep
|
||||||
|
}
|
||||||
|
|
||||||
|
suspend fun main(args: Array<String>) {
|
||||||
|
val botToken = args.first()
|
||||||
|
|
||||||
|
val bot = telegramBot(botToken)
|
||||||
|
|
||||||
|
val allowedAdmin = ChatId(args[1].toLong())
|
||||||
|
|
||||||
|
fun Boolean?.allowedSymbol() = when (this) {
|
||||||
|
true -> "✅"
|
||||||
|
false -> "❌"
|
||||||
|
null -> ""
|
||||||
|
}
|
||||||
|
|
||||||
|
val granularDataPrefix = "granular"
|
||||||
|
val messagesToggleGranularData = "$granularDataPrefix messages"
|
||||||
|
val otherMessagesToggleGranularData = "$granularDataPrefix other messages"
|
||||||
|
val audiosToggleGranularData = "$granularDataPrefix audios"
|
||||||
|
val voicesToggleGranularData = "$granularDataPrefix voices"
|
||||||
|
val videosToggleGranularData = "$granularDataPrefix videos"
|
||||||
|
val videoNotesToggleGranularData = "$granularDataPrefix video notes"
|
||||||
|
val photosToggleGranularData = "$granularDataPrefix photos"
|
||||||
|
val webPagePreviewToggleGranularData = "$granularDataPrefix web page preview"
|
||||||
|
val pollsToggleGranularData = "$granularDataPrefix polls"
|
||||||
|
val documentsToggleGranularData = "$granularDataPrefix documents"
|
||||||
|
|
||||||
|
val commonDataPrefix = "common"
|
||||||
|
val pollsToggleCommonData = "$commonDataPrefix polls"
|
||||||
|
val otherMessagesToggleCommonData = "$commonDataPrefix other messages"
|
||||||
|
val webPagePreviewToggleCommonData = "$commonDataPrefix web page preview"
|
||||||
|
|
||||||
|
val adminRightsDataPrefix = "admin"
|
||||||
|
val refreshAdminRightsData = "${adminRightsDataPrefix}_refresh"
|
||||||
|
val postMessagesToggleAdminRightsData = "${adminRightsDataPrefix}_post_messages"
|
||||||
|
val editMessagesToggleAdminRightsData = "${adminRightsDataPrefix}_edit_messages"
|
||||||
|
val deleteMessagesToggleAdminRightsData = "${adminRightsDataPrefix}_delete_messages"
|
||||||
|
val editStoriesToggleAdminRightsData = "${adminRightsDataPrefix}_edit_stories"
|
||||||
|
val deleteStoriesToggleAdminRightsData = "${adminRightsDataPrefix}_delete_stories"
|
||||||
|
val postStoriesToggleAdminRightsData = "${adminRightsDataPrefix}_post_stories"
|
||||||
|
|
||||||
|
suspend fun BehaviourContext.getUserChatPermissions(chatId: ChatId, userId: UserId): ChatPermissions? {
|
||||||
|
val chatMember = getChatMember(chatId, userId)
|
||||||
|
return chatMember.restrictedChatMemberOrNull() ?: chatMember.whenMemberChatMember {
|
||||||
|
getChat(chatId).extendedGroupChatOrNull() ?.permissions
|
||||||
|
}
|
||||||
|
}
|
||||||
|
fun buildGranularKeyboard(
|
||||||
|
permissions: ChatPermissions
|
||||||
|
): InlineKeyboardMarkup {
|
||||||
|
return inlineKeyboard {
|
||||||
|
row {
|
||||||
|
dataButton("Send messages${permissions.canSendMessages.allowedSymbol()}", messagesToggleGranularData)
|
||||||
|
dataButton(
|
||||||
|
"Send other messages${permissions.canSendOtherMessages.allowedSymbol()}",
|
||||||
|
otherMessagesToggleGranularData
|
||||||
|
)
|
||||||
|
}
|
||||||
|
row {
|
||||||
|
dataButton("Send audios${permissions.canSendAudios.allowedSymbol()}", audiosToggleGranularData)
|
||||||
|
dataButton("Send voices${permissions.canSendVoiceNotes.allowedSymbol()}", voicesToggleGranularData)
|
||||||
|
}
|
||||||
|
row {
|
||||||
|
dataButton("Send videos${permissions.canSendVideos.allowedSymbol()}", videosToggleGranularData)
|
||||||
|
dataButton(
|
||||||
|
"Send video notes${permissions.canSendVideoNotes.allowedSymbol()}",
|
||||||
|
videoNotesToggleGranularData
|
||||||
|
)
|
||||||
|
}
|
||||||
|
row {
|
||||||
|
dataButton("Send photos${permissions.canSendPhotos.allowedSymbol()}", photosToggleGranularData)
|
||||||
|
dataButton(
|
||||||
|
"Add web preview${permissions.canAddWebPagePreviews.allowedSymbol()}",
|
||||||
|
webPagePreviewToggleGranularData
|
||||||
|
)
|
||||||
|
}
|
||||||
|
row {
|
||||||
|
dataButton("Send polls${permissions.canSendPolls.allowedSymbol()}", pollsToggleGranularData)
|
||||||
|
dataButton("Send documents${permissions.canSendDocuments.allowedSymbol()}", documentsToggleGranularData)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
fun buildAdminRightsKeyboard(
|
||||||
|
permissions: AdministratorChatMember?,
|
||||||
|
channelId: ChatId,
|
||||||
|
userId: UserId
|
||||||
|
): InlineKeyboardMarkup {
|
||||||
|
return inlineKeyboard {
|
||||||
|
permissions ?.also {
|
||||||
|
row {
|
||||||
|
dataButton("Refresh", "$refreshAdminRightsData ${channelId.chatId} ${userId.chatId}")
|
||||||
|
}
|
||||||
|
row {
|
||||||
|
dataButton("Edit messages${permissions.canEditMessages.allowedSymbol()}", "$editMessagesToggleAdminRightsData ${channelId.chatId} ${userId.chatId}")
|
||||||
|
dataButton("Delete messages${permissions.canRemoveMessages.allowedSymbol()}", "$deleteMessagesToggleAdminRightsData ${channelId.chatId} ${userId.chatId}")
|
||||||
|
}
|
||||||
|
row {
|
||||||
|
dataButton("Post messages${permissions.canPostMessages.allowedSymbol()}", "$postMessagesToggleAdminRightsData ${channelId.chatId} ${userId.chatId}")
|
||||||
|
}
|
||||||
|
row {
|
||||||
|
dataButton("Edit stories${permissions.canEditStories.allowedSymbol()}", "$editStoriesToggleAdminRightsData ${channelId.chatId} ${userId.chatId}")
|
||||||
|
dataButton("Delete stories${permissions.canDeleteStories.allowedSymbol()}", "$deleteStoriesToggleAdminRightsData ${channelId.chatId} ${userId.chatId}")
|
||||||
|
}
|
||||||
|
row {
|
||||||
|
dataButton("Post stories${permissions.canPostStories.allowedSymbol()}", "$postStoriesToggleAdminRightsData ${channelId.chatId} ${userId.chatId}")
|
||||||
|
}
|
||||||
|
} ?: row {
|
||||||
|
dataButton("Promote to admin", "$postMessagesToggleAdminRightsData ${channelId.chatId} ${userId.chatId}")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
suspend fun BehaviourContext.buildGranularKeyboard(chatId: ChatId, userId: UserId): InlineKeyboardMarkup? {
|
||||||
|
return buildGranularKeyboard(
|
||||||
|
getUserChatPermissions(chatId, userId) ?: return null
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
suspend fun BehaviourContext.buildCommonKeyboard(chatId: ChatId, userId: UserId): InlineKeyboardMarkup? {
|
||||||
|
val permissions = getUserChatPermissions(chatId, userId) ?: return null
|
||||||
|
|
||||||
|
return inlineKeyboard {
|
||||||
|
row {
|
||||||
|
dataButton("Send polls${permissions.canSendPolls.allowedSymbol()}", pollsToggleCommonData)
|
||||||
|
}
|
||||||
|
row {
|
||||||
|
dataButton("Send other messages${permissions.canSendOtherMessages.allowedSymbol()}", otherMessagesToggleCommonData)
|
||||||
|
}
|
||||||
|
row {
|
||||||
|
dataButton("Add web preview${permissions.canAddWebPagePreviews.allowedSymbol()}", webPagePreviewToggleCommonData)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bot.buildBehaviourWithFSMAndStartLongPolling<UserRetrievingStep>(
|
||||||
|
defaultExceptionsHandler = {
|
||||||
|
it.printStackTrace()
|
||||||
|
},
|
||||||
|
) {
|
||||||
|
onCommand(
|
||||||
|
"simple",
|
||||||
|
initialFilter = { it.chat is PublicChat && it.fromUserMessageOrNull()?.user?.id == allowedAdmin }
|
||||||
|
) {
|
||||||
|
val replyMessage = it.replyTo
|
||||||
|
val userInReply = replyMessage?.fromUserMessageOrNull()?.user?.id ?: return@onCommand
|
||||||
|
if (replyMessage is AccessibleMessage) {
|
||||||
|
reply(
|
||||||
|
replyMessage,
|
||||||
|
"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(
|
||||||
|
"granular",
|
||||||
|
initialFilter = {
|
||||||
|
it.chat is ChannelChat || (it.chat is PublicChat && it.fromUserMessageOrNull()?.user?.id == allowedAdmin)
|
||||||
|
}
|
||||||
|
) {
|
||||||
|
val replyMessage = it.replyTo
|
||||||
|
val usernameInText = it.content.textSources.firstNotNullOfOrNull { it.mentionTextSourceOrNull() } ?.username
|
||||||
|
val userInReply = replyMessage?.fromUserMessageOrNull()?.user?.id ?: return@onCommand
|
||||||
|
|
||||||
|
if (replyMessage is AccessibleMessage) {
|
||||||
|
reply(
|
||||||
|
replyMessage,
|
||||||
|
"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(
|
||||||
|
Regex("^${granularDataPrefix}.*"),
|
||||||
|
initialFilter = { it.user.id == allowedAdmin }
|
||||||
|
) {
|
||||||
|
val messageReply =
|
||||||
|
it.message.commonMessageOrNull()?.replyTo?.fromUserMessageOrNull() ?: return@onMessageDataCallbackQuery
|
||||||
|
val userId = messageReply.user.id
|
||||||
|
val permissions =
|
||||||
|
getUserChatPermissions(it.message.chat.id.toChatId(), userId) ?: return@onMessageDataCallbackQuery
|
||||||
|
val newPermission = when (it.data) {
|
||||||
|
messagesToggleGranularData -> {
|
||||||
|
permissions.copyGranular(
|
||||||
|
canSendMessages = permissions.canSendMessages?.let { !it } ?: false
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
otherMessagesToggleGranularData -> {
|
||||||
|
permissions.copyGranular(
|
||||||
|
canSendOtherMessages = permissions.canSendOtherMessages?.let { !it } ?: false
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
audiosToggleGranularData -> {
|
||||||
|
permissions.copyGranular(
|
||||||
|
canSendAudios = permissions.canSendAudios?.let { !it } ?: false
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
voicesToggleGranularData -> {
|
||||||
|
permissions.copyGranular(
|
||||||
|
canSendVoiceNotes = permissions.canSendVoiceNotes?.let { !it } ?: false
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
videosToggleGranularData -> {
|
||||||
|
permissions.copyGranular(
|
||||||
|
canSendVideos = permissions.canSendVideos?.let { !it } ?: false
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
videoNotesToggleGranularData -> {
|
||||||
|
permissions.copyGranular(
|
||||||
|
canSendVideoNotes = permissions.canSendVideoNotes?.let { !it } ?: false
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
photosToggleGranularData -> {
|
||||||
|
permissions.copyGranular(
|
||||||
|
canSendPhotos = permissions.canSendPhotos?.let { !it } ?: false
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
webPagePreviewToggleGranularData -> {
|
||||||
|
permissions.copyGranular(
|
||||||
|
canAddWebPagePreviews = permissions.canAddWebPagePreviews?.let { !it } ?: false
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
pollsToggleGranularData -> {
|
||||||
|
permissions.copyGranular(
|
||||||
|
canSendPolls = permissions.canSendPolls?.let { !it } ?: false
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
documentsToggleGranularData -> {
|
||||||
|
permissions.copyGranular(
|
||||||
|
canSendDocuments = permissions.canSendDocuments?.let { !it } ?: false
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
else -> permissions.copyGranular()
|
||||||
|
}
|
||||||
|
|
||||||
|
restrictChatMember(
|
||||||
|
it.message.chat.id,
|
||||||
|
userId,
|
||||||
|
permissions = newPermission,
|
||||||
|
useIndependentChatPermissions = true
|
||||||
|
)
|
||||||
|
|
||||||
|
edit(
|
||||||
|
it.message,
|
||||||
|
replyMarkup = buildGranularKeyboard(it.message.chat.id.toChatId(), userId)
|
||||||
|
?: return@onMessageDataCallbackQuery
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
onMessageDataCallbackQuery(
|
||||||
|
Regex("^${commonDataPrefix}.*"),
|
||||||
|
initialFilter = { it.user.id == allowedAdmin }
|
||||||
|
) {
|
||||||
|
val messageReply =
|
||||||
|
it.message.commonMessageOrNull()?.replyTo?.fromUserMessageOrNull() ?: return@onMessageDataCallbackQuery
|
||||||
|
val userId = messageReply.user.id
|
||||||
|
val permissions =
|
||||||
|
getUserChatPermissions(it.message.chat.id.toChatId(), userId) ?: return@onMessageDataCallbackQuery
|
||||||
|
val newPermission = when (it.data) {
|
||||||
|
pollsToggleCommonData -> {
|
||||||
|
permissions.copyCommon(
|
||||||
|
canSendPolls = permissions.canSendPolls?.let { !it } ?: false
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
otherMessagesToggleCommonData -> {
|
||||||
|
permissions.copyCommon(
|
||||||
|
canSendOtherMessages = permissions.canSendOtherMessages?.let { !it } ?: false
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
webPagePreviewToggleCommonData -> {
|
||||||
|
permissions.copyCommon(
|
||||||
|
canAddWebPagePreviews = permissions.canAddWebPagePreviews?.let { !it } ?: false
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
else -> permissions.copyCommon()
|
||||||
|
}
|
||||||
|
|
||||||
|
restrictChatMember(
|
||||||
|
it.message.chat.id,
|
||||||
|
userId,
|
||||||
|
permissions = newPermission,
|
||||||
|
useIndependentChatPermissions = false
|
||||||
|
)
|
||||||
|
|
||||||
|
edit(
|
||||||
|
it.message,
|
||||||
|
replyMarkup = buildCommonKeyboard(it.message.chat.id.toChatId(), userId)
|
||||||
|
?: return@onMessageDataCallbackQuery
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
onMessageDataCallbackQuery(
|
||||||
|
Regex("^${adminRightsDataPrefix}.*"),
|
||||||
|
initialFilter = { it.user.id == allowedAdmin }
|
||||||
|
) {
|
||||||
|
val (channelIdString, userIdString) = it.data.split(" ").drop(1)
|
||||||
|
val channelId = ChatId(channelIdString.toLong())
|
||||||
|
val userId = ChatId(userIdString.toLong())
|
||||||
|
val chatMember = getChatMember(channelId, userId)
|
||||||
|
val asAdmin = chatMember.administratorChatMemberOrNull()
|
||||||
|
val asMember = chatMember.memberChatMemberOrNull()
|
||||||
|
|
||||||
|
val realData = it.data.takeWhile { it != ' ' }
|
||||||
|
|
||||||
|
fun Boolean?.toggleIfData(data: String) = if (realData == data) {
|
||||||
|
!(this ?: false)
|
||||||
|
} else {
|
||||||
|
null
|
||||||
|
}
|
||||||
|
|
||||||
|
if (realData != refreshAdminRightsData) {
|
||||||
|
promoteChannelAdministrator(
|
||||||
|
channelId,
|
||||||
|
userId,
|
||||||
|
canPostMessages = asAdmin ?.canPostMessages.toggleIfData(postMessagesToggleAdminRightsData),
|
||||||
|
canEditMessages = asAdmin ?.canEditMessages.toggleIfData(editMessagesToggleAdminRightsData),
|
||||||
|
canDeleteMessages = asAdmin ?.canRemoveMessages.toggleIfData(deleteMessagesToggleAdminRightsData),
|
||||||
|
canEditStories = asAdmin ?.canEditStories.toggleIfData(editStoriesToggleAdminRightsData),
|
||||||
|
canDeleteStories = asAdmin ?.canDeleteStories.toggleIfData(deleteStoriesToggleAdminRightsData),
|
||||||
|
canPostStories = asAdmin ?.canPostStories.toggleIfData(postStoriesToggleAdminRightsData),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
edit(
|
||||||
|
it.message,
|
||||||
|
replyMarkup = buildAdminRightsKeyboard(
|
||||||
|
getChatMember(
|
||||||
|
channelId,
|
||||||
|
userId
|
||||||
|
).administratorChatMemberOrNull(),
|
||||||
|
channelId,
|
||||||
|
userId
|
||||||
|
)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
strictlyOn<UserRetrievingStep.RetrievingChannelChatState> { state ->
|
||||||
|
val requestId = RequestId.random()
|
||||||
|
send(
|
||||||
|
state.context,
|
||||||
|
replyMarkup = replyKeyboard(
|
||||||
|
oneTimeKeyboard = true,
|
||||||
|
resizeKeyboard = true
|
||||||
|
) {
|
||||||
|
row {
|
||||||
|
requestChatButton(
|
||||||
|
"Choose channel",
|
||||||
|
requestId = requestId,
|
||||||
|
isChannel = true,
|
||||||
|
botIsMember = true,
|
||||||
|
botRightsInChat = ChatCommonAdministratorRights(
|
||||||
|
canPromoteMembers = true,
|
||||||
|
canRestrictMembers = true
|
||||||
|
),
|
||||||
|
userRightsInChat = ChatCommonAdministratorRights(
|
||||||
|
canPromoteMembers = true,
|
||||||
|
canRestrictMembers = true
|
||||||
|
)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
) {
|
||||||
|
regular("Ok, send me the channel in which you wish to manage user, or use ")
|
||||||
|
botCommand("cancel")
|
||||||
|
regular(" to cancel the request")
|
||||||
|
}
|
||||||
|
firstOf {
|
||||||
|
include {
|
||||||
|
val chatId = waitChatSharedEventsMessages().mapNotNull {
|
||||||
|
it.chatEvent.chatId.takeIf { _ ->
|
||||||
|
it.chatEvent.requestId == requestId && it.sameChat(state.context)
|
||||||
|
}
|
||||||
|
}.first()
|
||||||
|
UserRetrievingStep.RetrievingUserIdChatState(state.context, chatId)
|
||||||
|
}
|
||||||
|
include {
|
||||||
|
waitCommandMessage("cancel").filter { it.sameChat(state.context) }.first()
|
||||||
|
null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
strictlyOn<UserRetrievingStep.RetrievingUserIdChatState> { state ->
|
||||||
|
val requestId = RequestId.random()
|
||||||
|
send(
|
||||||
|
state.context,
|
||||||
|
replyMarkup = replyKeyboard(
|
||||||
|
oneTimeKeyboard = true,
|
||||||
|
resizeKeyboard = true
|
||||||
|
) {
|
||||||
|
row {
|
||||||
|
requestUserButton(
|
||||||
|
"Choose user",
|
||||||
|
requestId = requestId
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
) {
|
||||||
|
regular("Ok, send me the user for which you wish to change rights, or use ")
|
||||||
|
botCommand("cancel")
|
||||||
|
regular(" to cancel the request")
|
||||||
|
}
|
||||||
|
|
||||||
|
firstOf {
|
||||||
|
include {
|
||||||
|
val userContactChatId = waitUserSharedEventsMessages().filter {
|
||||||
|
it.sameChat(state.context)
|
||||||
|
}.first().chatEvent.chatId
|
||||||
|
UserRetrievingStep.RetrievingChatInfoDoneState(
|
||||||
|
state.context,
|
||||||
|
state.channelId,
|
||||||
|
userContactChatId
|
||||||
|
)
|
||||||
|
}
|
||||||
|
include {
|
||||||
|
waitCommandMessage("cancel").filter { it.sameChat(state.context) }.first()
|
||||||
|
null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
strictlyOn<UserRetrievingStep.RetrievingChatInfoDoneState> { state ->
|
||||||
|
val chatMember = getChatMember(state.channelId, state.userId).administratorChatMemberOrNull()
|
||||||
|
if (chatMember == null) {
|
||||||
|
|
||||||
|
return@strictlyOn null
|
||||||
|
}
|
||||||
|
send(
|
||||||
|
state.context,
|
||||||
|
replyMarkup = buildAdminRightsKeyboard(
|
||||||
|
chatMember,
|
||||||
|
state.channelId,
|
||||||
|
state.userId
|
||||||
|
)
|
||||||
|
) {
|
||||||
|
regular("Rights of ")
|
||||||
|
mentionln(chatMember.user)
|
||||||
|
regular("Please, remember, that to be able to change user rights bot must promote user by itself to admin")
|
||||||
|
}
|
||||||
|
null
|
||||||
|
}
|
||||||
|
|
||||||
|
onCommand("rights_in_channel") {
|
||||||
|
startChain(UserRetrievingStep.RetrievingChannelChatState(it.chat.id.toChatId()))
|
||||||
|
}
|
||||||
|
|
||||||
|
setMyCommands(
|
||||||
|
BotCommand("simple", "Trigger simple keyboard. Use with reply to user"),
|
||||||
|
BotCommand("granular", "Trigger granular keyboard. Use with reply to user"),
|
||||||
|
BotCommand("rights_in_channel", "Trigger granular keyboard. Use with reply to user"),
|
||||||
|
scope = BotCommandScope.AllGroupChats
|
||||||
|
)
|
||||||
|
}.join()
|
||||||
|
}
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
buildscript {
|
buildscript {
|
||||||
repositories {
|
repositories {
|
||||||
jcenter()
|
mavenCentral()
|
||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
@@ -15,7 +15,7 @@ mainClassName="SlotMachineDetectorBotKt"
|
|||||||
|
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$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"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,35 +1,26 @@
|
|||||||
import dev.inmo.micro_utils.coroutines.safely
|
import dev.inmo.tgbotapi.bot.ktor.telegramBot
|
||||||
import dev.inmo.tgbotapi.bot.Ktor.telegramBot
|
|
||||||
import dev.inmo.tgbotapi.extensions.api.send.reply
|
import dev.inmo.tgbotapi.extensions.api.send.reply
|
||||||
|
import dev.inmo.tgbotapi.extensions.behaviour_builder.buildBehaviourWithLongPolling
|
||||||
|
import dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling.onDice
|
||||||
import dev.inmo.tgbotapi.extensions.utils.*
|
import dev.inmo.tgbotapi.extensions.utils.*
|
||||||
import dev.inmo.tgbotapi.extensions.utils.shortcuts.filterContentMessages
|
|
||||||
import dev.inmo.tgbotapi.extensions.utils.updates.retrieving.longPolling
|
|
||||||
import dev.inmo.tgbotapi.types.dice.SlotMachineDiceAnimationType
|
import dev.inmo.tgbotapi.types.dice.SlotMachineDiceAnimationType
|
||||||
import dev.inmo.tgbotapi.types.message.content.DiceContent
|
|
||||||
import kotlinx.coroutines.*
|
import kotlinx.coroutines.*
|
||||||
import kotlinx.coroutines.flow.launchIn
|
|
||||||
import kotlinx.coroutines.flow.onEach
|
|
||||||
|
|
||||||
suspend fun main(args: Array<String>) {
|
suspend fun main(args: Array<String>) {
|
||||||
val bot = telegramBot(args.first())
|
val bot = telegramBot(args.first())
|
||||||
|
|
||||||
val scope = CoroutineScope(Dispatchers.Default)
|
bot.buildBehaviourWithLongPolling(scope = CoroutineScope(Dispatchers.IO)) {
|
||||||
bot.longPolling(scope = scope) {
|
onDice {
|
||||||
filterContentMessages<DiceContent>(scope).onEach {
|
|
||||||
val content = it.content
|
val content = it.content
|
||||||
val dice = content.dice
|
val dice = content.dice
|
||||||
val diceType = dice.animationType
|
val diceType = dice.animationType
|
||||||
|
|
||||||
safely ({ it.printStackTrace() }) {
|
if (diceType == SlotMachineDiceAnimationType) {
|
||||||
if (diceType == SlotMachineDiceAnimationType) {
|
val result = dice.calculateSlotMachineResult() ?: return@onDice
|
||||||
val result = dice.calculateSlotMachineResult() ?: return@safely
|
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")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}.launchIn(scope)
|
}
|
||||||
}
|
}.join()
|
||||||
|
}
|
||||||
scope.coroutineContext[Job]!!.join()
|
|
||||||
}
|
|
||||||
|
|||||||
33
StickerInfoBot/StickerInfoBotLib/build.gradle
Normal file
33
StickerInfoBot/StickerInfoBotLib/build.gradle
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
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"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,93 @@
|
|||||||
|
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.*
|
||||||
|
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.types.StickerFormat
|
||||||
|
import dev.inmo.tgbotapi.types.StickerType
|
||||||
|
import dev.inmo.tgbotapi.types.message.textsources.*
|
||||||
|
import dev.inmo.tgbotapi.types.stickers.AnimatedStickerSet
|
||||||
|
import dev.inmo.tgbotapi.types.stickers.CustomEmojiSimpleStickerSet
|
||||||
|
import dev.inmo.tgbotapi.types.stickers.CustomEmojiStickerSet
|
||||||
|
import dev.inmo.tgbotapi.types.stickers.CustomEmojiVideoStickerSet
|
||||||
|
import dev.inmo.tgbotapi.types.stickers.MaskSimpleStickerSet
|
||||||
|
import dev.inmo.tgbotapi.types.stickers.MaskStickerSet
|
||||||
|
import dev.inmo.tgbotapi.types.stickers.MaskVideoStickerSet
|
||||||
|
import dev.inmo.tgbotapi.types.stickers.RegularSimpleStickerSet
|
||||||
|
import dev.inmo.tgbotapi.types.stickers.RegularStickerSet
|
||||||
|
import dev.inmo.tgbotapi.types.stickers.RegularVideoStickerSet
|
||||||
|
import dev.inmo.tgbotapi.types.stickers.StickerSet
|
||||||
|
import dev.inmo.tgbotapi.types.stickers.UnknownStickerSet
|
||||||
|
import dev.inmo.tgbotapi.utils.bold
|
||||||
|
import dev.inmo.tgbotapi.utils.buildEntities
|
||||||
|
import kotlinx.coroutines.*
|
||||||
|
|
||||||
|
fun StickerSet?.buildInfo() = buildEntities {
|
||||||
|
if (this@buildInfo == null) {
|
||||||
|
bold("Looks like this stickerset has been removed")
|
||||||
|
} else {
|
||||||
|
bold("StickerSet name: ") + "${name}\n"
|
||||||
|
bold("StickerSet title: ") + "${title}\n"
|
||||||
|
bold("Sticker format: ") + when (stickerFormat) {
|
||||||
|
StickerFormat.Animated -> "Animated"
|
||||||
|
StickerFormat.Static -> "Static"
|
||||||
|
is StickerFormat.Unknown -> stickerFormat.type
|
||||||
|
StickerFormat.Video -> "Video"
|
||||||
|
} + "\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 = getStickerSetOrNull(it.content.media)
|
||||||
|
reply(
|
||||||
|
it,
|
||||||
|
stickerSetInfo.buildInfo()
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
allUpdatesFlow.subscribeSafelyWithoutExceptions(this) {
|
||||||
|
println(it)
|
||||||
|
}
|
||||||
|
}.join()
|
||||||
|
}
|
||||||
@@ -0,0 +1,32 @@
|
|||||||
|
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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
<!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>
|
||||||
21
StickerInfoBot/jvm_launcher/build.gradle
Normal file
21
StickerInfoBot/jvm_launcher/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="StickerInfoBotJvmKt"
|
||||||
|
|
||||||
|
|
||||||
|
dependencies {
|
||||||
|
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
|
||||||
|
|
||||||
|
implementation project(":StickerInfoBot:StickerInfoBotLib")
|
||||||
|
}
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
suspend fun main(args: Array<String>) {
|
||||||
|
activateStickerInfoBot(args.first()) {
|
||||||
|
println(it)
|
||||||
|
}
|
||||||
|
}
|
||||||
9
StickerSetHandler/README.md
Normal file
9
StickerSetHandler/README.md
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
# StickerSetHandler
|
||||||
|
|
||||||
|
Send sticker to this bot to form your own stickers set. Send /delete to delete this sticker set
|
||||||
|
|
||||||
|
## How to run
|
||||||
|
|
||||||
|
```bash
|
||||||
|
./gradlew run --args="TOKEN"
|
||||||
|
```
|
||||||
21
StickerSetHandler/build.gradle
Normal file
21
StickerSetHandler/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="StickerSetHandlerBotKt"
|
||||||
|
|
||||||
|
|
||||||
|
dependencies {
|
||||||
|
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
|
||||||
|
|
||||||
|
implementation "dev.inmo:tgbotapi:$telegram_bot_api_version"
|
||||||
|
}
|
||||||
101
StickerSetHandler/src/main/kotlin/StickerSetHandlerBot.kt
Normal file
101
StickerSetHandler/src/main/kotlin/StickerSetHandlerBot.kt
Normal file
@@ -0,0 +1,101 @@
|
|||||||
|
import dev.inmo.micro_utils.coroutines.runCatchingSafely
|
||||||
|
import dev.inmo.tgbotapi.extensions.api.bot.getMe
|
||||||
|
import dev.inmo.tgbotapi.extensions.api.files.downloadFile
|
||||||
|
import dev.inmo.tgbotapi.extensions.api.files.downloadFileToTemp
|
||||||
|
import dev.inmo.tgbotapi.extensions.api.get.getStickerSet
|
||||||
|
import dev.inmo.tgbotapi.extensions.api.send.reply
|
||||||
|
import dev.inmo.tgbotapi.extensions.api.stickers.addStickerToSet
|
||||||
|
import dev.inmo.tgbotapi.extensions.api.stickers.createNewStickerSet
|
||||||
|
import dev.inmo.tgbotapi.extensions.api.stickers.deleteStickerSet
|
||||||
|
import dev.inmo.tgbotapi.extensions.behaviour_builder.telegramBotWithBehaviourAndLongPolling
|
||||||
|
import dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling.onCommand
|
||||||
|
import dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling.onSticker
|
||||||
|
import dev.inmo.tgbotapi.extensions.utils.extensions.raw.sticker
|
||||||
|
import dev.inmo.tgbotapi.requests.abstracts.asMultipartFile
|
||||||
|
import dev.inmo.tgbotapi.requests.stickers.InputSticker
|
||||||
|
import dev.inmo.tgbotapi.types.chat.Chat
|
||||||
|
import dev.inmo.tgbotapi.types.files.*
|
||||||
|
import dev.inmo.tgbotapi.types.toChatId
|
||||||
|
import dev.inmo.tgbotapi.utils.botCommand
|
||||||
|
import kotlinx.coroutines.CoroutineScope
|
||||||
|
import kotlinx.coroutines.Dispatchers
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Send sticker to this bot to form your own stickers set. Send /delete to delete this sticker set
|
||||||
|
*/
|
||||||
|
suspend fun main(args: Array<String>) {
|
||||||
|
telegramBotWithBehaviourAndLongPolling(
|
||||||
|
args.first(),
|
||||||
|
scope = CoroutineScope(Dispatchers.IO),
|
||||||
|
defaultExceptionsHandler = {
|
||||||
|
it.printStackTrace()
|
||||||
|
}
|
||||||
|
) {
|
||||||
|
val me = getMe()
|
||||||
|
fun Chat.stickerSetName() = "s${id.chatId}_by_${me.username ?.usernameWithoutAt}"
|
||||||
|
onCommand("start") {
|
||||||
|
reply(it) {
|
||||||
|
botCommand("delete") + " - to clear stickers"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
onCommand("delete") {
|
||||||
|
val deleted = runCatchingSafely {
|
||||||
|
deleteStickerSet(it.chat.stickerSetName())
|
||||||
|
}.getOrElse { false }
|
||||||
|
|
||||||
|
if (deleted) {
|
||||||
|
reply(it, "Deleted")
|
||||||
|
} else {
|
||||||
|
reply(it, "Can't delete for some of reason")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
onSticker {
|
||||||
|
val stickerSetName = it.chat.stickerSetName()
|
||||||
|
val sticker = it.content.media
|
||||||
|
val newSticker = when (sticker) {
|
||||||
|
is CustomEmojiSticker -> InputSticker.WithKeywords.CustomEmoji(
|
||||||
|
downloadFileToTemp(sticker.fileId).asMultipartFile(),
|
||||||
|
listOf(sticker.emoji ?: "\uD83D\uDE0A"),
|
||||||
|
emptyList()
|
||||||
|
)
|
||||||
|
is MaskSticker -> InputSticker.Mask(
|
||||||
|
downloadFileToTemp(sticker.fileId).asMultipartFile(),
|
||||||
|
listOf(sticker.emoji ?: "\uD83D\uDE0A"),
|
||||||
|
sticker.maskPosition
|
||||||
|
)
|
||||||
|
is RegularSticker -> InputSticker.WithKeywords.Regular(
|
||||||
|
downloadFileToTemp(sticker.fileId).asMultipartFile(),
|
||||||
|
listOf(sticker.emoji ?: "\uD83D\uDE0A"),
|
||||||
|
emptyList()
|
||||||
|
)
|
||||||
|
is UnknownSticker -> return@onSticker
|
||||||
|
}
|
||||||
|
runCatchingSafely {
|
||||||
|
getStickerSet(stickerSetName)
|
||||||
|
}.onSuccess { stickerSet ->
|
||||||
|
addStickerToSet(it.chat.id.toChatId(), stickerSet.name, newSticker).also { _ ->
|
||||||
|
reply(
|
||||||
|
it,
|
||||||
|
getStickerSet(stickerSetName).stickers.last()
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}.onFailure { _ ->
|
||||||
|
createNewStickerSet(
|
||||||
|
it.chat.id.toChatId(),
|
||||||
|
stickerSetName,
|
||||||
|
"Sticker set by ${me.firstName}",
|
||||||
|
it.content.media.stickerFormat,
|
||||||
|
listOf(
|
||||||
|
newSticker
|
||||||
|
),
|
||||||
|
(sticker as? CustomEmojiSticker) ?.needsRepainting ?: false
|
||||||
|
).also { _ ->
|
||||||
|
reply(
|
||||||
|
it,
|
||||||
|
getStickerSet(stickerSetName).stickers.first()
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}.second.join()
|
||||||
|
}
|
||||||
9
TopicsHandling/README.md
Normal file
9
TopicsHandling/README.md
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
# HelloBot
|
||||||
|
|
||||||
|
The main purpose of this bot is just to answer "Oh, hi, " and add user mention here
|
||||||
|
|
||||||
|
## Launch
|
||||||
|
|
||||||
|
```bash
|
||||||
|
../gradlew run --args="BOT_TOKEN"
|
||||||
|
```
|
||||||
21
TopicsHandling/build.gradle
Normal file
21
TopicsHandling/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="TopicsHandlingKt"
|
||||||
|
|
||||||
|
|
||||||
|
dependencies {
|
||||||
|
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
|
||||||
|
|
||||||
|
implementation "dev.inmo:tgbotapi:$telegram_bot_api_version"
|
||||||
|
}
|
||||||
145
TopicsHandling/src/main/kotlin/TopicsHandling.kt
Normal file
145
TopicsHandling/src/main/kotlin/TopicsHandling.kt
Normal file
@@ -0,0 +1,145 @@
|
|||||||
|
import com.benasher44.uuid.uuid4
|
||||||
|
import dev.inmo.micro_utils.common.repeatOnFailure
|
||||||
|
import dev.inmo.micro_utils.coroutines.runCatchingSafely
|
||||||
|
import dev.inmo.micro_utils.coroutines.subscribeSafelyWithoutExceptions
|
||||||
|
import dev.inmo.tgbotapi.extensions.api.bot.setMyCommands
|
||||||
|
import dev.inmo.tgbotapi.extensions.api.chat.forum.closeForumTopic
|
||||||
|
import dev.inmo.tgbotapi.extensions.api.chat.forum.closeGeneralForumTopic
|
||||||
|
import dev.inmo.tgbotapi.extensions.api.chat.forum.createForumTopic
|
||||||
|
import dev.inmo.tgbotapi.extensions.api.chat.forum.deleteForumTopic
|
||||||
|
import dev.inmo.tgbotapi.extensions.api.chat.forum.editForumTopic
|
||||||
|
import dev.inmo.tgbotapi.extensions.api.chat.forum.editGeneralForumTopic
|
||||||
|
import dev.inmo.tgbotapi.extensions.api.chat.forum.hideGeneralForumTopic
|
||||||
|
import dev.inmo.tgbotapi.extensions.api.chat.forum.reopenForumTopic
|
||||||
|
import dev.inmo.tgbotapi.extensions.api.chat.forum.reopenGeneralForumTopic
|
||||||
|
import dev.inmo.tgbotapi.extensions.api.chat.forum.unhideGeneralForumTopic
|
||||||
|
import dev.inmo.tgbotapi.extensions.api.send.reply
|
||||||
|
import dev.inmo.tgbotapi.extensions.behaviour_builder.telegramBotWithBehaviourAndLongPolling
|
||||||
|
import dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling.onCommand
|
||||||
|
import dev.inmo.tgbotapi.extensions.utils.updates.retrieving.flushAccumulatedUpdates
|
||||||
|
import dev.inmo.tgbotapi.types.BotCommand
|
||||||
|
import dev.inmo.tgbotapi.types.ForumTopic
|
||||||
|
import dev.inmo.tgbotapi.types.commands.BotCommandScope
|
||||||
|
import kotlinx.coroutines.CoroutineScope
|
||||||
|
import kotlinx.coroutines.Dispatchers
|
||||||
|
import kotlinx.coroutines.delay
|
||||||
|
|
||||||
|
suspend fun main(vararg args: String) {
|
||||||
|
telegramBotWithBehaviourAndLongPolling(
|
||||||
|
args.first(),
|
||||||
|
CoroutineScope(Dispatchers.Default),
|
||||||
|
defaultExceptionsHandler = {
|
||||||
|
it.printStackTrace()
|
||||||
|
}
|
||||||
|
) {
|
||||||
|
flushAccumulatedUpdates()
|
||||||
|
allUpdatesFlow.subscribeSafelyWithoutExceptions(this) {
|
||||||
|
println(it)
|
||||||
|
}
|
||||||
|
onCommand("start_test_topics") {
|
||||||
|
val forumTopic = createForumTopic(
|
||||||
|
it.chat,
|
||||||
|
"Test",
|
||||||
|
ForumTopic.GREEN
|
||||||
|
)
|
||||||
|
|
||||||
|
reply(it, "Test topic has been created")
|
||||||
|
|
||||||
|
delay(1000L)
|
||||||
|
editForumTopic(
|
||||||
|
it.chat.id,
|
||||||
|
forumTopic.messageThreadId,
|
||||||
|
"Test 01"
|
||||||
|
)
|
||||||
|
|
||||||
|
reply(it, "Test topic has changed its name to Test 01")
|
||||||
|
|
||||||
|
delay(1000L)
|
||||||
|
closeForumTopic(
|
||||||
|
it.chat.id,
|
||||||
|
forumTopic.messageThreadId,
|
||||||
|
)
|
||||||
|
|
||||||
|
reply(it, "Test topic has been closed")
|
||||||
|
|
||||||
|
delay(1000L)
|
||||||
|
reopenForumTopic(
|
||||||
|
it.chat.id,
|
||||||
|
forumTopic.messageThreadId,
|
||||||
|
)
|
||||||
|
|
||||||
|
reply(it, "Test topic has been reopened")
|
||||||
|
|
||||||
|
delay(1000L)
|
||||||
|
deleteForumTopic(
|
||||||
|
it.chat.id,
|
||||||
|
forumTopic.messageThreadId,
|
||||||
|
)
|
||||||
|
|
||||||
|
reply(it, "Test topic has been deleted")
|
||||||
|
|
||||||
|
delay(1000L)
|
||||||
|
hideGeneralForumTopic(
|
||||||
|
it.chat.id,
|
||||||
|
)
|
||||||
|
|
||||||
|
reply(it, "General topic has been hidden")
|
||||||
|
|
||||||
|
delay(1000L)
|
||||||
|
unhideGeneralForumTopic(
|
||||||
|
it.chat.id
|
||||||
|
)
|
||||||
|
|
||||||
|
reply(it, "General topic has been shown")
|
||||||
|
|
||||||
|
delay(1000L)
|
||||||
|
runCatchingSafely(
|
||||||
|
{ _ ->
|
||||||
|
reopenGeneralForumTopic(
|
||||||
|
it.chat.id
|
||||||
|
)
|
||||||
|
|
||||||
|
closeGeneralForumTopic(
|
||||||
|
it.chat.id
|
||||||
|
)
|
||||||
|
}
|
||||||
|
) {
|
||||||
|
closeGeneralForumTopic(
|
||||||
|
it.chat.id
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
reply(it, "General topic has been closed")
|
||||||
|
|
||||||
|
delay(1000L)
|
||||||
|
reopenGeneralForumTopic(
|
||||||
|
it.chat.id
|
||||||
|
)
|
||||||
|
|
||||||
|
reply(it, "General topic has been opened")
|
||||||
|
|
||||||
|
delay(1000L)
|
||||||
|
editGeneralForumTopic(
|
||||||
|
it.chat.id,
|
||||||
|
uuid4().toString().take(10)
|
||||||
|
)
|
||||||
|
|
||||||
|
reply(it, "General topic has been renamed")
|
||||||
|
|
||||||
|
delay(1000L)
|
||||||
|
editGeneralForumTopic(
|
||||||
|
it.chat.id,
|
||||||
|
"Main topic"
|
||||||
|
)
|
||||||
|
|
||||||
|
reply(it, "General topic has been renamed")
|
||||||
|
|
||||||
|
delay(1000L)
|
||||||
|
}
|
||||||
|
|
||||||
|
setMyCommands(
|
||||||
|
BotCommand("start_test_topics", "start test topics"),
|
||||||
|
scope = BotCommandScope.AllGroupChats
|
||||||
|
)
|
||||||
|
}.second.join()
|
||||||
|
}
|
||||||
9
UserChatShared/README.md
Normal file
9
UserChatShared/README.md
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
# UserChatShared
|
||||||
|
|
||||||
|
Use `/start` with bot to get request buttons. Bot will ask you to choose user/chat from your list and send it to him.
|
||||||
|
|
||||||
|
## Launch
|
||||||
|
|
||||||
|
```bash
|
||||||
|
../gradlew run --args="BOT_TOKEN"
|
||||||
|
```
|
||||||
21
UserChatShared/build.gradle
Normal file
21
UserChatShared/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="UserChatSharedKt"
|
||||||
|
|
||||||
|
|
||||||
|
dependencies {
|
||||||
|
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
|
||||||
|
|
||||||
|
implementation "dev.inmo:tgbotapi:$telegram_bot_api_version"
|
||||||
|
}
|
||||||
254
UserChatShared/src/main/kotlin/UserChatShared.kt
Normal file
254
UserChatShared/src/main/kotlin/UserChatShared.kt
Normal file
@@ -0,0 +1,254 @@
|
|||||||
|
import dev.inmo.micro_utils.coroutines.runCatchingSafely
|
||||||
|
import dev.inmo.tgbotapi.bot.ktor.telegramBot
|
||||||
|
import dev.inmo.tgbotapi.extensions.api.bot.setMyCommands
|
||||||
|
import dev.inmo.tgbotapi.extensions.api.chat.get.getChat
|
||||||
|
import dev.inmo.tgbotapi.extensions.api.send.*
|
||||||
|
import dev.inmo.tgbotapi.extensions.behaviour_builder.buildBehaviourWithLongPolling
|
||||||
|
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.onUserShared
|
||||||
|
import dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling.onUsersShared
|
||||||
|
import dev.inmo.tgbotapi.extensions.utils.types.buttons.*
|
||||||
|
import dev.inmo.tgbotapi.types.BotCommand
|
||||||
|
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.request.RequestId
|
||||||
|
import dev.inmo.tgbotapi.utils.row
|
||||||
|
|
||||||
|
suspend fun main(args: Array<String>) {
|
||||||
|
val botToken = args.first()
|
||||||
|
|
||||||
|
val bot = telegramBot(botToken)
|
||||||
|
|
||||||
|
val requestIdUserOrBot = RequestId(0)
|
||||||
|
val requestIdUserNonPremium = RequestId(1)
|
||||||
|
val requestIdUserAny = RequestId(2)
|
||||||
|
val requestIdUserPremium = RequestId(3)
|
||||||
|
val requestIdBot = RequestId(4)
|
||||||
|
|
||||||
|
val requestIdUsersOrBots = RequestId(5)
|
||||||
|
val requestIdUsersNonPremium = RequestId(6)
|
||||||
|
val requestIdUsersAny = RequestId(7)
|
||||||
|
val requestIdUsersPremium = RequestId(8)
|
||||||
|
val requestIdBots = RequestId(9)
|
||||||
|
|
||||||
|
val requestIdAnyChat = RequestId(10)
|
||||||
|
val requestIdChannel = RequestId(11)
|
||||||
|
val requestIdPublicChannel = RequestId(12)
|
||||||
|
val requestIdPrivateChannel = RequestId(13)
|
||||||
|
val requestIdChannelUserOwner = RequestId(14)
|
||||||
|
|
||||||
|
val requestIdGroup = RequestId(15)
|
||||||
|
val requestIdPublicGroup = RequestId(16)
|
||||||
|
val requestIdPrivateGroup = 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(
|
||||||
|
resizeKeyboard = true,
|
||||||
|
) {
|
||||||
|
row {
|
||||||
|
requestUserOrBotButton(
|
||||||
|
"\uD83D\uDC64/\uD83E\uDD16 (1)",
|
||||||
|
requestIdUserOrBot
|
||||||
|
)
|
||||||
|
}
|
||||||
|
row {
|
||||||
|
requestUserButton(
|
||||||
|
"\uD83D\uDC64☆ (1)",
|
||||||
|
requestIdUserNonPremium,
|
||||||
|
premiumUser = false
|
||||||
|
)
|
||||||
|
requestUserButton(
|
||||||
|
"\uD83D\uDC64 (1)",
|
||||||
|
requestIdUserAny,
|
||||||
|
premiumUser = null
|
||||||
|
)
|
||||||
|
requestUserButton(
|
||||||
|
"\uD83D\uDC64★ (1)",
|
||||||
|
requestIdUserPremium,
|
||||||
|
premiumUser = true
|
||||||
|
)
|
||||||
|
requestBotButton(
|
||||||
|
"\uD83E\uDD16 (1)",
|
||||||
|
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 {
|
||||||
|
requestChatButton(
|
||||||
|
"\uD83D\uDDE3/\uD83D\uDC65",
|
||||||
|
requestIdAnyChat
|
||||||
|
)
|
||||||
|
}
|
||||||
|
row {
|
||||||
|
requestChatButton(
|
||||||
|
"\uD83D\uDDE3",
|
||||||
|
requestIdChannel,
|
||||||
|
isChannel = true
|
||||||
|
)
|
||||||
|
requestChatButton(
|
||||||
|
"\uD83D\uDDE3\uD83D\uDD17",
|
||||||
|
requestIdPublicChannel,
|
||||||
|
isChannel = true,
|
||||||
|
isPublic = true
|
||||||
|
)
|
||||||
|
requestChatButton(
|
||||||
|
"\uD83D\uDDE3❌\uD83D\uDD17",
|
||||||
|
requestIdPrivateChannel,
|
||||||
|
isChannel = true,
|
||||||
|
isPublic = false
|
||||||
|
)
|
||||||
|
requestChatButton(
|
||||||
|
"\uD83D\uDDE3\uD83D\uDC6E",
|
||||||
|
requestIdChannelUserOwner,
|
||||||
|
isChannel = true,
|
||||||
|
isOwnedBy = true
|
||||||
|
)
|
||||||
|
}
|
||||||
|
row {
|
||||||
|
requestGroupButton(
|
||||||
|
"👥",
|
||||||
|
requestIdGroup
|
||||||
|
)
|
||||||
|
requestGroupButton(
|
||||||
|
"👥\uD83D\uDD17",
|
||||||
|
requestIdPublicGroup,
|
||||||
|
isPublic = true
|
||||||
|
)
|
||||||
|
requestGroupButton(
|
||||||
|
"👥❌\uD83D\uDD17",
|
||||||
|
requestIdPrivateGroup,
|
||||||
|
isPublic = false
|
||||||
|
)
|
||||||
|
requestGroupButton(
|
||||||
|
"👥\uD83D\uDC6E",
|
||||||
|
requestIdGroupUserOwner,
|
||||||
|
isOwnedBy = true
|
||||||
|
)
|
||||||
|
}
|
||||||
|
row {
|
||||||
|
requestGroupButton(
|
||||||
|
"🏛",
|
||||||
|
requestIdForum,
|
||||||
|
isForum = true
|
||||||
|
)
|
||||||
|
requestGroupButton(
|
||||||
|
"🏛\uD83D\uDD17",
|
||||||
|
requestIdPublicForum,
|
||||||
|
isPublic = true,
|
||||||
|
isForum = true
|
||||||
|
)
|
||||||
|
requestGroupButton(
|
||||||
|
"🏛❌\uD83D\uDD17",
|
||||||
|
requestIdPrivateForum,
|
||||||
|
isPublic = false,
|
||||||
|
isForum = true
|
||||||
|
)
|
||||||
|
requestGroupButton(
|
||||||
|
"🏛\uD83D\uDC6E",
|
||||||
|
requestIdForumUserOwner,
|
||||||
|
isOwnedBy = true,
|
||||||
|
isForum = true
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bot.buildBehaviourWithLongPolling (defaultExceptionsHandler = { it.printStackTrace() }) {
|
||||||
|
onCommand("start", initialFilter = { it.chat is PrivateChat }) {
|
||||||
|
reply(
|
||||||
|
it,
|
||||||
|
"Here possible requests buttons:",
|
||||||
|
replyMarkup = keyboard
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
onUsersShared {
|
||||||
|
it.chatEvent.userIds.forEach { userId ->
|
||||||
|
val userInfo = runCatchingSafely { getChat(userId) }.getOrNull()
|
||||||
|
reply(
|
||||||
|
it,
|
||||||
|
) {
|
||||||
|
+"You have shared "
|
||||||
|
+mention(
|
||||||
|
when (it.chatEvent.requestId) {
|
||||||
|
requestIdUserOrBot -> "user or bot"
|
||||||
|
requestIdUserNonPremium -> "non premium user"
|
||||||
|
requestIdUserAny -> "any user"
|
||||||
|
requestIdUserPremium -> "premium user"
|
||||||
|
requestIdBot -> "bot"
|
||||||
|
else -> "somebody O.o"
|
||||||
|
},
|
||||||
|
userId
|
||||||
|
)
|
||||||
|
+" (user info: $userInfo; user id: $userId)"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
onChatShared {
|
||||||
|
val chatId = it.chatEvent.chatId
|
||||||
|
val chatInfo = runCatchingSafely { getChat(chatId) }.getOrNull()
|
||||||
|
reply(
|
||||||
|
it,
|
||||||
|
) {
|
||||||
|
+"You have shared "
|
||||||
|
+when (it.chatEvent.requestId) {
|
||||||
|
requestIdAnyChat -> "some chat"
|
||||||
|
requestIdChannel -> "any channel"
|
||||||
|
requestIdPublicChannel -> "public channel"
|
||||||
|
requestIdPrivateChannel -> "private channel"
|
||||||
|
requestIdChannelUserOwner -> "channel owned by you"
|
||||||
|
requestIdGroup -> "any group"
|
||||||
|
requestIdPublicGroup -> "public group"
|
||||||
|
requestIdPrivateGroup -> "private group"
|
||||||
|
requestIdGroupUserOwner -> "group owned by you"
|
||||||
|
requestIdForum -> "any forum"
|
||||||
|
requestIdPublicForum -> "public forum"
|
||||||
|
requestIdPrivateForum -> "private forum"
|
||||||
|
requestIdForumUserOwner -> "forum owned by you"
|
||||||
|
else -> "some chat O.o"
|
||||||
|
}
|
||||||
|
+" (chat info: $chatInfo; chat id: $chatId)"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
setMyCommands(BotCommand("start", "Trigger buttons"))
|
||||||
|
}.join()
|
||||||
|
}
|
||||||
17
WebApp/README.md
Normal file
17
WebApp/README.md
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
# WebApp
|
||||||
|
|
||||||
|
Here you may find simple example of `WebApp`. For work of this example you will need one of two things:
|
||||||
|
|
||||||
|
* Your own domain with SSL (letsencrypt is okay)
|
||||||
|
* Test account in telegram
|
||||||
|
|
||||||
|
What is there in this module:
|
||||||
|
|
||||||
|
* JVM part of this example is a server with simple static webapp sharing and bot which just gives the webapp button to open webapp
|
||||||
|
* JS part is the WebApp with one button and reacting to chaged user theme and app viewport
|
||||||
|
|
||||||
|
## How to run
|
||||||
|
|
||||||
|
```bash
|
||||||
|
./gradlew run --args="TOKEN WEB_APP_ADDRESS"
|
||||||
|
```
|
||||||
57
WebApp/build.gradle
Normal file
57
WebApp/build.gradle
Normal file
@@ -0,0 +1,57 @@
|
|||||||
|
buildscript {
|
||||||
|
repositories {
|
||||||
|
mavenCentral()
|
||||||
|
}
|
||||||
|
|
||||||
|
dependencies {
|
||||||
|
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
plugins {
|
||||||
|
id "org.jetbrains.kotlin.multiplatform"
|
||||||
|
id "org.jetbrains.kotlin.plugin.serialization"
|
||||||
|
}
|
||||||
|
|
||||||
|
apply plugin: 'application'
|
||||||
|
|
||||||
|
kotlin {
|
||||||
|
jvm()
|
||||||
|
js(IR) {
|
||||||
|
browser()
|
||||||
|
binaries.executable()
|
||||||
|
}
|
||||||
|
|
||||||
|
sourceSets {
|
||||||
|
commonMain {
|
||||||
|
dependencies {
|
||||||
|
implementation kotlin('stdlib')
|
||||||
|
implementation "org.jetbrains.kotlinx:kotlinx-serialization-json:$serialization_version"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
jsMain {
|
||||||
|
dependencies {
|
||||||
|
implementation "dev.inmo:tgbotapi.webapps:$telegram_bot_api_version"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
jvmMain {
|
||||||
|
dependencies {
|
||||||
|
implementation "dev.inmo:tgbotapi:$telegram_bot_api_version"
|
||||||
|
implementation "dev.inmo:micro_utils.ktor.server:$micro_utils_version"
|
||||||
|
implementation "io.ktor:ktor-server-cio:$ktor_version"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
application {
|
||||||
|
mainClassName = "WebAppServerKt"
|
||||||
|
}
|
||||||
|
|
||||||
|
tasks.getByName("compileKotlinJvm")
|
||||||
|
.dependsOn(jsBrowserDistribution)
|
||||||
|
tasks.getByName("compileKotlinJvm").configure {
|
||||||
|
mustRunAfter jsBrowserDistribution
|
||||||
|
}
|
||||||
7
WebApp/src/commonMain/kotlin/WebAppDataWrapper.kt
Normal file
7
WebApp/src/commonMain/kotlin/WebAppDataWrapper.kt
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
import kotlinx.serialization.Serializable
|
||||||
|
|
||||||
|
@Serializable
|
||||||
|
data class WebAppDataWrapper(
|
||||||
|
val data: String,
|
||||||
|
val hash: String
|
||||||
|
)
|
||||||
308
WebApp/src/jsMain/kotlin/main.kt
Normal file
308
WebApp/src/jsMain/kotlin/main.kt
Normal file
@@ -0,0 +1,308 @@
|
|||||||
|
import dev.inmo.micro_utils.coroutines.launchSafelyWithoutExceptions
|
||||||
|
import dev.inmo.tgbotapi.types.webAppQueryIdField
|
||||||
|
import dev.inmo.tgbotapi.webapps.*
|
||||||
|
import dev.inmo.tgbotapi.webapps.cloud.*
|
||||||
|
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.request.*
|
||||||
|
import io.ktor.client.statement.bodyAsText
|
||||||
|
import io.ktor.http.*
|
||||||
|
import io.ktor.http.content.TextContent
|
||||||
|
import kotlinx.browser.document
|
||||||
|
import kotlinx.browser.window
|
||||||
|
import kotlinx.coroutines.*
|
||||||
|
import kotlinx.dom.appendElement
|
||||||
|
import kotlinx.dom.appendText
|
||||||
|
import kotlinx.dom.clear
|
||||||
|
import kotlinx.serialization.json.Json
|
||||||
|
import org.w3c.dom.*
|
||||||
|
import kotlin.random.Random
|
||||||
|
import kotlin.random.nextUBytes
|
||||||
|
|
||||||
|
fun HTMLElement.log(text: String) {
|
||||||
|
appendText(text)
|
||||||
|
appendElement("p", {})
|
||||||
|
}
|
||||||
|
|
||||||
|
fun main() {
|
||||||
|
console.log("Web app started")
|
||||||
|
val client = HttpClient()
|
||||||
|
val baseUrl = window.location.origin.removeSuffix("/")
|
||||||
|
|
||||||
|
window.onload = {
|
||||||
|
val scope = CoroutineScope(Dispatchers.Default)
|
||||||
|
runCatching {
|
||||||
|
|
||||||
|
scope.launchSafelyWithoutExceptions {
|
||||||
|
val response = client.post("$baseUrl/check") {
|
||||||
|
setBody(
|
||||||
|
Json { }.encodeToString(
|
||||||
|
WebAppDataWrapper.serializer(),
|
||||||
|
WebAppDataWrapper(webApp.initData, webApp.initDataUnsafe.hash)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
val dataIsSafe = response.bodyAsText().toBoolean()
|
||||||
|
|
||||||
|
document.body ?.log(
|
||||||
|
if (dataIsSafe) {
|
||||||
|
"Data is safe"
|
||||||
|
} else {
|
||||||
|
"Data is unsafe"
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
document.body ?.log(
|
||||||
|
webApp.initDataUnsafe.chat.toString()
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
document.body ?.appendElement("button") {
|
||||||
|
addEventListener("click", {
|
||||||
|
scope.launchSafelyWithoutExceptions {
|
||||||
|
handleResult({ "Clicked" }) {
|
||||||
|
client.post("${window.location.origin.removeSuffix("/")}/inline") {
|
||||||
|
parameter(webAppQueryIdField, it)
|
||||||
|
setBody(TextContent("Clicked", ContentType.Text.Plain))
|
||||||
|
document.body ?.log(url.build().toString())
|
||||||
|
}.coroutineContext.job.join()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
appendText("Answer in chat button")
|
||||||
|
} ?: window.alert("Unable to load body")
|
||||||
|
|
||||||
|
document.body ?.appendElement("p", {})
|
||||||
|
document.body ?.appendText("Allow to write in private messages: ${webApp.initDataUnsafe.user ?.allowsWriteToPM ?: "User unavailable"}")
|
||||||
|
|
||||||
|
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("p", {})
|
||||||
|
|
||||||
|
document.body ?.appendElement("button") {
|
||||||
|
addEventListener("click", { webApp.requestWriteAccess() })
|
||||||
|
appendText("Request write access without callback")
|
||||||
|
} ?: window.alert("Unable to load body")
|
||||||
|
|
||||||
|
document.body ?.appendElement("button") {
|
||||||
|
addEventListener("click", { webApp.requestWriteAccess { document.body ?.log("Write access request result: $it") } })
|
||||||
|
appendText("Request write access with callback")
|
||||||
|
} ?: window.alert("Unable to load body")
|
||||||
|
|
||||||
|
document.body ?.appendElement("p", {})
|
||||||
|
|
||||||
|
document.body ?.appendElement("button") {
|
||||||
|
addEventListener("click", { webApp.requestContact() })
|
||||||
|
appendText("Request contact without callback")
|
||||||
|
} ?: window.alert("Unable to load body")
|
||||||
|
|
||||||
|
document.body ?.appendElement("button") {
|
||||||
|
addEventListener("click", { webApp.requestContact { document.body ?.log("Contact request result: $it") } })
|
||||||
|
appendText("Request contact with callback")
|
||||||
|
} ?: window.alert("Unable to load body")
|
||||||
|
|
||||||
|
document.body ?.appendElement("p", {})
|
||||||
|
|
||||||
|
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", {})
|
||||||
|
|
||||||
|
document.body ?.appendElement("button") {
|
||||||
|
fun updateHeaderColor() {
|
||||||
|
val (r, g, b) = Random.nextUBytes(3)
|
||||||
|
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)"
|
||||||
|
}
|
||||||
|
addEventListener("click", {
|
||||||
|
updateHeaderColor()
|
||||||
|
})
|
||||||
|
updateHeaderColor()
|
||||||
|
} ?: window.alert("Unable to load body")
|
||||||
|
|
||||||
|
document.body ?.appendElement("p", {})
|
||||||
|
|
||||||
|
fun Element.updateCloudStorageContent() {
|
||||||
|
clear()
|
||||||
|
webApp.cloudStorage.getAll {
|
||||||
|
it.onSuccess {
|
||||||
|
document.body ?.log(it.toString())
|
||||||
|
appendElement("label") { textContent = "Cloud storage" }
|
||||||
|
|
||||||
|
appendElement("p", {})
|
||||||
|
|
||||||
|
it.forEach { (k, v) ->
|
||||||
|
appendElement("div") {
|
||||||
|
val kInput = appendElement("input", {}) as HTMLInputElement
|
||||||
|
val vInput = appendElement("input", {}) as HTMLInputElement
|
||||||
|
|
||||||
|
kInput.value = k.key
|
||||||
|
vInput.value = v.value
|
||||||
|
|
||||||
|
appendElement("button") {
|
||||||
|
addEventListener("click", {
|
||||||
|
if (k.key == kInput.value) {
|
||||||
|
webApp.cloudStorage.set(k.key, vInput.value) {
|
||||||
|
document.body ?.log(it.toString())
|
||||||
|
this@updateCloudStorageContent.updateCloudStorageContent()
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
webApp.cloudStorage.remove(k.key) {
|
||||||
|
it.onSuccess {
|
||||||
|
webApp.cloudStorage.set(kInput.value, vInput.value) {
|
||||||
|
document.body ?.log(it.toString())
|
||||||
|
this@updateCloudStorageContent.updateCloudStorageContent()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
this.textContent = "Save"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
appendElement("p", {})
|
||||||
|
}
|
||||||
|
appendElement("label") { textContent = "Cloud storage: add new" }
|
||||||
|
|
||||||
|
appendElement("p", {})
|
||||||
|
|
||||||
|
appendElement("div") {
|
||||||
|
val kInput = appendElement("input", {}) as HTMLInputElement
|
||||||
|
|
||||||
|
appendElement("button") {
|
||||||
|
textContent = "Add key"
|
||||||
|
addEventListener("click", {
|
||||||
|
webApp.cloudStorage.set(kInput.value, kInput.value) {
|
||||||
|
document.body ?.log(it.toString())
|
||||||
|
this@updateCloudStorageContent.updateCloudStorageContent()
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
appendElement("p", {})
|
||||||
|
}.onFailure {
|
||||||
|
document.body ?.log(it.stackTraceToString())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
val cloudStorageContentDiv = document.body ?.appendElement("div") {} as HTMLDivElement
|
||||||
|
|
||||||
|
document.body ?.appendElement("p", {})
|
||||||
|
|
||||||
|
webApp.apply {
|
||||||
|
onThemeChanged {
|
||||||
|
document.body ?.log("Theme changed: ${webApp.themeParams}")
|
||||||
|
}
|
||||||
|
onViewportChanged {
|
||||||
|
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")
|
||||||
|
}
|
||||||
|
onWriteAccessRequested {
|
||||||
|
document.body ?.log("Write access request result: $it")
|
||||||
|
}
|
||||||
|
onContactRequested {
|
||||||
|
document.body ?.log("Contact request result: $it")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
webApp.ready()
|
||||||
|
document.body ?.appendElement("input", {
|
||||||
|
(this as HTMLInputElement).value = window.location.href
|
||||||
|
})
|
||||||
|
cloudStorageContentDiv.updateCloudStorageContent()
|
||||||
|
}.onFailure {
|
||||||
|
window.alert(it.stackTraceToString())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
16
WebApp/src/jsMain/resources/index.html
Normal file
16
WebApp/src/jsMain/resources/index.html
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<meta name="format-detection" content="telephone=no"/>
|
||||||
|
<meta http-equiv="X-UA-Compatible" content="IE=edge"/>
|
||||||
|
<meta name="HandheldFriendly" content="True"/>
|
||||||
|
<meta name="robots" content="noindex,nofollow"/>
|
||||||
|
<meta name="viewport" content="width=device-width, height=device-height, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no"/>
|
||||||
|
<title>Web App Example</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<script type="application/javascript" src="https://telegram.org/js/telegram-web-app.js"></script>
|
||||||
|
<script type="application/javascript" src="WebApp.js"></script>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
172
WebApp/src/jvmMain/kotlin/WebAppServer.kt
Normal file
172
WebApp/src/jvmMain/kotlin/WebAppServer.kt
Normal file
@@ -0,0 +1,172 @@
|
|||||||
|
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.ktor.server.createKtorServer
|
||||||
|
import dev.inmo.tgbotapi.extensions.api.answers.answer
|
||||||
|
import dev.inmo.tgbotapi.extensions.api.answers.answerInlineQuery
|
||||||
|
import dev.inmo.tgbotapi.extensions.api.bot.getMe
|
||||||
|
import dev.inmo.tgbotapi.extensions.api.bot.setMyCommands
|
||||||
|
import dev.inmo.tgbotapi.extensions.api.send.*
|
||||||
|
import dev.inmo.tgbotapi.extensions.api.telegramBot
|
||||||
|
import dev.inmo.tgbotapi.extensions.behaviour_builder.*
|
||||||
|
import dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling.*
|
||||||
|
import dev.inmo.tgbotapi.extensions.utils.formatting.makeTelegramStartattach
|
||||||
|
import dev.inmo.tgbotapi.extensions.utils.types.buttons.*
|
||||||
|
import dev.inmo.tgbotapi.requests.answers.InlineQueryResultsButton
|
||||||
|
import dev.inmo.tgbotapi.types.BotCommand
|
||||||
|
import dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.InlineQueryResultArticle
|
||||||
|
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.webapps.WebAppInfo
|
||||||
|
import dev.inmo.tgbotapi.utils.*
|
||||||
|
import io.ktor.http.*
|
||||||
|
import io.ktor.server.application.call
|
||||||
|
import io.ktor.server.http.content.*
|
||||||
|
import io.ktor.server.request.receiveText
|
||||||
|
import io.ktor.server.response.respond
|
||||||
|
import io.ktor.server.routing.post
|
||||||
|
import io.ktor.server.routing.routing
|
||||||
|
import kotlinx.coroutines.Dispatchers
|
||||||
|
import kotlinx.serialization.json.Json
|
||||||
|
import java.io.File
|
||||||
|
import java.nio.charset.Charset
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Accepts two parameters:
|
||||||
|
*
|
||||||
|
* * Telegram Token
|
||||||
|
* * URL where will be placed
|
||||||
|
*
|
||||||
|
* Will start the server to share the static (index.html and WebApp.js) on 0.0.0.0:8080
|
||||||
|
*/
|
||||||
|
@OptIn(PreviewFeature::class)
|
||||||
|
suspend fun main(vararg args: String) {
|
||||||
|
val telegramBotAPIUrlsKeeper = TelegramAPIUrlsKeeper(
|
||||||
|
args.first(),
|
||||||
|
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)
|
||||||
|
createKtorServer(
|
||||||
|
"0.0.0.0",
|
||||||
|
args.getOrNull(2) ?.toIntOrNull() ?: 8080,
|
||||||
|
additionalEngineEnvironmentConfigurator = {
|
||||||
|
parentCoroutineContext += Dispatchers.IO
|
||||||
|
}
|
||||||
|
) {
|
||||||
|
routing {
|
||||||
|
val baseJsFolder = File("WebApp/build/dist/js/")
|
||||||
|
baseJsFolder.list() ?.forEach {
|
||||||
|
if (it == "productionExecutable" || it == "developmentExecutable") {
|
||||||
|
staticFiles("", File(baseJsFolder, it)) {
|
||||||
|
default("WebApp/build/dist/js/$it/index.html")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
post("inline") {
|
||||||
|
val requestBody = call.receiveText()
|
||||||
|
val queryId = call.parameters[webAppQueryIdField] ?: error("$webAppQueryIdField should be presented")
|
||||||
|
|
||||||
|
bot.answer(queryId, InlineQueryResultArticle(queryId, "Result", InputTextMessageContent(requestBody)))
|
||||||
|
call.respond(HttpStatusCode.OK)
|
||||||
|
}
|
||||||
|
post("check") {
|
||||||
|
val requestBody = call.receiveText()
|
||||||
|
val webAppCheckData = Json { }.decodeFromString(WebAppDataWrapper.serializer(), requestBody)
|
||||||
|
|
||||||
|
val isSafe = telegramBotAPIUrlsKeeper.checkWebAppData(webAppCheckData.data, webAppCheckData.hash)
|
||||||
|
|
||||||
|
call.respond(HttpStatusCode.OK, isSafe.toString())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}.start(false)
|
||||||
|
|
||||||
|
bot.buildBehaviourWithLongPolling(
|
||||||
|
defaultExceptionsHandler = { it.printStackTrace() }
|
||||||
|
) {
|
||||||
|
val me = getMe()
|
||||||
|
onCommand("reply_markup") {
|
||||||
|
reply(
|
||||||
|
it,
|
||||||
|
"Button",
|
||||||
|
replyMarkup = replyKeyboard(resizeKeyboard = true, oneTimeKeyboard = true) {
|
||||||
|
row {
|
||||||
|
webAppButton("Open WebApp", WebAppInfo(args[1]))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
)
|
||||||
|
}
|
||||||
|
onCommand("inline") {
|
||||||
|
reply(
|
||||||
|
it,
|
||||||
|
"Button",
|
||||||
|
replyMarkup = inlineKeyboard {
|
||||||
|
row {
|
||||||
|
webAppButton("Open WebApp", WebAppInfo(args[1]))
|
||||||
|
}
|
||||||
|
},
|
||||||
|
linkPreviewOptions = LinkPreviewOptions.Small(
|
||||||
|
args[1],
|
||||||
|
showAboveText = false
|
||||||
|
)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
onCommand("attachment_menu") {
|
||||||
|
reply(
|
||||||
|
it,
|
||||||
|
"Button",
|
||||||
|
replyMarkup = inlineKeyboard {
|
||||||
|
row {
|
||||||
|
webAppButton("Open WebApp", WebAppInfo(args[1]))
|
||||||
|
}
|
||||||
|
},
|
||||||
|
linkPreviewOptions = LinkPreviewOptions.Large(
|
||||||
|
args[1],
|
||||||
|
showAboveText = true
|
||||||
|
)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
onBaseInlineQuery {
|
||||||
|
answerInlineQuery(
|
||||||
|
it,
|
||||||
|
button = InlineQueryResultsButton.invoke(
|
||||||
|
"Open webApp",
|
||||||
|
WebAppInfo(args[1])
|
||||||
|
)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
onUnhandledCommand {
|
||||||
|
reply(
|
||||||
|
it,
|
||||||
|
buildEntities {
|
||||||
|
+"Use " + botCommand("inline") + " to get inline web app button\n"
|
||||||
|
+"Use " + botCommand("reply_markup") + " to get reply markup web app button\n"
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
onWriteAccessAllowed(initialFilter = { it.chatEvent.webAppName != null }) {
|
||||||
|
send(it.chat, "Thanks for adding ${it.chatEvent.webAppName} to the attachment menu")
|
||||||
|
}
|
||||||
|
setMyCommands(
|
||||||
|
BotCommand("reply_markup", "Use to get reply markup keyboard with web app trigger"),
|
||||||
|
BotCommand("inline", "Use to get inline keyboard with web app trigger"),
|
||||||
|
)
|
||||||
|
allUpdatesFlow.subscribeSafelyWithoutExceptions(this) {
|
||||||
|
println(it)
|
||||||
|
}
|
||||||
|
println(getMe())
|
||||||
|
}.join()
|
||||||
|
}
|
||||||
20
build.gradle
20
build.gradle
@@ -1,7 +1,21 @@
|
|||||||
|
buildscript {
|
||||||
|
repositories {
|
||||||
|
mavenCentral()
|
||||||
|
}
|
||||||
|
|
||||||
|
dependencies {
|
||||||
|
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
|
||||||
|
classpath "org.jetbrains.kotlin:kotlin-serialization:$kotlin_version"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
allprojects {
|
allprojects {
|
||||||
|
ext {
|
||||||
|
nativePartTemplate = "${rootProject.projectDir.absolutePath}/native_template.gradle"
|
||||||
|
}
|
||||||
repositories {
|
repositories {
|
||||||
mavenLocal()
|
mavenLocal()
|
||||||
jcenter()
|
mavenCentral()
|
||||||
if (project.hasProperty("GITHUB_USER") && project.hasProperty("GITHUB_TOKEN")) {
|
if (project.hasProperty("GITHUB_USER") && project.hasProperty("GITHUB_TOKEN")) {
|
||||||
maven {
|
maven {
|
||||||
url "https://maven.pkg.github.com/InsanusMokrassar/TelegramBotAPI"
|
url "https://maven.pkg.github.com/InsanusMokrassar/TelegramBotAPI"
|
||||||
@@ -11,5 +25,7 @@ allprojects {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
maven { url "https://nexus.inmo.dev/repository/maven-releases/" }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +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
|
||||||
|
org.gradle.jvmargs=-Xmx2344m
|
||||||
|
|
||||||
|
|
||||||
kotlin_version=1.5.20
|
kotlin_version=1.9.22
|
||||||
telegram_bot_api_version=0.35.1
|
telegram_bot_api_version=10.0.0
|
||||||
micro_utils_version=0.5.15
|
micro_utils_version=0.20.26
|
||||||
|
serialization_version=1.6.2
|
||||||
|
ktor_version=2.3.7
|
||||||
|
|||||||
BIN
gradle/wrapper/gradle-wrapper.jar
vendored
BIN
gradle/wrapper/gradle-wrapper.jar
vendored
Binary file not shown.
4
gradle/wrapper/gradle-wrapper.properties
vendored
4
gradle/wrapper/gradle-wrapper.properties
vendored
@@ -1,5 +1,7 @@
|
|||||||
distributionBase=GRADLE_USER_HOME
|
distributionBase=GRADLE_USER_HOME
|
||||||
distributionPath=wrapper/dists
|
distributionPath=wrapper/dists
|
||||||
|
distributionUrl=https\://services.gradle.org/distributions/gradle-8.6-bin.zip
|
||||||
|
networkTimeout=10000
|
||||||
|
validateDistributionUrl=true
|
||||||
zipStoreBase=GRADLE_USER_HOME
|
zipStoreBase=GRADLE_USER_HOME
|
||||||
zipStorePath=wrapper/dists
|
zipStorePath=wrapper/dists
|
||||||
distributionUrl=https\://services.gradle.org/distributions/gradle-7.0-bin.zip
|
|
||||||
|
|||||||
309
gradlew
vendored
309
gradlew
vendored
@@ -1,78 +1,127 @@
|
|||||||
#!/usr/bin/env sh
|
#!/bin/sh
|
||||||
|
|
||||||
|
#
|
||||||
|
# Copyright © 2015-2021 the original authors.
|
||||||
|
#
|
||||||
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
# you may not use this file except in compliance with the License.
|
||||||
|
# You may obtain a copy of the License at
|
||||||
|
#
|
||||||
|
# https://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
#
|
||||||
|
# Unless required by applicable law or agreed to in writing, software
|
||||||
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
# See the License for the specific language governing permissions and
|
||||||
|
# limitations under the License.
|
||||||
|
#
|
||||||
|
|
||||||
##############################################################################
|
##############################################################################
|
||||||
##
|
#
|
||||||
## Gradle start up script for UN*X
|
# Gradle start up script for POSIX generated by Gradle.
|
||||||
##
|
#
|
||||||
|
# Important for running:
|
||||||
|
#
|
||||||
|
# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is
|
||||||
|
# noncompliant, but you have some other compliant shell such as ksh or
|
||||||
|
# bash, then to run this script, type that shell name before the whole
|
||||||
|
# command line, like:
|
||||||
|
#
|
||||||
|
# ksh Gradle
|
||||||
|
#
|
||||||
|
# Busybox and similar reduced shells will NOT work, because this script
|
||||||
|
# requires all of these POSIX shell features:
|
||||||
|
# * functions;
|
||||||
|
# * expansions «$var», «${var}», «${var:-default}», «${var+SET}»,
|
||||||
|
# «${var#prefix}», «${var%suffix}», and «$( cmd )»;
|
||||||
|
# * compound commands having a testable exit status, especially «case»;
|
||||||
|
# * various built-in commands including «command», «set», and «ulimit».
|
||||||
|
#
|
||||||
|
# Important for patching:
|
||||||
|
#
|
||||||
|
# (2) This script targets any POSIX shell, so it avoids extensions provided
|
||||||
|
# by Bash, Ksh, etc; in particular arrays are avoided.
|
||||||
|
#
|
||||||
|
# The "traditional" practice of packing multiple parameters into a
|
||||||
|
# space-separated string is a well documented source of bugs and security
|
||||||
|
# problems, so this is (mostly) avoided, by progressively accumulating
|
||||||
|
# options in "$@", and eventually passing that to Java.
|
||||||
|
#
|
||||||
|
# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS,
|
||||||
|
# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly;
|
||||||
|
# see the in-line comments for details.
|
||||||
|
#
|
||||||
|
# There are tweaks for specific operating systems such as AIX, CygWin,
|
||||||
|
# Darwin, MinGW, and NonStop.
|
||||||
|
#
|
||||||
|
# (3) This script is generated from the Groovy template
|
||||||
|
# https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
|
||||||
|
# within the Gradle project.
|
||||||
|
#
|
||||||
|
# You can find Gradle at https://github.com/gradle/gradle/.
|
||||||
|
#
|
||||||
##############################################################################
|
##############################################################################
|
||||||
|
|
||||||
# Attempt to set APP_HOME
|
# Attempt to set APP_HOME
|
||||||
|
|
||||||
# Resolve links: $0 may be a link
|
# Resolve links: $0 may be a link
|
||||||
PRG="$0"
|
app_path=$0
|
||||||
# Need this for relative symlinks.
|
|
||||||
while [ -h "$PRG" ] ; do
|
# Need this for daisy-chained symlinks.
|
||||||
ls=`ls -ld "$PRG"`
|
while
|
||||||
link=`expr "$ls" : '.*-> \(.*\)$'`
|
APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path
|
||||||
if expr "$link" : '/.*' > /dev/null; then
|
[ -h "$app_path" ]
|
||||||
PRG="$link"
|
do
|
||||||
else
|
ls=$( ls -ld "$app_path" )
|
||||||
PRG=`dirname "$PRG"`"/$link"
|
link=${ls#*' -> '}
|
||||||
fi
|
case $link in #(
|
||||||
|
/*) app_path=$link ;; #(
|
||||||
|
*) app_path=$APP_HOME$link ;;
|
||||||
|
esac
|
||||||
done
|
done
|
||||||
SAVED="`pwd`"
|
|
||||||
cd "`dirname \"$PRG\"`/" >/dev/null
|
|
||||||
APP_HOME="`pwd -P`"
|
|
||||||
cd "$SAVED" >/dev/null
|
|
||||||
|
|
||||||
APP_NAME="Gradle"
|
# This is normally unused
|
||||||
APP_BASE_NAME=`basename "$0"`
|
# shellcheck disable=SC2034
|
||||||
|
APP_BASE_NAME=${0##*/}
|
||||||
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036)
|
||||||
DEFAULT_JVM_OPTS=""
|
APP_HOME=$( cd "${APP_HOME:-./}" > /dev/null && pwd -P ) || exit
|
||||||
|
|
||||||
# Use the maximum available, or set MAX_FD != -1 to use that value.
|
# Use the maximum available, or set MAX_FD != -1 to use that value.
|
||||||
MAX_FD="maximum"
|
MAX_FD=maximum
|
||||||
|
|
||||||
warn () {
|
warn () {
|
||||||
echo "$*"
|
echo "$*"
|
||||||
}
|
} >&2
|
||||||
|
|
||||||
die () {
|
die () {
|
||||||
echo
|
echo
|
||||||
echo "$*"
|
echo "$*"
|
||||||
echo
|
echo
|
||||||
exit 1
|
exit 1
|
||||||
}
|
} >&2
|
||||||
|
|
||||||
# OS specific support (must be 'true' or 'false').
|
# OS specific support (must be 'true' or 'false').
|
||||||
cygwin=false
|
cygwin=false
|
||||||
msys=false
|
msys=false
|
||||||
darwin=false
|
darwin=false
|
||||||
nonstop=false
|
nonstop=false
|
||||||
case "`uname`" in
|
case "$( uname )" in #(
|
||||||
CYGWIN* )
|
CYGWIN* ) cygwin=true ;; #(
|
||||||
cygwin=true
|
Darwin* ) darwin=true ;; #(
|
||||||
;;
|
MSYS* | MINGW* ) msys=true ;; #(
|
||||||
Darwin* )
|
NONSTOP* ) nonstop=true ;;
|
||||||
darwin=true
|
|
||||||
;;
|
|
||||||
MINGW* )
|
|
||||||
msys=true
|
|
||||||
;;
|
|
||||||
NONSTOP* )
|
|
||||||
nonstop=true
|
|
||||||
;;
|
|
||||||
esac
|
esac
|
||||||
|
|
||||||
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
|
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
|
||||||
|
|
||||||
|
|
||||||
# Determine the Java command to use to start the JVM.
|
# Determine the Java command to use to start the JVM.
|
||||||
if [ -n "$JAVA_HOME" ] ; then
|
if [ -n "$JAVA_HOME" ] ; then
|
||||||
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
|
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
|
||||||
# IBM's JDK on AIX uses strange locations for the executables
|
# IBM's JDK on AIX uses strange locations for the executables
|
||||||
JAVACMD="$JAVA_HOME/jre/sh/java"
|
JAVACMD=$JAVA_HOME/jre/sh/java
|
||||||
else
|
else
|
||||||
JAVACMD="$JAVA_HOME/bin/java"
|
JAVACMD=$JAVA_HOME/bin/java
|
||||||
fi
|
fi
|
||||||
if [ ! -x "$JAVACMD" ] ; then
|
if [ ! -x "$JAVACMD" ] ; then
|
||||||
die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
|
die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
|
||||||
@@ -81,92 +130,120 @@ Please set the JAVA_HOME variable in your environment to match the
|
|||||||
location of your Java installation."
|
location of your Java installation."
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
JAVACMD="java"
|
JAVACMD=java
|
||||||
which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
if ! command -v java >/dev/null 2>&1
|
||||||
|
then
|
||||||
|
die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
||||||
|
|
||||||
Please set the JAVA_HOME variable in your environment to match the
|
Please set the JAVA_HOME variable in your environment to match the
|
||||||
location of your Java installation."
|
location of your Java installation."
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Increase the maximum file descriptors if we can.
|
# Increase the maximum file descriptors if we can.
|
||||||
if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
|
if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
|
||||||
MAX_FD_LIMIT=`ulimit -H -n`
|
case $MAX_FD in #(
|
||||||
if [ $? -eq 0 ] ; then
|
max*)
|
||||||
if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
|
# In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked.
|
||||||
MAX_FD="$MAX_FD_LIMIT"
|
# shellcheck disable=SC2039,SC3045
|
||||||
fi
|
MAX_FD=$( ulimit -H -n ) ||
|
||||||
ulimit -n $MAX_FD
|
warn "Could not query maximum file descriptor limit"
|
||||||
if [ $? -ne 0 ] ; then
|
esac
|
||||||
warn "Could not set maximum file descriptor limit: $MAX_FD"
|
case $MAX_FD in #(
|
||||||
fi
|
'' | soft) :;; #(
|
||||||
else
|
*)
|
||||||
warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
|
# In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked.
|
||||||
fi
|
# shellcheck disable=SC2039,SC3045
|
||||||
fi
|
ulimit -n "$MAX_FD" ||
|
||||||
|
warn "Could not set maximum file descriptor limit to $MAX_FD"
|
||||||
# For Darwin, add options to specify how the application appears in the dock
|
|
||||||
if $darwin; then
|
|
||||||
GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
|
|
||||||
fi
|
|
||||||
|
|
||||||
# For Cygwin, switch paths to Windows format before running java
|
|
||||||
if $cygwin ; then
|
|
||||||
APP_HOME=`cygpath --path --mixed "$APP_HOME"`
|
|
||||||
CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
|
|
||||||
JAVACMD=`cygpath --unix "$JAVACMD"`
|
|
||||||
|
|
||||||
# We build the pattern for arguments to be converted via cygpath
|
|
||||||
ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
|
|
||||||
SEP=""
|
|
||||||
for dir in $ROOTDIRSRAW ; do
|
|
||||||
ROOTDIRS="$ROOTDIRS$SEP$dir"
|
|
||||||
SEP="|"
|
|
||||||
done
|
|
||||||
OURCYGPATTERN="(^($ROOTDIRS))"
|
|
||||||
# Add a user-defined pattern to the cygpath arguments
|
|
||||||
if [ "$GRADLE_CYGPATTERN" != "" ] ; then
|
|
||||||
OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
|
|
||||||
fi
|
|
||||||
# Now convert the arguments - kludge to limit ourselves to /bin/sh
|
|
||||||
i=0
|
|
||||||
for arg in "$@" ; do
|
|
||||||
CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
|
|
||||||
CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
|
|
||||||
|
|
||||||
if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
|
|
||||||
eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
|
|
||||||
else
|
|
||||||
eval `echo args$i`="\"$arg\""
|
|
||||||
fi
|
|
||||||
i=$((i+1))
|
|
||||||
done
|
|
||||||
case $i in
|
|
||||||
(0) set -- ;;
|
|
||||||
(1) set -- "$args0" ;;
|
|
||||||
(2) set -- "$args0" "$args1" ;;
|
|
||||||
(3) set -- "$args0" "$args1" "$args2" ;;
|
|
||||||
(4) set -- "$args0" "$args1" "$args2" "$args3" ;;
|
|
||||||
(5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
|
|
||||||
(6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
|
|
||||||
(7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
|
|
||||||
(8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
|
|
||||||
(9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
|
|
||||||
esac
|
esac
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Escape application args
|
# Collect all arguments for the java command, stacking in reverse order:
|
||||||
save () {
|
# * args from the command line
|
||||||
for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
|
# * the main class name
|
||||||
echo " "
|
# * -classpath
|
||||||
}
|
# * -D...appname settings
|
||||||
APP_ARGS=$(save "$@")
|
# * --module-path (only if needed)
|
||||||
|
# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables.
|
||||||
|
|
||||||
# Collect all arguments for the java command, following the shell quoting and substitution rules
|
# For Cygwin or MSYS, switch paths to Windows format before running java
|
||||||
eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
|
if "$cygwin" || "$msys" ; then
|
||||||
|
APP_HOME=$( cygpath --path --mixed "$APP_HOME" )
|
||||||
|
CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" )
|
||||||
|
|
||||||
# by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong
|
JAVACMD=$( cygpath --unix "$JAVACMD" )
|
||||||
if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then
|
|
||||||
cd "$(dirname "$0")"
|
# Now convert the arguments - kludge to limit ourselves to /bin/sh
|
||||||
|
for arg do
|
||||||
|
if
|
||||||
|
case $arg in #(
|
||||||
|
-*) false ;; # don't mess with options #(
|
||||||
|
/?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath
|
||||||
|
[ -e "$t" ] ;; #(
|
||||||
|
*) false ;;
|
||||||
|
esac
|
||||||
|
then
|
||||||
|
arg=$( cygpath --path --ignore --mixed "$arg" )
|
||||||
|
fi
|
||||||
|
# Roll the args list around exactly as many times as the number of
|
||||||
|
# args, so each arg winds up back in the position where it started, but
|
||||||
|
# possibly modified.
|
||||||
|
#
|
||||||
|
# NB: a `for` loop captures its iteration list before it begins, so
|
||||||
|
# changing the positional parameters here affects neither the number of
|
||||||
|
# iterations, nor the values presented in `arg`.
|
||||||
|
shift # remove old arg
|
||||||
|
set -- "$@" "$arg" # push replacement arg
|
||||||
|
done
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
||||||
|
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
||||||
|
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
|
||||||
|
|
||||||
|
# Collect all arguments for the java command:
|
||||||
|
# * DEFAULT_JVM_OPTS, JAVA_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments,
|
||||||
|
# and any embedded shellness will be escaped.
|
||||||
|
# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be
|
||||||
|
# treated as '${Hostname}' itself on the command line.
|
||||||
|
|
||||||
|
set -- \
|
||||||
|
"-Dorg.gradle.appname=$APP_BASE_NAME" \
|
||||||
|
-classpath "$CLASSPATH" \
|
||||||
|
org.gradle.wrapper.GradleWrapperMain \
|
||||||
|
"$@"
|
||||||
|
|
||||||
|
# Stop when "xargs" is not available.
|
||||||
|
if ! command -v xargs >/dev/null 2>&1
|
||||||
|
then
|
||||||
|
die "xargs is not available"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Use "xargs" to parse quoted args.
|
||||||
|
#
|
||||||
|
# With -n1 it outputs one arg per line, with the quotes and backslashes removed.
|
||||||
|
#
|
||||||
|
# In Bash we could simply go:
|
||||||
|
#
|
||||||
|
# readarray ARGS < <( xargs -n1 <<<"$var" ) &&
|
||||||
|
# set -- "${ARGS[@]}" "$@"
|
||||||
|
#
|
||||||
|
# but POSIX shell has neither arrays nor command substitution, so instead we
|
||||||
|
# post-process each arg (as a line of input to sed) to backslash-escape any
|
||||||
|
# character that might be a shell metacharacter, then use eval to reverse
|
||||||
|
# that process (while maintaining the separation between arguments), and wrap
|
||||||
|
# the whole thing up as a single "set" statement.
|
||||||
|
#
|
||||||
|
# This will of course break if any of these variables contains a newline or
|
||||||
|
# an unmatched quote.
|
||||||
|
#
|
||||||
|
|
||||||
|
eval "set -- $(
|
||||||
|
printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" |
|
||||||
|
xargs -n1 |
|
||||||
|
sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' |
|
||||||
|
tr '\n' ' '
|
||||||
|
)" '"$@"'
|
||||||
|
|
||||||
exec "$JAVACMD" "$@"
|
exec "$JAVACMD" "$@"
|
||||||
|
|||||||
76
gradlew.bat
vendored
76
gradlew.bat
vendored
@@ -1,4 +1,20 @@
|
|||||||
@if "%DEBUG%" == "" @echo off
|
@rem
|
||||||
|
@rem Copyright 2015 the original author or authors.
|
||||||
|
@rem
|
||||||
|
@rem Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
@rem you may not use this file except in compliance with the License.
|
||||||
|
@rem You may obtain a copy of the License at
|
||||||
|
@rem
|
||||||
|
@rem https://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
@rem
|
||||||
|
@rem Unless required by applicable law or agreed to in writing, software
|
||||||
|
@rem distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
@rem See the License for the specific language governing permissions and
|
||||||
|
@rem limitations under the License.
|
||||||
|
@rem
|
||||||
|
|
||||||
|
@if "%DEBUG%"=="" @echo off
|
||||||
@rem ##########################################################################
|
@rem ##########################################################################
|
||||||
@rem
|
@rem
|
||||||
@rem Gradle startup script for Windows
|
@rem Gradle startup script for Windows
|
||||||
@@ -9,25 +25,29 @@
|
|||||||
if "%OS%"=="Windows_NT" setlocal
|
if "%OS%"=="Windows_NT" setlocal
|
||||||
|
|
||||||
set DIRNAME=%~dp0
|
set DIRNAME=%~dp0
|
||||||
if "%DIRNAME%" == "" set DIRNAME=.
|
if "%DIRNAME%"=="" set DIRNAME=.
|
||||||
|
@rem This is normally unused
|
||||||
set APP_BASE_NAME=%~n0
|
set APP_BASE_NAME=%~n0
|
||||||
set APP_HOME=%DIRNAME%
|
set APP_HOME=%DIRNAME%
|
||||||
|
|
||||||
|
@rem Resolve any "." and ".." in APP_HOME to make it shorter.
|
||||||
|
for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi
|
||||||
|
|
||||||
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
||||||
set DEFAULT_JVM_OPTS=
|
set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
|
||||||
|
|
||||||
@rem Find java.exe
|
@rem Find java.exe
|
||||||
if defined JAVA_HOME goto findJavaFromJavaHome
|
if defined JAVA_HOME goto findJavaFromJavaHome
|
||||||
|
|
||||||
set JAVA_EXE=java.exe
|
set JAVA_EXE=java.exe
|
||||||
%JAVA_EXE% -version >NUL 2>&1
|
%JAVA_EXE% -version >NUL 2>&1
|
||||||
if "%ERRORLEVEL%" == "0" goto init
|
if %ERRORLEVEL% equ 0 goto execute
|
||||||
|
|
||||||
echo.
|
echo. 1>&2
|
||||||
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2
|
||||||
echo.
|
echo. 1>&2
|
||||||
echo Please set the JAVA_HOME variable in your environment to match the
|
echo Please set the JAVA_HOME variable in your environment to match the 1>&2
|
||||||
echo location of your Java installation.
|
echo location of your Java installation. 1>&2
|
||||||
|
|
||||||
goto fail
|
goto fail
|
||||||
|
|
||||||
@@ -35,48 +55,36 @@ goto fail
|
|||||||
set JAVA_HOME=%JAVA_HOME:"=%
|
set JAVA_HOME=%JAVA_HOME:"=%
|
||||||
set JAVA_EXE=%JAVA_HOME%/bin/java.exe
|
set JAVA_EXE=%JAVA_HOME%/bin/java.exe
|
||||||
|
|
||||||
if exist "%JAVA_EXE%" goto init
|
if exist "%JAVA_EXE%" goto execute
|
||||||
|
|
||||||
echo.
|
echo. 1>&2
|
||||||
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
|
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2
|
||||||
echo.
|
echo. 1>&2
|
||||||
echo Please set the JAVA_HOME variable in your environment to match the
|
echo Please set the JAVA_HOME variable in your environment to match the 1>&2
|
||||||
echo location of your Java installation.
|
echo location of your Java installation. 1>&2
|
||||||
|
|
||||||
goto fail
|
goto fail
|
||||||
|
|
||||||
:init
|
|
||||||
@rem Get command-line arguments, handling Windows variants
|
|
||||||
|
|
||||||
if not "%OS%" == "Windows_NT" goto win9xME_args
|
|
||||||
|
|
||||||
:win9xME_args
|
|
||||||
@rem Slurp the command line arguments.
|
|
||||||
set CMD_LINE_ARGS=
|
|
||||||
set _SKIP=2
|
|
||||||
|
|
||||||
:win9xME_args_slurp
|
|
||||||
if "x%~1" == "x" goto execute
|
|
||||||
|
|
||||||
set CMD_LINE_ARGS=%*
|
|
||||||
|
|
||||||
:execute
|
:execute
|
||||||
@rem Setup the command line
|
@rem Setup the command line
|
||||||
|
|
||||||
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
|
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
|
||||||
|
|
||||||
|
|
||||||
@rem Execute Gradle
|
@rem Execute Gradle
|
||||||
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
|
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %*
|
||||||
|
|
||||||
:end
|
:end
|
||||||
@rem End local scope for the variables with windows NT shell
|
@rem End local scope for the variables with windows NT shell
|
||||||
if "%ERRORLEVEL%"=="0" goto mainEnd
|
if %ERRORLEVEL% equ 0 goto mainEnd
|
||||||
|
|
||||||
:fail
|
:fail
|
||||||
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
|
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
|
||||||
rem the _cmd.exe /c_ return code!
|
rem the _cmd.exe /c_ return code!
|
||||||
if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
|
set EXIT_CODE=%ERRORLEVEL%
|
||||||
exit /b 1
|
if %EXIT_CODE% equ 0 set EXIT_CODE=1
|
||||||
|
if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE%
|
||||||
|
exit /b %EXIT_CODE%
|
||||||
|
|
||||||
:mainEnd
|
:mainEnd
|
||||||
if "%OS%"=="Windows_NT" endlocal
|
if "%OS%"=="Windows_NT" endlocal
|
||||||
|
|||||||
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.")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,9 +1,49 @@
|
|||||||
include ":ForwardInfoSenderBot"
|
include ":ForwardInfoSenderBot"
|
||||||
|
|
||||||
include ":RandomFileSenderBot"
|
include ":RandomFileSenderBot"
|
||||||
|
|
||||||
include ":HelloBot"
|
include ":HelloBot"
|
||||||
|
|
||||||
|
include ":PollsBot"
|
||||||
|
|
||||||
include ":GetMeBot"
|
include ":GetMeBot"
|
||||||
|
|
||||||
|
include ":DeepLinksBot"
|
||||||
|
|
||||||
include ":FilesLoaderBot"
|
include ":FilesLoaderBot"
|
||||||
|
|
||||||
include ":ResenderBot:ResenderBotLib"
|
include ":ResenderBot:ResenderBotLib"
|
||||||
include ":ResenderBot:jvm_launcher"
|
include ":ResenderBot:jvm_launcher"
|
||||||
|
include ":ResenderBot:native_launcher"
|
||||||
|
|
||||||
|
include ":KeyboardsBot:KeyboardsBotLib"
|
||||||
|
include ":KeyboardsBot:jvm_launcher"
|
||||||
|
|
||||||
|
include ":StickerInfoBot:StickerInfoBotLib"
|
||||||
|
include ":StickerInfoBot:jvm_launcher"
|
||||||
|
|
||||||
include ":SlotMachineDetectorBot"
|
include ":SlotMachineDetectorBot"
|
||||||
|
|
||||||
|
include ":ChatAvatarSetter"
|
||||||
|
|
||||||
|
include ":WebApp"
|
||||||
|
|
||||||
include ":FSMBot"
|
include ":FSMBot"
|
||||||
|
|
||||||
|
include ":TopicsHandling"
|
||||||
|
|
||||||
|
include ":UserChatShared"
|
||||||
|
|
||||||
|
include ":RightsChangerBot"
|
||||||
|
|
||||||
|
include ":LiveLocationsBot"
|
||||||
|
|
||||||
|
include ":StickerSetHandler"
|
||||||
|
|
||||||
|
include ":InlineQueriesBot"
|
||||||
|
|
||||||
|
include ":ReactionsInfoBot"
|
||||||
|
|
||||||
|
include ":LinkPreviewsBot"
|
||||||
|
|
||||||
|
include ":BoostsInfoBot"
|
||||||
|
|||||||
Reference in New Issue
Block a user