Browse Source

Add XMLDocs

pull/988/head
Hsu Still 7 years ago
parent
commit
1d2db3a61c
No known key found for this signature in database GPG Key ID: 8601A145FDA95209
8 changed files with 80 additions and 14 deletions
  1. +7
    -4
      src/Discord.Net.Commands/Attributes/Preconditions/RequireContextAttribute.cs
  2. +1
    -0
      src/Discord.Net.Commands/Results/IResult.cs
  3. +4
    -0
      src/Discord.Net.Core/Entities/Activities/Game.cs
  4. +55
    -0
      src/Discord.Net.Core/Entities/Messages/EmbedBuilder.cs
  5. +1
    -1
      src/Discord.Net.Core/Entities/Messages/IAttachment.cs
  6. +7
    -7
      src/Discord.Net.Rest/Entities/Messages/Attachment.cs
  7. +5
    -1
      src/Discord.Net.WebSocket/Commands/ShardedCommandContext.cs
  8. +0
    -1
      src/Discord.Net.WebSocket/Commands/SocketCommandContext.cs

+ 7
- 4
src/Discord.Net.Commands/Attributes/Preconditions/RequireContextAttribute.cs View File

@@ -4,25 +4,28 @@ using Microsoft.Extensions.DependencyInjection;


namespace Discord.Commands namespace Discord.Commands
{ {
/// <summary> Defines the type of command context. </summary>
[Flags] [Flags]
public enum ContextType public enum ContextType
{ {
/// <summary> Specifies the command to be executed within a guild. </summary>
Guild = 0x01, Guild = 0x01,
/// <summary> Specifies the command to be executed within a DM. </summary>
DM = 0x02, DM = 0x02,
/// <summary> Specifies the command to be executed within a group. </summary>
Group = 0x04 Group = 0x04
} }


/// <summary> /// <summary>
/// Requires the command to be invoked in a specified context. (e.g. in guild, DM)
/// Requires the command to be invoked in a specified context (e.g. in guild, DM).
/// </summary> /// </summary>
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, AllowMultiple = true, Inherited = true)] [AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, AllowMultiple = true, Inherited = true)]
public class RequireContextAttribute : PreconditionAttribute public class RequireContextAttribute : PreconditionAttribute
{ {
/// <summary> Gets the context required to execute the command. </summary>
public ContextType Contexts { get; } public ContextType Contexts { get; }


/// <summary>
/// Requires that the command be invoked in the specified context.
/// </summary>
/// <summary> Requires that the command be invoked in the specified context. </summary>
/// <param name="contexts">The type of context the command can be invoked in. Multiple contexts can be specified by ORing the contexts together.</param> /// <param name="contexts">The type of context the command can be invoked in. Multiple contexts can be specified by ORing the contexts together.</param>
/// <example> /// <example>
/// <code language="c#"> /// <code language="c#">


+ 1
- 0
src/Discord.Net.Commands/Results/IResult.cs View File

@@ -1,5 +1,6 @@
namespace Discord.Commands namespace Discord.Commands
{ {
/// <summary> Represents the information of command execution result. </summary>
public interface IResult public interface IResult
{ {
/// <summary> Describes the error type that may have occurred during the operation. </summary> /// <summary> Describes the error type that may have occurred during the operation. </summary>


+ 4
- 0
src/Discord.Net.Core/Entities/Activities/Game.cs View File

@@ -12,12 +12,16 @@ namespace Discord
public ActivityType Type { get; internal set; } public ActivityType Type { get; internal set; }


internal Game() { } internal Game() { }
/// <summary> Creates a <see cref="Game"/> with the provided name and <see cref="ActivityType"/>. </summary>
/// <param name="name">The name of the game.</param>
/// <param name="type">The type of activity. Default is <see cref="ActivityType.Playing"/>. </param>
public Game(string name, ActivityType type = ActivityType.Playing) public Game(string name, ActivityType type = ActivityType.Playing)
{ {
Name = name; Name = name;
Type = type; Type = type;
} }
/// <summary> Returns the name of the <see cref="Game"/>. </summary>
public override string ToString() => Name; public override string ToString() => Name;
private string DebuggerDisplay => Name; private string DebuggerDisplay => Name;
} }


+ 55
- 0
src/Discord.Net.Core/Entities/Messages/EmbedBuilder.cs View File

@@ -9,17 +9,23 @@ namespace Discord
{ {
private readonly Embed _embed; private readonly Embed _embed;


/// <summary> The maximum number of fields allowed by Discord. </summary>
public const int MaxFieldCount = 25; public const int MaxFieldCount = 25;
/// <summary> The maximum length of title allowed by Discord. </summary>
public const int MaxTitleLength = 256; public const int MaxTitleLength = 256;
/// <summary> The maximum length of description allowed by Discord. </summary>
public const int MaxDescriptionLength = 2048; public const int MaxDescriptionLength = 2048;
/// <summary> The maximum length of total characters allowed by Discord. </summary>
public const int MaxEmbedLength = 6000; // user bot limit is 2000, but we don't validate that here. public const int MaxEmbedLength = 6000; // user bot limit is 2000, but we don't validate that here.


/// <summary> Creates a new <see cref="EmbedBuilder"/>. </summary>
public EmbedBuilder() public EmbedBuilder()
{ {
_embed = new Embed(EmbedType.Rich); _embed = new Embed(EmbedType.Rich);
Fields = new List<EmbedFieldBuilder>(); Fields = new List<EmbedFieldBuilder>();
} }


/// <summary> Gets or sets the title of an <see cref="Embed"/>. </summary>
public string Title public string Title
{ {
get => _embed.Title; get => _embed.Title;
@@ -30,6 +36,7 @@ namespace Discord
} }
} }


/// <summary> Gets or sets the description of an <see cref="Embed"/>. </summary>
public string Description public string Description
{ {
get => _embed.Description; get => _embed.Description;
@@ -40,6 +47,7 @@ namespace Discord
} }
} }


/// <summary> Gets or sets the URL of an <see cref="Embed"/>. </summary>
public string Url public string Url
{ {
get => _embed.Url; get => _embed.Url;
@@ -49,6 +57,7 @@ namespace Discord
_embed.Url = value; _embed.Url = value;
} }
} }
/// <summary> Gets or sets the thumbnail URL of an <see cref="Embed"/>. </summary>
public string ThumbnailUrl public string ThumbnailUrl
{ {
get => _embed.Thumbnail?.Url; get => _embed.Thumbnail?.Url;
@@ -58,6 +67,7 @@ namespace Discord
_embed.Thumbnail = new EmbedThumbnail(value, null, null, null); _embed.Thumbnail = new EmbedThumbnail(value, null, null, null);
} }
} }
/// <summary> Gets or sets the image URL of an <see cref="Embed"/>. </summary>
public string ImageUrl public string ImageUrl
{ {
get => _embed.Image?.Url; get => _embed.Image?.Url;
@@ -67,12 +77,17 @@ namespace Discord
_embed.Image = new EmbedImage(value, null, null, null); _embed.Image = new EmbedImage(value, null, null, null);
} }
} }
/// <summary> Gets or sets the timestamp of an <see cref="Embed"/>. </summary>
public DateTimeOffset? Timestamp { get => _embed.Timestamp; set { _embed.Timestamp = value; } } public DateTimeOffset? Timestamp { get => _embed.Timestamp; set { _embed.Timestamp = value; } }
/// <summary> Gets or sets the sidebar color of an <see cref="Embed"/>. </summary>
public Color? Color { get => _embed.Color; set { _embed.Color = value; } } public Color? Color { get => _embed.Color; set { _embed.Color = value; } }


