-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathcheck.go
54 lines (46 loc) · 1.16 KB
/
check.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
package main
import (
"fmt"
"strconv"
)
// check takes id[s] of torrent[s] or 'all' to verify them
func check(tokens []string) {
// make sure that we got at least one argument
if len(tokens) == 0 {
send("check: needs an argument", false)
return
}
torrents, err := rtorrent.Torrents()
if err != nil {
logger.Print("check:", err)
send("check: "+err.Error(), false)
return
}
// if the first argument is 'all' then start all torrents
if tokens[0] == "all" {
if err := rtorrent.Check(torrents...); err != nil {
logger.Print("check:", err)
send("check: error occurred while verifying some torrents", false)
return
}
send("hash checking all torrents", false)
return
}
for _, i := range tokens {
id, err := strconv.Atoi(i)
if err != nil {
send(fmt.Sprintf("check: %s is not a number", i), false)
continue
}
if id >= len(torrents) || id < 0 {
send(fmt.Sprintf("Check: No torrent with an ID of '%d'", id), false)
continue
}
if err := rtorrent.Check(torrents[id]); err != nil {
logger.Print("Check:", err)
send("Check: "+err.Error(), false)
continue
}
send(fmt.Sprintf("Checking: %s", torrents[id].Name), false)
}
}