| D++ (DPP) C++ Discord API Bot Library

Search
Loading...
Searching...
No Matches
dpp::emoji Class Reference

Represents an emoji for a dpp::guild. More...

`#include <emoji.h>`

Inheritance diagram for dpp::emoji:
[legend]
Collaboration diagram for dpp::emoji:
[legend]

## Public Member Functions

| emoji ()=default
| Construct a new emoji object.
| emoji (const emoji &rhs)=default
| Copy constructor, copies another emoji's data.
| emoji (const std::string_view name, const snowflake id=0, const uint8_t flags=0)
| Construct a new emoji object with name, ID and flags.
| emoji (emoji &&rhs) noexcept=default
| Move constructor, moves another emoji's data to this.
| ~emoji () override=default
| Destroy the emoji object.
std::string | build_json (bool with_id=false) const
| Convert object to json string.
emoji & | fill_from_json (nlohmann::json *j)
| Convert object from nlohmann::json.
std::string | format () const
| Format to name if unicode, name:id if has id or a:name:id if animated.
constexpr double | get_creation_time () const noexcept
| Get the creation time of this object according to Discord.
std::string | get_mention () const
| Get the mention/ping for the emoji.
std::string | get_url (uint16_t size=0, const image_type format=i_png, bool prefer_animated=true) const
| Get the custom emoji url.
bool | is_animated () const
| Emoji is animated.
bool | is_available () const
| Is available.
bool | is_managed () const
| Emoji is managed.
emoji & | load_image (const std::byte *data, uint32_t size, const image_type type)
| Load an image into the object.
emoji & | load_image (std::string_view image_blob, const image_type type)
| Load an image into the object.
constexpr bool | operator!= (const managed &other) const noexcept
| Comparison operator for comparing two managed objects by id.
emoji & | operator= (const emoji &rhs)=default
| Copy assignment operator, copies another emoji's data.
emoji & | operator= (emoji &&rhs) noexcept=default
| Move constructor, moves another emoji's data to this.
constexpr bool | operator== (const managed &other) const noexcept
| Comparison operator for comparing two managed objects by id.
bool | requires_colons () const
| Emoji requires colons.
auto | to_json (bool with_id=false) const
| Convert object to nlohmann::json.

## Static Public Member Functions

static std::string | get_mention (std::string_view name, snowflake id, bool is_animated=false)
| Create a mentionable emoji.

## Public Attributes

uint8_t | flags {0}
| Flags for the emoji from dpp::emoji_flags.
snowflake | id = {}
| Unique ID of object set by Discord. This value contains a timestamp, worker ID, internal server ID, and an incrementing value. Only the timestamp is relevant to us as useful metadata.
utility::image_data | image_data
| Image data for the emoji, if uploading.
std::string | name {}
| Emoji name.
std::vector< snowflake > | roles
| Roles allowed to use this emoji.
snowflake | user_id
| The id of the user that created this emoji.

## Protected Member Functions

emoji & | fill_from_json_impl (nlohmann::json *j)
| Read class values from json object.
json | to_json_impl (bool with_id=false) const
| Build the json for this object.

## Friends

struct | json_interface< emoji >

## Detailed Description

Represents an emoji for a dpp::guild.

## Constructor & Destructor Documentation

## ◆ emoji() [1/4]

dpp::emoji::emoji | ( |  | ) |

default

Construct a new emoji object.

## ◆ emoji() [2/4]

dpp::emoji::emoji | ( | const std::string_view | name,
|  | const snowflake | id = 0,
|  | const uint8_t | flags = 0 )

Construct a new emoji object with name, ID and flags.

Parameters

  name | The emoji's name
  id | ID, if it has one (unicode does not)
  flags | Emoji flags (emoji_flags)

## ◆ emoji() [3/4]

dpp::emoji::emoji | ( | const emoji & | rhs | ) |

default

Copy constructor, copies another emoji's data.

Parameters

  rhs | Emoji to copy

## ◆ emoji() [4/4]

dpp::emoji::emoji | ( | emoji && | rhs | ) |

default noexcept

Move constructor, moves another emoji's data to this.

Parameters

  rhs | Emoji to move from

## ◆ ~emoji()

dpp::emoji::~emoji | ( |  | ) |

override default

Destroy the emoji object.

## Member Function Documentation

## ◆ build_json()

std::string dpp::json_interface< emoji >::build_json | ( | bool | with_id = false | ) | const

inline inherited

Convert object to json string.

Parameters

  with_id | Whether to include the ID or not

Note
  Some fields are conditionally filled, do not rely on all fields being present

Returns
  std::string Json built from the structure

## ◆ fill_from_json()

emoji & dpp::json_interface< emoji >::fill_from_json | ( | nlohmann::json * | j | ) |

inline inherited

Convert object from nlohmann::json.

Parameters

  j | nlohmann::json object

Returns
  T& Reference to self for fluent calling

## ◆ fill_from_json_impl()

emoji & dpp::emoji::fill_from_json_impl | ( | nlohmann::json * | j | ) |

protected

Read class values from json object.

Parameters

  j | A json object to read from

Returns
  A reference to self

## ◆ format()

std::string dpp::emoji::format | ( |  | ) | const

Format to name if unicode, name:id if has id or a:name:id if animated.

Returns
  Formatted name for reactions

## ◆ get_creation_time()

double dpp::managed::get_creation_time | ( |  | ) | const

inline constexpr noexcept inherited

Get the creation time of this object according to Discord.

Returns
  double creation time inferred from the snowflake ID. The minimum possible value is the first second of 2015.

## ◆ get_mention() [1/2]

std::string dpp::emoji::get_mention | ( |  | ) | const

