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
|
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}'
|
||||||
|
```
|
||||||
|
166
main.go
166
main.go
@ -19,10 +19,10 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
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.
|
||||||
@ -312,10 +312,18 @@ 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":
|
||||||
@ -378,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":
|
||||||
@ -387,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 "":
|
||||||
@ -396,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)
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -408,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
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -418,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
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -436,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
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -456,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
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -482,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
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -537,14 +545,14 @@ func tail(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
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -563,7 +571,7 @@ func tail(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
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -612,7 +620,7 @@ func tail(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
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -636,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
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -661,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
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -687,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
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -714,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
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -796,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
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -817,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)
|
||||||
@ -897,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]://([^:/]*)`)
|
||||||
@ -909,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
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -945,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
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -955,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)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -980,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
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -992,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
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1000,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
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1033,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
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1057,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)
|
||||||
@ -1066,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
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1151,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)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1190,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
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -1208,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)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1230,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
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -1248,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)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -1271,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
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1312,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
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1349,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
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1385,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
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1393,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)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1411,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
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user