/// <summary> Gets or sets the <see cref="EmbedAuthorBuilder"/> of an <see cref="Embed"/>. </summary>
public EmbedAuthorBuilder Author { get; set; } public EmbedAuthorBuilder Author { get; set; }
/// <summary> Gets or sets the <see cref="EmbedFooterBuilder"/> of an <see cref="Embed"/>. </summary>
public EmbedFooterBuilder Footer { get; set; } public EmbedFooterBuilder Footer { get; set; }
private List<EmbedFieldBuilder> _fields; private List<EmbedFieldBuilder> _fields;
/// <summary> Gets or sets the list of <see cref="EmbedFieldBuilder"/> of an <see cref="Embed"/>. </summary>
public List<EmbedFieldBuilder> Fields public List<EmbedFieldBuilder> Fields
{ {
get => _fields; get => _fields;
@@ -85,52 +100,71 @@ namespace Discord
} }
} }


/// <summary> Sets the title of an <see cref="Embed"/>. </summary>
/// <param name="title"> The title to be set. </param>
public EmbedBuilder WithTitle(string title) public EmbedBuilder WithTitle(string title)
{ {
Title = title; Title = title;
return this; return this;
} }
/// <summary> Sets the description of an <see cref="Embed"/>. </summary>
/// <param name="description"> The description to be set. </param>
public EmbedBuilder WithDescription(string description) public EmbedBuilder WithDescription(string description)
{ {
Description = description; Description = description;
return this; return this;
} }
/// <summary> Sets the URL of an <see cref="Embed"/>. </summary>
/// <param name="url"> The URL to be set. </param>
public EmbedBuilder WithUrl(string url) public EmbedBuilder WithUrl(string url)
{ {
Url = url; Url = url;
return this; return this;
} }
/// <summary> Sets the thumbnail URL of an <see cref="Embed"/>. </summary>
/// <param name="thumbnailUrl"> The thumbnail URL to be set. </param>
public EmbedBuilder WithThumbnailUrl(string thumbnailUrl) public EmbedBuilder WithThumbnailUrl(string thumbnailUrl)
{ {
ThumbnailUrl = thumbnailUrl; ThumbnailUrl = thumbnailUrl;
return this; return this;
} }
/// <summary> Sets the image URL of an <see cref="Embed"/>. </summary>
/// <param name="imageUrl"> The image URL to be set. </param>
public EmbedBuilder WithImageUrl(string imageUrl) public EmbedBuilder WithImageUrl(string imageUrl)
{ {
ImageUrl = imageUrl; ImageUrl = imageUrl;
return this; return this;
} }
/// <summary> Sets the timestamp of an <see cref="Embed"/> to the current time. </summary>
public EmbedBuilder WithCurrentTimestamp() public EmbedBuilder WithCurrentTimestamp()
{ {
Timestamp = DateTimeOffset.UtcNow; Timestamp = DateTimeOffset.UtcNow;
return this; return this;
} }
/// <summary> Sets the timestamp of an <see cref="Embed"/>. </summary>
/// <param name="dateTimeOffset"> The timestamp to be set. </param>
public EmbedBuilder WithTimestamp(DateTimeOffset dateTimeOffset) public EmbedBuilder WithTimestamp(DateTimeOffset dateTimeOffset)
{ {
Timestamp = dateTimeOffset; Timestamp = dateTimeOffset;
return this; return this;
} }
/// <summary> Sets the sidebar color of an <see cref="Embed"/>. </summary>
/// <param name="color"> The color to be set. </param>
public EmbedBuilder WithColor(Color color) public EmbedBuilder WithColor(Color color)
{ {
Color = color; Color = color;
return this; return this;
} }


