Skip to content
This repository has been archived by the owner on Nov 18, 2024. It is now read-only.

Commit

Permalink
Merge pull request #192 from get-got/master
Browse files Browse the repository at this point in the history
Status Settings, Go 1.15, dg v0.22, xurls v2 fix; readme improvements
  • Loading branch information
Seklfreak authored Dec 28, 2020
2 parents 7676cc5 + 94c481c commit 50b338a
Show file tree
Hide file tree
Showing 10 changed files with 96 additions and 57 deletions.
11 changes: 6 additions & 5 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,13 @@ _testmain.go
config.ini
crossbuild.bat

testfolder/*
test/*
database*/

.idea/

vendor
credentials.json
.DS_Store
.DS_Store

# Exclude subdirectories (things like database, saved images during testing)
/**
# Exclude build command shortcut(s)
*.cmd
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
language: go
go:
- "1.13"
- "1.15"
install:
- env GO111MODULE=on go mod download
- go get github.com/mitchellh/gox
Expand Down
20 changes: 13 additions & 7 deletions common.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,19 @@ func deduplicateDownloadItems(DownloadItems []*DownloadItem) []*DownloadItem {
}

func updateDiscordStatus() {
dg.UpdateStatusComplex(discordgo.UpdateStatusData{
Game: &discordgo.Game{
Name: fmt.Sprintf("%d downloaded pictures", countDownloadedImages()),
Type: discordgo.GameTypeWatching,
},
Status: "online",
})
if StatusEnabled {
dg.UpdateStatusComplex(discordgo.UpdateStatusData{
Game: &discordgo.Game{
Name: fmt.Sprintf("%d %s", countDownloadedImages(), StatusSuffix),
Type: StatusLabel,
},
Status: StatusType,
})
} else if StatusType != "online" {
dg.UpdateStatusComplex(discordgo.UpdateStatusData{
Status: StatusType,
})
}
}

func Pagify(text string, delimiter string) []string {
Expand Down
6 changes: 3 additions & 3 deletions extract.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"time"

"github.com/bwmarrin/discordgo"
"mvdan.cc/xurls"
"mvdan.cc/xurls/v2"
)

func getDownloadLinks(inputURL string, channelID string, interactive bool) (map[string]string, bool) {
Expand Down Expand Up @@ -216,7 +216,7 @@ func getRawLinksOfMessage(message *discordgo.Message) []*DownloadItem {
})
}

foundLinks := xurls.Strict.FindAllString(message.Content, -1)
foundLinks := xurls.Strict().FindAllString(message.Content, -1)
for _, foundLink := range foundLinks {
links = append(links, &DownloadItem{
Link: foundLink,
Expand All @@ -231,7 +231,7 @@ func getRawLinksOfMessage(message *discordgo.Message) []*DownloadItem {
}

if embed.Description != "" {
foundLinks = xurls.Strict.FindAllString(embed.Description, -1)
foundLinks = xurls.Strict().FindAllString(embed.Description, -1)
for _, foundLink := range foundLinks {
links = append(links, &DownloadItem{
Link: foundLink,
Expand Down
7 changes: 3 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/Seklfreak/discord-image-downloader-go

go 1.13
go 1.15

require (
bou.ke/monkey v1.0.1 // indirect
Expand All @@ -10,16 +10,15 @@ require (
github.com/Jeffail/gabs v1.2.0
github.com/PuerkitoBio/goquery v1.5.0
github.com/azr/backoff v0.0.0-20160115115103-53511d3c7330 // indirect
github.com/bwmarrin/discordgo v0.16.1-0.20190826195003-1d90c5da95a4
github.com/bwmarrin/discordgo v0.22.0
github.com/dustin/go-jsonpointer v0.0.0-20160814072949-ba0abeacc3dc // indirect
github.com/dustin/gojson v0.0.0-20160307161227-2e71ec9dd5ad // indirect
github.com/garyburd/go-oauth v0.0.0-20180319155456-bca2e7f09a17 // indirect
github.com/hashicorp/go-version v1.1.0
github.com/mvdan/xurls v1.1.0 // indirect
github.com/smartystreets/goconvey v0.0.0-20190306220146-200a235640ff // indirect
golang.org/x/net v0.0.0-20190322120337-addf6b3196f6
golang.org/x/oauth2 v0.0.0-20190319182350-c85d3e98c914
google.golang.org/api v0.2.0
gopkg.in/ini.v1 v1.42.0
mvdan.cc/xurls v1.1.0
mvdan.cc/xurls/v2 v2.2.0
)
29 changes: 10 additions & 19 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
bou.ke/monkey v1.0.1 h1:zEMLInw9xvNakzUUPjfS4Ds6jYPqCFx3m7bRmG5NH2U=
bou.ke/monkey v1.0.1/go.mod h1:FgHuK96Rv2Nlf+0u1OOVDpCMdsWyOFmeeketDHE7LIg=
cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
cloud.google.com/go v0.34.0 h1:eOI3/cP2VTU6uZLDYAoic+eyzzB9YyGmJ7eIjl8rOPg=
Expand All @@ -22,10 +21,9 @@ github.com/andybalholm/cascadia v1.0.0/go.mod h1:GsXiBklL0woXo1j/WYWtSYYC4ouU9Pq
github.com/azr/backoff v0.0.0-20160115115103-53511d3c7330 h1:ekDALXAVvY/Ub1UtNta3inKQwZ/jMB/zpOtD8rAYh78=
github.com/azr/backoff v0.0.0-20160115115103-53511d3c7330/go.mod h1:nH+k0SvAt3HeiYyOlJpLLv1HG1p7KWP7qU9QPp2/pCo=
github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q=
github.com/bwmarrin/discordgo v0.16.1-0.20190826195003-1d90c5da95a4 h1:8hQXi5T6l9U8ckOd4RSpgJLJOJzruDX7NJRfY82WKQM=
github.com/bwmarrin/discordgo v0.16.1-0.20190826195003-1d90c5da95a4/go.mod h1:O9S4p+ofTFwB02em7jkpkV8M3R0/PUVOwN61zSZ0r4Q=
github.com/bwmarrin/discordgo v0.22.0 h1:uBxY1HmlVCsW1IuaPjpCGT6A2DBwRn0nvOguQIxDdFM=
github.com/bwmarrin/discordgo v0.22.0/go.mod h1:c1WtWUGN6nREDmzIpyTp/iD3VYt4Fpx+bVyfBG7JE+M=
github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/dustin/go-jsonpointer v0.0.0-20160814072949-ba0abeacc3dc h1:tP7tkU+vIsEOKiK+l/NSLN4uUtkyuxc6hgYpQeCWAeI=
github.com/dustin/go-jsonpointer v0.0.0-20160814072949-ba0abeacc3dc/go.mod h1:ORH5Qp2bskd9NzSfKqAF7tKfONsEkCarTE5ESr/RVBw=
Expand All @@ -42,31 +40,27 @@ github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfU
github.com/golang/lint v0.0.0-20180702182130-06c8688daad7/go.mod h1:tluoj9z5200jBnyusfRPU2LqT6J+DAorxEvtC7LHB+E=
github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A=
github.com/golang/mock v1.2.0/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A=
github.com/golang/protobuf v1.2.0 h1:P3YflyNX/ehuJFLhxviNdFxQPkGK5cDcApsge1SqnvM=
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M=
github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1 h1:EGx4pi6eqNxGaHF6qqu48+N2wcFQ5qg5FXgOdqsJ5d8=
github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY=
github.com/gorilla/websocket v1.4.0 h1:WDFjx/TMzVgy9VdMMQi2K2Emtwi2QcUQsztZ/zLaH/Q=
github.com/gorilla/websocket v1.4.0/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoAMk2YaljkQ=
github.com/grpc-ecosystem/grpc-gateway v1.6.2/go.mod h1:RSKVYQBd5MCa4OVpNdGskqpgL2+G+NZTnrVHpWWfpdw=
github.com/hashicorp/go-version v1.1.0 h1:bPIoEKD27tNdebFGGxxYwcL4nepeY4j1QP23PFRGzg0=
github.com/hashicorp/go-version v1.1.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA=
github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8=
github.com/jtolds/gls v4.20.0+incompatible h1:xdiiI2gbIgH/gLH7ADydsJ1uDOEzR8yvV7C0MuV77Wo=
github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU=
github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w=
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFBFZlji/RkVcI2GknAs/DXo4wKdlNEc=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0=
github.com/mvdan/xurls v1.1.0 h1:OpuDelGQ1R1ueQ6sSryzi6P+1RtBpfQHM8fJwlE45ww=
github.com/mvdan/xurls v1.1.0/go.mod h1:tQlNn3BED8bE/15hnSL2HLkDeLWpNPAwtw7wkEq44oU=
github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U=
github.com/openzipkin/zipkin-go v0.1.3/go.mod h1:NtoC/o8u3JlF1lSlyPNswIbeQH9bJTmOf0Erfk+hxe8=
github.com/pkg/errors v0.8.0 h1:WdK/asTD0HN+q6hsWO3/vpuAkAr+tw6aNJNDFFf0+qw=
github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/prometheus/client_golang v0.9.1/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw=
github.com/prometheus/client_golang v0.9.3-0.20190127221311-3c4408c8b829/go.mod h1:p2iRAGwDERtqlqzRXnrOVns+ignqQo//hLXqYxZYVNs=
Expand All @@ -75,13 +69,11 @@ github.com/prometheus/client_model v0.0.0-20190115171406-56726106282f/go.mod h1:
github.com/prometheus/common v0.2.0/go.mod h1:TNfzLD0ON7rHzMJeJkieUDPYmFC7Snx/y86RQel1bk4=
github.com/prometheus/procfs v0.0.0-20181005140218-185b4288413d/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk=
github.com/prometheus/procfs v0.0.0-20190117184657-bf6a532e95b1/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk=
github.com/rogpeppe/go-internal v1.5.2/go.mod h1:xXDCJY+GAPziupqXw64V24skbSoqbTEfhy4qGm1nDQc=
github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo=
github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d h1:zE9ykElWQ6/NYmHa3jpm/yHnI4xSofP+UP6SpjHcSeM=
github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc=
github.com/smartystreets/goconvey v0.0.0-20190306220146-200a235640ff h1:86HlEv0yBCry9syNuylzqznKXDK11p6D0DT596yNMys=
github.com/smartystreets/goconvey v0.0.0-20190306220146-200a235640ff/go.mod h1:KSQcGKpxUMHk3nbYzs/tIBAM2iDooCn0BmttHOJEbLs=
github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.2.2 h1:bSDNvY7ZPG5RlJ8otE/7V6gMiyenm9RtJ7IUVIAoJ1w=
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
go.opencensus.io v0.19.1/go.mod h1:gug0GbSHa8Pafr0d2urOSgoXHZ6x/RUlaiT0d9pqb4A=
golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
Expand Down Expand Up @@ -113,13 +105,11 @@ golang.org/x/oauth2 v0.0.0-20190319182350-c85d3e98c914/go.mod h1:gOpvHmFTYa4Iltr
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20190227155943-e225da77a7e6 h1:bjcUS9ztw9kFmmIxJInhon/0Is3p+EHBKNgquIzo1OI=
golang.org/x/sync v0.0.0-20190227155943-e225da77a7e6/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20181116152217-5ac8a444bdc5/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20181218192612-074acd46bca6/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a h1:1BGLXjeY4akVXGgbC9HugT3Jv3hCI0z56oJR5vAMgBU=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/tools v0.0.0-20180828015842-6cd1fcedba52/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
Expand All @@ -132,7 +122,6 @@ google.golang.org/api v0.2.0 h1:B5VXkdjt7K2Gm6fGBC9C9a1OAKJDT95cTqwet+2zib0=
google.golang.org/api v0.2.0/go.mod h1:IfRCZScioGtypHNTlz3gFk67J8uePVW7uDTBzXuIkhU=
google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM=
google.golang.org/appengine v1.3.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4=
google.golang.org/appengine v1.4.0 h1:/wp5JvzpHIxhs/dumFmF7BXTf3Z+dd4uXta4kVyO508=
google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4=
google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc=
google.golang.org/genproto v0.0.0-20181219182458-5a97ab628bfb/go.mod h1:7Ep/1NZk928CDR8SjdVbjWNpdIf6nzjE3BTgJDr2Atg=
Expand All @@ -143,12 +132,14 @@ google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZi
gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI=
gopkg.in/ini.v1 v1.42.0 h1:7N3gPTt50s8GuLortA00n8AqRTk75qOP98+mTPpgzRk=
gopkg.in/ini.v1 v1.42.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k=
gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
honnef.co/go/tools v0.0.0-20180728063816-88497007e858/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
honnef.co/go/tools v0.0.0-20180920025451-e3ad64cb4ed3/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
mvdan.cc/xurls v1.1.0 h1:kj0j2lonKseISJCiq1Tfk+iTv65dDGCl0rTbanXJGGc=
mvdan.cc/xurls v1.1.0/go.mod h1:TNWuhvo+IqbUCmtUIb/3LJSQdrzel8loVpgFm0HikbI=
mvdan.cc/xurls/v2 v2.2.0 h1:NSZPykBXJFCetGZykLAxaL6SIpvbVy/UFEniIfHAa8A=
mvdan.cc/xurls/v2 v2.2.0/go.mod h1:EV1RMtya9D6G5DMYPGD8zTQzaHet6Jh8gFlRgGRJeO8=
6 changes: 3 additions & 3 deletions handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"time"

"github.com/bwmarrin/discordgo"
"mvdan.cc/xurls"
"mvdan.cc/xurls/v2"
)

// helpHandler displays the help message
Expand Down Expand Up @@ -212,7 +212,7 @@ func historyHandler(message *discordgo.Message) {
startDownload(iAttachment.URL, iAttachment.Filename, folder, msg.ChannelID, msg.Author.ID, fileTime)
}
}
foundUrls := xurls.Strict.FindAllString(msg.Content, -1)
foundUrls := xurls.Strict().FindAllString(msg.Content, -1)
for _, iFoundUrl := range foundUrls {
links, _ := getDownloadLinks(iFoundUrl, msg.ChannelID, false)
for link, filename := range links {
Expand Down Expand Up @@ -284,7 +284,7 @@ func defaultHandler(message *discordgo.Message) {
interactiveChannelLinkTemp[message.ChannelID] = iAttachment.URL
foundLinks = true
}
foundUrls := xurls.Strict.FindAllString(message.Content, -1)
foundUrls := xurls.Strict().FindAllString(message.Content, -1)
for _, iFoundUrl := range foundUrls {
dg.ChannelMessageSend(message.ChannelID, fmt.Sprintf("Where do you want to save <%s>?\nType **.** for default path or **cancel** to cancel the download %s", iFoundUrl, folderName))
interactiveChannelLinkTemp[message.ChannelID] = iFoundUrl
Expand Down
39 changes: 33 additions & 6 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"os"
"os/signal"
"path"
"path/filepath"
"regexp"
"sort"
"strconv"
Expand Down Expand Up @@ -47,6 +48,10 @@ var (
twitterClient *anaconda.TwitterApi
DownloadTimeout int
SendNoticesToInteractiveChannels bool
StatusEnabled bool
StatusType string
StatusLabel discordgo.GameType
StatusSuffix string
clientCredentialsJson string
DriveService *drive.Service
RegexpFilename *regexp.Regexp
Expand All @@ -65,7 +70,7 @@ type ImgurAlbumObject struct {
}

func main() {
fmt.Printf("discord-image-downloader-go version %s\n", VERSION)
fmt.Printf("> discord-image-downloader-go v%s -- discordgo v%s\n", VERSION, discordgo.VERSION)
if !isLatestRelease() {
fmt.Printf("update available on %s !\n", RELEASE_URL)
}
Expand Down Expand Up @@ -98,6 +103,10 @@ func main() {
cfg.Section("general").NewKey("max download retries", "5")
cfg.Section("general").NewKey("download timeout", "60")
cfg.Section("general").NewKey("send notices to interactive channels", "false")
cfg.Section("status").NewKey("status enabled", "true")
cfg.Section("status").NewKey("status type", "online")
cfg.Section("status").NewKey("status label", fmt.Sprint(discordgo.GameTypeWatching))
cfg.Section("status").NewKey("status suffix", "downloaded pictures")
cfg.Section("channels").NewKey("channelid1", "C:\\full\\path\\1")
cfg.Section("channels").NewKey("channelid2", "C:\\full\\path\\2")
cfg.Section("channels").NewKey("channelid3", "C:\\full\\path\\3")
Expand All @@ -122,6 +131,7 @@ func main() {
return
}
if myDB.Use("Downloads") == nil {
fmt.Println("Creating new database...")
if err := myDB.Create("Downloads"); err != nil {
fmt.Println("unable to create db", err)
return
Expand Down Expand Up @@ -167,8 +177,11 @@ func main() {
cfg.Section("auth").Key("password").String())
}
if err != nil {
fmt.Println("error creating Discord session,", err)
return
// Newer discordgo throws this error for some reason with Email/Password login
if err.Error() != "Unable to fetch discord authentication token. <nil>" {
fmt.Println("error creating Discord session,", err)
return
}
}

dg.AddHandler(messageCreate)
Expand All @@ -184,6 +197,11 @@ func main() {
DownloadTimeout = cfg.Section("general").Key("download timeout").MustInt(60)
SendNoticesToInteractiveChannels = cfg.Section("general").Key("send notices to interactive channels").MustBool(false)

StatusEnabled = cfg.Section("status").Key("status enabled").MustBool(true)
StatusType = cfg.Section("status").Key("status type").MustString("online")
StatusLabel = discordgo.GameType(cfg.Section("status").Key("status label").MustInt(int(discordgo.GameTypeWatching)))
StatusSuffix = cfg.Section("status").Key("status suffix").MustString("downloaded pictures")

// setup google drive client
clientCredentialsJson = cfg.Section("google").Key("client credentials json").MustString("")
if clientCredentialsJson != "" {
Expand All @@ -204,12 +222,13 @@ func main() {
}
}
}

dg.LogLevel = -1 // to ignore dumb wsapi error
err = dg.Open()
if err != nil {
fmt.Println("error opening connection,", err)
return
}
dg.LogLevel = 0 // reset

u, err := dg.User("@me")
if err != nil {
Expand All @@ -226,7 +245,11 @@ func main() {
sc := make(chan os.Signal, 1)
signal.Notify(sc, syscall.SIGINT, syscall.SIGTERM, os.Interrupt)
<-sc
fmt.Println("Closing database...")
myDB.Close()
fmt.Println("Logging out of Discord...")
dg.Close()
fmt.Println("Exiting...")
return
}

Expand Down Expand Up @@ -967,7 +990,7 @@ func startDownload(dUrl string, filename string, path string, channelId string,
}

func downloadFromUrl(dUrl string, filename string, path string, channelId string, userId string, fileTime time.Time) bool {
err := os.MkdirAll(path, 755)
err := os.MkdirAll(path, 0755)
if err != nil {
fmt.Println("Error while creating folder", path, "-", err)
return false
Expand Down Expand Up @@ -1040,9 +1063,13 @@ func downloadFromUrl(dUrl string, filename string, path string, channelId string
fmt.Printf("[%s] Saving possible duplicate (filenames match): %s to %s\n", time.Now().Format(time.Stamp), tmpPath, completePath)
}

extension := filepath.Ext(filename)
contentTypeParts := strings.Split(contentType, "/")
if t := contentTypeParts[0]; t != "image" && t != "video" && t != "audio" &&
!(t == "application" && isAudioFile(filename)) {
!(t == "application" && isAudioFile(filename)) &&
strings.ToLower(extension) != ".mov" &&
strings.ToLower(extension) != ".mp4" &&
strings.ToLower(extension) != ".webm" {
fmt.Println("No image, video, or audio found at", dUrl)
return true
}
Expand Down
Loading

0 comments on commit 50b338a

Please sign in to comment.