forked from pyed/rtelegram
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtrackers.go
42 lines (35 loc) · 789 Bytes
/
trackers.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 (
"bytes"
"fmt"
"regexp"
)
var trackerRegex = regexp.MustCompile(`[https?|udp]://([^:/]*)`)
// trackers will send a list of trackers and how many torrents each one has
func trackers() {
torrents, err := rtorrent.Torrents()
if err != nil {
logger.Print(err)
send("trackers: "+err.Error(), false)
return
}
trackers := make(map[string]int)
for i := range torrents {
currentTracker := torrents[i].Tracker.Hostname()
n, ok := trackers[currentTracker]
if !ok {
trackers[currentTracker] = 1
continue
}
trackers[currentTracker] = n + 1
}
buf := new(bytes.Buffer)
for k, v := range trackers {
buf.WriteString(fmt.Sprintf("%d - %s\n", v, k))
}
if buf.Len() == 0 {
send("No trackers!", false)
return
}
send(buf.String(), false)
}