/// <summary> Sets the <see cref="EmbedAuthorBuilder"/> of an <see cref="Embed"/>. </summary>
/// <param name="author"> The author builder class containing the author field properties. </param>
public EmbedBuilder WithAuthor(EmbedAuthorBuilder author) public EmbedBuilder WithAuthor(EmbedAuthorBuilder author)
{ {
Author = author; Author = author;
return this; return this;
} }
/// <summary> Sets the author field of an <see cref="Embed"/> with the provided properties. </summary>
/// <param name="action"> The delegate containing the author field properties. </param>
public EmbedBuilder WithAuthor(Action<EmbedAuthorBuilder> action) public EmbedBuilder WithAuthor(Action<EmbedAuthorBuilder> action)
{ {
var author = new EmbedAuthorBuilder(); var author = new EmbedAuthorBuilder();
@@ -138,6 +172,10 @@ namespace Discord
Author = author; Author = author;
return this; return this;
} }
/// <summary> Sets the author field of an <see cref="Embed"/> with the provided name, icon URL, and URL. </summary>
/// <param name="name"> The title of the author field. </param>
/// <param name="iconUrl"> The icon URL of the author field. </param>
/// <param name="url"> The URL of the author field. </param>
public EmbedBuilder WithAuthor(string name, string iconUrl = null, string url = null) public EmbedBuilder WithAuthor(string name, string iconUrl = null, string url = null)
{ {
var author = new EmbedAuthorBuilder var author = new EmbedAuthorBuilder
@@ -149,11 +187,15 @@ namespace Discord
Author = author; Author = author;
return this; return this;
} }
/// <summary> Sets the <see cref="EmbedFooterBuilder"/> of an <see cref="Embed"/>. </summary>
/// <param name="footer"> The footer builder class containing the footer field properties. </param>
public EmbedBuilder WithFooter(EmbedFooterBuilder footer) public EmbedBuilder WithFooter(EmbedFooterBuilder footer)
{ {
Footer = footer; Footer = footer;
return this; return this;
} }
/// <summary> Sets the footer field of an <see cref="Embed"/> with the provided properties. </summary>
/// <param name="action"> The delegate containing the footer field properties. </param>
public EmbedBuilder WithFooter(Action<EmbedFooterBuilder> action) public EmbedBuilder WithFooter(Action<EmbedFooterBuilder> action)
{ {
var footer = new EmbedFooterBuilder(); var footer = new EmbedFooterBuilder();
@@ -161,6 +203,9 @@ namespace Discord
Footer = footer; Footer = footer;
return this; return this;
} }
/// <summary> Sets the footer field of an <see cref="Embed"/> with the provided name, icon URL. </summary>
/// <param name="text"> The title of the footer field. </param>
/// <param name="iconUrl"> The icon URL of the footer field. </param>
public EmbedBuilder WithFooter(string text, string iconUrl = null) public EmbedBuilder WithFooter(string text, string iconUrl = null)
{ {
var footer = new EmbedFooterBuilder var footer = new EmbedFooterBuilder
@@ -172,6 +217,10 @@ namespace Discord
return this; return this;
} }


