EDA.Sticker (EDA v0.3.0)

Copy Markdown View Source

Represents a Discord sticker.

Types: :standard (Nitro stickers), :guild (guild-specific). Formats: :png, :apng, :lottie, :gif.

Summary

Functions

Returns the CDN URL for a sticker.

Converts a raw Discord sticker map into this struct.

Types

t()

@type t() :: %EDA.Sticker{
  available: boolean() | nil,
  description: String.t() | nil,
  format_type: :png | :apng | :lottie | :gif | integer() | nil,
  guild_id: String.t() | nil,
  id: String.t() | nil,
  name: String.t() | nil,
  pack_id: String.t() | nil,
  sort_value: integer() | nil,
  tags: String.t() | nil,
  type: :standard | :guild | integer() | nil,
  user: map() | nil
}

Functions

cdn_url(sticker)

@spec cdn_url(t()) :: String.t() | nil

Returns the CDN URL for a sticker.

Lottie stickers return a .json URL, GIF stickers return .gif, and all others return .png. Returns nil if the sticker has no id.

Examples

iex> EDA.Sticker.cdn_url(%EDA.Sticker{id: "1", format_type: :lottie})
"https://cdn.discordapp.com/stickers/1.json"

iex> EDA.Sticker.cdn_url(%EDA.Sticker{id: "1", format_type: :gif})
"https://cdn.discordapp.com/stickers/1.gif"

iex> EDA.Sticker.cdn_url(%EDA.Sticker{id: "1", format_type: :png})
"https://cdn.discordapp.com/stickers/1.png"

iex> EDA.Sticker.cdn_url(%EDA.Sticker{id: nil})
nil

from_raw(raw)

@spec from_raw(map()) :: t()

Converts a raw Discord sticker map into this struct.

Resolves integer type and format_type to atoms where known.

Examples

iex> EDA.Sticker.from_raw(%{"id" => "1", "name" => "wave", "type" => 2, "format_type" => 1})
%EDA.Sticker{id: "1", name: "wave", type: :guild, format_type: :png}