Skip to content

feat: use byte sniffing - #477

Open
Droid00000 wants to merge 1 commit into
shardlab:mainfrom
Droid00000:feat/magic-byte-sniffing
Open

feat: use byte sniffing#477
Droid00000 wants to merge 1 commit into
shardlab:mainfrom
Droid00000:feat/magic-byte-sniffing

Conversation

@Droid00000

Copy link
Copy Markdown
Collaborator

Summary

I understand that this is kinda out of the blue, and that this makes the code slightly more complex/approachable since you're dealing with file signatures and the like, but i have a kinda decent reason for wanting to change this

  • Unfortunately, if we ever want to support stickers (specifically allowing them to be uploaded to servers), we need to provide the exact content type of the sticker file. Unlike every-other endpoint that accepts file uploads, the sticker endpoint is strict and rejects application/octet-stream or a content type that doesn't match the contents of a file.

  • If you provide something like a Tempfile or StringIO to something like Server#create_emoji it's currently always fallback to a image/jpeg content type. While this is okay right now because Discord basically ignores the content-type your provide in the base64 string, they could decide to make it strict at anytime (like stickers). You could technically do something like below, to provide the content type, I think it's pretty janky to expect people to be defining singleton methods:

  • If we ever decide to ditch rest-client, we won't be able to use the mime-types gem (unless we want to make it an explicit dependency) since it's a transitive dependency from rest-client.

  • All of the file types that Discord supports are well-documented and easy to find: https://en.wikipedia.org/wiki/List_of_file_signatures

string_io.define_singleton_method(:original_filename) { "foo.#{my_extension}" }

Added

Discordrb.sniff_mime_type (thanks discord.py)

Fixed

I snuck in the doc fixes related to the component builder not being documented on a few interaction methods.

@Droid00000
Droid00000 force-pushed the feat/magic-byte-sniffing branch from 4b2fe2e to f2be16d Compare July 25, 2026 06:10
@Droid00000
Droid00000 force-pushed the feat/magic-byte-sniffing branch from 132e841 to 0984abd Compare July 25, 2026 06:11
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.

1 participant