matrix-org / matrix-appservice-discord

A bridge between Matrix and Discord.
Apache License 2.0
805 stars 151 forks source link

Forwarded images are not bridged to Discord #145

Open anoadragon453 opened 6 years ago

anoadragon453 commented 6 years ago

Forwarding an image to a bridged room does not send the image over to Discord, which made people very confused when I started describing how cupcakes looked without having any visual representation :P

anoadragon453 commented 6 years ago

Here is a copy of the log when it happened.

sill SQL get_user_discord_ids => @andrewm:amorgan.xyz                                    
verb matrix-appservice-bridge [-] GET http://amorgan.xyz:8008/_matrix/client/r0/rooms/!jvaOtgjswhzJGxFLEK%3Aamorgan.xyz/state/m.room.member/%40andrewm%3Aamorgan.xyz (AS) Body:
verb matrix-appservice-bridge [-] GET http://amorgan.xyz:8008/_matrix/client/r0/rooms/!jvaOtgjswhzJGxFLEK%3Aamorgan.xyz/state/m.room.member/%40andrewm%3Aamorgan.xyz (AS) HTTP 200 {"membership":"join","avatar_url":"mxc://amorgan.xyz/lYiIcCTEuLjgQdzqLtKnwhkN","
WARN MatrixRoomHandler Error [ERR_INVALID_DOMAIN_NAME]: Unable to determine the domain name
WARN MatrixRoomHandler     at new ClientRequest (_http_client.js:86:13)
WARN MatrixRoomHandler     at request (http.js:41:10)                                                            
WARN MatrixRoomHandler     at Object.get (http.js:45:13)
WARN MatrixRoomHandler     at DownloadFile.Promise (/home/ops/.matrix-appservice-discord/build/src/util.js:24:28) 
WARN MatrixRoomHandler     at new Promise (<anonymous>)                                                            
WARN MatrixRoomHandler     at Function.DownloadFile (/home/ops/.matrix-appservice-discord/build/src/util.js:16:16)
WARN MatrixRoomHandler     at DiscordBot.<anonymous> (/home/ops/.matrix-appservice-discord/build/src/bot.js:192:54)
WARN MatrixRoomHandler     at Generator.next (<anonymous>)
WARN MatrixRoomHandler     at fulfilled (/home/ops/.matrix-appservice-discord/build/src/bot.js:4:58)
WARN MatrixRoomHandler     at <anonymous>                                                                                                                                                                                                                                                   
WARN MatrixRoomHandler     at process._tickCallback (internal/process/next_tick.js:182:7)                                                                                                                                                                                                   
WARN MatrixRoomHandler  There was an error sending a matrix event { Error [ERR_INVALID_DOMAIN_NAME]: Unable to determine the domain name                                  
WARN MatrixRoomHandler     at new ClientRequest (_http_client.js:86:13)                                                                                                                                            
WARN MatrixRoomHandler     at request (http.js:41:10)                                                                                                                                              
WARN MatrixRoomHandler     at Object.get (http.js:45:13)                                                                                                                                                           
WARN MatrixRoomHandler     at DownloadFile.Promise (/home/ops/.matrix-appservice-discord/build/src/util.js:24:28)                                                                                  
WARN MatrixRoomHandler     at new Promise (<anonymous>)                                                                                                                                                                                                    
WARN MatrixRoomHandler     at Function.DownloadFile (/home/ops/.matrix-appservice-discord/build/src/util.js:16:16)                                                                                 
WARN MatrixRoomHandler     at DiscordBot.<anonymous> (/home/ops/.matrix-appservice-discord/build/src/bot.js:192:54)                                                                                              
WARN MatrixRoomHandler     at Generator.next (<anonymous>)                                                                                                                                       
WARN MatrixRoomHandler     at fulfilled (/home/ops/.matrix-appservice-discord/build/src/bot.js:4:58)                                                                                                               
WARN MatrixRoomHandler     at <anonymous>                                                                                                                                                                                                                                                   
WARN MatrixRoomHandler     at process._tickCallback (internal/process/next_tick.js:182:7)
WARN MatrixRoomHandler   stack: 'Error [ERR_INVALID_DOMAIN_NAME]: Unable to determine the domain name\n    at new ClientRequest (_http_client.js:86:13)\n    at request (http.js:41:10)\n    at Object.get (http.js:45:13)\n    at DownloadFile.Promise (/home/ops/.matrix-appservice-discord/build/src/util.js:24:28)\n    at new Promise (<anonymous>)\n    at Function.DownloadFile (/home/ops/.matrix-appservice-discord/build/src/util.js:16:16)\n    at DiscordBot.<anonymous> (/home/ops/.matrix-appservice-discord/build/src/bot.js:192:54)\n    at Generator.next (<anonymous>)\n    at fulfilled (/home/ops/.matrix-appservice-discord/build/src/bot.js:4:58)\n    at <anonymous>\n    at process._tickCallback (internal/process/next_tick.js:182:7)' }   
Half-Shot commented 6 years ago

