public class MiscUtil
extends java.lang.Object
Modifier and Type | Field | Description |
---|---|---|
static long |
DISCORD_EPOCH |
|
static long |
TIMESTAMP_OFFSET |
Constructor | Description |
---|---|
MiscUtil() |
Modifier and Type | Method | Description |
---|---|---|
static void |
appendTo(java.util.Formatter formatter,
int width,
int precision,
boolean leftJustified,
java.lang.String out) |
Can be used to append a String to a formatter.
|
static okhttp3.RequestBody |
createRequestBody(okhttp3.MediaType contentType,
java.io.InputStream stream) |
Creates a new request body that transmits the provided
InputStream . |
static java.lang.String |
encodeUTF8(java.lang.String chars) |
URL-Encodes the given String to UTF-8 after
form-data specifications (space -> +)
|
static java.time.OffsetDateTime |
getCreationTime(long entityId) |
Gets the creation-time of a JDA-entity by doing the reverse snowflake algorithm on its id.
|
static java.time.OffsetDateTime |
getCreationTime(ISnowflake entity) |
Gets the creation-time of a JDA-entity by doing the reverse snowflake algorithm on its id.
|
static java.lang.String |
getDateTimeString(java.time.OffsetDateTime time) |
Returns a prettier String-representation of a OffsetDateTime object
|
static long |
getDiscordTimestamp(long millisTimestamp) |
Converts the provided epoch millisecond timestamp to a Discord Snowflake.
|
static int |
getShardForGuild(long guildId,
int shards) |
Returns the shard id the given guild will be loaded on for the given amount of shards.
|
static int |
getShardForGuild(java.lang.String guildId,
int shards) |
Returns the shard id the given guild will be loaded on for the given amount of shards.
|
static int |
getShardForGuild(Guild guild,
int shards) |
Returns the shard id the given
Guild will be loaded on for the given amount of shards. |
static void |
locked(java.util.concurrent.locks.ReentrantLock lock,
java.lang.Runnable task) |
|
static <E> E |
locked(java.util.concurrent.locks.ReentrantLock lock,
java.util.function.Supplier<E> task) |
|
static <T> gnu.trove.map.TLongObjectMap<T> |
newLongMap() |
Generates a new thread-safe
TLongObjectMap |
static long |
parseSnowflake(java.lang.String input) |
public static final long DISCORD_EPOCH
public static final long TIMESTAMP_OFFSET
public static long getDiscordTimestamp(long millisTimestamp)
MessageHistory
creation.millisTimestamp
- The epoch millis to convertpublic static java.time.OffsetDateTime getCreationTime(long entityId)
entityId
- The id of the JDA entity where the creation-time should be determined forpublic static java.time.OffsetDateTime getCreationTime(ISnowflake entity)
entity
- The JDA entity where the creation-time should be determined forjava.lang.IllegalArgumentException
- If the provided entity is null
public static java.lang.String getDateTimeString(java.time.OffsetDateTime time)
time
- The OffsetDateTime object to formatpublic static int getShardForGuild(long guildId, int shards)
shardId == (guildId >>> 22) % totalShards
guildId
- The guild id.shards
- The amount of shards.public static int getShardForGuild(java.lang.String guildId, int shards)
shardId == (guildId >>> 22) % totalShards
guildId
- The guild id.shards
- The amount of shards.public static int getShardForGuild(Guild guild, int shards)
Guild
will be loaded on for the given amount of shards.
Discord determines which guilds a shard is connect to using the following format:
shardId == (guildId >>> 22) % totalShards
guild
- The guild.shards
- The amount of shards.public static <T> gnu.trove.map.TLongObjectMap<T> newLongMap()
TLongObjectMap
T
- The Object typeTLongObjectMap
public static java.lang.String encodeUTF8(java.lang.String chars)
chars
- The characters to encodepublic static long parseSnowflake(java.lang.String input)
public static <E> E locked(java.util.concurrent.locks.ReentrantLock lock, java.util.function.Supplier<E> task)
public static void locked(java.util.concurrent.locks.ReentrantLock lock, java.lang.Runnable task)
public static void appendTo(java.util.Formatter formatter, int width, int precision, boolean leftJustified, java.lang.String out)
formatter
- The Formatter
width
- Minimum width to meet, filled with space if neededprecision
- Maximum amount of characters to appendleftJustified
- Whether or not to left-justify the valueout
- The String to appendpublic static okhttp3.RequestBody createRequestBody(okhttp3.MediaType contentType, java.io.InputStream stream)
InputStream
.contentType
- The MediaType
of the datastream
- The InputStream
to be transmitted