⛓️Extensions

Useful functions to use for the library or your own purposes :)

chevron-rightFormathashtag

Easily format text using markdown features.

Format.Bold( string text )

Format.Italic( string text )

Format.BoldItalic( string text )

Format.Strikethrough( string text )

Format.Quote( string text )

Format.Spoiler( string text )

Format.Link( string title, string url )

Format.Code( string text )

Format.CodeBlock( string code, string language )

Format.Heading( string text, HeadingFormat format )

public enum HeadingFormat
{
    H1 = 1,
    H2 = 2,
    H3 = 3,
    H4 = 4,
    H5 = 5,
    H6 = 6
}
chevron-rightQueryBuilderhashtag

Quickly add query parameters to a url with optional condition check.

QueryBuilder Query = new QueryBuilder()
    .Add("user", "bob") // Add ?user=bob to the url
    .AddIf(user == "bob", "limit", 1) // Add ?limit=1 to the url if user is bob
    
string Url = "https://test.com" + Query.ToString(); // Add the query to the url
chevron-rightUlidhashtag

The id system that Revolt uses to give objects a unique date based id.

You can parse string ids to a Ulid to chekc for valid ids or get the created date.

Ulid Ulid.Parse( string id )

bool Ulid.TryParse( string id, out Ulid ulid)

Ulid

DateTime Time

chevron-rightOptionhashtag

Used to specify optional parameters that may be empty, useful for modify requests.

null - No option is given and will be excluded. new Option("" or null) - Option specified but is empty. new Option("Bob") - Option specified with text.

chevron-rightDownloadablehashtag

An id and object that can be fetched from cache or downloaded from rest.

The example below will attempt to fetch the user from the WebSocket cache or will download the user from rest.

Downloadable<string, User> DownloadUser = new Downloadable<string, User>(
     UserId,
     async () =>
     {
          if (UserCache.TryGetValue(UserId, out User User))
               return User;
          
          return await Client.Rest.GetUserAsync(UserId);
     }
);
chevron-rightConditionshashtag

Various condition checks for parameters, length, null and client checks used in requests to detect early issues.

public static void ChannelIdLength(string id, string request)
{
    if (string.IsNullOrEmpty(id) || id.Length < 1)
        throw new RevoltArgumentException($"Channel id can't be 
        empty for the {request} request.");

    if (id.Length > Const.All_MaxIdLength)
        throw new RevoltArgumentException($"Channel id length can't be more 
        than {Const.All_MaxIdLength} characters for the {request} request.");
}
chevron-rightConsthashtag

Various static limits and values for Revolt.

Last updated