Skip to content

Discord: Download files, don't send as URLs#44

Merged
poVoq merged 3 commits into
matterbridge-org:masterfrom
Wohlstand:discord-file-upload
Dec 19, 2025
Merged

Discord: Download files, don't send as URLs#44
poVoq merged 3 commits into
matterbridge-org:masterfrom
Wohlstand:discord-file-upload

Conversation

@Wohlstand

Copy link
Copy Markdown

My old tweak that allows re-uploading of files from Discord to destination server (Telegram, Matrix, or the MediaProxy if destination is not available).

Fixes #37

@Wohlstand

Wohlstand commented Dec 4, 2025

Copy link
Copy Markdown
Author

Heck, freaking linter, actually I am not "gopher", I am C/C++ developer, and the rest of stuff I done, just done on the production server during debugging (I made many other fixes including this, because it just failed with several cases already), written via mcedit and commited via terminal. I will probably ask true gophers to polish this properly.

Comment thread bridge/discord/handlers.go Outdated
url = attach.URL
name = attach.Filename

err := helper.HandleDownloadSize(b.Log, &rmsg, name, int64(attach.Size), b.General)

@poVoq poVoq Dec 4, 2025

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No expert at all here, but it might be that the linter doesn't like that err wasn't declared as a variable name for some reason?

At least the possible solutions here make it sound like this should fix it?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I always find golang so confusing with := vs = it's like the exact opposite of ergonomic! Here variable err was already defined so you should be doing err = instead of err := (assignment to a new variable shadowing previous assignment).

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one I fixed.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like there is another same one at line 118.

Comment thread bridge/discord/handlers.go Outdated

// no empty messages
if rmsg.Text == "" {
if rmsg.Text == "" && len(m.Attachments) == 0 {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we should check the length of rmsg.Extra['file'] instead of the original number of attachments, because we are checking for max allowed size and blacklisted files, so we may end up with 0 attachments to forward despite having some incoming.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't knew about that field, primarily because I didn't investigated entire project and I wanted to implement the most simple thing that just work, I'll try to place the thing, but I am not sure WHAT stuff that field contains? Array? Structures?

@Wohlstand Wohlstand Dec 4, 2025

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Anyway, to properly finish that (I mean the full pile of changes) I will need to set up go compiler on my local system and debug thing locally, not on production server (that I usually alternate only when any troubles gets bringed up).

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for the extra trouble. It is much appreciated if you could look into this further while we try to fix some other general linter issues.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So here this is the method called when a message is received from Discord. So you're generating a new config.Message instance (rmsg) that will be passed to other bridges (b.Remote <- rmsg).

That check is meant to prevent empty messages from reaching other bridges. So you should check if after the logic has been applied (eg. preventing too big files), some files have been added to that rmsg.Extra['file'] which contains info about attachments. If you check m.Attachments, you're checking if there were attachments in the original Discord message, not if those attachments have been successfully "imported" in the matterbridge message.

}
first = false
} else {
caption = ""

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So on discord only the first image can have a caption? Or am i missing something?

@Wohlstand Wohlstand Dec 4, 2025

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Discord has one united caption for all the images sent in the pack. Probably I should merge them into list?

  • like
  • this

To make it display all the captions properly?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure what should be the policy here, when there's a united caption for a bunch of attachments. Should we apply it only on the first attachment? On all attachments? In all cases, this is beyond this specific bridge so i'd be happy to merge anything, but we should definitely document that kind of expected behavior in the guide to write new bridges (and align existing ones with expectations).

@selfhoster1312

Copy link
Copy Markdown
Collaborator

Hello, thanks for taking the time to write and test this!

I have a few minor review comments, but i have one more fundamental question: why do HandleDownloadSize then DownloadFile then HandleDownloadData. I was wondering about XMPP uploads too, i didn't find good documentation on the expected data flow, so i'm wondering if you have good knowledge of the codebase, or if you found documentation somewhere about how this should be handled.

I'm also curious if you would be interested in becoming a maintainer for the discord bridge alongside @poVoq. It's not exactly more responsibilities, but we'd ping you to review and test discord changes before they are merged.

Comment thread bridge/discord/handlers.go
@Wohlstand Wohlstand force-pushed the discord-file-upload branch 2 times, most recently from d438615 to fd5b697 Compare December 4, 2025 21:37
@selfhoster1312

Copy link
Copy Markdown
Collaborator

Hello @Wohlstand do you think you would have some time to take care of the changes requested here soon? If you have no time in the coming weeks, i can take care of it myself since this is a high-priority PR for @poVoq. Just say the word whatever you prefer.

My review comment about HandleDownloadSize/HandleDownloadData will wait for #59 to get merged, but the rest can move on :)

@poVoq

poVoq commented Dec 18, 2025

Copy link
Copy Markdown
Collaborator

Now that #59 is merged can we get this fixed up ready for merge as well?

@Wohlstand

Wohlstand commented Dec 18, 2025

Copy link
Copy Markdown
Author

I didn't yet worked on the stuff, because I was busy on other thingies, and I would like try to set up a kind of local IDE to properly apply these tweaks and test the stuff locally. As I already said I developed these thingies just using mcedit in terminal and debugged locally on production server with a goal to just get it working as I need.

@Wohlstand

Copy link
Copy Markdown
Author

Rebased and updated

@poVoq

poVoq commented Dec 19, 2025

Copy link
Copy Markdown
Collaborator

I am testing this right now, but it doesn't seem to make a difference, I still get the Discord CDN links on IRC and XMPP despite having the Matterbridge mediaserver configured.

Does this require some additional setting to work? And if so, please add a change to the documentation for it.

Also: can you please include a changelog entry for this change?

Thanks!

@Wohlstand

Copy link
Copy Markdown
Author

I am testing this right now, but it doesn't seem to make a difference, I still get the Discord CDN links on IRC and XMPP despite having the Matterbridge mediaserver configured.

Does this require some additional setting to work? And if so, please add a change to the documentation for it.

Also: can you please include a changelog entry for this change?

Thanks!

I may guess something got been broken... The original code that I developed, worked flawlessly.

@Wohlstand

Copy link
Copy Markdown
Author

And ye, I do have the file sharing proxy configured on the bridge with a web server frontend. So, files gets re-uploaded to the mediaserver. Actually, let me try some again...

@Wohlstand

Copy link
Copy Markdown
Author

Tested just now: with MY current state of repo (that works on my production server) does this:

Снимок экрана 2025-12-19 в 17 44 38

@Wohlstand

Copy link
Copy Markdown
Author

Now the question: DID you properly set the AlwaysDownloadFiles setting? It's a boolean at Discord's gateway config.

@poVoq

poVoq commented Dec 19, 2025

Copy link
Copy Markdown
Collaborator

Now the question: DID you properly set the AlwaysDownloadFiles setting? It's a boolean at Discord's gateway config.

Ideed that was the issue. With AlwaysDownloadFiles=true it seems to work. Great!

But that is what I meant with documentation missing in your PR.

@Wohlstand

Copy link
Copy Markdown
Author

Now the question: DID you properly set the AlwaysDownloadFiles setting? It's a boolean at Discord's gateway config.

Ideed that was the issue. With AlwaysDownloadFiles=true it seems to work. Great!

But that is what I meant with documentation missing in your PR.

I basically didn't care about docs, but now it's a time. I will try to add documentation note then.

@poVoq poVoq merged commit 7556893 into matterbridge-org:master Dec 19, 2025
7 checks passed
@poVoq

poVoq commented Dec 19, 2025

Copy link
Copy Markdown
Collaborator

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support for mediaproxy in Discord

3 participants