mirror of
https://github.com/InsanusMokrassar/TelegramBotAPI-examples.git
synced 2025-12-23 06:35:37 +00:00
Compare commits
13 Commits
371f5e933c
...
3.0.0
| Author | SHA1 | Date | |
|---|---|---|---|
| bca2ae905b | |||
| 19a713a3e3 | |||
| e039f90961 | |||
| 21692d16ca | |||
| d547dce2ab | |||
| 9bfe88a79c | |||
|
|
bfa327acf3 | ||
| 88a031b05a | |||
| 20e942b2ac | |||
|
|
3e20cbd22c | ||
| bcd35de038 | |||
|
|
2aec45d453 | ||
| ee55378e7a |
@@ -14,14 +14,18 @@ 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()
|
||||||
|
|
||||||
telegramBotWithBehaviourAndLongPolling(botToken, CoroutineScope(Dispatchers.IO)) {
|
telegramBotWithBehaviourAndLongPolling(botToken, CoroutineScope(Dispatchers.IO)) {
|
||||||
onMedia(initialFilter = null) {
|
onMedia(initialFilter = null) {
|
||||||
val pathedFile = bot.getFileAdditionalInfo(it.content.media)
|
val pathedFile = bot.getFileAdditionalInfo(it.content.media)
|
||||||
val outFile = File(directoryOrFile, pathedFile.filePath.filenameFromUrl)
|
val outFile = File(directoryOrFile, pathedFile.filePath.filenameFromUrl)
|
||||||
bot.downloadFile(it.content.media, outFile)
|
runCatching {
|
||||||
|
bot.downloadFile(it.content.media, outFile)
|
||||||
|
}.onFailure {
|
||||||
|
it.printStackTrace()
|
||||||
|
}
|
||||||
reply(it, "Saved to ${outFile.absolutePath}")
|
reply(it, "Saved to ${outFile.absolutePath}")
|
||||||
}
|
}
|
||||||
onContentMessage { println(it) }
|
onContentMessage { println(it) }
|
||||||
|
|||||||
@@ -16,14 +16,14 @@ suspend fun main(vararg args: String) {
|
|||||||
val botToken = args.first()
|
val botToken = args.first()
|
||||||
|
|
||||||
telegramBotWithBehaviourAndLongPolling(botToken, CoroutineScope(Dispatchers.IO)) {
|
telegramBotWithBehaviourAndLongPolling(botToken, CoroutineScope(Dispatchers.IO)) {
|
||||||
onContentMessage(subcontextUpdatesFilter = { _, _ -> 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
|
||||||
when (user) {
|
when (user) {
|
||||||
is CommonUser -> {
|
is CommonUser -> {
|
||||||
@@ -37,8 +37,9 @@ suspend fun main(vararg args: String) {
|
|||||||
is ExtendedBot -> regular("Bot ")
|
is ExtendedBot -> regular("Bot ")
|
||||||
} + code(user.id.chatId.toString()) + " (${user.firstName} ${user.lastName}: ${user.username ?.username ?: "Without username"})"
|
} + code(user.id.chatId.toString()) + " (${user.firstName} ${user.lastName}: ${user.username ?.username ?: "Without username"})"
|
||||||
}
|
}
|
||||||
is ForwardFromChannelInfo -> regular("Channel (") + code((forwardInfo.channelChat).title) + ")"
|
is ForwardInfo.PublicChat.FromChannel -> regular("Channel (") + code(forwardInfo.channelChat.title) + ")"
|
||||||
is ForwardFromSupergroupInfo -> regular("Supergroup (") + code((forwardInfo.group).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)
|
||||||
|
|||||||
@@ -100,6 +100,7 @@ suspend fun activateKeyboardsBot(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
answer(it)
|
||||||
}
|
}
|
||||||
|
|
||||||
onUnhandledCommand {
|
onUnhandledCommand {
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
import dev.inmo.micro_utils.coroutines.subscribeSafelyWithoutExceptions
|
import dev.inmo.micro_utils.coroutines.subscribeSafelyWithoutExceptions
|
||||||
import dev.inmo.micro_utils.crypto.hmacSha256
|
|
||||||
import dev.inmo.micro_utils.ktor.server.createKtorServer
|
import dev.inmo.micro_utils.ktor.server.createKtorServer
|
||||||
import dev.inmo.tgbotapi.extensions.api.answers.answer
|
import dev.inmo.tgbotapi.extensions.api.answers.answer
|
||||||
import dev.inmo.tgbotapi.extensions.api.bot.getMe
|
import dev.inmo.tgbotapi.extensions.api.bot.getMe
|
||||||
|
|||||||
@@ -4,8 +4,8 @@ org.gradle.parallel=true
|
|||||||
org.gradle.jvmargs=-Xmx768m
|
org.gradle.jvmargs=-Xmx768m
|
||||||
|
|
||||||
|
|
||||||
kotlin_version=1.6.21
|
kotlin_version=1.7.10
|
||||||
telegram_bot_api_version=2.1.2
|
telegram_bot_api_version=3.0.2
|
||||||
micro_utils_version=0.11.12
|
micro_utils_version=0.12.0
|
||||||
serialization_version=1.3.3
|
serialization_version=1.4.0-RC
|
||||||
ktor_version=2.0.3
|
ktor_version=2.0.3
|
||||||
|
|||||||
2
gradle/wrapper/gradle-wrapper.properties
vendored
2
gradle/wrapper/gradle-wrapper.properties
vendored
@@ -2,4 +2,4 @@ distributionBase=GRADLE_USER_HOME
|
|||||||
distributionPath=wrapper/dists
|
distributionPath=wrapper/dists
|
||||||
zipStoreBase=GRADLE_USER_HOME
|
zipStoreBase=GRADLE_USER_HOME
|
||||||
zipStorePath=wrapper/dists
|
zipStorePath=wrapper/dists
|
||||||
distributionUrl=https\://services.gradle.org/distributions/gradle-7.4.2-bin.zip
|
distributionUrl=https\://services.gradle.org/distributions/gradle-7.5.1-bin.zip
|
||||||
|
|||||||
Reference in New Issue
Block a user