-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathspeed.go
39 lines (29 loc) · 919 Bytes
/
speed.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
package main
import (
"fmt"
"time"
humanize "github.com/pyed/go-humanize"
tgbotapi "gopkg.in/telegram-bot-api.v4"
)
// speed will echo back the current download and upload speeds
func speed() {
down, up := rtorrent.Speeds()
msg := fmt.Sprintf("↓ %s ↑ %s", humanize.IBytes(down), humanize.IBytes(up))
msgID := send(msg, false)
if NoLive {
return
}
for i := 0; i < duration; i++ {
time.Sleep(time.Second * interval)
down, up = rtorrent.Speeds()
msg = fmt.Sprintf("↓ %s ↑ %s", humanize.IBytes(down), humanize.IBytes(up))
editConf := tgbotapi.NewEditMessageText(chatID, msgID, msg)
Bot.Send(editConf)
time.Sleep(time.Second * interval)
}
// sleep one more time before switching to dashes
time.Sleep(time.Second * interval)
// show dashes to indicate that we are done updating.
editConf := tgbotapi.NewEditMessageText(chatID, msgID, "↓ - B ↑ - B")
Bot.Send(editConf)
}