Compare commits
7 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
4fd68bb874 | ||
|
8491708366 | ||
|
67a40f39b9 | ||
|
2365907fd7 | ||
|
7e4d1b7989 | ||
|
274f19ebe7 | ||
|
576279cfe8 |
3
.dockerignore
Normal file
3
.dockerignore
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
# ignore .git and .cache folders
|
||||||
|
.git
|
||||||
|
README.md
|
12
.gitmodules
vendored
12
.gitmodules
vendored
@ -1,12 +0,0 @@
|
|||||||
[submodule "vendor/github.com/dustin/go-humanize"]
|
|
||||||
path = vendor/github.com/dustin/go-humanize
|
|
||||||
url = https://github.com/dustin/go-humanize
|
|
||||||
[submodule "vendor/github.com/hpcloud/tail"]
|
|
||||||
path = vendor/github.com/hpcloud/tail
|
|
||||||
url = https://github.com/hpcloud/tail
|
|
||||||
[submodule "vendor/github.com/pyed/transmission"]
|
|
||||||
path = vendor/github.com/pyed/transmission
|
|
||||||
url = https://github.com/pyed/transmission
|
|
||||||
[submodule "vendor/gopkg.in/telegram-bot-api.v4"]
|
|
||||||
path = vendor/gopkg.in/telegram-bot-api.v4
|
|
||||||
url = https://gopkg.in/telegram-bot-api.v4
|
|
26
Dockerfile
Normal file
26
Dockerfile
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
FROM golang:alpine as build
|
||||||
|
|
||||||
|
ENV GOOS=linux \
|
||||||
|
GOARCH=amd64
|
||||||
|
|
||||||
|
RUN apk add --no-cache git
|
||||||
|
|
||||||
|
WORKDIR /go/src/transmission-telegram
|
||||||
|
COPY . .
|
||||||
|
|
||||||
|
RUN go mod init transmission-telegram
|
||||||
|
RUN go mod tidy
|
||||||
|
RUN go get -d -v ./...
|
||||||
|
RUN go install -v ./...
|
||||||
|
|
||||||
|
RUN go build -o main .
|
||||||
|
|
||||||
|
FROM alpine:latest as certs
|
||||||
|
RUN apk --update add ca-certificates
|
||||||
|
|
||||||
|
FROM bash:latest
|
||||||
|
COPY --from=certs /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ca-certificates.crt
|
||||||
|
COPY --from=build /go/bin/transmission-telegram /
|
||||||
|
RUN chmod 777 transmission-telegram
|
||||||
|
|
||||||
|
ENTRYPOINT ["/transmission-telegram"]
|
50
README.md
50
README.md
@ -4,7 +4,9 @@
|
|||||||
|
|
||||||
<img src="https://raw.github.com/pyed/transmission-telegram/master/demo.gif" width="400" />
|
<img src="https://raw.github.com/pyed/transmission-telegram/master/demo.gif" width="400" />
|
||||||
|
|
||||||
## Install
|
## CLI
|
||||||
|
|
||||||
|
### Install
|
||||||
|
|
||||||
Just [download](https://github.com/pyed/transmission-telegram/releases) the appropriate binary for your OS, place `transmission-telegram` in your `$PATH` and you are good to go.
|
Just [download](https://github.com/pyed/transmission-telegram/releases) the appropriate binary for your OS, place `transmission-telegram` in your `$PATH` and you are good to go.
|
||||||
|
|
||||||
@ -12,4 +14,48 @@ Or if you have `Go` installed: `go get -u github.com/pyed/transmission-telegram`
|
|||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
[Wiki](https://github.com/pyed/transmission-telegram/wiki)
|
[Wiki](https://github.com/pyed/transmission-telegram/wiki)
|
||||||
|
|
||||||
|
|
||||||
|
## Docker Alternate Installation Route
|
||||||
|
|
||||||
|
### Standalone
|
||||||
|
|
||||||
|
```
|
||||||
|
docker run -d --name transmission-telegram \
|
||||||
|
kevinhalpin/transmission-telegram:latest \
|
||||||
|
-token=<Your Bot Token> \
|
||||||
|
-master=<Your Username> \
|
||||||
|
-url=<Transmission RPC> \
|
||||||
|
-username=<Transmission If Needed> \
|
||||||
|
-password=<Transmissions If Needed>
|
||||||
|
```
|
||||||
|
|
||||||
|
### docker-compose Example
|
||||||
|
|
||||||
|
```
|
||||||
|
version: '2.4'
|
||||||
|
services:
|
||||||
|
transmission:
|
||||||
|
container_name: transmission
|
||||||
|
environment:
|
||||||
|
- PUID=${PUID_DOCKUSER}
|
||||||
|
- PGID=${PGID_APPZ}
|
||||||
|
image: linuxserver/transmission
|
||||||
|
network_mode: 'host'
|
||||||
|
hostname: 'transmission'
|
||||||
|
volumes:
|
||||||
|
- ${CONFIG}/transmission:/config
|
||||||
|
- ${DATA}/transmission/downloads:/downloads
|
||||||
|
|
||||||
|
telegram-transmission-bot:
|
||||||
|
container_name: telegram-transmission-bot
|
||||||
|
restart: on-failure
|
||||||
|
depends_on:
|
||||||
|
- transmission
|
||||||
|
- plex
|
||||||
|
- emby
|
||||||
|
network_mode: 'host'
|
||||||
|
image: kevinhalpin/transmission-telegram:latest
|
||||||
|
command: '-token=${TELEGRAM_TRANSMISSION_BOT} -master=${TELEGRAM_USERNAME} -url=${TRANSMISSION_URL} - username=${TRANSMISSION_USERNAME} -password=${PASS}'
|
||||||
|
```
|
||||||
|
225
main.go
225
main.go
@ -13,16 +13,16 @@ import (
|
|||||||
"unicode/utf8"
|
"unicode/utf8"
|
||||||
|
|
||||||
"github.com/dustin/go-humanize"
|
"github.com/dustin/go-humanize"
|
||||||
"github.com/hpcloud/tail"
|
"github.com/pyed/tailer"
|
||||||
"github.com/pyed/transmission"
|
"github.com/pyed/transmission"
|
||||||
"gopkg.in/telegram-bot-api.v4"
|
"gopkg.in/telegram-bot-api.v4"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
VERSION = "v1.4"
|
VERSION = "v1.4.1"
|
||||||
|
|
||||||
HELP = `
|
HELP = `
|
||||||
*list* or *li*
|
*list* or *li* or *ls*
|
||||||
Lists all the torrents, takes an optional argument which is a query to list only torrents that has a tracker matches the query, or some of it.
|
Lists all the torrents, takes an optional argument which is a query to list only torrents that has a tracker matches the query, or some of it.
|
||||||
|
|
||||||
*head* or *he*
|
*head* or *he*
|
||||||
@ -32,16 +32,16 @@ const (
|
|||||||
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.
|
||||||
|
|
||||||
*down* or *dl*
|
*down* 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*
|
||||||
Lists torrents with the status of Seeding or in the queue to seed.
|
Lists torrents with the status of _Seeding_ or in the queue to seed.
|
||||||
|
|
||||||
*paused* or *pa*
|
*paused* or *pa*
|
||||||
Lists Paused torrents.
|
Lists _Paused_ torrents.
|
||||||
|
|
||||||
*checking* or *ch*
|
*checking* or *ch*
|
||||||
Lists torrents with the status of Verifying or in the queue to verify.
|
Lists torrents with the status of _Verifying_ or in the queue to verify.
|
||||||
|
|
||||||
*active* or *ac*
|
*active* or *ac*
|
||||||
Lists torrents that are actively uploading or downloading.
|
Lists torrents that are actively uploading or downloading.
|
||||||
@ -50,13 +50,13 @@ const (
|
|||||||
Lists torrents with with errors along with the error message.
|
Lists torrents with with errors along with the error message.
|
||||||
|
|
||||||
*sort* or *so*
|
*sort* or *so*
|
||||||
Manipulate the sorting of the aforementioned commands, Call it without arguments for more.
|
Manipulate the sorting of the aforementioned commands. Call it without arguments for more.
|
||||||
|
|
||||||
*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.
|
||||||
|
|
||||||
*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.
|
||||||
|
|
||||||
*search* or *se*
|
*search* or *se*
|
||||||
Takes a query and lists torrents with matching names.
|
Takes a query and lists torrents with matching names.
|
||||||
@ -76,7 +76,7 @@ const (
|
|||||||
*check* or *ck*
|
*check* or *ck*
|
||||||
Takes one or more torrent's IDs to verify them, or _all_ to verify all torrents.
|
Takes one or more torrent's IDs to verify them, or _all_ to verify all torrents.
|
||||||
|
|
||||||
*del*
|
*del* or *rm*
|
||||||
Takes one or more torrent's IDs to delete them.
|
Takes one or more torrent's IDs to delete them.
|
||||||
|
|
||||||
*deldata*
|
*deldata*
|
||||||
@ -94,7 +94,7 @@ const (
|
|||||||
*help*
|
*help*
|
||||||
Shows this help message.
|
Shows this help message.
|
||||||
|
|
||||||
*version*
|
*version* or *ver*
|
||||||
Shows version numbers.
|
Shows version numbers.
|
||||||
|
|
||||||
- Prefix commands with '/' if you want to talk to your bot in a group.
|
- Prefix commands with '/' if you want to talk to your bot in a group.
|
||||||
@ -169,7 +169,7 @@ func (masters masterSlice) Contains(master string) bool {
|
|||||||
// init flags
|
// init flags
|
||||||
func init() {
|
func init() {
|
||||||
// define arguments and parse them.
|
// define arguments and parse them.
|
||||||
flag.StringVar(&BotToken, "token", "", "Telegram bot token")
|
flag.StringVar(&BotToken, "token", "", "Telegram bot token, Can be passed via environment variable 'TT_BOTT'")
|
||||||
flag.Var(&Masters, "master", "Your telegram handler, So the bot will only respond to you. Can specify more than one")
|
flag.Var(&Masters, "master", "Your telegram handler, So the bot will only respond to you. Can specify more than one")
|
||||||
flag.StringVar(&RPCURL, "url", "http://localhost:9091/transmission/rpc", "Transmission RPC URL")
|
flag.StringVar(&RPCURL, "url", "http://localhost:9091/transmission/rpc", "Transmission RPC URL")
|
||||||
flag.StringVar(&Username, "username", "", "Transmission username")
|
flag.StringVar(&Username, "username", "", "Transmission username")
|
||||||
@ -180,12 +180,19 @@ func init() {
|
|||||||
|
|
||||||
// set the usage message
|
// set the usage message
|
||||||
flag.Usage = func() {
|
flag.Usage = func() {
|
||||||
fmt.Fprint(os.Stderr, "Usage: transmission-bot <-token=TOKEN> <-master=@tuser> [-master=@yuser2] [-url=http://] [-username=user] [-password=pass]\n\n")
|
fmt.Fprint(os.Stderr, "Usage: transmission-telegram <-token=TOKEN> <-master=@tuser> [-master=@yuser2] [-url=http://] [-username=user] [-password=pass]\n\n")
|
||||||
flag.PrintDefaults()
|
flag.PrintDefaults()
|
||||||
}
|
}
|
||||||
|
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
|
// if we don't have BotToken passed, check the environment variable "TT_BOTT"
|
||||||
|
if BotToken == "" {
|
||||||
|
if token := os.Getenv("TT_BOTT"); len(token) > 1 {
|
||||||
|
BotToken = token
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// make sure that we have the two madatory arguments: telegram token & master's handler.
|
// make sure that we have the two madatory arguments: telegram token & master's handler.
|
||||||
if BotToken == "" ||
|
if BotToken == "" ||
|
||||||
len(Masters) < 1 {
|
len(Masters) < 1 {
|
||||||
@ -211,16 +218,7 @@ func init() {
|
|||||||
// if we got a transmission log file, monitor it for torrents completion to notify upon them.
|
// if we got a transmission log file, monitor it for torrents completion to notify upon them.
|
||||||
if TransLogFile != "" {
|
if TransLogFile != "" {
|
||||||
go func() {
|
go func() {
|
||||||
ft, err := tail.TailFile(TransLogFile, tail.Config{
|
ft := tailer.RunFileTailer(TransLogFile, false, nil)
|
||||||
Location: &tail.SeekInfo{0, 2}, // ignore previous log lines
|
|
||||||
Follow: true, // as the -f in tail -f
|
|
||||||
MustExist: true, // if you can't find the file, don't wait for it to be created
|
|
||||||
Logger: logger, // log to our logger
|
|
||||||
})
|
|
||||||
if err != nil {
|
|
||||||
logger.Printf("[ERROR] tailing transmission log: %s", err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// [2017-02-22 21:00:00.898] File-Name State changed from "Incomplete" to "Complete" (torrent.c:2218)
|
// [2017-02-22 21:00:00.898] File-Name State changed from "Incomplete" to "Complete" (torrent.c:2218)
|
||||||
const (
|
const (
|
||||||
@ -229,16 +227,23 @@ func init() {
|
|||||||
end = len(` State changed from "Incomplete" to "Complete" (torrent.c:2218)`)
|
end = len(` State changed from "Incomplete" to "Complete" (torrent.c:2218)`)
|
||||||
)
|
)
|
||||||
|
|
||||||
for line := range ft.Lines {
|
for {
|
||||||
if strings.Contains(line.Text, substring) {
|
select {
|
||||||
// if we don't have a chatID continue
|
case line := <-ft.Lines():
|
||||||
if chatID == 0 {
|
if strings.Contains(line, substring) {
|
||||||
continue
|
// if we don't have a chatID continue
|
||||||
}
|
if chatID == 0 {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
msg := fmt.Sprintf("Completed: %s", line.Text[start:len(line.Text)-end])
|
msg := fmt.Sprintf("Completed: %s", line[start:len(line)-end])
|
||||||
send(msg, chatID, false)
|
send(msg, chatID, false)
|
||||||
|
}
|
||||||
|
case err := <-ft.Errors():
|
||||||
|
logger.Printf("[ERROR] tailing transmission log: %s", err)
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
@ -260,7 +265,7 @@ func init() {
|
|||||||
var err error
|
var err error
|
||||||
Client, err = transmission.New(RPCURL, Username, Password)
|
Client, err = transmission.New(RPCURL, Username, Password)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Fprintf(os.Stderr, "[ERROR] Transmission: Make sure you have the right URL, Username and Password")
|
fmt.Fprintf(os.Stderr, "[ERROR] Transmission: Make sure you have the right URL, Username and Password\n")
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -272,7 +277,7 @@ func init() {
|
|||||||
var err error
|
var err error
|
||||||
Bot, err = tgbotapi.NewBotAPI(BotToken)
|
Bot, err = tgbotapi.NewBotAPI(BotToken)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Fprintf(os.Stderr, "[ERROR] Telegram: %s", err)
|
fmt.Fprintf(os.Stderr, "[ERROR] Telegram: %s\n", err)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
logger.Printf("[INFO] Authorized: %s", Bot.Self.UserName)
|
logger.Printf("[INFO] Authorized: %s", Bot.Self.UserName)
|
||||||
@ -282,7 +287,7 @@ func init() {
|
|||||||
|
|
||||||
Updates, err = Bot.GetUpdatesChan(u)
|
Updates, err = Bot.GetUpdatesChan(u)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Fprintf(os.Stderr, "[ERROR] Telegram: %s", err)
|
fmt.Fprintf(os.Stderr, "[ERROR] Telegram: %s\n", err)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -307,17 +312,25 @@ func main() {
|
|||||||
|
|
||||||
// tokenize the update
|
// tokenize the update
|
||||||
tokens := strings.Split(update.Message.Text, " ")
|
tokens := strings.Split(update.Message.Text, " ")
|
||||||
|
|
||||||
|
// preprocess message based on URL schema
|
||||||
|
// in case those were added from the mobile via "Share..." option
|
||||||
|
// when it is not possible to easily prepend it with "add" command
|
||||||
|
if strings.HasPrefix(tokens[0], "magnet") || strings.HasPrefix(tokens[0], "http") {
|
||||||
|
tokens = append([]string{"add"}, tokens...)
|
||||||
|
}
|
||||||
|
|
||||||
command := strings.ToLower(tokens[0])
|
command := strings.ToLower(tokens[0])
|
||||||
|
|
||||||
switch command {
|
switch command {
|
||||||
case "list", "/list", "li", "/li":
|
case "list", "/list", "li", "/li", "/ls", "ls":
|
||||||
go list(update, tokens[1:])
|
go list(update, tokens[1:])
|
||||||
|
|
||||||
case "head", "/head", "he", "/he":
|
case "head", "/head", "he", "/he":
|
||||||
go head(update, tokens[1:])
|
go head(update, tokens[1:])
|
||||||
|
|
||||||
case "tail", "/tail", "ta", "/ta":
|
case "tail", "/tail", "ta", "/ta":
|
||||||
go tailf(update, tokens[1:])
|
go tail(update, tokens[1:])
|
||||||
|
|
||||||
case "downs", "/downs", "dl", "/dl":
|
case "downs", "/downs", "dl", "/dl":
|
||||||
go downs(update)
|
go downs(update)
|
||||||
@ -373,7 +386,7 @@ func main() {
|
|||||||
case "count", "/count", "co", "/co":
|
case "count", "/count", "co", "/co":
|
||||||
go count(update)
|
go count(update)
|
||||||
|
|
||||||
case "del", "/del":
|
case "del", "/del", "rm", "/rm":
|
||||||
go del(update, tokens[1:])
|
go del(update, tokens[1:])
|
||||||
|
|
||||||
case "deldata", "/deldata":
|
case "deldata", "/deldata":
|
||||||
@ -382,7 +395,7 @@ func main() {
|
|||||||
case "help", "/help":
|
case "help", "/help":
|
||||||
go send(HELP, update.Message.Chat.ID, true)
|
go send(HELP, update.Message.Chat.ID, true)
|
||||||
|
|
||||||
case "version", "/version":
|
case "version", "/version", "ver", "/ver":
|
||||||
go getVersion(update)
|
go getVersion(update)
|
||||||
|
|
||||||
case "":
|
case "":
|
||||||
@ -391,7 +404,7 @@ func main() {
|
|||||||
|
|
||||||
default:
|
default:
|
||||||
// no such command, try help
|
// no such command, try help
|
||||||
go send("no such command, try /help", update.Message.Chat.ID, false)
|
go send("No such command, try /help", update.Message.Chat.ID, false)
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -403,7 +416,7 @@ func main() {
|
|||||||
func list(ud tgbotapi.Update, tokens []string) {
|
func list(ud tgbotapi.Update, tokens []string) {
|
||||||
torrents, err := Client.GetTorrents()
|
torrents, err := Client.GetTorrents()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
send("list: "+err.Error(), ud.Message.Chat.ID, false)
|
send("*list:* "+err.Error(), ud.Message.Chat.ID, false)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -413,7 +426,7 @@ func list(ud tgbotapi.Update, tokens []string) {
|
|||||||
// (?i) for case insensitivity
|
// (?i) for case insensitivity
|
||||||
regx, err := regexp.Compile("(?i)" + tokens[0])
|
regx, err := regexp.Compile("(?i)" + tokens[0])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
send("list: "+err.Error(), ud.Message.Chat.ID, false)
|
send("*list:* "+err.Error(), ud.Message.Chat.ID, false)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -431,10 +444,10 @@ func list(ud tgbotapi.Update, tokens []string) {
|
|||||||
if buf.Len() == 0 {
|
if buf.Len() == 0 {
|
||||||
// if we got a tracker query show different message
|
// if we got a tracker query show different message
|
||||||
if len(tokens) != 0 {
|
if len(tokens) != 0 {
|
||||||
send(fmt.Sprintf("list: No tracker matches: *%s*", tokens[0]), ud.Message.Chat.ID, true)
|
send(fmt.Sprintf("*list:* No tracker matches: *%s*", tokens[0]), ud.Message.Chat.ID, true)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
send("list: No torrents", ud.Message.Chat.ID, false)
|
send("*list:* no torrents", ud.Message.Chat.ID, false)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -451,14 +464,14 @@ func head(ud tgbotapi.Update, tokens []string) {
|
|||||||
if len(tokens) > 0 {
|
if len(tokens) > 0 {
|
||||||
n, err = strconv.Atoi(tokens[0])
|
n, err = strconv.Atoi(tokens[0])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
send("head: argument must be a number", ud.Message.Chat.ID, false)
|
send("*head:* argument must be a number", ud.Message.Chat.ID, false)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
torrents, err := Client.GetTorrents()
|
torrents, err := Client.GetTorrents()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
send("head: "+err.Error(), ud.Message.Chat.ID, false)
|
send("*head:* "+err.Error(), ud.Message.Chat.ID, false)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -477,7 +490,7 @@ func head(ud tgbotapi.Update, tokens []string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if buf.Len() == 0 {
|
if buf.Len() == 0 {
|
||||||
send("head: No torrents", ud.Message.Chat.ID, false)
|
send("*head:* no torrents", ud.Message.Chat.ID, false)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -522,8 +535,8 @@ func head(ud tgbotapi.Update, tokens []string) {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// tailf lists the last 5 or n torrents
|
// tail lists the last 5 or n torrents
|
||||||
func tailf(ud tgbotapi.Update, tokens []string) {
|
func tail(ud tgbotapi.Update, tokens []string) {
|
||||||
var (
|
var (
|
||||||
n = 5 // default to 5
|
n = 5 // default to 5
|
||||||
err error
|
err error
|
||||||
@ -532,14 +545,14 @@ func tailf(ud tgbotapi.Update, tokens []string) {
|
|||||||
if len(tokens) > 0 {
|
if len(tokens) > 0 {
|
||||||
n, err = strconv.Atoi(tokens[0])
|
n, err = strconv.Atoi(tokens[0])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
send("tail: argument must be a number", ud.Message.Chat.ID, false)
|
send("*tail:* argument must be a number", ud.Message.Chat.ID, false)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
torrents, err := Client.GetTorrents()
|
torrents, err := Client.GetTorrents()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
send("tail: "+err.Error(), ud.Message.Chat.ID, false)
|
send("*tail:* "+err.Error(), ud.Message.Chat.ID, false)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -558,7 +571,7 @@ func tailf(ud tgbotapi.Update, tokens []string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if buf.Len() == 0 {
|
if buf.Len() == 0 {
|
||||||
send("tail: No torrents", ud.Message.Chat.ID, false)
|
send("*tail:* no torrents", ud.Message.Chat.ID, false)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -607,7 +620,7 @@ func tailf(ud tgbotapi.Update, tokens []string) {
|
|||||||
func downs(ud tgbotapi.Update) {
|
func downs(ud tgbotapi.Update) {
|
||||||
torrents, err := Client.GetTorrents()
|
torrents, err := Client.GetTorrents()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
send("downs: "+err.Error(), ud.Message.Chat.ID, false)
|
send("*downs:* "+err.Error(), ud.Message.Chat.ID, false)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -631,7 +644,7 @@ func downs(ud tgbotapi.Update) {
|
|||||||
func seeding(ud tgbotapi.Update) {
|
func seeding(ud tgbotapi.Update) {
|
||||||
torrents, err := Client.GetTorrents()
|
torrents, err := Client.GetTorrents()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
send("seeding: "+err.Error(), ud.Message.Chat.ID, false)
|
send("*seeding:* "+err.Error(), ud.Message.Chat.ID, false)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -656,7 +669,7 @@ func seeding(ud tgbotapi.Update) {
|
|||||||
func paused(ud tgbotapi.Update) {
|
func paused(ud tgbotapi.Update) {
|
||||||
torrents, err := Client.GetTorrents()
|
torrents, err := Client.GetTorrents()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
send("paused: "+err.Error(), ud.Message.Chat.ID, false)
|
send("*paused:* "+err.Error(), ud.Message.Chat.ID, false)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -682,7 +695,7 @@ func paused(ud tgbotapi.Update) {
|
|||||||
func checking(ud tgbotapi.Update) {
|
func checking(ud tgbotapi.Update) {
|
||||||
torrents, err := Client.GetTorrents()
|
torrents, err := Client.GetTorrents()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
send("checking: "+err.Error(), ud.Message.Chat.ID, false)
|
send("*checking:* "+err.Error(), ud.Message.Chat.ID, false)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -709,7 +722,7 @@ func checking(ud tgbotapi.Update) {
|
|||||||
func active(ud tgbotapi.Update) {
|
func active(ud tgbotapi.Update) {
|
||||||
torrents, err := Client.GetTorrents()
|
torrents, err := Client.GetTorrents()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
send("active: "+err.Error(), ud.Message.Chat.ID, false)
|
send("*active:* "+err.Error(), ud.Message.Chat.ID, false)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -791,7 +804,7 @@ func active(ud tgbotapi.Update) {
|
|||||||
func errors(ud tgbotapi.Update) {
|
func errors(ud tgbotapi.Update) {
|
||||||
torrents, err := Client.GetTorrents()
|
torrents, err := Client.GetTorrents()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
send("errors: "+err.Error(), ud.Message.Chat.ID, false)
|
send("*errors:* "+err.Error(), ud.Message.Chat.ID, false)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -812,7 +825,7 @@ func errors(ud tgbotapi.Update) {
|
|||||||
// sort changes torrents sorting
|
// sort changes torrents sorting
|
||||||
func sort(ud tgbotapi.Update, tokens []string) {
|
func sort(ud tgbotapi.Update, tokens []string) {
|
||||||
if len(tokens) == 0 {
|
if len(tokens) == 0 {
|
||||||
send(`sort takes one of:
|
send(`*sort* takes one of:
|
||||||
(*id, name, age, size, progress, downspeed, upspeed, download, upload, ratio*)
|
(*id, name, age, size, progress, downspeed, upspeed, download, upload, ratio*)
|
||||||
optionally start with (*rev*) for reversed order
|
optionally start with (*rev*) for reversed order
|
||||||
e.g. "*sort rev size*" to get biggest torrents first.`, ud.Message.Chat.ID, true)
|
e.g. "*sort rev size*" to get biggest torrents first.`, ud.Message.Chat.ID, true)
|
||||||
@ -892,10 +905,10 @@ func sort(ud tgbotapi.Update, tokens []string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if reversed {
|
if reversed {
|
||||||
send("sort: reversed "+tokens[0], ud.Message.Chat.ID, false)
|
send("*sort:* reversed "+tokens[0], ud.Message.Chat.ID, false)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
send("sort: "+tokens[0], ud.Message.Chat.ID, false)
|
send("*sort:* "+tokens[0], ud.Message.Chat.ID, false)
|
||||||
}
|
}
|
||||||
|
|
||||||
var trackerRegex = regexp.MustCompile(`[https?|udp]://([^:/]*)`)
|
var trackerRegex = regexp.MustCompile(`[https?|udp]://([^:/]*)`)
|
||||||
@ -904,7 +917,7 @@ var trackerRegex = regexp.MustCompile(`[https?|udp]://([^:/]*)`)
|
|||||||
func trackers(ud tgbotapi.Update) {
|
func trackers(ud tgbotapi.Update) {
|
||||||
torrents, err := Client.GetTorrents()
|
torrents, err := Client.GetTorrents()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
send("trackers: "+err.Error(), ud.Message.Chat.ID, false)
|
send("*trackers:* "+err.Error(), ud.Message.Chat.ID, false)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -940,7 +953,7 @@ func trackers(ud tgbotapi.Update) {
|
|||||||
// 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 {
|
||||||
send("add: needs atleast one URL", ud.Message.Chat.ID, false)
|
send("*add:* needs at least one URL", ud.Message.Chat.ID, false)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -950,16 +963,16 @@ func add(ud tgbotapi.Update, tokens []string) {
|
|||||||
|
|
||||||
torrent, err := Client.ExecuteAddCommand(cmd)
|
torrent, err := Client.ExecuteAddCommand(cmd)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
send("add: "+err.Error(), ud.Message.Chat.ID, false)
|
send("*add:* "+err.Error(), ud.Message.Chat.ID, false)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
// check if torrent.Name is empty, then an error happened
|
// check if torrent.Name is empty, then an error happened
|
||||||
if torrent.Name == "" {
|
if torrent.Name == "" {
|
||||||
send("add: error adding "+url, ud.Message.Chat.ID, false)
|
send("*add:* error adding "+url, ud.Message.Chat.ID, false)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
send(fmt.Sprintf("Added: <%d> %s", torrent.ID, torrent.Name), ud.Message.Chat.ID, false)
|
send(fmt.Sprintf("*Added:* <%d> %s", torrent.ID, torrent.Name), ud.Message.Chat.ID, false)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -975,7 +988,7 @@ func receiveTorrent(ud tgbotapi.Update) {
|
|||||||
}
|
}
|
||||||
file, err := Bot.GetFile(fconfig)
|
file, err := Bot.GetFile(fconfig)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
send("receiver: "+err.Error(), ud.Message.Chat.ID, false)
|
send("*receiver:* "+err.Error(), ud.Message.Chat.ID, false)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -987,7 +1000,7 @@ func receiveTorrent(ud tgbotapi.Update) {
|
|||||||
func search(ud tgbotapi.Update, tokens []string) {
|
func search(ud tgbotapi.Update, tokens []string) {
|
||||||
// make sure that we got a query
|
// make sure that we got a query
|
||||||
if len(tokens) == 0 {
|
if len(tokens) == 0 {
|
||||||
send("search: needs an argument", ud.Message.Chat.ID, false)
|
send("*search:* needs an argument", ud.Message.Chat.ID, false)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -995,13 +1008,13 @@ func search(ud tgbotapi.Update, tokens []string) {
|
|||||||
// "(?i)" for case insensitivity
|
// "(?i)" for case insensitivity
|
||||||
regx, err := regexp.Compile("(?i)" + query)
|
regx, err := regexp.Compile("(?i)" + query)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
send("search: "+err.Error(), ud.Message.Chat.ID, false)
|
send("*search:* "+err.Error(), ud.Message.Chat.ID, false)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
torrents, err := Client.GetTorrents()
|
torrents, err := Client.GetTorrents()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
send("search: "+err.Error(), ud.Message.Chat.ID, false)
|
send("*search:* "+err.Error(), ud.Message.Chat.ID, false)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1028,14 +1041,14 @@ func latest(ud tgbotapi.Update, tokens []string) {
|
|||||||
if len(tokens) > 0 {
|
if len(tokens) > 0 {
|
||||||
n, err = strconv.Atoi(tokens[0])
|
n, err = strconv.Atoi(tokens[0])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
send("latest: argument must be a number", ud.Message.Chat.ID, false)
|
send("*latest:* argument must be a number", ud.Message.Chat.ID, false)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
torrents, err := Client.GetTorrents()
|
torrents, err := Client.GetTorrents()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
send("latest: "+err.Error(), ud.Message.Chat.ID, false)
|
send("*latest:* "+err.Error(), ud.Message.Chat.ID, false)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1052,7 +1065,7 @@ func latest(ud tgbotapi.Update, tokens []string) {
|
|||||||
buf.WriteString(fmt.Sprintf("<%d> %s\n", torrents[i].ID, torrents[i].Name))
|
buf.WriteString(fmt.Sprintf("<%d> %s\n", torrents[i].ID, torrents[i].Name))
|
||||||
}
|
}
|
||||||
if buf.Len() == 0 {
|
if buf.Len() == 0 {
|
||||||
send("latest: No torrents", ud.Message.Chat.ID, false)
|
send("*latest:* No torrents", ud.Message.Chat.ID, false)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
send(buf.String(), ud.Message.Chat.ID, false)
|
send(buf.String(), ud.Message.Chat.ID, false)
|
||||||
@ -1061,21 +1074,21 @@ func latest(ud tgbotapi.Update, tokens []string) {
|
|||||||
// info takes an id of a torrent and returns some info about it
|
// info takes an id of a torrent and returns some info about it
|
||||||
func info(ud tgbotapi.Update, tokens []string) {
|
func info(ud tgbotapi.Update, tokens []string) {
|
||||||
if len(tokens) == 0 {
|
if len(tokens) == 0 {
|
||||||
send("info: needs a torrent ID number", ud.Message.Chat.ID, false)
|
send("*info:* needs a torrent ID number", ud.Message.Chat.ID, false)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, id := range tokens {
|
for _, id := range tokens {
|
||||||
torrentID, err := strconv.Atoi(id)
|
torrentID, err := strconv.Atoi(id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
send(fmt.Sprintf("info: %s is not a number", id), ud.Message.Chat.ID, false)
|
send(fmt.Sprintf("*info:* %s is not a number", id), ud.Message.Chat.ID, false)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
// get the torrent
|
// get the torrent
|
||||||
torrent, err := Client.GetTorrent(torrentID)
|
torrent, err := Client.GetTorrent(torrentID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
send(fmt.Sprintf("info: Can't find a torrent with an ID of %d", torrentID), ud.Message.Chat.ID, false)
|
send(fmt.Sprintf("*info:* Can't find a torrent with an ID of %d", torrentID), ud.Message.Chat.ID, false)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1146,38 +1159,38 @@ func info(ud tgbotapi.Update, tokens []string) {
|
|||||||
func stop(ud tgbotapi.Update, tokens []string) {
|
func stop(ud tgbotapi.Update, tokens []string) {
|
||||||
// make sure that we got at least one argument
|
// make sure that we got at least one argument
|
||||||
if len(tokens) == 0 {
|
if len(tokens) == 0 {
|
||||||
send("stop: needs an argument", ud.Message.Chat.ID, false)
|
send("*stop:* needs an argument", ud.Message.Chat.ID, false)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// if the first argument is 'all' then stop all torrents
|
// if the first argument is 'all' then stop all torrents
|
||||||
if tokens[0] == "all" {
|
if tokens[0] == "all" {
|
||||||
if err := Client.StopAll(); err != nil {
|
if err := Client.StopAll(); err != nil {
|
||||||
send("stop: error occurred while stopping some torrents", ud.Message.Chat.ID, false)
|
send("*stop:* error occurred while stopping some torrents", ud.Message.Chat.ID, false)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
send("stopped all torrents", ud.Message.Chat.ID, false)
|
send("Stopped all torrents", ud.Message.Chat.ID, false)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, id := range tokens {
|
for _, id := range tokens {
|
||||||
num, err := strconv.Atoi(id)
|
num, err := strconv.Atoi(id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
send(fmt.Sprintf("stop: %s is not a number", id), ud.Message.Chat.ID, false)
|
send(fmt.Sprintf("*stop:* %s is not a number", id), ud.Message.Chat.ID, false)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
status, err := Client.StopTorrent(num)
|
status, err := Client.StopTorrent(num)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
send("stop: "+err.Error(), ud.Message.Chat.ID, false)
|
send("*stop:* "+err.Error(), ud.Message.Chat.ID, false)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
torrent, err := Client.GetTorrent(num)
|
torrent, err := Client.GetTorrent(num)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
send(fmt.Sprintf("[fail] stop: No torrent with an ID of %d", num), ud.Message.Chat.ID, false)
|
send(fmt.Sprintf("[fail] *stop:* No torrent with an ID of %d", num), ud.Message.Chat.ID, false)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
send(fmt.Sprintf("[%s] stop: %s", status, torrent.Name), ud.Message.Chat.ID, false)
|
send(fmt.Sprintf("[%s] *stop:* %s", status, torrent.Name), ud.Message.Chat.ID, false)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1185,17 +1198,17 @@ func stop(ud tgbotapi.Update, tokens []string) {
|
|||||||
func start(ud tgbotapi.Update, tokens []string) {
|
func start(ud tgbotapi.Update, tokens []string) {
|
||||||
// make sure that we got at least one argument
|
// make sure that we got at least one argument
|
||||||
if len(tokens) == 0 {
|
if len(tokens) == 0 {
|
||||||
send("start: needs an argument", ud.Message.Chat.ID, false)
|
send("*start:* needs an argument", ud.Message.Chat.ID, false)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// if the first argument is 'all' then start all torrents
|
// if the first argument is 'all' then start all torrents
|
||||||
if tokens[0] == "all" {
|
if tokens[0] == "all" {
|
||||||
if err := Client.StartAll(); err != nil {
|
if err := Client.StartAll(); err != nil {
|
||||||
send("start: error occurred while starting some torrents", ud.Message.Chat.ID, false)
|
send("*start:* error occurred while starting some torrents", ud.Message.Chat.ID, false)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
send("started all torrents", ud.Message.Chat.ID, false)
|
send("Started all torrents", ud.Message.Chat.ID, false)
|
||||||
return
|
return
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -1203,21 +1216,21 @@ func start(ud tgbotapi.Update, tokens []string) {
|
|||||||
for _, id := range tokens {
|
for _, id := range tokens {
|
||||||
num, err := strconv.Atoi(id)
|
num, err := strconv.Atoi(id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
send(fmt.Sprintf("start: %s is not a number", id), ud.Message.Chat.ID, false)
|
send(fmt.Sprintf("*start:* %s is not a number", id), ud.Message.Chat.ID, false)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
status, err := Client.StartTorrent(num)
|
status, err := Client.StartTorrent(num)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
send("stop: "+err.Error(), ud.Message.Chat.ID, false)
|
send("*start:* "+err.Error(), ud.Message.Chat.ID, false)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
torrent, err := Client.GetTorrent(num)
|
torrent, err := Client.GetTorrent(num)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
send(fmt.Sprintf("[fail] start: No torrent with an ID of %d", num), ud.Message.Chat.ID, false)
|
send(fmt.Sprintf("[fail] *start:* No torrent with an ID of %d", num), ud.Message.Chat.ID, false)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
send(fmt.Sprintf("[%s] start: %s", status, torrent.Name), ud.Message.Chat.ID, false)
|
send(fmt.Sprintf("[%s] *start:* %s", status, torrent.Name), ud.Message.Chat.ID, false)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1225,17 +1238,17 @@ func start(ud tgbotapi.Update, tokens []string) {
|
|||||||
func check(ud tgbotapi.Update, tokens []string) {
|
func check(ud tgbotapi.Update, tokens []string) {
|
||||||
// make sure that we got at least one argument
|
// make sure that we got at least one argument
|
||||||
if len(tokens) == 0 {
|
if len(tokens) == 0 {
|
||||||
send("check: needs an argument", ud.Message.Chat.ID, false)
|
send("*check:* needs an argument", ud.Message.Chat.ID, false)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// if the first argument is 'all' then start all torrents
|
// if the first argument is 'all' then start all torrents
|
||||||
if tokens[0] == "all" {
|
if tokens[0] == "all" {
|
||||||
if err := Client.VerifyAll(); err != nil {
|
if err := Client.VerifyAll(); err != nil {
|
||||||
send("check: error occurred while verifying some torrents", ud.Message.Chat.ID, false)
|
send("*check:* error occurred while verifying some torrents", ud.Message.Chat.ID, false)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
send("verifying all torrents", ud.Message.Chat.ID, false)
|
send("Verifying all torrents", ud.Message.Chat.ID, false)
|
||||||
return
|
return
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -1243,21 +1256,21 @@ func check(ud tgbotapi.Update, tokens []string) {
|
|||||||
for _, id := range tokens {
|
for _, id := range tokens {
|
||||||
num, err := strconv.Atoi(id)
|
num, err := strconv.Atoi(id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
send(fmt.Sprintf("check: %s is not a number", id), ud.Message.Chat.ID, false)
|
send(fmt.Sprintf("*check:* %s is not a number", id), ud.Message.Chat.ID, false)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
status, err := Client.VerifyTorrent(num)
|
status, err := Client.VerifyTorrent(num)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
send("stop: "+err.Error(), ud.Message.Chat.ID, false)
|
send("*check:* "+err.Error(), ud.Message.Chat.ID, false)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
torrent, err := Client.GetTorrent(num)
|
torrent, err := Client.GetTorrent(num)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
send(fmt.Sprintf("[fail] check: No torrent with an ID of %d", num), ud.Message.Chat.ID, false)
|
send(fmt.Sprintf("[fail] *check:* No torrent with an ID of %d", num), ud.Message.Chat.ID, false)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
send(fmt.Sprintf("[%s] check: %s", status, torrent.Name), ud.Message.Chat.ID, false)
|
send(fmt.Sprintf("[%s] *check:* %s", status, torrent.Name), ud.Message.Chat.ID, false)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -1266,7 +1279,7 @@ func check(ud tgbotapi.Update, tokens []string) {
|
|||||||
func stats(ud tgbotapi.Update) {
|
func stats(ud tgbotapi.Update) {
|
||||||
stats, err := Client.GetStats()
|
stats, err := Client.GetStats()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
send("stats: "+err.Error(), ud.Message.Chat.ID, false)
|
send("*stats:* "+err.Error(), ud.Message.Chat.ID, false)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1307,7 +1320,7 @@ func stats(ud tgbotapi.Update) {
|
|||||||
func speed(ud tgbotapi.Update) {
|
func speed(ud tgbotapi.Update) {
|
||||||
stats, err := Client.GetStats()
|
stats, err := Client.GetStats()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
send("speed: "+err.Error(), ud.Message.Chat.ID, false)
|
send("*speed:* "+err.Error(), ud.Message.Chat.ID, false)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1344,7 +1357,7 @@ func speed(ud tgbotapi.Update) {
|
|||||||
func count(ud tgbotapi.Update) {
|
func count(ud tgbotapi.Update) {
|
||||||
torrents, err := Client.GetTorrents()
|
torrents, err := Client.GetTorrents()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
send("count: "+err.Error(), ud.Message.Chat.ID, false)
|
send("*count:* "+err.Error(), ud.Message.Chat.ID, false)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1380,7 +1393,7 @@ func count(ud tgbotapi.Update) {
|
|||||||
func del(ud tgbotapi.Update, tokens []string) {
|
func del(ud tgbotapi.Update, tokens []string) {
|
||||||
// make sure that we got an argument
|
// make sure that we got an argument
|
||||||
if len(tokens) == 0 {
|
if len(tokens) == 0 {
|
||||||
send("del: needs an ID", ud.Message.Chat.ID, false)
|
send("*del:* needs an ID", ud.Message.Chat.ID, false)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1388,17 +1401,17 @@ func del(ud tgbotapi.Update, tokens []string) {
|
|||||||
for _, id := range tokens {
|
for _, id := range tokens {
|
||||||
num, err := strconv.Atoi(id)
|
num, err := strconv.Atoi(id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
send(fmt.Sprintf("del: %s is not an ID", id), ud.Message.Chat.ID, false)
|
send(fmt.Sprintf("*del:* %s is not an ID", id), ud.Message.Chat.ID, false)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
name, err := Client.DeleteTorrent(num, false)
|
name, err := Client.DeleteTorrent(num, false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
send("del: "+err.Error(), ud.Message.Chat.ID, false)
|
send("*del:* "+err.Error(), ud.Message.Chat.ID, false)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
send("Deleted: "+name, ud.Message.Chat.ID, false)
|
send("*Deleted:* "+name, ud.Message.Chat.ID, false)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1406,20 +1419,20 @@ func del(ud tgbotapi.Update, tokens []string) {
|
|||||||
func deldata(ud tgbotapi.Update, tokens []string) {
|
func deldata(ud tgbotapi.Update, tokens []string) {
|
||||||
// make sure that we got an argument
|
// make sure that we got an argument
|
||||||
if len(tokens) == 0 {
|
if len(tokens) == 0 {
|
||||||
send("deldata: needs an ID", ud.Message.Chat.ID, false)
|
send("*deldata:* needs an ID", ud.Message.Chat.ID, false)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
// loop over tokens to read each potential id
|
// loop over tokens to read each potential id
|
||||||
for _, id := range tokens {
|
for _, id := range tokens {
|
||||||
num, err := strconv.Atoi(id)
|
num, err := strconv.Atoi(id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
send(fmt.Sprintf("deldata: %s is not an ID", id), ud.Message.Chat.ID, false)
|
send(fmt.Sprintf("*deldata:* %s is not an ID", id), ud.Message.Chat.ID, false)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
name, err := Client.DeleteTorrent(num, true)
|
name, err := Client.DeleteTorrent(num, true)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
send("deldata: "+err.Error(), ud.Message.Chat.ID, false)
|
send("*deldata:* "+err.Error(), ud.Message.Chat.ID, false)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
1
vendor/github.com/dustin/go-humanize
generated
vendored
1
vendor/github.com/dustin/go-humanize
generated
vendored
@ -1 +0,0 @@
|
|||||||
Subproject commit 7a41df006ff9af79a29f0ffa9c5f21fbe6314a2d
|
|
1
vendor/github.com/hpcloud/tail
generated
vendored
1
vendor/github.com/hpcloud/tail
generated
vendored
@ -1 +0,0 @@
|
|||||||
Subproject commit a30252cb686a21eb2d0b98132633053ec2f7f1e5
|
|
1
vendor/github.com/pyed/transmission
generated
vendored
1
vendor/github.com/pyed/transmission
generated
vendored
@ -1 +0,0 @@
|
|||||||
Subproject commit 065032b0e966f5cfb06d0126d5aea72a92b30b8a
|
|
1
vendor/gopkg.in/telegram-bot-api.v4
generated
vendored
1
vendor/gopkg.in/telegram-bot-api.v4
generated
vendored
@ -1 +0,0 @@
|
|||||||
Subproject commit 0a57807db79efce7f6719fbb2c0e0f83fda79aec
|
|
Loading…
Reference in New Issue
Block a user