Compare commits
No commits in common. "cf149f7a8929dd06562ae7f918a0158e248125ef" and "16cb1dfbe7f4879e9a84555d8bf900ce70877e42" have entirely different histories.
cf149f7a89
...
16cb1dfbe7
@ -29,7 +29,7 @@ trigger:
|
|||||||
services:
|
services:
|
||||||
- name: docker
|
- name: docker
|
||||||
# https://hub.docker.com/r/library/docker
|
# https://hub.docker.com/r/library/docker
|
||||||
image: hub.docker.struchkov.dev/docker:27.3.1-dind-alpine3.20
|
image: hub.docker.struchkov.dev/docker:27.0.3-dind-alpine3.20
|
||||||
privileged: true
|
privileged: true
|
||||||
volumes:
|
volumes:
|
||||||
- name: dockersock
|
- name: dockersock
|
||||||
@ -45,6 +45,6 @@ image_pull_secrets:
|
|||||||
# drone sign --save DockerFiles/transmission-telegram
|
# drone sign --save DockerFiles/transmission-telegram
|
||||||
---
|
---
|
||||||
kind: signature
|
kind: signature
|
||||||
hmac: 5af7a78fc831318a31863c4f713b3c6e10d752e80f2208344a91e503ecc300c6
|
hmac: 361d5ccc8e44241263fa87233c4d9454eb9f22eb9da12ee4012d91f99d823253
|
||||||
|
|
||||||
...
|
...
|
||||||
|
98
main.go
98
main.go
@ -15,7 +15,7 @@ import (
|
|||||||
"github.com/dustin/go-humanize"
|
"github.com/dustin/go-humanize"
|
||||||
"github.com/pyed/tailer"
|
"github.com/pyed/tailer"
|
||||||
"github.com/pyed/transmission"
|
"github.com/pyed/transmission"
|
||||||
tgbotapi "gopkg.in/telegram-bot-api.v4"
|
"gopkg.in/telegram-bot-api.v4"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@ -31,7 +31,7 @@ const (
|
|||||||
*tail* or *ta*
|
*tail* or *ta*
|
||||||
Lists the last n number of torrents, n defaults to 5 if no argument is provided.
|
Lists the last n number of torrents, n defaults to 5 if no argument is provided.
|
||||||
|
|
||||||
*downs* or *dg*
|
*downs* or *dl*
|
||||||
Lists torrents with the status of _Downloading_ or in the queue to download.
|
Lists torrents with the status of _Downloading_ or in the queue to download.
|
||||||
|
|
||||||
*seeding* or *sd*
|
*seeding* or *sd*
|
||||||
@ -55,10 +55,6 @@ const (
|
|||||||
*trackers* or *tr*
|
*trackers* or *tr*
|
||||||
Lists all the trackers along with the number of torrents.
|
Lists all the trackers along with the number of torrents.
|
||||||
|
|
||||||
*downloaddir* or *dd*
|
|
||||||
Set download directory to the specified path. Transmission will automatically create a
|
|
||||||
directory in case you provided an inexistent one.
|
|
||||||
|
|
||||||
*add* or *ad*
|
*add* or *ad*
|
||||||
Takes one or many URLs or magnets to add them. You can send a ".torrent" file via Telegram to add it.
|
Takes one or many URLs or magnets to add them. You can send a ".torrent" file via Telegram to add it.
|
||||||
|
|
||||||
@ -89,12 +85,6 @@ const (
|
|||||||
*stats* or *sa*
|
*stats* or *sa*
|
||||||
Shows Transmission's stats.
|
Shows Transmission's stats.
|
||||||
|
|
||||||
*downlimit* or *dl*
|
|
||||||
Set global limit for download speed in kilobytes.
|
|
||||||
|
|
||||||
*uplimit* or *ul*
|
|
||||||
Set global limit for upload speed in kilobytes.
|
|
||||||
|
|
||||||
*speed* or *ss*
|
*speed* or *ss*
|
||||||
Shows the upload and download speeds.
|
Shows the upload and download speeds.
|
||||||
|
|
||||||
@ -342,7 +332,7 @@ func main() {
|
|||||||
case "tail", "/tail", "ta", "/ta":
|
case "tail", "/tail", "ta", "/ta":
|
||||||
go tail(update, tokens[1:])
|
go tail(update, tokens[1:])
|
||||||
|
|
||||||
case "downs", "/downs", "dg", "/dg":
|
case "downs", "/downs", "dl", "/dl":
|
||||||
go downs(update)
|
go downs(update)
|
||||||
|
|
||||||
case "seeding", "/seeding", "sd", "/sd":
|
case "seeding", "/seeding", "sd", "/sd":
|
||||||
@ -366,9 +356,6 @@ func main() {
|
|||||||
case "trackers", "/trackers", "tr", "/tr":
|
case "trackers", "/trackers", "tr", "/tr":
|
||||||
go trackers(update)
|
go trackers(update)
|
||||||
|
|
||||||
case "downloaddir", "dd":
|
|
||||||
go downloaddir(update, tokens[1:])
|
|
||||||
|
|
||||||
case "add", "/add", "ad", "/ad":
|
case "add", "/add", "ad", "/ad":
|
||||||
go add(update, tokens[1:])
|
go add(update, tokens[1:])
|
||||||
|
|
||||||
@ -393,12 +380,6 @@ func main() {
|
|||||||
case "stats", "/stats", "sa", "/sa":
|
case "stats", "/stats", "sa", "/sa":
|
||||||
go stats(update)
|
go stats(update)
|
||||||
|
|
||||||
case "downlimit", "dl":
|
|
||||||
go downlimit(update, tokens[1:])
|
|
||||||
|
|
||||||
case "uplimit", "ul":
|
|
||||||
go uplimit(update, tokens[1:])
|
|
||||||
|
|
||||||
case "speed", "/speed", "ss", "/ss":
|
case "speed", "/speed", "ss", "/ss":
|
||||||
go speed(update)
|
go speed(update)
|
||||||
|
|
||||||
@ -969,34 +950,6 @@ func trackers(ud tgbotapi.Update) {
|
|||||||
send(buf.String(), ud.Message.Chat.ID, false)
|
send(buf.String(), ud.Message.Chat.ID, false)
|
||||||
}
|
}
|
||||||
|
|
||||||
// downloaddir takes a path and sets it as the download directory
|
|
||||||
func downloaddir(ud tgbotapi.Update, tokens []string) {
|
|
||||||
if len(tokens) < 1 {
|
|
||||||
send("Please, specify a path for downloaddir", ud.Message.Chat.ID, false)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
downloadDir := tokens[0]
|
|
||||||
|
|
||||||
cmd := transmission.NewSessionSetCommand()
|
|
||||||
cmd.SetDownloadDir(downloadDir)
|
|
||||||
|
|
||||||
out, err := Client.ExecuteCommand(cmd)
|
|
||||||
if err != nil {
|
|
||||||
send("*downloaddir:* "+err.Error(), ud.Message.Chat.ID, false)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if out.Result != "success" {
|
|
||||||
send("*downloaddir:* "+out.Result, ud.Message.Chat.ID, false)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
send(
|
|
||||||
"*downloaddir:* downloaddir has been successfully changed to"+downloadDir,
|
|
||||||
ud.Message.Chat.ID, false,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
// add takes an URL to a .torrent file to add it to transmission
|
// add takes an URL to a .torrent file to add it to transmission
|
||||||
func add(ud tgbotapi.Update, tokens []string) {
|
func add(ud tgbotapi.Update, tokens []string) {
|
||||||
if len(tokens) == 0 {
|
if len(tokens) == 0 {
|
||||||
@ -1363,51 +1316,6 @@ func stats(ud tgbotapi.Update) {
|
|||||||
send(msg, ud.Message.Chat.ID, true)
|
send(msg, ud.Message.Chat.ID, true)
|
||||||
}
|
}
|
||||||
|
|
||||||
// downlimit sets the global downlimit to a provided value in kilobytes
|
|
||||||
func downlimit(ud tgbotapi.Update, tokens []string) {
|
|
||||||
speedLimit(ud, tokens, transmission.DownloadLimitType)
|
|
||||||
}
|
|
||||||
|
|
||||||
// uplimit sets the global uplimit to a provided value in kilobytes
|
|
||||||
func uplimit(ud tgbotapi.Update, tokens []string) {
|
|
||||||
speedLimit(ud, tokens, transmission.UploadLimitType)
|
|
||||||
}
|
|
||||||
|
|
||||||
// speedLimit sets either a donwload or upload limit
|
|
||||||
func speedLimit(ud tgbotapi.Update, tokens []string, limitType transmission.SpeedLimitType) {
|
|
||||||
if len(tokens) < 1 {
|
|
||||||
send("Please, specify the limit", ud.Message.Chat.ID, false)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
limit, err := strconv.ParseUint(tokens[0], 10, 32)
|
|
||||||
if err != nil {
|
|
||||||
send("Please, specify the limit as number of kilobytes", ud.Message.Chat.ID, false)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
speedLimitCmd := transmission.NewSpeedLimitCommand(limitType, uint(limit))
|
|
||||||
if speedLimitCmd == nil {
|
|
||||||
send(fmt.Sprintf("*%s:* internal error", limitType), ud.Message.Chat.ID, false)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
out, err := Client.ExecuteCommand(speedLimitCmd)
|
|
||||||
if err != nil {
|
|
||||||
send(fmt.Sprintf("*%s:* %v", limitType, err.Error()), ud.Message.Chat.ID, false)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if out.Result != "success" {
|
|
||||||
send(fmt.Sprintf("*%s:* %v", limitType, out.Result), ud.Message.Chat.ID, false)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
send(
|
|
||||||
fmt.Sprintf("*%s:* limit has been successfully changed to %d KB/s", limitType, limit),
|
|
||||||
ud.Message.Chat.ID, false,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
// speed will echo back the current download and upload speeds
|
// speed will echo back the current download and upload speeds
|
||||||
func speed(ud tgbotapi.Update) {
|
func speed(ud tgbotapi.Update) {
|
||||||
stats, err := Client.GetStats()
|
stats, err := Client.GetStats()
|
||||||
|
Loading…
Reference in New Issue
Block a user