mirror of
https://github.com/InsanusMokrassar/TelegramBotAPI-examples.git
synced 2024-11-22 00:03:54 +00:00
fixes in forward chat info bot
This commit is contained in:
parent
d547dce2ab
commit
21692d16ca
@ -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,7 +16,7 @@ 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"
|
||||||
@ -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 ForwardFromPublicChatInfo.FromChannel -> regular("Channel (") + code(forwardInfo.channelChat.title) + ")"
|
||||||
is ForwardFromSupergroupInfo -> regular("Supergroup (") + code((forwardInfo.group).title) + ")"
|
is ForwardFromPublicChatInfo.FromSupergroup -> regular("Supergroup (") + code(forwardInfo.group.title) + ")"
|
||||||
|
is ForwardFromPublicChatInfo.SentByChannel -> regular("Sent by channel (") + code(forwardInfo.channelChat.title) + ")"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
reply(it, toAnswer)
|
reply(it, toAnswer)
|
||||||
|
Loading…
Reference in New Issue
Block a user