@@ -19,6 +19,7 @@ import dev.inmo.tgbotapi.extensions.api.files.downloadFileToTemp
1919import dev.inmo.tgbotapi.extensions.api.get.getBusinessConnection
2020import dev.inmo.tgbotapi.extensions.api.send.reply
2121import dev.inmo.tgbotapi.extensions.api.send.send
22+ import dev.inmo.tgbotapi.extensions.api.stories.deleteStory
2223import dev.inmo.tgbotapi.extensions.api.stories.postStory
2324import dev.inmo.tgbotapi.extensions.behaviour_builder.telegramBotWithBehaviourAndLongPolling
2425import dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling.*
@@ -40,7 +41,10 @@ import dev.inmo.tgbotapi.types.business_connection.BusinessConnectionId
4041import dev.inmo.tgbotapi.types.chat.PrivateChat
4142import dev.inmo.tgbotapi.types.message.abstracts.CommonMessage
4243import dev.inmo.tgbotapi.types.message.content.PhotoContent
44+ import dev.inmo.tgbotapi.types.message.content.StoryContent
4345import dev.inmo.tgbotapi.types.message.content.TextContent
46+ import dev.inmo.tgbotapi.types.message.content.VideoContent
47+ import dev.inmo.tgbotapi.types.message.content.VisualMediaGroupPartContent
4448import dev.inmo.tgbotapi.types.stories.InputStoryContent
4549import dev.inmo.tgbotapi.types.stories.StoryArea
4650import dev.inmo.tgbotapi.types.stories.StoryAreaPosition
@@ -325,23 +329,28 @@ suspend fun main(args: Array<String>) {
325329 handleSetProfilePhoto(it, true )
326330 }
327331
328- onCommand(" postStory " , initialFilter = { it.chat is PrivateChat }) {
332+ onCommand(" post_story " , initialFilter = { it.chat is PrivateChat }) {
329333 val businessConnectionId = chatsBusinessConnections[it.chat.id] ? : return @onCommand
330- val replyTo = it.replyTo ?.commonMessageOrNull() ?.withContentOrNull<PhotoContent >()
334+ val replyTo = it.replyTo ?.commonMessageOrNull() ?.withContentOrNull<VisualMediaGroupPartContent >()
331335 if (replyTo == null ) {
332336 reply(it) {
333- + " Reply to photo for using of this command"
337+ + " Reply to photo or video for using of this command"
334338 }
335339 return @onCommand
336340 }
337341
338- val set = runCatching {
342+ val posted = runCatching {
339343 val file = downloadFileToTemp(replyTo.content)
340344 postStory(
341345 businessConnectionId,
342- InputStoryContent .Photo (
343- file.multipartFile()
344- ),
346+ when (replyTo.content) {
347+ is PhotoContent -> InputStoryContent .Photo (
348+ file.multipartFile()
349+ )
350+ is VideoContent -> InputStoryContent .Video (
351+ file.multipartFile()
352+ )
353+ },
345354 activePeriod = PostStory .ACTIVE_PERIOD_6_HOURS ,
346355 areas = listOf (
347356 StoryArea (
@@ -366,12 +375,37 @@ suspend fun main(args: Array<String>) {
366375 null
367376 }
368377 reply(it) {
369- if (set != null ) {
378+ if (posted != null ) {
370379 + " Story has been posted. You may unpost it with " + botCommand(" remove_story" )
371380 } else {
372381 + " Story has not been posted"
373382 }
374383 }
375384 }
385+
386+ onCommand(" delete_story" , initialFilter = { it.chat is PrivateChat }) {
387+ val businessConnectionId = chatsBusinessConnections[it.chat.id] ? : return @onCommand
388+ val replyTo = it.replyTo ?.commonMessageOrNull() ?.withContentOrNull<StoryContent >()
389+ if (replyTo == null ) {
390+ reply(it) {
391+ + " Reply to photo or video for using of this command"
392+ }
393+ return @onCommand
394+ }
395+
396+ val deleted = runCatching {
397+ deleteStory(businessConnectionId, replyTo.content.story.id)
398+ }.getOrElse {
399+ it.printStackTrace()
400+ false
401+ }
402+ reply(it) {
403+ if (deleted) {
404+ + " Story has been deleted"
405+ } else {
406+ + " Story has not been deleted"
407+ }
408+ }
409+ }
376410 }.second.join()
377411}
0 commit comments