simmsb / calamity

A library for writing discord bots in haskell
https://hackage.haskell.org/package/calamity
MIT License
109 stars 11 forks source link

use RequestBody for attachment content #65

Closed pufferffish closed 1 year ago

pufferffish commented 1 year ago

This PR let's people use a RequestBody instead of Lazy Bytestring to create an attachment. This gives people more fine grained control on how the content of the attachment is loaded. For example, in my use case, I had to load a file from Amazon S3, and upload it as an attachment. However due to the memory limit of the VM I'm running the bot on, it would crash due to OOM if I try to upload a huge file. Fiddling with Lazy Bytestring wasn't yielding any good results so I came up with this PR.

With this PR, I can upload a body :: ConduitM () ByteString (ResourceT IO) () with requestBodySourceChunked from http-conduit, without running into memory problems.

let file = CreateMessageAttachment filename Nothing $ requestBodySourceChunked body
followUp (intoMsg ([i|<@#{showID $ user ^. #id}>|] :: Text) <> intoMsg file)
simmsb commented 1 year ago

Nice, thanks :)