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

Workaround for userbot endpoint issue #207

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 25 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,20 @@ func skipDuplicateLinks(linkList map[string]string, channelID string, interactiv
}

func handleDiscordMessage(m *discordgo.Message) {
// If message content is empty (likely due to userbot/selfbot)
if m.Content == "" && len(m.Attachments) == 0 {
nms, err := dg.ChannelMessages(m.ChannelID, 10, "", "", "")
if err == nil {
if len(nms) > 0 {
for _, nm := range nms {
if nm.ID == m.ID {
m = nm
}
}
}
}
}

if folderName, ok := ChannelWhitelist[m.ChannelID]; ok {
// download from whitelisted channels
downloadItems := getDownloadItemsOfMessage(m)
Expand Down Expand Up @@ -990,7 +1004,17 @@ 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, 0755)

var err error

// Source validation
_, err = url.ParseRequestURI(dUrl)
if err != nil {
fmt.Println("Error while parsing url", dUrl, "-", err)
return false
}

err = os.MkdirAll(path, 0755)
if err != nil {
fmt.Println("Error while creating folder", path, "-", err)
return false
Expand Down
2 changes: 1 addition & 1 deletion vars.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package main

const (
VERSION = "1.38"
VERSION = "1.39"
DATABASE_DIR = "database"
RELEASE_URL = "https://github.com/Seklfreak/discord-image-downloader-go/releases/latest"
RELEASE_API_URL = "https://api.github.com/repos/Seklfreak/discord-image-downloader-go/releases/latest"
Expand Down