matrix-discord-bridge
matrix-discord-bridge copied to clipboard
Attachment uploading
I have the bandwidth to support a bot that can reupload everything a user uploads on the server over to a Matrix server (or another service if need be).
The obvious hurdle is messages becoming desynced due to waiting on uploads, as well as messages not being able to be attached directly to attachments like in Discord. Additionally, files above 10MB pose a problem.
The most obvious solution would probably be to either rely on a third-party service for uploads or having a matrix channel designated for uploads and editing the message with the new URL once the upload is complete. If a matrix channel is used, files above 10MB could either be discarded, or, alternatively, handled by said third-party service.
Or, perhaps the bot just waits until the upload is complete before continuing to forward messages to the matrix server. This would probably be the easiest to implement, but any complications in uploading could lead to a wide variety of unpredictable errors.
You could even limit this to images only, discarding images beyond 10MB.
It might be asking too much, but please do consider it. It's well beyond my own ability, unfortunately.
There are some more issues with this in addition to what you mentioned regarding the uploads being too large. The bridge doesn't keep any track of message IDs / event IDs in a database (Only in RAM for figuring out who replied to what) so, say that you upload an image and the bot stores it into another matrix room or whatever, and then the bot is down for 30 mins or so and the original image was deleted in those 30 mins. So when the bot comes online again it wouldn't know whether the image was deleted or not and everyone would have access to the deleted image.
I have made code so it uploads from discord to matrix instead of sending image url. Send me a message if you want it, I need to cleanup the code first since it is very spaghetti at the moment. (I have no idea how to push git)
You can just post the output of git diff
here, in code blocks
Ok so I may have missunderstood what git commit is or does. I git commited and now I cannot git diff.
Anyhow, here is a short description of the changes I have successfully made:
There is some documentation in the code missing which I plan to add later.
Changes in no particular order:
There is now an option to disable text messages. Reason was that
I personally needed to disable messages but instead added it as an option.
In the config.json file there is now a textenabled variable. If set to either
"True" or "true" it sets the variable textenabled to True (boolean), and vice versa.
It is not by room/bridge, if you disable text then it will be disabled for all room and channel bridges.
Image, video, and audio files are now sent to matrix as attachments
instead of links.
All attachements in matrix are now sent to discord as attachements. No limits.
Example: A PDF sent to matrix will be sent as an attachment to discord.
However, a pdf file sent to discord will not be sent to matrix.
I have also commented out the embedding of images on discord since I
personally think it looks bad and looks much better when pic is sent as
attachment instead of embed
If you commited then you can do git diff HEAD^
to get all the changes made by the commit.
Okay so here it comes, it is a bit spaghetti and I have to fix some parts here and there. I will write the line number and what issues they cause. I will fix all of them in a day or two since I am a bit busy.
I need to fix some comments and remove old comments that no longer apply or move to correct space
I think lines 9 and 10 are not needed. (+from PIL import Image +from tempfile import gettempdir). mygit.txt
I forgot to mention that there is no upload limit filter, so if matrix server allows for big files over 8mb then there will be exception when bot tries to upload image to discord servers without boosts since discord has an 8mb limit
Ok if anyone read my comment with the git diff I corrected it since I brainfarted. There is no ping issue
I improved it and removed the unnecessary imports. Here. mygit1.txt
Ok I undid git commit and here is the end file that is fixed diff from your branch. mygit.txt
I found one mistake and that was I missed to remove one unecessary import (from tempfile import gettempdir) but I think it is in the default python library.