Class Utilities
Various Discord-related utilities.
Inheritance
Namespace: DisCatSharp
Assembly: DisCatSharp.dll
Syntax
public static class Utilities
Methods
| Improve this Doc View SourceContains(String, Char[])
Checks whether this string contains given characters.
Declaration
public static bool Contains(this string str, params char[] characters)
Parameters
Type | Name | Description |
---|---|---|
System.String | str | String to check. |
System.Char[] | characters | Characters to check for. |
Returns
Type | Description |
---|---|
System.Boolean | Whether the string contained these characters. |
GetDateTimeOffset(Int64, Boolean)
Helper method to create a System.DateTimeOffset from Unix time seconds for targets that do not support this natively.
Declaration
public static DateTimeOffset GetDateTimeOffset(long unixTime, bool shouldThrow = true)
Parameters
Type | Name | Description |
---|---|---|
System.Int64 | unixTime | Unix time seconds to convert. |
System.Boolean | shouldThrow | Whether the method should throw on failure. Defaults to true. |
Returns
Type | Description |
---|---|
System.DateTimeOffset | Calculated System.DateTimeOffset. |
GetDateTimeOffsetFromMilliseconds(Int64, Boolean)
Helper method to create a System.DateTimeOffset from Unix time milliseconds for targets that do not support this natively.
Declaration
public static DateTimeOffset GetDateTimeOffsetFromMilliseconds(long unixTime, bool shouldThrow = true)
Parameters
Type | Name | Description |
---|---|---|
System.Int64 | unixTime | Unix time milliseconds to convert. |
System.Boolean | shouldThrow | Whether the method should throw on failure. Defaults to true. |
Returns
Type | Description |
---|---|
System.DateTimeOffset | Calculated System.DateTimeOffset. |
GetShardId(UInt64, Int32)
Gets a shard id from a guild id and total shard count.
Declaration
public static int GetShardId(ulong guildId, int shardCount)
Parameters
Type | Name | Description |
---|---|---|
System.UInt64 | guildId | The guild id the shard is on. |
System.Int32 | shardCount | The total amount of shards. |
Returns
Type | Description |
---|---|
System.Int32 | The shard id. |
GetSnowflakeTime(UInt64)
Computes a timestamp from a given snowflake.
Declaration
public static DateTimeOffset GetSnowflakeTime(this ulong snowflake)
Parameters
Type | Name | Description |
---|---|---|
System.UInt64 | snowflake | Snowflake to compute a timestamp from. |
Returns
Type | Description |
---|---|
System.DateTimeOffset | Computed timestamp. |
GetUnixTime(DateTimeOffset)
Helper method to calculate Unix time seconds from a System.DateTimeOffset for targets that do not support this natively.
Declaration
public static long GetUnixTime(DateTimeOffset dto)
Parameters
Type | Name | Description |
---|---|---|
System.DateTimeOffset | dto | System.DateTimeOffset to calculate Unix time for. |
Returns
Type | Description |
---|---|
System.Int64 | Calculated Unix time. |
ToPermissionString(Permissions)
Converts this Permissions into human-readable format.
Declaration
public static string ToPermissionString(this Permissions perm)
Parameters
Type | Name | Description |
---|---|---|
Permissions | perm | Permissions enumeration to convert. |
Returns
Type | Description |
---|---|
System.String | Human-readable permissions. |