EDA.App (EDA v0.5.0-beta.2)

Copy Markdown View Source

The Discord application a bot belongs to — its public profile, install settings and flags.

{:ok, app} = EDA.App.me()
app.name
EDA.App.flags(app)            #=> [:gateway_message_content_limited, :application_command_badge]
EDA.App.integration_types(app) #=> [:guild_install, :user_install]

Named EDA.App because EDA.Application is EDA's own OTP application.

The struct keeps the fields a bot has use for. Discord's response carries more — rpc_origins for desktop RPC apps, and a number of undocumented ones — which EDA.API.Application.me/0 returns as they are.

Flags

Discord serialises flags as a number that will never grow past 31 bits; any flag above bit 30 appears only in flags_new, a string. from_raw/1 reads flags_new when it is there, so :flags holds the complete set as an integer, and code that only ever read flags does not silently miss the newer bits. flags/1 names them.

Editing

modify/1 edits the application; see EDA.API.Application.modify_me/1 for the fields. Only the limited intent flags can be changed through the API.

Summary

Functions

The app's rich presence cover image URL, or nil.

The flags set on the app, as atoms. Bits Discord has not documented are left out.

Converts a raw application object into this struct.

Whether the app has flag set.

The app's icon URL, or nil when it has none.

Where the app can be installed: :guild_install, :user_install, or both.

Fetches the application the bot belongs to.

Edits the application the bot belongs to and returns it updated. See EDA.API.Application.modify_me/1 for the fields.

Types

flag()

@type flag() ::
  :application_auto_moderation_rule_create_badge
  | :gateway_presence
  | :gateway_presence_limited
  | :gateway_guild_members
  | :gateway_guild_members_limited
  | :verification_pending_guild_limit
  | :embedded
  | :gateway_message_content
  | :gateway_message_content_limited
  | :application_command_badge

install_params()

@type install_params() :: %{scopes: [String.t()], permissions: non_neg_integer()}

t()

@type t() :: %EDA.App{
  approximate_guild_count: non_neg_integer() | nil,
  approximate_user_authorization_count: non_neg_integer() | nil,
  approximate_user_install_count: non_neg_integer() | nil,
  bot: EDA.User.t() | nil,
  bot_public: boolean() | nil,
  bot_require_code_grant: boolean() | nil,
  cover_image: String.t() | nil,
  custom_install_url: String.t() | nil,
  description: String.t() | nil,
  event_webhooks_status:
    :disabled | :enabled | :disabled_by_discord | integer() | nil,
  event_webhooks_types: [String.t()] | nil,
  event_webhooks_url: String.t() | nil,
  flags: non_neg_integer() | nil,
  guild: map() | nil,
  guild_id: String.t() | nil,
  icon: String.t() | nil,
  id: String.t() | nil,
  install_params: install_params() | nil,
  integration_types_config: %{required(atom()) => install_params() | nil} | nil,
  interactions_endpoint_url: String.t() | nil,
  name: String.t() | nil,
  owner: EDA.User.t() | nil,
  primary_sku_id: String.t() | nil,
  privacy_policy_url: String.t() | nil,
  redirect_uris: [String.t()] | nil,
  role_connections_verification_url: String.t() | nil,
  slug: String.t() | nil,
  tags: [String.t()] | nil,
  team: map() | nil,
  terms_of_service_url: String.t() | nil,
  verify_key: String.t() | nil
}

Functions

cover_image_url(app, opts \\ [])

@spec cover_image_url(
  t(),
  keyword()
) :: String.t() | nil

The app's rich presence cover image URL, or nil.

flags(app)

@spec flags(t()) :: [flag()]

The flags set on the app, as atoms. Bits Discord has not documented are left out.

iex> EDA.App.flags(%EDA.App{flags: 524_288 + 8_388_608})
[:gateway_message_content_limited, :application_command_badge]

from_raw(raw)

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

Converts a raw application object into this struct.

iex> app = EDA.App.from_raw(%{"id" => "1", "name" => "Bot", "flags" => 8192, "flags_new" => "8192"})
iex> {app.name, app.flags}
{"Bot", 8192}

has_flag?(app, flag)

@spec has_flag?(t(), flag()) :: boolean()

Whether the app has flag set.

icon_url(app, opts \\ [])

@spec icon_url(
  t(),
  keyword()
) :: String.t() | nil

The app's icon URL, or nil when it has none.

integration_types(app)

@spec integration_types(t()) :: [:guild_install | :user_install]

Where the app can be installed: :guild_install, :user_install, or both.

iex> EDA.App.integration_types(%EDA.App{integration_types_config: %{guild_install: nil}})
[:guild_install]

me()

@spec me() :: {:ok, t()} | {:error, term()}

Fetches the application the bot belongs to.

modify(opts)

@spec modify(keyword() | map()) :: {:ok, t()} | {:error, term()}

Edits the application the bot belongs to and returns it updated. See EDA.API.Application.modify_me/1 for the fields.

EDA.App.modify(description: "Moderation for busy servers", tags: ["moderation"])