⛓️Extensions

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

Format

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
}
QueryBuilder

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
Ulid

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

Option

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.

Downloadable

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);
     }
);
Conditions

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.");
}
Const

Various static limits and values for Revolt.

public static class Const
{
    public const int All_MaxIdLength = 128;
    public const int All_MaxNameLength = 32;
    public const int All_MaxUrlLength = 256;
    public const int Color_MaxLength = 128;

    // Most descriptions and reasons will use this.
    public const int All_MaxDescriptionLength = 1024;

    public const int User_MinNameLength = 2;
    public const int User_MaxStatusTextLength = 128;
    public const int User_ProfileBioLength = 2000;

    public const int Group_MaxUserIdsListCount = 49;

    public const int Message_MaxSearchListCount = 100;
    public const int Message_MaxDeleteListCount = 100;
    public const int Message_MaxEmbedsListCount = 10;
    public const int Message_MaxContentLength = 2000;
    public const int Message_EmbedTitleMaxLength = 100;

    public const int Message_ReactionsMaxCount = 20;
}

Last updated