Get the mention/ping for the emoji.

Returns
  std::string mention

## ◆ get_mention() [2/2]

std::string dpp::emoji::get_mention | ( | std::string_view | name,
|  | snowflake | id,
|  | bool | is_animated = false )

static

Create a mentionable emoji.

Parameters

  name | The name of the emoji.
  id | The ID of the emoji.
  is_animated | is emoji animated.

Returns
  std::string The formatted mention of the emoji.

## ◆ get_url()

std::string dpp::emoji::get_url | ( | uint16_t | size = 0,
|  | const image_type | format = i_png,
|  | bool | prefer_animated = true ) const

Get the custom emoji url.

Parameters

  size | The size of the emoji in pixels. It can be any power of two between 16 and 4096, otherwise the default sized emoji is returned.
  format | The format to use for the emoji. It can be one of i_webp, i_jpg, i_png or i_gif. When passing i_gif, it returns an empty string for non-animated emojis. Consider using the prefer_animated parameter instead.
  prefer_animated | Whether you prefer gif format. If true, it'll return gif format whenever the emoji is available as animated.

Returns
  std::string emoji url or an empty string, if the id is not set

## ◆ is_animated()

bool dpp::emoji::is_animated | ( |  | ) | const

Emoji is animated.

Returns
  true Is animated
  false Is noy animated

## ◆ is_available()

bool dpp::emoji::is_available | ( |  | ) | const

Is available.

Returns
  true Is available
  false Is unavailable

## ◆ is_managed()

bool dpp::emoji::is_managed | ( |  | ) | const

Emoji is managed.

Returns
  true Is managed
  false Is not managed

## ◆ load_image() [1/2]

emoji & dpp::emoji::load_image | ( | const std::byte * | data,
|  | uint32_t | size,
|  | const image_type | type )

Load an image into the object.

Parameters

  data | Image binary data
  size | Size of the image.
  type | Type of image. It can be one of i_gif, i_jpg or i_png.

Returns
  emoji& Reference to self

Exceptions

  dpp::length_exception | Image content exceeds discord maximum of 256 kilobytes

## ◆ load_image() [2/2]

emoji & dpp::emoji::load_image | ( | std::string_view | image_blob,
|  | const image_type | type )

Load an image into the object.

Parameters

  image_blob | Image binary data
  type | Type of image. It can be one of i_gif, i_jpg or i_png.

Returns
  emoji& Reference to self

Exceptions

  dpp::length_exception | Image content exceeds discord maximum of 256 kilobytes

## ◆ operator!=()

bool dpp::managed::operator!= | ( | const managed & | other | ) | const

inline constexpr noexcept inherited

Comparison operator for comparing two managed objects by id.

Parameters

  other | Other object to compare against

Returns
  true objects are not the same id
  false objects are the same id

## ◆ operator=() [1/2]

emoji & dpp::emoji::operator= | ( | const emoji & | rhs | ) |

default

Copy assignment operator, copies another emoji's data.

Parameters

  rhs | Emoji to copy

## ◆ operator=() [2/2]

emoji & dpp::emoji::operator= | ( | emoji && | rhs | ) |

default noexcept

Move constructor, moves another emoji's data to this.

Parameters

  rhs | Emoji to move from

## ◆ operator==()

bool dpp::managed::operator== | ( | const managed & | other | ) | const

inline constexpr noexcept inherited

Comparison operator for comparing two managed objects by id.

Parameters

  other | Other object to compare against

Returns
  true objects are the same id
  false objects are not the same id

## ◆ requires_colons()

bool dpp::emoji::requires_colons | ( |  | ) | const

Emoji requires colons.

Returns
  true Requires colons
  false Does not require colons

## ◆ to_json()

auto dpp::json_interface< emoji >::to_json | ( | bool | with_id = false | ) | const

inline inherited

Convert object to nlohmann::json.

Parameters

  with_id | Whether to include the ID or not

Note
  Some fields are conditionally filled, do not rely on all fields being present

Returns
  json Json built from the structure

## ◆ to_json_impl()

json dpp::emoji::to_json_impl | ( | bool | with_id = false | ) | const

protected

Build the json for this object.

Parameters

  with_id | include the id in the JSON

Returns
  std::string json data

## Friends And Related Symbol Documentation

## ◆ json_interface< emoji >

friend struct json_interface< emoji >

friend

## Member Data Documentation

## ◆ flags

uint8_t dpp::emoji::flags {0}

Flags for the emoji from dpp::emoji_flags.

## ◆ id

snowflake dpp::managed::id = {}

inherited

Unique ID of object set by Discord. This value contains a timestamp, worker ID, internal server ID, and an incrementing value. Only the timestamp is relevant to us as useful metadata.

## ◆ image_data

utility::image_data dpp::emoji::image_data

Image data for the emoji, if uploading.

## ◆ name

std::string dpp::emoji::name {}

Emoji name.

## ◆ roles

std::vector<snowflake> dpp::emoji::roles

Roles allowed to use this emoji.

## ◆ user_id

snowflake dpp::emoji::user_id

The id of the user that created this emoji.

D++ Library version 9.0.13 D++ Library version 9.0.12 D++ Library version 9.0.11 D++ Library version 9.0.10 D++ Library version 9.0.9 D++ Library version 9.0.8 D++ Library version 9.0.7 D++ Library version 9.0.6 D++ Library version 9.0.5 D++ Library version 9.0.4 D++ Library version 9.0.3 D++ Library version 9.0.2 D++ Library version 9.0.1 D++ Library version 9.0.0 D++ Library version 1.0.2 D++ Library version 1.0.1 D++ Library version 1.0.0