Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Another one try of adding new stuff #42

Open
wants to merge 13 commits into
base: master
Choose a base branch
from
14 changes: 13 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ var (
SendNoticesToInteractiveChannels bool
clientCredentialsJson string
DriveService *drive.Service
SendNoticesAboutNoImgOrVid bool
)

const (
Expand Down Expand Up @@ -125,6 +126,7 @@ 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("general").NewKey("send notices about inability to find image or video","false")
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 Down Expand Up @@ -269,7 +271,8 @@ func main() {
MaxDownloadRetries = cfg.Section("general").Key("max download retries").MustInt(3)
DownloadTimeout = cfg.Section("general").Key("download timeout").MustInt(60)
SendNoticesToInteractiveChannels = cfg.Section("general").Key("send notices to interactive channels").MustBool(false)

SendNoticesAboutNoImgOrVid = cfg.Section("general").Key("send notices about inability to find image or video").MustBool(false)

// setup google drive client
clientCredentialsJson = cfg.Section("google").Key("client credentials json").MustString("")
if clientCredentialsJson != "" {
Expand Down Expand Up @@ -1469,6 +1472,15 @@ func downloadFromUrl(dUrl string, filename string, path string, channelId string
contentTypeParts := strings.Split(contentType, "/")
if contentTypeParts[0] != "image" && contentTypeParts[0] != "video" {
fmt.Println("No image or video found at", dUrl)
if SendNoticesAboutNoImgOrVid == true && SendNoticesToInteractiveChannels == true {
for channelId := range InteractiveChannelWhitelist {
content := fmt.Sprintf("No image or video found at %s\n", dUrl)
_, err := dg.ChannelMessageSend(channelId, content)
if err != nil {
fmt.Println("Failed to send notice to", channelId, "-", err)
}
}
}
return true
}

Expand Down