-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathcount.go
42 lines (34 loc) · 816 Bytes
/
count.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
package main
import (
"fmt"
"github.com/pyed/rtapi"
)
// count returns current torrents count per status
func count() {
torrents, err := rtorrent.Torrents()
if err != nil {
logger.Print("count:", err)
send("count: "+err.Error(), false)
return
}
var Leeching, Seeding, Complete, Stopped, Hashing, Error int
for i := range torrents {
switch torrents[i].State {
case rtapi.Leeching:
Leeching++
case rtapi.Seeding:
Seeding++
case rtapi.Complete:
Complete++
case rtapi.Stopped:
Stopped++
case rtapi.Hashing:
Hashing++
case rtapi.Error:
Error++
}
}
msg := fmt.Sprintf("Leeching: *%d*\nSeeding: *%d*\nComplete: *%d*\nStopped: *%d*\nHashing: *%d*\nError: *%d*\n\nTotal: *%d*",
Leeching, Seeding, Complete, Stopped, Hashing, Error, len(torrents))
send(msg, true)
}