-
Notifications
You must be signed in to change notification settings - Fork 40
/
helpers.go
43 lines (37 loc) · 960 Bytes
/
helpers.go
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
package main
import (
"math"
"math/rand"
"strings"
"time"
)
func init() {
rand.Seed(time.Now().UnixNano())
}
var letterRunes = []rune("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ")
func RandStringRunes(n int) string {
b := make([]rune, n)
for i := range b {
b[i] = letterRunes[rand.Intn(len(letterRunes))]
}
return string(b)
}
func GetMemoFromCommand(command string, fromWord int) string {
// check for memo in command
memo := ""
if len(strings.Split(command, " ")) > fromWord {
memo = strings.SplitN(command, " ", fromWord+1)[fromWord]
memoMaxLen := 159
if len(memo) > memoMaxLen {
memo = memo[:memoMaxLen]
}
}
return memo
}
func MakeProgressbar(current int, total int) string {
MAX_BARS := 16
progress := math.Round((float64(current) / float64(total)) * float64(MAX_BARS))
progressbar := strings.Repeat("🟩", int(progress))
progressbar += strings.Repeat("⬜️", MAX_BARS-int(progress))
return progressbar
}