-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathutils.go
More file actions
44 lines (38 loc) · 1.05 KB
/
utils.go
File metadata and controls
44 lines (38 loc) · 1.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package main
import (
"fmt"
"log"
"os"
"strconv"
"strings"
tgbotapi "github.com/go-telegram-bot-api/telegram-bot-api"
)
func getFileSize(filename string) (int64, error) {
var size int64
fi, err := os.Stat(filename)
if err != nil {
return size, err
}
size = fi.Size()
return size, nil
}
func parseTimeToSeconds(timeStr string) float64 {
parts := strings.Split(timeStr, ":")
hours, _ := strconv.ParseFloat(parts[0], 64)
minutes, _ := strconv.ParseFloat(parts[1], 64)
seconds, _ := strconv.ParseFloat(parts[2], 64)
return hours*3600 + minutes*60 + seconds
}
func updateProgress(bot *tgbotapi.BotAPI, chatID int64, messageID, percentage int) {
progressBar := generateProgressBar(percentage)
editMsg := tgbotapi.NewEditMessageText(chatID, messageID, progressBar)
_, err := bot.Send(editMsg)
if err != nil {
log.Println(err)
}
}
func generateProgressBar(percentage int) string {
progress := percentage / 10
bar := strings.Repeat("◼️", progress) + strings.Repeat("◽️", 10-progress)
return fmt.Sprintf("-=[%s]=- %d%%", bar, percentage)
}