From a88060423fe5be5daa0b7fda4992b87d08de91dc Mon Sep 17 00:00:00 2001 From: wrench Date: Fri, 15 Dec 2023 01:20:27 +0530 Subject: [PATCH] feat(bot): add stream and download buttons --- internal/commands/stream.go | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/internal/commands/stream.go b/internal/commands/stream.go index c9cf77da..89b5fff1 100644 --- a/internal/commands/stream.go +++ b/internal/commands/stream.go @@ -2,6 +2,7 @@ package commands import ( "fmt" + "strings" "EverythingSuckz/fsb/config" "EverythingSuckz/fsb/internal/utils" @@ -58,6 +59,34 @@ func sendLink(ctx *ext.Context, u *ext.Update) error { ) hash := utils.GetShortHash(fullHash) link := fmt.Sprintf("%s/stream/%d?hash=%s", config.ValueOf.Host, messageID, hash) - ctx.Reply(u, link, nil) + row := tg.KeyboardButtonRow{ + Buttons: []tg.KeyboardButtonClass{ + &tg.KeyboardButtonURL{ + Text: "Download", + URL: link + "&d=true", + }, + }, + } + if strings.Contains(file.MimeType, "video") || strings.Contains(file.MimeType, "audio") || strings.Contains(file.MimeType, "pdf") { + row.Buttons = append(row.Buttons, &tg.KeyboardButtonURL{ + Text: "Stream", + URL: link, + }) + } + markup := &tg.ReplyInlineMarkup{ + Rows: []tg.KeyboardButtonRow{row}, + } + if strings.Contains(link, "http://localhost") { + markup = nil + } + _, err = ctx.Reply(u, link, &ext.ReplyOpts{ + Markup: markup, + NoWebpage: false, + ReplyToMessageId: u.EffectiveMessage.ID, + }) + if err != nil { + utils.Logger.Sugar().Error(err) + ctx.Reply(u, fmt.Sprintf("Error - %s", err.Error()), nil) + } return dispatcher.EndGroups }