/// <summary> Adds an <see cref="Embed"/> field with the provided name and value. </summary>
/// <param name="name"> The title of the field. </param>
/// <param name="value"> The value of the field. </param>
/// <param name="inline"> Indicates whether the field is in-line or not. </param>
public EmbedBuilder AddField(string name, object value, bool inline = false) public EmbedBuilder AddField(string name, object value, bool inline = false)
{ {
var field = new EmbedFieldBuilder() var field = new EmbedFieldBuilder()
@@ -182,6 +231,8 @@ namespace Discord
return this; return this;
} }


/// <summary> Adds a field with the provided <see cref="EmbedFieldBuilder"/> to an <see cref="Embed"/>. </summary>
/// <param name="field"> The field builder class containing the field properties. </param>
public EmbedBuilder AddField(EmbedFieldBuilder field) public EmbedBuilder AddField(EmbedFieldBuilder field)
{ {
if (Fields.Count >= MaxFieldCount) if (Fields.Count >= MaxFieldCount)
@@ -192,6 +243,8 @@ namespace Discord
Fields.Add(field); Fields.Add(field);
return this; return this;
} }
/// <summary> Adds an <see cref="Embed"/> field with the provided properties. </summary>
/// <param name="action"> The delegate containing the field properties. </param>
public EmbedBuilder AddField(Action<EmbedFieldBuilder> action) public EmbedBuilder AddField(Action<EmbedFieldBuilder> action)
{ {
var field = new EmbedFieldBuilder(); var field = new EmbedFieldBuilder();
@@ -200,6 +253,8 @@ namespace Discord
return this; return this;
} }