At a guess, this looks like the URL of the matrix content is screwy :(. Needs some logging me thinks

anoadragon453 commented 6 years ago

Indeed. What domain is it referring to? I'll work on this with you once you get back.

Half-Shot commented 6 years ago

@anoadragon453 Right, back I am. What's the status of this?

anoadragon453 commented 6 years ago

Oh, uh, you were gonna add logging? :D:D:D:D

On 05/30/2018 07:37 PM, Will Hunt wrote:

@anoadragon453 https://github.com/anoadragon453 Right, back I am. What's the status of this?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/Half-Shot/matrix-appservice-discord/issues/145#issuecomment-393271634, or mute the thread https://github.com/notifications/unsubscribe-auth/ABR7mPvJa95JaGH1nU3jpdlgap3pG8sBks5t3ucDgaJpZM4UOsAh.

Half-Shot commented 6 years ago

@anoadragon453 https://github.com/Half-Shot/matrix-appservice-discord/tree/hs/add-download-logging see what logging this spits out.

anoadragon453 commented 6 years ago

Here you are:

verb matrix-appservice-bridge 
verb MatrixRoomHandler Got m.room.message event
verb DiscordBot Looking up 417077507075080204_417077507590848526
sill SQL get_user_discord_ids => @andrewm:amorgan.xyz
verb matrix-appservice-bridge [-] GET http://amorgan.xyz:8008/_matrix/client/r0/rooms/!cjkkYxLsofubMdpnCd%3Aamorgan.xyz/state/m.room.member/%40andrewm%3Aamorgan.xyz (AS) Body:
verb matrix-appservice-bridge [-] GET http://amorgan.xyz:8008/_matrix/client/r0/rooms/!cjkkYxLsofubMdpnCd%3Aamorgan.xyz/state/m.room.member/%40andrewm%3Aamorgan.xyz (AS) HTTP 200 {"membership":"join","avatar_url":"mxc://amorgan.xyz/lYiIcCTEuLjgQdzqLtKnwhkN","
verb Util Downloading file "" 
WARN MatrixRoomHandler Error [ERR_INVALID_DOMAIN_NAME]: Unable to determine the domain name
WARN MatrixRoomHandler     at new ClientRequest (_http_client.js:86:13)
WARN MatrixRoomHandler     at request (http.js:41:10)
WARN MatrixRoomHandler     at Object.get (http.js:45:13)
WARN MatrixRoomHandler     at DownloadFile.Promise (/home/ops/.matrix-appservice-discord/build/src/util.js:25:28)
WARN MatrixRoomHandler     at new Promise (<anonymous>)
WARN MatrixRoomHandler     at Function.DownloadFile (/home/ops/.matrix-appservice-discord/build/src/util.js:16:16)
WARN MatrixRoomHandler     at MatrixEventProcessor.<anonymous> (/home/ops/.matrix-appservice-discord/build/src/matrixeventprocessor.js:122:54)
WARN MatrixRoomHandler     at Generator.next (<anonymous>)
WARN MatrixRoomHandler     at /home/ops/.matrix-appservice-discord/build/src/matrixeventprocessor.js:7:71
WARN MatrixRoomHandler     at new Promise (<anonymous>)
WARN MatrixRoomHandler     at __awaiter (/home/ops/.matrix-appservice-discord/build/src/matrixeventprocessor.js:3:12)
WARN MatrixRoomHandler     at MatrixEventProcessor.HandleAttachment (/home/ops/.matrix-appservice-discord/build/src/matrixeventprocessor.js:103:16)
WARN MatrixRoomHandler     at DiscordBot.<anonymous> (/home/ops/.matrix-appservice-discord/build/src/bot.js:163:54)
WARN MatrixRoomHandler     at Generator.next (<anonymous>)
WARN MatrixRoomHandler     at fulfilled (/home/ops/.matrix-appservice-discord/build/src/bot.js:4:58)
WARN MatrixRoomHandler     at <anonymous>
WARN MatrixRoomHandler     at process._tickCallback (internal/process/next_tick.js:182:7)
WARN MatrixRoomHandler  There was an error sending a matrix event { Error [ERR_INVALID_DOMAIN_NAME]: Unable to determine the domain name
WARN MatrixRoomHandler     at new ClientRequest (_http_client.js:86:13)
WARN MatrixRoomHandler     at request (http.js:41:10)
WARN MatrixRoomHandler     at Object.get (http.js:45:13)
WARN MatrixRoomHandler     at DownloadFile.Promise (/home/ops/.matrix-appservice-discord/build/src/util.js:25:28)
WARN MatrixRoomHandler     at new Promise (<anonymous>)
WARN MatrixRoomHandler     at Function.DownloadFile (/home/ops/.matrix-appservice-discord/build/src/util.js:16:16)
WARN MatrixRoomHandler     at MatrixEventProcessor.<anonymous> (/home/ops/.matrix-appservice-discord/build/src/matrixeventprocessor.js:122:54)
WARN MatrixRoomHandler     at Generator.next (<anonymous>)
WARN MatrixRoomHandler     at /home/ops/.matrix-appservice-discord/build/src/matrixeventprocessor.js:7:71
WARN MatrixRoomHandler     at new Promise (<anonymous>)
WARN MatrixRoomHandler     at __awaiter (/home/ops/.matrix-appservice-discord/build/src/matrixeventprocessor.js:3:12)
WARN MatrixRoomHandler     at MatrixEventProcessor.HandleAttachment (/home/ops/.matrix-appservice-discord/build/src/matrixeventprocessor.js:103:16)
WARN MatrixRoomHandler     at DiscordBot.<anonymous> (/home/ops/.matrix-appservice-discord/build/src/bot.js:163:54)
WARN MatrixRoomHandler     at Generator.next (<anonymous>)
WARN MatrixRoomHandler     at fulfilled (/home/ops/.matrix-appservice-discord/build/src/bot.js:4:58)
WARN MatrixRoomHandler     at <anonymous>
WARN MatrixRoomHandler     at process._tickCallback (internal/process/next_tick.js:182:7)
WARN MatrixRoomHandler   stack: 'Error [ERR_INVALID_DOMAIN_NAME]: Unable to determine the domain name\n    at new ClientRequest (_http_client.js:86:13)\n    at request (http.js:41:10)\n    at Object.get (http.js:45:13)\n    at DownloadFile.Promise (/home/ops/.matrix-appservice-discord/build/src/util.js:25:28)\n    at new Promise (<anonymous>)\n    at Function.DownloadFile (/home/ops/.matrix-appservice-discord/build/src/util.js:16:16)\n    at MatrixEventProcessor.<anonym
ous> (/home/ops/.matrix-appservice-discord/build/src/matrixeventprocessor.js:122:54)\n    at Generator.next (<anonymous>)\n    at /home/ops/.matrix-appservice-discord/build/src/matrixeventprocessor.js:7:71\n    at new Promise (<anonymous>)\n    at __awaiter (/home/ops/.matrix-appservice-discord/build/src/matrixeventprocessor.js:3:12)\n    at MatrixEventProcessor.HandleAttachment (/home/ops/.matrix-appservice-discord/build/src/matrixeventprocessor.js:103:16)\n    at Disc
ordBot.<anonymous> (/home/ops/.matrix-appservice-discord/build/src/bot.js:163:54)\n   at Generator.next (<anonymous>)\n    at fulfilled (/home/ops/.matrix-appservice-discord/build/src/bot.js:4:58)\n    at <anonymous>\n    at process._tickCallback (internal/process/next_tick.js:182:7)' }
verb matrix-appservice-bridge

If I forward an image from Discord it works fine. Possible the image source being an mxc:// address instead of an http:// one?

Half-Shot commented 6 years ago

@anoadragon453 can you send along the event of the image it's trying to process?

Half-Shot commented 6 years ago

I did try reproducing this just now but I can't seem to :(

anoadragon453 commented 6 years ago

You mean forwarding images works for you? Even if the image was originally uploaded through Riot?

On 01/06/18 10:35, Will Hunt wrote:

I did try reproducing this just now but I can't seem to :(

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/Half-Shot/matrix-appservice-discord/issues/145#issuecomment-393828042, or mute the thread https://github.com/notifications/unsubscribe-auth/ABR7mJceN9n6WprsD_VI0PtUbxpNGaPxks5t4QrogaJpZM4UOsAh.

anoadragon453 commented 6 years ago
{
  "origin_server_ts": 1527811985370,
  "sender": "@andrewm:amorgan.xyz",
  "event_id": "$1527811985833KEgER:amorgan.xyz",
  "unsigned": {
    "age": 59
  },
  "content": {
    "body": "20180513_180146.jpg",
    "info": {
      "mimetype": "image/jpeg",
      "thumbnail_info": {
        "mimetype": "image/jpeg",
        "h": 648,
        "w": 864,
        "size": 599020
      },
      "h": 1494,
      "thumbnail_file": {
        "mimetype": "image/jpeg",
        "url": "mxc://matrix.org/SrxvtPUgXxsunbJESYtWNZFU",
        "iv": "bnCgukNbdgsAAAAAAAAAAA",
        "key": {
          "alg": "A256CTR",
          "ext": true,
          "key_ops": [
            "encrypt",
            "decrypt"
          ],
          "k": "Sh6FrmDdW_wEtDlZVQr18sCf2TIwW3IwA1J7QpNiCNs",
          "kty": "oct"
        },
        "v": "v2",
        "hashes": {
          "sha256": "Vq5nebSq9gpcl49sZcKRERKmHERVqkjcAVKfPWDBJws"
        }
      },
      "w": 1992,
      "size": 488558,
      "orientation": 0
    },
    "msgtype": "m.image",
    "file": {
      "mimetype": "image/jpeg",
      "url": "mxc://matrix.org/zyYTtzUbxMenCATFzWYDMQHP",
      "iv": "Zp+JKWadsLAAAAAAAAAAAA",
      "key": {
        "alg": "A256CTR",
        "ext": true,
        "key_ops": [
          "encrypt",
          "decrypt"
        ],
        "k": "Qg4Ia1OdrcLH3IgZPNgGTx50kbRZyi7Fa_hArTxkB4M",
        "kty": "oct"
      },
      "v": "v2",
      "hashes": {
        "sha256": "5eAs+G2WZlepb3Fxyq/RdD816rO2zPANXagDgliWuUM"
      }
    }
  },
  "type": "m.room.message",
  "room_id": "!cjkkYxLsofubMdpnCd:amorgan.xyz"
}
Half-Shot commented 6 years ago

Okay, then that's why. Your event is non-conforming. This is the image event I get when I upload something via Riot:

{
  "origin_server_ts": 1527845636466,
  "sender": "@Half-Shot:half-shot.uk",
  "event_id": "$1527845636295trLYE:half-shot.uk",
  "unsigned": {
    "age": 270,
    "transaction_id": "m1527845636425.61"
  },
  "content": {
    "body": "4ed9701a58082119.jpeg",
    "info": {
      "mimetype": "image/jpeg",
      "thumbnail_info": {
        "mimetype": "image/jpeg",
        "h": 162,
        "w": 288,
        "size": 34979
      },
      "h": 360,
      "thumbnail_url": "mxc://matrix.org/skaAYQsuMmfpyofkOJFpEPkO",
      "w": 640,
      "size": 18494,
      "orientation": 0
    },
    "msgtype": "m.image",
    "url": "mxc://matrix.org/PJOthHojEmUEZCEzWFqjSrUn"
  },
  "type": "m.room.message",
  "room_id": "!UcYsUzyxTGDxLBEvLz:matrix.org"
}
Half-Shot commented 6 years ago

See https://matrix.org/docs/spec/client_server/r0.3.0.html#m-image and tell whoever wrote your client to fix their shit?

anoadragon453 commented 6 years ago

I using Riot, lol

Half-Shot commented 6 years ago

I using Riot, lol

:roll_eyes: Whenever you think Riot cannot possibly cock something up.

anoadragon453 commented 6 years ago

I copied the source of the forwarded image though. Just uploading an image looks like this:

{
  "origin_server_ts": 1527846097860,
  "sender": "@andrewm:amorgan.xyz",
  "event_id": "$1527846097992ZvWgE:amorgan.xyz",
  "unsigned": {
    "age": 42,
    "transaction_id": "m1527846097825.1133"
  },
  "content": {
    "body": "image.png",
    "info": {
      "mimetype": "image/png",
      "thumbnail_info": {
        "mimetype": "image/png",
        "h": 600,
        "w": 600,
        "size": 377540
      },
      "h": 666,
      "thumbnail_url": "mxc://amorgan.xyz/oYNwpfwrXESDZtvSxezECLRk",
      "w": 666,
      "size": 436536
    },
    "msgtype": "m.image",
    "url": "mxc://amorgan.xyz/afucjoAbkPLmcAWnlKolcVGM"
  },
  "type": "m.room.message",
  "room_id": "!jvaOtgjswhzJGxFLEK:amorgan.xyz"
}
Half-Shot commented 6 years ago

Yes, that one will work. The forwarded message is the wrong format.

anoadragon453 commented 6 years ago

Riot-web issue filed here: https://github.com/vector-im/riot-web/issues/6832