@@ -0,0 +1,27 @@ | |||||
using System; | |||||
using System.Collections.Generic; | |||||
using System.Threading.Tasks; | |||||
namespace Discord.Commands | |||||
{ | |||||
public static class CommandServiceExtensions | |||||
{ | |||||
public static async Task<IReadOnlyCollection<CommandInfo>> GetExecutableCommandsAsync(this IEnumerable<CommandInfo> commands, ICommandContext context, IServiceProvider provider) | |||||
{ | |||||
var executableCommands = new List<CommandInfo>(); | |||||
foreach (var command in commands) | |||||
{ | |||||
var result = await command.CheckPreconditionsAsync(context, provider).ConfigureAwait(false); | |||||
if (result.IsSuccess) | |||||
executableCommands.Add(command); | |||||
} | |||||
return executableCommands; | |||||
} | |||||
public static Task<IReadOnlyCollection<CommandInfo>> GetExecutableCommandsAsync(this CommandService commandService, ICommandContext context, IServiceProvider provider) | |||||
=> GetExecutableCommandsAsync(commandService.Commands, context, provider); | |||||
public static Task<IReadOnlyCollection<CommandInfo>> GetExecutableCommandAsync(this ModuleInfo module, ICommandContext context, IServiceProvider provider) | |||||
=> GetExecutableCommandsAsync(module.Commands, context, provider); | |||||
} | |||||
} |
@@ -1,4 +1,6 @@ | |||||
using System; | using System; | ||||
using System.Collections.Generic; | |||||
using System.Linq; | |||||
namespace Discord | namespace Discord | ||||
{ | { | ||||
@@ -54,5 +56,15 @@ namespace Discord | |||||
return builder; | return builder; | ||||
} | } | ||||
public static EmbedBuilder WithFields(this EmbedBuilder builder, IEnumerable<EmbedFieldBuilder> fields) | |||||
{ | |||||
foreach (var field in fields) | |||||
builder.AddField(field); | |||||
return builder; | |||||
} | |||||
public static EmbedBuilder WithFields(this EmbedBuilder builder, params EmbedFieldBuilder[] fields) | |||||
=> WithFields(builder, fields.AsEnumerable()); | |||||
} | } | ||||
} | } |
@@ -1,5 +1,7 @@ | |||||
using Discord.Rest; | |||||
using Discord.Rest; | |||||
using System; | using System; | ||||
using System.Collections.Generic; | |||||
using System.Linq; | |||||
using System.Threading.Tasks; | using System.Threading.Tasks; | ||||
using Model = Discord.API.User; | using Model = Discord.API.User; | ||||
@@ -20,6 +22,8 @@ namespace Discord.WebSocket | |||||
public string Mention => MentionUtils.MentionUser(Id); | public string Mention => MentionUtils.MentionUser(Id); | ||||
public IActivity Activity => Presence.Activity; | public IActivity Activity => Presence.Activity; | ||||
public UserStatus Status => Presence.Status; | public UserStatus Status => Presence.Status; | ||||
public IEnumerable<SocketGuild> MutualGuilds | |||||
=> Discord.Guilds.Where(g => g.Users.Any(u => u.Id == Id)); | |||||
internal SocketUser(DiscordSocketClient discord, ulong id) | internal SocketUser(DiscordSocketClient discord, ulong id) | ||||
: base(discord, id) | : base(discord, id) | ||||