/
stats.go
55 lines (44 loc) · 1.08 KB
/
stats.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
44
45
46
47
48
49
50
51
52
53
54
55
package cmd
import (
"fmt"
"github.com/darenliang/dscli/common"
"github.com/dustin/go-humanize"
"github.com/spf13/cobra"
"strconv"
)
// statsCmd represents the stats command
var statsCmd = &cobra.Command{
Use: "stats",
Short: "Statistics for dscli",
RunE: stats,
}
func init() {
rootCmd.AddCommand(statsCmd)
}
func stats(cmd *cobra.Command, args []string) error {
session, guild, channels, err := common.GetDiscordSession()
if err != nil {
return err
}
defer session.Close()
fileMap, err := common.ParseFileMap(channels)
if err != nil {
return err
}
fmt.Printf("Number of files stored: %d/500\n", len(fileMap))
// calculate total size
var totalSize uint64
for _, channel := range fileMap {
filesize, err := strconv.ParseUint(channel.Topic, 10, 64)
if err == nil {
totalSize += filesize
}
}
fmt.Printf("Total size stored: %s\n", humanize.Bytes(totalSize))
maxFileSizeUpload, err := common.GetMaxFileSizeUpload(session, guild)
if err != nil {
return err
}
fmt.Printf("Upload chunk size: %s\n", humanize.Bytes(uint64(maxFileSizeUpload)))
return nil
}