/// <summary> Builds the <see cref="Embed"/> into a Rich Embed format. </summary>
/// <returns> The built embed object. </returns>
public Embed Build() public Embed Build()
{ {
_embed.Footer = Footer?.Build(); _embed.Footer = Footer?.Build();


+ 1
- 1
src/Discord.Net.Core/Entities/Messages/IAttachment.cs View File

@@ -1,6 +1,6 @@
namespace Discord namespace Discord
{ {
/// <summary> Represents a Discord attachment object. </summary>
/// <summary> Represents a Discord attachment. </summary>
public interface IAttachment public interface IAttachment
{ {
/// <summary> Gets the snowflake ID of the attachment. </summary> /// <summary> Gets the snowflake ID of the attachment. </summary>


+ 7
- 7
src/Discord.Net.Rest/Entities/Messages/Attachment.cs View File

@@ -7,19 +7,19 @@ namespace Discord
[DebuggerDisplay(@"{DebuggerDisplay,nq}")] [DebuggerDisplay(@"{DebuggerDisplay,nq}")]
public class Attachment : IAttachment public class Attachment : IAttachment
{ {
/// <inheritdoc/>
/// <inheritdoc />
public ulong Id { get; } public ulong Id { get; }
/// <inheritdoc/>
/// <inheritdoc />
public string Filename { get; } public string Filename { get; }
/// <inheritdoc/>
/// <inheritdoc />
public string Url { get; } public string Url { get; }
/// <inheritdoc/>
/// <inheritdoc />
public string ProxyUrl { get; } public string ProxyUrl { get; }
/// <inheritdoc/>
/// <inheritdoc />
public int Size { get; } public int Size { get; }
/// <inheritdoc/>
/// <inheritdoc />
public int? Height { get; } public int? Height { get; }
/// <inheritdoc/>
/// <inheritdoc />
public int? Width { get; } public int? Width { get; }


internal Attachment(ulong id, string filename, string url, string proxyUrl, int size, int? height, int? width) internal Attachment(ulong id, string filename, string url, string proxyUrl, int size, int? height, int? width)


+ 5
- 1
src/Discord.Net.WebSocket/Commands/ShardedCommandContext.cs View File

@@ -1,9 +1,11 @@
using Discord.WebSocket;
using Discord.WebSocket;


namespace Discord.Commands namespace Discord.Commands
{ {
/// <summary> The sharded variant of <see cref="ICommandContext"/>, which may contain the client, user, guild, channel, and message. </summary>
public class ShardedCommandContext : SocketCommandContext, ICommandContext public class ShardedCommandContext : SocketCommandContext, ICommandContext
{ {
/// <summary> Gets the <see cref="DiscordShardedClient"/> that the command is executed with. </summary>
public new DiscordShardedClient Client { get; } public new DiscordShardedClient Client { get; }


public ShardedCommandContext(DiscordShardedClient client, SocketUserMessage msg) public ShardedCommandContext(DiscordShardedClient client, SocketUserMessage msg)
@@ -12,10 +14,12 @@ namespace Discord.Commands
Client = client; Client = client;
} }


/// <summary> Gets the shard ID of the command context. </summary>
private static int GetShardId(DiscordShardedClient client, IGuild guild) private static int GetShardId(DiscordShardedClient client, IGuild guild)
=> guild == null ? 0 : client.GetShardIdFor(guild); => guild == null ? 0 : client.GetShardIdFor(guild);


//ICommandContext //ICommandContext
/// <inheritdoc />
IDiscordClient ICommandContext.Client => Client; IDiscordClient ICommandContext.Client => Client;
} }
} }

+ 0
- 1
src/Discord.Net.WebSocket/Commands/SocketCommandContext.cs View File

@@ -3,7 +3,6 @@ using Discord.WebSocket;
namespace Discord.Commands namespace Discord.Commands
{ {
/// <summary> The WebSocket variant of <see cref="ICommandContext"/>, which may contain the client, user, guild, channel, and message. </summary> /// <summary> The WebSocket variant of <see cref="ICommandContext"/>, which may contain the client, user, guild, channel, and message. </summary>
/// <seealso cref="ICommandContext"/>
public class SocketCommandContext : ICommandContext public class SocketCommandContext : ICommandContext
{ {
/// <summary> Gets the <see cref="DiscordSocketClient"/> that the command is executed with. </summary> /// <summary> Gets the <see cref="DiscordSocketClient"/> that the command is executed with. </summary>


Loading…
Cancel
Save