Still Hsu 6 years ago
parent
commit
f17916b901
No known key found for this signature in database GPG Key ID: 8601A145FDA95209
3 changed files with 40 additions and 0 deletions
  1. +30
    -0
      src/Discord.Net.Commands/Extensions/CommandServiceExtensions.cs
  2. +7
    -0
      src/Discord.Net.Core/Extensions/EmbedBuilderExtensions.cs
  3. +3
    -0
      src/Discord.Net.WebSocket/Entities/Users/SocketUser.cs

+ 30
- 0
src/Discord.Net.Commands/Extensions/CommandServiceExtensions.cs View File

@@ -5,8 +5,20 @@ using System.Threading.Tasks;

namespace Discord.Commands
{
/// <summary>
/// Provides extension methods for the <see cref="CommandService"/> class.
/// </summary>
public static class CommandServiceExtensions
{
/// <summary>
/// Returns commands that can be executed under the current context.
/// </summary>
/// <param name="commands">The set of commands to be checked against.</param>
/// <param name="context">The current command context.</param>
/// <param name="provider">The service provider used for dependency injection upon precondition check.</param>
/// <returns>
/// A read-only collection of commands that can be executed under the current context.
/// </returns>
public static async Task<IReadOnlyCollection<CommandInfo>> GetExecutableCommandsAsync(this ICollection<CommandInfo> commands, ICommandContext context, IServiceProvider provider)
{
var executableCommands = new List<CommandInfo>();
@@ -27,8 +39,26 @@ namespace Discord.Commands

return executableCommands;
}
/// <summary>
/// Returns commands that can be executed under the current context.
/// </summary>
/// <param name="commandService">The desired command service class to check against.</param>
/// <param name="context">The current command context.</param>
/// <param name="provider">The service provider used for dependency injection upon precondition check.</param>
/// <returns>
/// A read-only collection of commands that can be executed under the current context.
/// </returns>
public static Task<IReadOnlyCollection<CommandInfo>> GetExecutableCommandsAsync(this CommandService commandService, ICommandContext context, IServiceProvider provider)
=> GetExecutableCommandsAsync(commandService.Commands.ToArray(), context, provider);
/// <summary>
/// Returns commands that can be executed under the current context.
/// </summary>
/// <param name="module">The module to be checked against.</param>
/// <param name="context">The current command context.</param>
/// <param name="provider">The service provider used for dependency injection upon precondition check.</param>
/// <returns>
/// A read-only collection of commands that can be executed under the current context.
/// </returns>
public static async Task<IReadOnlyCollection<CommandInfo>> GetExecutableCommandsAsync(this ModuleInfo module, ICommandContext context, IServiceProvider provider)
{
var executableCommands = new List<CommandInfo>();


+ 7
- 0
src/Discord.Net.Core/Extensions/EmbedBuilderExtensions.cs View File

@@ -68,6 +68,10 @@ namespace Discord
return builder;
}

/// <summary>
/// Adds the specified fields into this <see cref="EmbedBuilder"/>.
/// </summary>
/// <exception cref="ArgumentException">Field count exceeds <see cref="EmbedBuilder.MaxFieldCount"/>.</exception>
public static EmbedBuilder WithFields(this EmbedBuilder builder, IEnumerable<EmbedFieldBuilder> fields)
{
foreach (var field in fields)
@@ -75,6 +79,9 @@ namespace Discord

return builder;
}
/// <summary>
/// Adds the specified fields into this <see cref="EmbedBuilder"/>.
/// </summary>
public static EmbedBuilder WithFields(this EmbedBuilder builder, params EmbedFieldBuilder[] fields)
=> WithFields(builder, fields.AsEnumerable());
}


+ 3
- 0
src/Discord.Net.WebSocket/Entities/Users/SocketUser.cs View File

@@ -38,6 +38,9 @@ namespace Discord.WebSocket
public IActivity Activity => Presence.Activity;
/// <inheritdoc />
public UserStatus Status => Presence.Status;
/// <summary>
/// Gets mutual guilds shared with this user.
/// </summary>
public IReadOnlyCollection<SocketGuild> MutualGuilds
=> Discord.Guilds.Where(g => g.Users.Any(u => u.Id == Id)).ToImmutableArray();



Loading…
Cancel
Save