From 21692d16ca5f5a8f9f3855e80a96a0f7755fac4a Mon Sep 17 00:00:00 2001
From: InsanusMokrassar <ovsyannikov.alexey95@gmail.com>
Date: Thu, 4 Aug 2022 22:32:36 +0600
Subject: [PATCH] fixes in forward chat info bot

---
 FilesLoaderBot/src/main/kotlin/FilesLoaderBot.kt          | 8 ++++++--
 .../src/main/kotlin/ForwardInfoSenderBot.kt               | 7 ++++---
 2 files changed, 10 insertions(+), 5 deletions(-)

diff --git a/FilesLoaderBot/src/main/kotlin/FilesLoaderBot.kt b/FilesLoaderBot/src/main/kotlin/FilesLoaderBot.kt
index 81183ba..193aa57 100644
--- a/FilesLoaderBot/src/main/kotlin/FilesLoaderBot.kt
+++ b/FilesLoaderBot/src/main/kotlin/FilesLoaderBot.kt
@@ -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) }
diff --git a/ForwardInfoSenderBot/src/main/kotlin/ForwardInfoSenderBot.kt b/ForwardInfoSenderBot/src/main/kotlin/ForwardInfoSenderBot.kt
index 7a23ff3..1fa7001 100644
--- a/ForwardInfoSenderBot/src/main/kotlin/ForwardInfoSenderBot.kt
+++ b/ForwardInfoSenderBot/src/main/kotlin/ForwardInfoSenderBot.kt
@@ -16,7 +16,7 @@ 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"
@@ -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 ForwardFromPublicChatInfo.FromChannel -> regular("Channel (") + code(forwardInfo.channelChat.title) + ")"
+                    is ForwardFromPublicChatInfo.FromSupergroup -> regular("Supergroup (") + code(forwardInfo.group.title) + ")"
+                    is ForwardFromPublicChatInfo.SentByChannel -> regular("Sent by channel (") + code(forwardInfo.channelChat.title) + ")"
                 }
             }
             reply(it, toAnswer)