Merge pull request #136 from InsanusMokrassar/3.0.0

3.0.0
This commit is contained in:
InsanusMokrassar 2022-08-06 08:33:15 +06:00 committed by GitHub
commit 36273adfd1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 18 additions and 13 deletions

View File

@ -14,14 +14,18 @@ import java.io.File
*/
suspend fun main(args: Array<String>) {
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()
telegramBotWithBehaviourAndLongPolling(botToken, CoroutineScope(Dispatchers.IO)) {
onMedia(initialFilter = null) {
val pathedFile = bot.getFileAdditionalInfo(it.content.media)
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}")
}
onContentMessage { println(it) }

View File

@ -16,14 +16,14 @@ suspend fun main(vararg args: String) {
val botToken = args.first()
telegramBotWithBehaviourAndLongPolling(botToken, CoroutineScope(Dispatchers.IO)) {
onContentMessage(subcontextUpdatesFilter = { _, _ -> true }) {
onContentMessage {
val toAnswer = buildEntities {
when (val forwardInfo = it.forwardInfo) {
null -> +"There is no forward info"
is AnonymousForwardInfo -> {
is ForwardInfo.ByAnonymous -> {
regular("Anonymous user which signed as \"") + code(forwardInfo.senderName) + "\""
}
is UserForwardInfo -> {
is ForwardInfo.ByUser -> {
val user = forwardInfo.from
when (user) {
is CommonUser -> {
@ -37,8 +37,9 @@ suspend fun main(vararg args: String) {
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 ForwardFromSupergroupInfo -> regular("Supergroup (") + code((forwardInfo.group).title) + ")"
is ForwardInfo.PublicChat.FromChannel -> regular("Channel (") + 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)

View File

@ -100,6 +100,7 @@ suspend fun activateKeyboardsBot(
}
}
)
answer(it)
}
onUnhandledCommand {

View File

@ -1,5 +1,4 @@
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.tgbotapi.extensions.api.answers.answer
import dev.inmo.tgbotapi.extensions.api.bot.getMe

View File

@ -4,8 +4,8 @@ org.gradle.parallel=true
org.gradle.jvmargs=-Xmx768m
kotlin_version=1.6.21
telegram_bot_api_version=2.2.2
micro_utils_version=0.11.13
serialization_version=1.3.3
kotlin_version=1.7.10
telegram_bot_api_version=3.0.2
micro_utils_version=0.12.0
serialization_version=1.4.0-RC
ktor_version=2.0.3

View File

@ -2,4 +2,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
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