Nostrum v0.4.1 Nostrum.Util View Source
Utility functions
Link to this section Summary
Functions
Returns the gateway url and shard count for current websocket connections.
Attempts to convert a string to an atom.
Helper for defining all the methods used for struct and encoding transformations.
Returns the number of milliseconds since unix epoch.
Returns the current date as an ISO formatted string.
Returns the number of shards.
Converts a map into an atom-keyed map.
Since we're being sacrilegious and converting strings to atoms from the WS, there will be some
atoms that we see that aren't defined in any Discord structs. This method mainly serves as a
means to define those atoms once so the user isn't warned about them in the
Nostrum.Util.maybe_to_atom/1
function when they are in fact harmless.
Link to this section Functions
enum_to_struct(enum, struct) View Source
gateway() View Source
Returns the gateway url and shard count for current websocket connections.
If by chance no gateway connection has been made, will fetch the url to use and store it for future use.
maybe_to_atom(token) View Source
Attempts to convert a string to an atom.
If atom does not currently exist, will warn that we're doing an unsafe conversion.
nostrum_struct(body) View Source (macro)
Helper for defining all the methods used for struct and encoding transformations.
Example
Nostrum.Util.nostrum_struct(%{
author: User,
mentions: [User],
mention_roles: [User],
embeds: [Embed]
})
now()
View Source
now() :: integer()
now() :: integer()
Returns the number of milliseconds since unix epoch.
now_iso()
View Source
now_iso() :: String.t()
now_iso() :: String.t()
Returns the current date as an ISO formatted string.
num_shards()
View Source
num_shards() :: integer()
num_shards() :: integer()
Returns the number of shards.
This is not the number of currently active shards, but the number of shards specified in your config.
safe_atom_map(term) View Source
Converts a map into an atom-keyed map.
Given a map with variable type keys, returns the same map with all keys as atoms
.
This function will attempt to convert keys to an existing atom, and if that fails will default to creating a new atom while displaying a warning. The idea here is that we should be able to see if any results from Discord are giving variable keys. Since we will define all types of objects returned by Discord, the amount of new atoms created SHOULD be 0. 👀
unused_atoms() View Source
Since we're being sacrilegious and converting strings to atoms from the WS, there will be some
atoms that we see that aren't defined in any Discord structs. This method mainly serves as a
means to define those atoms once so the user isn't warned about them in the
Nostrum.Util.maybe_to_atom/1
function when they are in fact harmless.