LemonChannels.Adapters.Discord.FileOperations (lemon_channels v0.1.0)

View Source

File upload/download operations for the Discord transport.

Handles /file put, /file get, and auto-put for bare attachment uploads. Reuses shared path-validation and write helpers from the Telegram FileOperations module where possible, adapting the download/upload paths for Discord's API.

Summary

Functions

Download attachment bytes from a Discord CDN URL.

Extract the resolved attachment struct from a /file put interaction.

Process auto-put for attachments on a regular (non-slash-command) message.

Handle the /file get slash command interaction.

Handle the /file put slash command interaction.

Returns true when the inbound message has attachments and auto-put is enabled in the files config.

Functions

download_attachment_bytes(url)

Download attachment bytes from a Discord CDN URL.

extract_resolved_attachment(interaction, subcommand, option_name)

Extract the resolved attachment struct from a /file put interaction.

Discord option type 11 (ATTACHMENT) stores the snowflake ID as the option value. The actual attachment data lives in interaction.data.resolved.attachments keyed by that snowflake.

handle_attachment_auto_put(state, inbound)

Process auto-put for attachments on a regular (non-slash-command) message.

Returns a list of {:ok, rel_path} or {:error, reason} tuples, one per attachment processed.

handle_file_get(state, interaction, file_path)

Handle the /file get slash command interaction.

Reads a file from disk and sends it to the Discord channel as an attachment.

Returns {:ok, msg} or {:error, msg}.

handle_file_put(state, interaction, attachment, dest_path, force)

Handle the /file put slash command interaction.

Downloads the resolved attachment from its URL, validates the destination path, and writes the file to disk.

Returns a reply string for the interaction response.

should_auto_put?(state, inbound)

Returns true when the inbound message has attachments and auto-put is enabled in the files config.