Compare commits

...

7 Commits
dev ... master

Author SHA1 Message Date
Kevin Halpin
4fd68bb874
fix depreciated call go get (#40)
* fix depreciated call go get

* it told me add go mod tidy
2022-03-21 03:04:28 +03:00
Yaroslav
8491708366
Now actions is more 'unix like' (#36)
Co-authored-by: Yaroslav Kargin <ykargin@virtuozzo.com>
2021-01-21 01:22:13 +03:00
Alex Manatskyi
67a40f39b9
Update docker file to include the process of building a go app into the image build process (#33) 2020-11-14 17:18:50 +03:00
Alex Manatskyi
2365907fd7
Pre-process input via mobile share (#32) 2020-11-14 12:24:00 +03:00
pyed
7e4d1b7989
Use pyed/tailer instead. (#24)
* Use pyed/tailer instead of hpcloud/tail

* Get rid of 'vendor' as we are no longer using hpcloud/tail

* Fix usage message

* Add the ability to pass the bot token via env variable

* Add new line to the error messages
2019-06-05 06:34:32 +03:00
JNat
274f19ebe7 Minor formatting tweaks on the help command (#22)
* Minor formatting tweaks on the `help` command

There were a few commas and capitalizations off. Also put some other stuff in italics or quotes for readibility.

* More formatting tweaks; error msgs slightly off

Some more formatting tweaks, for readibility.

Also fixed a minor typo on `add`: "atleast" -> "at least"

`check` and `start` also appeared to have a minor bug in an error message, as it displayed `stop: ` instead of the respective command. Read this as a copy-paste of a chunk of code and then forgetting to update it to the relevant command, but if I misunderstood and the behavior is actually intentional and I just missed the point, just ignore that bit :)
2019-04-26 16:55:00 +03:00
Kevin Halpin
576279cfe8 Wrap the cli script in a docker container (#17)
* README Changes

* amend

* Add the Dockerfile
2019-01-08 02:22:25 +03:00
9 changed files with 196 additions and 124 deletions

3
.dockerignore Normal file
View File

@ -0,0 +1,3 @@
# ignore .git and .cache folders
.git
README.md

12
.gitmodules vendored
View File

@ -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
View 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"]

View File

@ -4,7 +4,9 @@
<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.
@ -13,3 +15,47 @@ Or if you have `Go` installed: `go get -u github.com/pyed/transmission-telegram`
## Usage
[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}'
```

215
main.go
View File

@ -13,16 +13,16 @@ import (
"unicode/utf8"
"github.com/dustin/go-humanize"
"github.com/hpcloud/tail"
"github.com/pyed/tailer"
"github.com/pyed/transmission"
"gopkg.in/telegram-bot-api.v4"
)
const (
VERSION = "v1.4"
VERSION = "v1.4.1"
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.
*head* or *he*
@ -32,16 +32,16 @@ const (
Lists the last n number of torrents, n defaults to 5 if no argument is provided.
*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*
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*
Lists Paused torrents.
Lists _Paused_ torrents.
*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*
Lists torrents that are actively uploading or downloading.
@ -50,13 +50,13 @@ const (
Lists torrents with with errors along with the error message.
*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*
Lists all the trackers along with the number of torrents.
*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*
Takes a query and lists torrents with matching names.
@ -76,7 +76,7 @@ const (
*check* or *ck*
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.
*deldata*
@ -94,7 +94,7 @@ const (
*help*
Shows this help message.
*version*
*version* or *ver*
Shows version numbers.
- 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
func init() {
// 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.StringVar(&RPCURL, "url", "http://localhost:9091/transmission/rpc", "Transmission RPC URL")
flag.StringVar(&Username, "username", "", "Transmission username")
@ -180,12 +180,19 @@ func init() {
// set the usage message
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.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.
if BotToken == "" ||
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 TransLogFile != "" {
go func() {
ft, err := tail.TailFile(TransLogFile, tail.Config{
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
}
ft := tailer.RunFileTailer(TransLogFile, false, nil)
// [2017-02-22 21:00:00.898] File-Name State changed from "Incomplete" to "Complete" (torrent.c:2218)
const (
@ -229,16 +227,23 @@ func init() {
end = len(` State changed from "Incomplete" to "Complete" (torrent.c:2218)`)
)
for line := range ft.Lines {
if strings.Contains(line.Text, substring) {
for {
select {
case line := <-ft.Lines():
if strings.Contains(line, substring) {
// 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)
}
case err := <-ft.Errors():
logger.Printf("[ERROR] tailing transmission log: %s", err)
return
}
}
}()
}
@ -260,7 +265,7 @@ func init() {
var err error
Client, err = transmission.New(RPCURL, Username, Password)
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)
}
@ -272,7 +277,7 @@ func init() {
var err error
Bot, err = tgbotapi.NewBotAPI(BotToken)
if err != nil {
fmt.Fprintf(os.Stderr, "[ERROR] Telegram: %s", err)
fmt.Fprintf(os.Stderr, "[ERROR] Telegram: %s\n", err)
os.Exit(1)
}
logger.Printf("[INFO] Authorized: %s", Bot.Self.UserName)
@ -282,7 +287,7 @@ func init() {
Updates, err = Bot.GetUpdatesChan(u)
if err != nil {
fmt.Fprintf(os.Stderr, "[ERROR] Telegram: %s", err)
fmt.Fprintf(os.Stderr, "[ERROR] Telegram: %s\n", err)
os.Exit(1)
}
}
@ -307,17 +312,25 @@ func main() {
// tokenize the update
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])
switch command {
case "list", "/list", "li", "/li":
case "list", "/list", "li", "/li", "/ls", "ls":
go list(update, tokens[1:])
case "head", "/head", "he", "/he":
go head(update, tokens[1:])
case "tail", "/tail", "ta", "/ta":
go tailf(update, tokens[1:])
go tail(update, tokens[1:])
case "downs", "/downs", "dl", "/dl":
go downs(update)
@ -373,7 +386,7 @@ func main() {
case "count", "/count", "co", "/co":
go count(update)
case "del", "/del":
case "del", "/del", "rm", "/rm":
go del(update, tokens[1:])
case "deldata", "/deldata":
@ -382,7 +395,7 @@ func main() {
case "help", "/help":
go send(HELP, update.Message.Chat.ID, true)
case "version", "/version":
case "version", "/version", "ver", "/ver":
go getVersion(update)
case "":
@ -391,7 +404,7 @@ func main() {
default:
// 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) {
torrents, err := Client.GetTorrents()
if err != nil {
send("list: "+err.Error(), ud.Message.Chat.ID, false)
send("*list:* "+err.Error(), ud.Message.Chat.ID, false)
return
}
@ -413,7 +426,7 @@ func list(ud tgbotapi.Update, tokens []string) {
// (?i) for case insensitivity
regx, err := regexp.Compile("(?i)" + tokens[0])
if err != nil {
send("list: "+err.Error(), ud.Message.Chat.ID, false)
send("*list:* "+err.Error(), ud.Message.Chat.ID, false)
return
}
@ -431,10 +444,10 @@ func list(ud tgbotapi.Update, tokens []string) {
if buf.Len() == 0 {
// if we got a tracker query show different message
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
}
send("list: No torrents", ud.Message.Chat.ID, false)
send("*list:* no torrents", ud.Message.Chat.ID, false)
return
}
@ -451,14 +464,14 @@ func head(ud tgbotapi.Update, tokens []string) {
if len(tokens) > 0 {
n, err = strconv.Atoi(tokens[0])
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
}
}
torrents, err := Client.GetTorrents()
if err != nil {
send("head: "+err.Error(), ud.Message.Chat.ID, false)
send("*head:* "+err.Error(), ud.Message.Chat.ID, false)
return
}
@ -477,7 +490,7 @@ func head(ud tgbotapi.Update, tokens []string) {
}
if buf.Len() == 0 {
send("head: No torrents", ud.Message.Chat.ID, false)
send("*head:* no torrents", ud.Message.Chat.ID, false)
return
}
@ -522,8 +535,8 @@ func head(ud tgbotapi.Update, tokens []string) {
}
// tailf lists the last 5 or n torrents
func tailf(ud tgbotapi.Update, tokens []string) {
// tail lists the last 5 or n torrents
func tail(ud tgbotapi.Update, tokens []string) {
var (
n = 5 // default to 5
err error
@ -532,14 +545,14 @@ func tailf(ud tgbotapi.Update, tokens []string) {
if len(tokens) > 0 {
n, err = strconv.Atoi(tokens[0])
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
}
}
torrents, err := Client.GetTorrents()
if err != nil {
send("tail: "+err.Error(), ud.Message.Chat.ID, false)
send("*tail:* "+err.Error(), ud.Message.Chat.ID, false)
return
}
@ -558,7 +571,7 @@ func tailf(ud tgbotapi.Update, tokens []string) {
}
if buf.Len() == 0 {
send("tail: No torrents", ud.Message.Chat.ID, false)
send("*tail:* no torrents", ud.Message.Chat.ID, false)
return
}
@ -607,7 +620,7 @@ func tailf(ud tgbotapi.Update, tokens []string) {
func downs(ud tgbotapi.Update) {
torrents, err := Client.GetTorrents()
if err != nil {
send("downs: "+err.Error(), ud.Message.Chat.ID, false)
send("*downs:* "+err.Error(), ud.Message.Chat.ID, false)
return
}
@ -631,7 +644,7 @@ func downs(ud tgbotapi.Update) {
func seeding(ud tgbotapi.Update) {
torrents, err := Client.GetTorrents()
if err != nil {
send("seeding: "+err.Error(), ud.Message.Chat.ID, false)
send("*seeding:* "+err.Error(), ud.Message.Chat.ID, false)
return
}
@ -656,7 +669,7 @@ func seeding(ud tgbotapi.Update) {
func paused(ud tgbotapi.Update) {
torrents, err := Client.GetTorrents()
if err != nil {
send("paused: "+err.Error(), ud.Message.Chat.ID, false)
send("*paused:* "+err.Error(), ud.Message.Chat.ID, false)
return
}
@ -682,7 +695,7 @@ func paused(ud tgbotapi.Update) {
func checking(ud tgbotapi.Update) {
torrents, err := Client.GetTorrents()
if err != nil {
send("checking: "+err.Error(), ud.Message.Chat.ID, false)
send("*checking:* "+err.Error(), ud.Message.Chat.ID, false)
return
}
@ -709,7 +722,7 @@ func checking(ud tgbotapi.Update) {
func active(ud tgbotapi.Update) {
torrents, err := Client.GetTorrents()
if err != nil {
send("active: "+err.Error(), ud.Message.Chat.ID, false)
send("*active:* "+err.Error(), ud.Message.Chat.ID, false)
return
}
@ -791,7 +804,7 @@ func active(ud tgbotapi.Update) {
func errors(ud tgbotapi.Update) {
torrents, err := Client.GetTorrents()
if err != nil {
send("errors: "+err.Error(), ud.Message.Chat.ID, false)
send("*errors:* "+err.Error(), ud.Message.Chat.ID, false)
return
}
@ -812,7 +825,7 @@ func errors(ud tgbotapi.Update) {
// sort changes torrents sorting
func sort(ud tgbotapi.Update, tokens []string) {
if len(tokens) == 0 {
send(`sort takes one of:
send(`*sort* takes one of:
(*id, name, age, size, progress, downspeed, upspeed, download, upload, ratio*)
optionally start with (*rev*) for reversed order
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 {
send("sort: reversed "+tokens[0], ud.Message.Chat.ID, false)
send("*sort:* reversed "+tokens[0], ud.Message.Chat.ID, false)
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]://([^:/]*)`)
@ -904,7 +917,7 @@ var trackerRegex = regexp.MustCompile(`[https?|udp]://([^:/]*)`)
func trackers(ud tgbotapi.Update) {
torrents, err := Client.GetTorrents()
if err != nil {
send("trackers: "+err.Error(), ud.Message.Chat.ID, false)
send("*trackers:* "+err.Error(), ud.Message.Chat.ID, false)
return
}
@ -940,7 +953,7 @@ func trackers(ud tgbotapi.Update) {
// add takes an URL to a .torrent file to add it to transmission
func add(ud tgbotapi.Update, tokens []string) {
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
}
@ -950,16 +963,16 @@ func add(ud tgbotapi.Update, tokens []string) {
torrent, err := Client.ExecuteAddCommand(cmd)
if err != nil {
send("add: "+err.Error(), ud.Message.Chat.ID, false)
send("*add:* "+err.Error(), ud.Message.Chat.ID, false)
continue
}
// check if torrent.Name is empty, then an error happened
if torrent.Name == "" {
send("add: error adding "+url, ud.Message.Chat.ID, false)
send("*add:* error adding "+url, ud.Message.Chat.ID, false)
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)
if err != nil {
send("receiver: "+err.Error(), ud.Message.Chat.ID, false)
send("*receiver:* "+err.Error(), ud.Message.Chat.ID, false)
return
}
@ -987,7 +1000,7 @@ func receiveTorrent(ud tgbotapi.Update) {
func search(ud tgbotapi.Update, tokens []string) {
// make sure that we got a query
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
}
@ -995,13 +1008,13 @@ func search(ud tgbotapi.Update, tokens []string) {
// "(?i)" for case insensitivity
regx, err := regexp.Compile("(?i)" + query)
if err != nil {
send("search: "+err.Error(), ud.Message.Chat.ID, false)
send("*search:* "+err.Error(), ud.Message.Chat.ID, false)
return
}
torrents, err := Client.GetTorrents()
if err != nil {
send("search: "+err.Error(), ud.Message.Chat.ID, false)
send("*search:* "+err.Error(), ud.Message.Chat.ID, false)
return
}
@ -1028,14 +1041,14 @@ func latest(ud tgbotapi.Update, tokens []string) {
if len(tokens) > 0 {
n, err = strconv.Atoi(tokens[0])
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
}
}
torrents, err := Client.GetTorrents()
if err != nil {
send("latest: "+err.Error(), ud.Message.Chat.ID, false)
send("*latest:* "+err.Error(), ud.Message.Chat.ID, false)
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))
}
if buf.Len() == 0 {
send("latest: No torrents", ud.Message.Chat.ID, false)
send("*latest:* No torrents", ud.Message.Chat.ID, false)
return
}
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
func info(ud tgbotapi.Update, tokens []string) {
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
}
for _, id := range tokens {
torrentID, err := strconv.Atoi(id)
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
}
// get the torrent
torrent, err := Client.GetTorrent(torrentID)
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
}
@ -1146,38 +1159,38 @@ func info(ud tgbotapi.Update, tokens []string) {
func stop(ud tgbotapi.Update, tokens []string) {
// make sure that we got at least one argument
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
}
// if the first argument is 'all' then stop all torrents
if tokens[0] == "all" {
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
}
send("stopped all torrents", ud.Message.Chat.ID, false)
send("Stopped all torrents", ud.Message.Chat.ID, false)
return
}
for _, id := range tokens {
num, err := strconv.Atoi(id)
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
}
status, err := Client.StopTorrent(num)
if err != nil {
send("stop: "+err.Error(), ud.Message.Chat.ID, false)
send("*stop:* "+err.Error(), ud.Message.Chat.ID, false)
continue
}
torrent, err := Client.GetTorrent(num)
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
}
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) {
// make sure that we got at least one argument
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
}
// if the first argument is 'all' then start all torrents
if tokens[0] == "all" {
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
}
send("started all torrents", ud.Message.Chat.ID, false)
send("Started all torrents", ud.Message.Chat.ID, false)
return
}
@ -1203,21 +1216,21 @@ func start(ud tgbotapi.Update, tokens []string) {
for _, id := range tokens {
num, err := strconv.Atoi(id)
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
}
status, err := Client.StartTorrent(num)
if err != nil {
send("stop: "+err.Error(), ud.Message.Chat.ID, false)
send("*start:* "+err.Error(), ud.Message.Chat.ID, false)
continue
}
torrent, err := Client.GetTorrent(num)
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
}
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) {
// make sure that we got at least one argument
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
}
// if the first argument is 'all' then start all torrents
if tokens[0] == "all" {
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
}
send("verifying all torrents", ud.Message.Chat.ID, false)
send("Verifying all torrents", ud.Message.Chat.ID, false)
return
}
@ -1243,21 +1256,21 @@ func check(ud tgbotapi.Update, tokens []string) {
for _, id := range tokens {
num, err := strconv.Atoi(id)
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
}
status, err := Client.VerifyTorrent(num)
if err != nil {
send("stop: "+err.Error(), ud.Message.Chat.ID, false)
send("*check:* "+err.Error(), ud.Message.Chat.ID, false)
continue
}
torrent, err := Client.GetTorrent(num)
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
}
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) {
stats, err := Client.GetStats()
if err != nil {
send("stats: "+err.Error(), ud.Message.Chat.ID, false)
send("*stats:* "+err.Error(), ud.Message.Chat.ID, false)
return
}
@ -1307,7 +1320,7 @@ func stats(ud tgbotapi.Update) {
func speed(ud tgbotapi.Update) {
stats, err := Client.GetStats()
if err != nil {
send("speed: "+err.Error(), ud.Message.Chat.ID, false)
send("*speed:* "+err.Error(), ud.Message.Chat.ID, false)
return
}
@ -1344,7 +1357,7 @@ func speed(ud tgbotapi.Update) {
func count(ud tgbotapi.Update) {
torrents, err := Client.GetTorrents()
if err != nil {
send("count: "+err.Error(), ud.Message.Chat.ID, false)
send("*count:* "+err.Error(), ud.Message.Chat.ID, false)
return
}
@ -1380,7 +1393,7 @@ func count(ud tgbotapi.Update) {
func del(ud tgbotapi.Update, tokens []string) {
// make sure that we got an argument
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
}
@ -1388,17 +1401,17 @@ func del(ud tgbotapi.Update, tokens []string) {
for _, id := range tokens {
num, err := strconv.Atoi(id)
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
}
name, err := Client.DeleteTorrent(num, false)
if err != nil {
send("del: "+err.Error(), ud.Message.Chat.ID, false)
send("*del:* "+err.Error(), ud.Message.Chat.ID, false)
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) {
// make sure that we got an argument
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
}
// loop over tokens to read each potential id
for _, id := range tokens {
num, err := strconv.Atoi(id)
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
}
name, err := Client.DeleteTorrent(num, true)
if err != nil {
send("deldata: "+err.Error(), ud.Message.Chat.ID, false)
send("*deldata:* "+err.Error(), ud.Message.Chat.ID, false)
return
}

@ -1 +0,0 @@
Subproject commit 7a41df006ff9af79a29f0ffa9c5f21fbe6314a2d

1
vendor/github.com/hpcloud/tail generated vendored

@ -1 +0,0 @@
Subproject commit a30252cb686a21eb2d0b98132633053ec2f7f1e5

@ -1 +0,0 @@
Subproject commit 065032b0e966f5cfb06d0126d5aea72a92b30b8a

@ -1 +0,0 @@
Subproject commit 0a57807db79efce7f6719fbb2c0e0f83fda79aec