Format the project with 'dotnet format' (#2551)
* Sync and Re-Format * Fix Title string. * Fix indentation.
This commit is contained in:
@@ -48,8 +48,8 @@ namespace Discord
|
|||||||
{
|
{
|
||||||
var result = new Override();
|
var result = new Override();
|
||||||
|
|
||||||
using(var textReader = new StringReader(json))
|
using (var textReader = new StringReader(json))
|
||||||
using(var reader = new JsonTextReader(textReader))
|
using (var reader = new JsonTextReader(textReader))
|
||||||
{
|
{
|
||||||
var obj = JObject.ReadFrom(reader);
|
var obj = JObject.ReadFrom(reader);
|
||||||
result.Id = obj["id"].ToObject<Guid>();
|
result.Id = obj["id"].ToObject<Guid>();
|
||||||
@@ -100,7 +100,7 @@ namespace Discord
|
|||||||
/// Gets a read-only dictionary containing the currently loaded overrides.
|
/// Gets a read-only dictionary containing the currently loaded overrides.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public IReadOnlyDictionary<Override, IReadOnlyCollection<LoadedOverride>> LoadedOverrides
|
public IReadOnlyDictionary<Override, IReadOnlyCollection<LoadedOverride>> LoadedOverrides
|
||||||
=> _loadedOverrides.Select(x => new KeyValuePair<Override, IReadOnlyCollection<LoadedOverride>> (x.Key, x.Value)).ToDictionary(x => x.Key, x => x.Value);
|
=> _loadedOverrides.Select(x => new KeyValuePair<Override, IReadOnlyCollection<LoadedOverride>>(x.Key, x.Value)).ToDictionary(x => x.Key, x => x.Value);
|
||||||
|
|
||||||
private static AssemblyLoadContext _overrideDomain;
|
private static AssemblyLoadContext _overrideDomain;
|
||||||
private static List<Func<Override, string, Task>> _logEvents = new();
|
private static List<Func<Override, string, Task>> _logEvents = new();
|
||||||
@@ -258,14 +258,14 @@ namespace Discord
|
|||||||
|
|
||||||
private static async Task<Assembly> GetDependencyAsync(Guid id, string name)
|
private static async Task<Assembly> GetDependencyAsync(Guid id, string name)
|
||||||
{
|
{
|
||||||
using(var client = new HttpClient())
|
using (var client = new HttpClient())
|
||||||
{
|
{
|
||||||
var result = await client.PostAsync($"{ApiUrl}/overrides/{id}/dependency", new StringContent($"{{ \"info\": \"{name}\"}}", Encoding.UTF8, "application/json"));
|
var result = await client.PostAsync($"{ApiUrl}/overrides/{id}/dependency", new StringContent($"{{ \"info\": \"{name}\"}}", Encoding.UTF8, "application/json"));
|
||||||
|
|
||||||
if (!result.IsSuccessStatusCode)
|
if (!result.IsSuccessStatusCode)
|
||||||
throw new Exception("Failed to get dependency");
|
throw new Exception("Failed to get dependency");
|
||||||
|
|
||||||
using(var ms = new MemoryStream())
|
using (var ms = new MemoryStream())
|
||||||
{
|
{
|
||||||
var innerStream = await result.Content.ReadAsStreamAsync();
|
var innerStream = await result.Content.ReadAsStreamAsync();
|
||||||
await innerStream.CopyToAsync(ms);
|
await innerStream.CopyToAsync(ms);
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
|
using Discord;
|
||||||
|
using Discord.WebSocket;
|
||||||
using System;
|
using System;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Discord;
|
|
||||||
using Discord.WebSocket;
|
|
||||||
|
|
||||||
namespace BasicBot
|
namespace BasicBot
|
||||||
{
|
{
|
||||||
@@ -112,7 +112,8 @@ namespace BasicBot
|
|||||||
if (component.Data.CustomId == "unique-id")
|
if (component.Data.CustomId == "unique-id")
|
||||||
await interaction.RespondAsync("Thank you for clicking my button!");
|
await interaction.RespondAsync("Thank you for clicking my button!");
|
||||||
|
|
||||||
else Console.WriteLine("An ID has been received that has no handler!");
|
else
|
||||||
|
Console.WriteLine("An ID has been received that has no handler!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -30,7 +30,8 @@ namespace InteractionFramework.Attributes
|
|||||||
? Task.FromResult(PreconditionResult.FromSuccess())
|
? Task.FromResult(PreconditionResult.FromSuccess())
|
||||||
: Task.FromResult(PreconditionResult.FromError("User ID does not match component ID!"));
|
: Task.FromResult(PreconditionResult.FromError("User ID does not match component ID!"));
|
||||||
|
|
||||||
else return Task.FromResult(PreconditionResult.FromError("Parse cannot be done if no userID exists."));
|
else
|
||||||
|
return Task.FromResult(PreconditionResult.FromError("Parse cannot be done if no userID exists."));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ namespace InteractionFramework.Attributes
|
|||||||
{
|
{
|
||||||
public class RequireOwnerAttribute : PreconditionAttribute
|
public class RequireOwnerAttribute : PreconditionAttribute
|
||||||
{
|
{
|
||||||
public override async Task<PreconditionResult> CheckRequirementsAsync (IInteractionContext context, ICommandInfo commandInfo, IServiceProvider services)
|
public override async Task<PreconditionResult> CheckRequirementsAsync(IInteractionContext context, ICommandInfo commandInfo, IServiceProvider services)
|
||||||
{
|
{
|
||||||
switch (context.Client.TokenType)
|
switch (context.Client.TokenType)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ namespace InteractionFramework.Modules
|
|||||||
|
|
||||||
// [Summary] lets you customize the name and the description of a parameter
|
// [Summary] lets you customize the name and the description of a parameter
|
||||||
[SlashCommand("echo", "Repeat the input")]
|
[SlashCommand("echo", "Repeat the input")]
|
||||||
public async Task Echo(string echo, [Summary(description: "mention the user")]bool mention = false)
|
public async Task Echo(string echo, [Summary(description: "mention the user")] bool mention = false)
|
||||||
=> await RespondAsync(echo + (mention ? Context.User.Mention : string.Empty));
|
=> await RespondAsync(echo + (mention ? Context.User.Mention : string.Empty));
|
||||||
|
|
||||||
[SlashCommand("ping", "Pings the bot and returns its latency.")]
|
[SlashCommand("ping", "Pings the bot and returns its latency.")]
|
||||||
|
|||||||
@@ -64,11 +64,11 @@ namespace InteractionFramework
|
|||||||
|
|
||||||
public static bool IsDebug()
|
public static bool IsDebug()
|
||||||
{
|
{
|
||||||
#if DEBUG
|
#if DEBUG
|
||||||
return true;
|
return true;
|
||||||
#else
|
#else
|
||||||
return false;
|
return false;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,11 +1,11 @@
|
|||||||
using System;
|
using Discord.Commands;
|
||||||
using System.Collections.Immutable;
|
|
||||||
using System.Linq;
|
|
||||||
using Microsoft.CodeAnalysis;
|
using Microsoft.CodeAnalysis;
|
||||||
using Microsoft.CodeAnalysis.CSharp;
|
using Microsoft.CodeAnalysis.CSharp;
|
||||||
using Microsoft.CodeAnalysis.CSharp.Syntax;
|
using Microsoft.CodeAnalysis.CSharp.Syntax;
|
||||||
using Microsoft.CodeAnalysis.Diagnostics;
|
using Microsoft.CodeAnalysis.Diagnostics;
|
||||||
using Discord.Commands;
|
using System;
|
||||||
|
using System.Collections.Immutable;
|
||||||
|
using System.Linq;
|
||||||
|
|
||||||
namespace Discord.Analyzers
|
namespace Discord.Analyzers
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
using System;
|
|
||||||
using Microsoft.CodeAnalysis;
|
|
||||||
using Discord.Commands;
|
using Discord.Commands;
|
||||||
|
using Microsoft.CodeAnalysis;
|
||||||
|
using System;
|
||||||
|
|
||||||
namespace Discord.Analyzers
|
namespace Discord.Analyzers
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
using System;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using System.Collections.Generic;
|
|
||||||
|
|
||||||
namespace Discord.Commands.Builders
|
namespace Discord.Commands.Builders
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -20,7 +20,9 @@ namespace Discord.Commands.Builders
|
|||||||
public string Name { get; set; }
|
public string Name { get; set; }
|
||||||
public string Summary { get; set; }
|
public string Summary { get; set; }
|
||||||
public string Remarks { get; set; }
|
public string Remarks { get; set; }
|
||||||
public string Group { get => _group;
|
public string Group
|
||||||
|
{
|
||||||
|
get => _group;
|
||||||
set
|
set
|
||||||
{
|
{
|
||||||
_aliases.Remove(_group);
|
_aliases.Remove(_group);
|
||||||
|
|||||||
@@ -1,11 +1,10 @@
|
|||||||
|
using Discord.Commands.Builders;
|
||||||
using System;
|
using System;
|
||||||
using System.Linq;
|
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
using Discord.Commands.Builders;
|
|
||||||
|
|
||||||
namespace Discord.Commands
|
namespace Discord.Commands
|
||||||
{
|
{
|
||||||
internal static class ModuleClassBuilder
|
internal static class ModuleClassBuilder
|
||||||
|
|||||||
@@ -1,9 +1,8 @@
|
|||||||
using System;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
|
|
||||||
using System.Collections.Generic;
|
|
||||||
|
|
||||||
namespace Discord.Commands.Builders
|
namespace Discord.Commands.Builders
|
||||||
{
|
{
|
||||||
public class ParameterBuilder
|
public class ParameterBuilder
|
||||||
@@ -25,7 +24,7 @@ namespace Discord.Commands.Builders
|
|||||||
|
|
||||||
public IReadOnlyList<ParameterPreconditionAttribute> Preconditions => _preconditions;
|
public IReadOnlyList<ParameterPreconditionAttribute> Preconditions => _preconditions;
|
||||||
public IReadOnlyList<Attribute> Attributes => _attributes;
|
public IReadOnlyList<Attribute> Attributes => _attributes;
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Automatic
|
#region Automatic
|
||||||
internal ParameterBuilder(CommandBuilder command)
|
internal ParameterBuilder(CommandBuilder command)
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
using Discord.Commands.Builders;
|
||||||
|
using Discord.Logging;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Concurrent;
|
using System.Collections.Concurrent;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
@@ -6,8 +8,6 @@ using System.Linq;
|
|||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Discord.Commands.Builders;
|
|
||||||
using Discord.Logging;
|
|
||||||
|
|
||||||
namespace Discord.Commands
|
namespace Discord.Commands
|
||||||
{
|
{
|
||||||
@@ -653,7 +653,7 @@ namespace Discord.Commands
|
|||||||
var bestCandidate = preconditionResults
|
var bestCandidate = preconditionResults
|
||||||
.OrderByDescending(x => x.Key.Command.Priority)
|
.OrderByDescending(x => x.Key.Command.Priority)
|
||||||
.FirstOrDefault(x => !x.Value.IsSuccess);
|
.FirstOrDefault(x => !x.Value.IsSuccess);
|
||||||
return MatchResult.FromSuccess(bestCandidate.Key,bestCandidate.Value);
|
return MatchResult.FromSuccess(bestCandidate.Key, bestCandidate.Value);
|
||||||
}
|
}
|
||||||
|
|
||||||
var parseResults = new Dictionary<CommandMatch, ParseResult>();
|
var parseResults = new Dictionary<CommandMatch, ParseResult>();
|
||||||
@@ -685,7 +685,7 @@ namespace Discord.Commands
|
|||||||
.Where(x => x.Value.IsSuccess)
|
.Where(x => x.Value.IsSuccess)
|
||||||
.ToArray();
|
.ToArray();
|
||||||
|
|
||||||
if(successfulParses.Length == 0)
|
if (successfulParses.Length == 0)
|
||||||
{
|
{
|
||||||
var bestMatch = parseResults
|
var bestMatch = parseResults
|
||||||
.FirstOrDefault(x => !x.Value.IsSuccess);
|
.FirstOrDefault(x => !x.Value.IsSuccess);
|
||||||
|
|||||||
@@ -45,13 +45,17 @@ namespace Discord.Commands
|
|||||||
public static bool HasMentionPrefix(this IUserMessage msg, IUser user, ref int argPos)
|
public static bool HasMentionPrefix(this IUserMessage msg, IUser user, ref int argPos)
|
||||||
{
|
{
|
||||||
var text = msg.Content;
|
var text = msg.Content;
|
||||||
if (string.IsNullOrEmpty(text) || text.Length <= 3 || text[0] != '<' || text[1] != '@') return false;
|
if (string.IsNullOrEmpty(text) || text.Length <= 3 || text[0] != '<' || text[1] != '@')
|
||||||
|
return false;
|
||||||
|
|
||||||
int endPos = text.IndexOf('>');
|
int endPos = text.IndexOf('>');
|
||||||
if (endPos == -1) return false;
|
if (endPos == -1)
|
||||||
if (text.Length < endPos + 2 || text[endPos + 1] != ' ') return false; //Must end in "> "
|
return false;
|
||||||
|
if (text.Length < endPos + 2 || text[endPos + 1] != ' ')
|
||||||
|
return false; //Must end in "> "
|
||||||
|
|
||||||
if (!MentionUtils.TryParseUser(text.Substring(0, endPos + 1), out ulong userId)) return false;
|
if (!MentionUtils.TryParseUser(text.Substring(0, endPos + 1), out ulong userId))
|
||||||
|
return false;
|
||||||
if (userId == user.Id)
|
if (userId == user.Id)
|
||||||
{
|
{
|
||||||
argPos = endPos + 2;
|
argPos = endPos + 2;
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
using Discord.Commands.Builders;
|
using Discord.Commands.Builders;
|
||||||
using System;
|
using System;
|
||||||
|
using System.Collections.Concurrent;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Collections.Immutable;
|
using System.Collections.Immutable;
|
||||||
using System.Collections.Concurrent;
|
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
|
using Discord.Commands.Builders;
|
||||||
using System;
|
using System;
|
||||||
using System.Linq;
|
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Collections.Immutable;
|
using System.Collections.Immutable;
|
||||||
using Discord.Commands.Builders;
|
using System.Linq;
|
||||||
|
|
||||||
namespace Discord.Commands
|
namespace Discord.Commands
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
|
using Discord.Commands.Builders;
|
||||||
using System;
|
using System;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Discord.Commands.Builders;
|
|
||||||
|
|
||||||
namespace Discord.Commands
|
namespace Discord.Commands
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -30,13 +30,13 @@ namespace Discord.Commands
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static MatchResult FromSuccess(CommandMatch match, IResult pipeline)
|
public static MatchResult FromSuccess(CommandMatch match, IResult pipeline)
|
||||||
=> new MatchResult(match,pipeline,null, null);
|
=> new MatchResult(match, pipeline, null, null);
|
||||||
public static MatchResult FromError(CommandError error, string reason)
|
public static MatchResult FromError(CommandError error, string reason)
|
||||||
=> new MatchResult(null,null,error, reason);
|
=> new MatchResult(null, null, error, reason);
|
||||||
public static MatchResult FromError(Exception ex)
|
public static MatchResult FromError(Exception ex)
|
||||||
=> FromError(CommandError.Exception, ex.Message);
|
=> FromError(CommandError.Exception, ex.Message);
|
||||||
public static MatchResult FromError(IResult result)
|
public static MatchResult FromError(IResult result)
|
||||||
=> new MatchResult(null, null,result.Error, result.ErrorReason);
|
=> new MatchResult(null, null, result.Error, result.ErrorReason);
|
||||||
public static MatchResult FromError(IResult pipeline, CommandError error, string reason)
|
public static MatchResult FromError(IResult pipeline, CommandError error, string reason)
|
||||||
=> new MatchResult(null, pipeline, error, reason);
|
=> new MatchResult(null, pipeline, error, reason);
|
||||||
|
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ namespace Discord.Commands
|
|||||||
args[i] = GetMember(commands, services, parameters[i].ParameterType, typeInfo);
|
args[i] = GetMember(commands, services, parameters[i].ParameterType, typeInfo);
|
||||||
var obj = InvokeConstructor<T>(constructor, args, typeInfo);
|
var obj = InvokeConstructor<T>(constructor, args, typeInfo);
|
||||||
|
|
||||||
foreach(var property in properties)
|
foreach (var property in properties)
|
||||||
property.SetValue(obj, GetMember(commands, services, property.PropertyType, typeInfo));
|
property.SetValue(obj, GetMember(commands, services, property.PropertyType, typeInfo));
|
||||||
return obj;
|
return obj;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
using System.Collections.Generic;
|
|
||||||
using System;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
using System.Collections.Immutable;
|
using System.Collections.Immutable;
|
||||||
|
|
||||||
namespace Discord;
|
namespace Discord;
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ public class RoleConnectionProperties
|
|||||||
get => _platformUsername;
|
get => _platformUsername;
|
||||||
set
|
set
|
||||||
{
|
{
|
||||||
if(value is not null)
|
if (value is not null)
|
||||||
Preconditions.AtMost(value.Length, MaxPlatformUsernameLength, nameof(PlatformUsername), $"Platform username length must be less or equal to {MaxPlatformUsernameLength}");
|
Preconditions.AtMost(value.Length, MaxPlatformUsernameLength, nameof(PlatformUsername), $"Platform username length must be less or equal to {MaxPlatformUsernameLength}");
|
||||||
_platformUsername = value;
|
_platformUsername = value;
|
||||||
}
|
}
|
||||||
@@ -103,7 +103,7 @@ public class RoleConnectionProperties
|
|||||||
internal RoleConnectionProperties AddMetadataRecord(string key, string value)
|
internal RoleConnectionProperties AddMetadataRecord(string key, string value)
|
||||||
{
|
{
|
||||||
Metadata ??= new Dictionary<string, string>();
|
Metadata ??= new Dictionary<string, string>();
|
||||||
if(!Metadata.ContainsKey(key))
|
if (!Metadata.ContainsKey(key))
|
||||||
Preconditions.AtMost(Metadata.Count + 1, MaxPlatformUsernameLength, nameof(Metadata), $"Metadata records count must be less or equal to {MaxMetadataRecords}");
|
Preconditions.AtMost(Metadata.Count + 1, MaxPlatformUsernameLength, nameof(Metadata), $"Metadata records count must be less or equal to {MaxMetadataRecords}");
|
||||||
|
|
||||||
_metadata[key] = value;
|
_metadata[key] = value;
|
||||||
@@ -126,7 +126,7 @@ public class RoleConnectionProperties
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Initializes a new instance of <see cref="RoleConnectionProperties"/>.
|
/// Initializes a new instance of <see cref="RoleConnectionProperties"/>.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public RoleConnectionProperties() {}
|
public RoleConnectionProperties() { }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Initializes a new <see cref="RoleConnectionProperties"/> with the data from provided <see cref="RoleConnection"/>.
|
/// Initializes a new <see cref="RoleConnectionProperties"/> with the data from provided <see cref="RoleConnection"/>.
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
namespace Discord
|
namespace Discord
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Provides properties that are used to modify an <see cref="IAudioChannel" /> with the specified changes.
|
/// Provides properties that are used to modify an <see cref="IAudioChannel" /> with the specified changes.
|
||||||
|
|||||||
@@ -172,7 +172,7 @@ namespace Discord
|
|||||||
public Task<IThreadChannel> CreatePostWithFileAsync(string title, Stream stream, string filename, ThreadArchiveDuration archiveDuration = ThreadArchiveDuration.OneDay,
|
public Task<IThreadChannel> CreatePostWithFileAsync(string title, Stream stream, string filename, ThreadArchiveDuration archiveDuration = ThreadArchiveDuration.OneDay,
|
||||||
int? slowmode = null, string text = null, Embed embed = null, RequestOptions options = null, bool isSpoiler = false,
|
int? slowmode = null, string text = null, Embed embed = null, RequestOptions options = null, bool isSpoiler = false,
|
||||||
AllowedMentions allowedMentions = null, MessageComponent components = null,
|
AllowedMentions allowedMentions = null, MessageComponent components = null,
|
||||||
ISticker[] stickers = null, Embed[] embeds = null,MessageFlags flags = MessageFlags.None, ForumTag[] tags = null);
|
ISticker[] stickers = null, Embed[] embeds = null, MessageFlags flags = MessageFlags.None, ForumTag[] tags = null);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Creates a new post (thread) within the forum.
|
/// Creates a new post (thread) within the forum.
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Globalization;
|
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
|
using System.Globalization;
|
||||||
|
|
||||||
namespace Discord
|
namespace Discord
|
||||||
{
|
{
|
||||||
@@ -44,11 +44,14 @@ namespace Discord
|
|||||||
/// <param name="other">The object to compare with the current object.</param>
|
/// <param name="other">The object to compare with the current object.</param>
|
||||||
public override bool Equals(object other)
|
public override bool Equals(object other)
|
||||||
{
|
{
|
||||||
if (other == null) return false;
|
if (other == null)
|
||||||
if (other == this) return true;
|
return false;
|
||||||
|
if (other == this)
|
||||||
|
return true;
|
||||||
|
|
||||||
var otherEmote = other as Emote;
|
var otherEmote = other as Emote;
|
||||||
if (otherEmote == null) return false;
|
if (otherEmote == null)
|
||||||
|
return false;
|
||||||
|
|
||||||
return Id == otherEmote.Id;
|
return Id == otherEmote.Id;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -110,7 +110,7 @@ public class ForumTagBuilder
|
|||||||
public ForumTagBuilder(string name, ulong? id = null, bool isModerated = false, ulong? emoteId = null)
|
public ForumTagBuilder(string name, ulong? id = null, bool isModerated = false, ulong? emoteId = null)
|
||||||
{
|
{
|
||||||
Name = name;
|
Name = name;
|
||||||
if(emoteId is not null)
|
if (emoteId is not null)
|
||||||
Emoji = new Emote(emoteId.Value, null, false);
|
Emoji = new Emote(emoteId.Value, null, false);
|
||||||
IsModerated = isModerated;
|
IsModerated = isModerated;
|
||||||
Id = id;
|
Id = id;
|
||||||
@@ -185,7 +185,7 @@ public class ForumTagBuilder
|
|||||||
IsModerated == builder.IsModerated;
|
IsModerated == builder.IsModerated;
|
||||||
|
|
||||||
public static bool operator ==(ForumTagBuilder? left, ForumTagBuilder? right)
|
public static bool operator ==(ForumTagBuilder? left, ForumTagBuilder? right)
|
||||||
=> left?.Equals(right) ?? right is null ;
|
=> left?.Equals(right) ?? right is null;
|
||||||
|
|
||||||
public static bool operator !=(ForumTagBuilder? left, ForumTagBuilder? right) => !(left == right);
|
public static bool operator !=(ForumTagBuilder? left, ForumTagBuilder? right) => !(left == right);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -50,5 +50,5 @@ public class WelcomeScreenChannelProperties : ISnowflakeEntity
|
|||||||
/// <param name="channel">A welcome screen channel to modify.</param>
|
/// <param name="channel">A welcome screen channel to modify.</param>
|
||||||
/// <returns>A new instance of <see cref="WelcomeScreenChannelProperties"/>.</returns>
|
/// <returns>A new instance of <see cref="WelcomeScreenChannelProperties"/>.</returns>
|
||||||
public static WelcomeScreenChannelProperties FromWelcomeScreenChannel(WelcomeScreenChannel channel)
|
public static WelcomeScreenChannelProperties FromWelcomeScreenChannel(WelcomeScreenChannel channel)
|
||||||
=> new (channel.Id, channel.Description, channel.Emoji);
|
=> new(channel.Id, channel.Description, channel.Emoji);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -110,7 +110,7 @@ namespace Discord
|
|||||||
{
|
{
|
||||||
foreach (var (locale, name) in value)
|
foreach (var (locale, name) in value)
|
||||||
{
|
{
|
||||||
if(!Regex.IsMatch(locale, @"^\w{2}(?:-\w{2})?$"))
|
if (!Regex.IsMatch(locale, @"^\w{2}(?:-\w{2})?$"))
|
||||||
throw new ArgumentException($"Invalid locale: {locale}", nameof(locale));
|
throw new ArgumentException($"Invalid locale: {locale}", nameof(locale));
|
||||||
|
|
||||||
EnsureValidOptionName(name);
|
EnsureValidOptionName(name);
|
||||||
@@ -134,7 +134,7 @@ namespace Discord
|
|||||||
{
|
{
|
||||||
foreach (var (locale, description) in value)
|
foreach (var (locale, description) in value)
|
||||||
{
|
{
|
||||||
if(!Regex.IsMatch(locale, @"^\w{2}(?:-\w{2})?$"))
|
if (!Regex.IsMatch(locale, @"^\w{2}(?:-\w{2})?$"))
|
||||||
throw new ArgumentException($"Invalid locale: {locale}", nameof(locale));
|
throw new ArgumentException($"Invalid locale: {locale}", nameof(locale));
|
||||||
|
|
||||||
EnsureValidOptionDescription(description);
|
EnsureValidOptionDescription(description);
|
||||||
|
|||||||
@@ -49,7 +49,7 @@ namespace Discord
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets whether or not this command is age restricted.
|
/// Gets or sets whether or not this command is age restricted.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public bool IsNsfw{ get; set; } = false;
|
public bool IsNsfw { get; set; } = false;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets the default permission required to use this slash command.
|
/// Gets or sets the default permission required to use this slash command.
|
||||||
@@ -118,7 +118,7 @@ namespace Discord
|
|||||||
|
|
||||||
foreach (var (locale, name) in nameLocalizations)
|
foreach (var (locale, name) in nameLocalizations)
|
||||||
{
|
{
|
||||||
if(!Regex.IsMatch(locale, @"^\w{2}(?:-\w{2})?$"))
|
if (!Regex.IsMatch(locale, @"^\w{2}(?:-\w{2})?$"))
|
||||||
throw new ArgumentException($"Invalid locale: {locale}", nameof(locale));
|
throw new ArgumentException($"Invalid locale: {locale}", nameof(locale));
|
||||||
|
|
||||||
EnsureValidCommandName(name);
|
EnsureValidCommandName(name);
|
||||||
@@ -159,7 +159,7 @@ namespace Discord
|
|||||||
/// <exception cref="ArgumentException">Thrown if <paramref name="locale"/> is an invalid locale string.</exception>
|
/// <exception cref="ArgumentException">Thrown if <paramref name="locale"/> is an invalid locale string.</exception>
|
||||||
public MessageCommandBuilder AddNameLocalization(string locale, string name)
|
public MessageCommandBuilder AddNameLocalization(string locale, string name)
|
||||||
{
|
{
|
||||||
if(!Regex.IsMatch(locale, @"^\w{2}(?:-\w{2})?$"))
|
if (!Regex.IsMatch(locale, @"^\w{2}(?:-\w{2})?$"))
|
||||||
throw new ArgumentException($"Invalid locale: {locale}", nameof(locale));
|
throw new ArgumentException($"Invalid locale: {locale}", nameof(locale));
|
||||||
|
|
||||||
EnsureValidCommandName(name);
|
EnsureValidCommandName(name);
|
||||||
|
|||||||
@@ -116,7 +116,7 @@ namespace Discord
|
|||||||
|
|
||||||
foreach (var (locale, name) in nameLocalizations)
|
foreach (var (locale, name) in nameLocalizations)
|
||||||
{
|
{
|
||||||
if(!Regex.IsMatch(locale, @"^\w{2}(?:-\w{2})?$"))
|
if (!Regex.IsMatch(locale, @"^\w{2}(?:-\w{2})?$"))
|
||||||
throw new ArgumentException($"Invalid locale: {locale}", nameof(locale));
|
throw new ArgumentException($"Invalid locale: {locale}", nameof(locale));
|
||||||
|
|
||||||
EnsureValidCommandName(name);
|
EnsureValidCommandName(name);
|
||||||
@@ -157,7 +157,7 @@ namespace Discord
|
|||||||
/// <exception cref="ArgumentException">Thrown if <paramref name="locale"/> is an invalid locale string.</exception>
|
/// <exception cref="ArgumentException">Thrown if <paramref name="locale"/> is an invalid locale string.</exception>
|
||||||
public UserCommandBuilder AddNameLocalization(string locale, string name)
|
public UserCommandBuilder AddNameLocalization(string locale, string name)
|
||||||
{
|
{
|
||||||
if(!Regex.IsMatch(locale, @"^\w{2}(?:-\w{2})?$"))
|
if (!Regex.IsMatch(locale, @"^\w{2}(?:-\w{2})?$"))
|
||||||
throw new ArgumentException($"Invalid locale: {locale}", nameof(locale));
|
throw new ArgumentException($"Invalid locale: {locale}", nameof(locale));
|
||||||
|
|
||||||
EnsureValidCommandName(name);
|
EnsureValidCommandName(name);
|
||||||
|
|||||||
@@ -130,7 +130,7 @@ namespace Discord
|
|||||||
async Task RespondWithFileAsync(Stream fileStream, string fileName, string text = null, Embed[] embeds = null, bool isTTS = false, bool ephemeral = false,
|
async Task RespondWithFileAsync(Stream fileStream, string fileName, string text = null, Embed[] embeds = null, bool isTTS = false, bool ephemeral = false,
|
||||||
AllowedMentions allowedMentions = null, MessageComponent components = null, Embed embed = null, RequestOptions options = null)
|
AllowedMentions allowedMentions = null, MessageComponent components = null, Embed embed = null, RequestOptions options = null)
|
||||||
{
|
{
|
||||||
using(var file = new FileAttachment(fileStream, fileName))
|
using (var file = new FileAttachment(fileStream, fileName))
|
||||||
{
|
{
|
||||||
await RespondWithFileAsync(file, text, embeds, isTTS, ephemeral, allowedMentions, components, embed, options).ConfigureAwait(false);
|
await RespondWithFileAsync(file, text, embeds, isTTS, ephemeral, allowedMentions, components, embed, options).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
@@ -249,7 +249,7 @@ namespace Discord
|
|||||||
async Task<IUserMessage> FollowupWithFileAsync(Stream fileStream, string fileName, string text = null, Embed[] embeds = null, bool isTTS = false, bool ephemeral = false,
|
async Task<IUserMessage> FollowupWithFileAsync(Stream fileStream, string fileName, string text = null, Embed[] embeds = null, bool isTTS = false, bool ephemeral = false,
|
||||||
AllowedMentions allowedMentions = null, MessageComponent components = null, Embed embed = null, RequestOptions options = null)
|
AllowedMentions allowedMentions = null, MessageComponent components = null, Embed embed = null, RequestOptions options = null)
|
||||||
{
|
{
|
||||||
using(var file = new FileAttachment(fileStream, fileName))
|
using (var file = new FileAttachment(fileStream, fileName))
|
||||||
{
|
{
|
||||||
return await FollowupWithFileAsync(file, text, embeds, isTTS, ephemeral, allowedMentions, components, embed, options).ConfigureAwait(false);
|
return await FollowupWithFileAsync(file, text, embeds, isTTS, ephemeral, allowedMentions, components, embed, options).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
namespace Discord
|
namespace Discord
|
||||||
{
|
{
|
||||||
public enum TextInputStyle
|
public enum TextInputStyle
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -263,6 +263,6 @@ namespace Discord
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns>A <see cref="ModalComponent"/> representing the builder.</returns>
|
/// <returns>A <see cref="ModalComponent"/> representing the builder.</returns>
|
||||||
public ModalComponent Build()
|
public ModalComponent Build()
|
||||||
=> new (ActionRows?.Select(x => x.Build()).ToList());
|
=> new(ActionRows?.Select(x => x.Build()).ToList());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -312,7 +312,7 @@ namespace Discord
|
|||||||
|
|
||||||
foreach (var (locale, name) in nameLocalizations)
|
foreach (var (locale, name) in nameLocalizations)
|
||||||
{
|
{
|
||||||
if(!Regex.IsMatch(locale, @"^\w{2}(?:-\w{2})?$"))
|
if (!Regex.IsMatch(locale, @"^\w{2}(?:-\w{2})?$"))
|
||||||
throw new ArgumentException($"Invalid locale: {locale}", nameof(locale));
|
throw new ArgumentException($"Invalid locale: {locale}", nameof(locale));
|
||||||
|
|
||||||
EnsureValidCommandName(name);
|
EnsureValidCommandName(name);
|
||||||
@@ -336,7 +336,7 @@ namespace Discord
|
|||||||
|
|
||||||
foreach (var (locale, description) in descriptionLocalizations)
|
foreach (var (locale, description) in descriptionLocalizations)
|
||||||
{
|
{
|
||||||
if(!Regex.IsMatch(locale, @"^\w{2}(?:-\w{2})?$"))
|
if (!Regex.IsMatch(locale, @"^\w{2}(?:-\w{2})?$"))
|
||||||
throw new ArgumentException($"Invalid locale: {locale}", nameof(locale));
|
throw new ArgumentException($"Invalid locale: {locale}", nameof(locale));
|
||||||
|
|
||||||
EnsureValidCommandDescription(description);
|
EnsureValidCommandDescription(description);
|
||||||
@@ -355,7 +355,7 @@ namespace Discord
|
|||||||
/// <exception cref="ArgumentException">Thrown if <paramref name="locale"/> is an invalid locale string.</exception>
|
/// <exception cref="ArgumentException">Thrown if <paramref name="locale"/> is an invalid locale string.</exception>
|
||||||
public SlashCommandBuilder AddNameLocalization(string locale, string name)
|
public SlashCommandBuilder AddNameLocalization(string locale, string name)
|
||||||
{
|
{
|
||||||
if(!Regex.IsMatch(locale, @"^\w{2}(?:-\w{2})?$"))
|
if (!Regex.IsMatch(locale, @"^\w{2}(?:-\w{2})?$"))
|
||||||
throw new ArgumentException($"Invalid locale: {locale}", nameof(locale));
|
throw new ArgumentException($"Invalid locale: {locale}", nameof(locale));
|
||||||
|
|
||||||
EnsureValidCommandName(name);
|
EnsureValidCommandName(name);
|
||||||
@@ -375,7 +375,7 @@ namespace Discord
|
|||||||
/// <exception cref="ArgumentException">Thrown if <paramref name="locale"/> is an invalid locale string.</exception>
|
/// <exception cref="ArgumentException">Thrown if <paramref name="locale"/> is an invalid locale string.</exception>
|
||||||
public SlashCommandBuilder AddDescriptionLocalization(string locale, string description)
|
public SlashCommandBuilder AddDescriptionLocalization(string locale, string description)
|
||||||
{
|
{
|
||||||
if(!Regex.IsMatch(locale, @"^\w{2}(?:-\w{2})?$"))
|
if (!Regex.IsMatch(locale, @"^\w{2}(?:-\w{2})?$"))
|
||||||
throw new ArgumentException($"Invalid locale: {locale}", nameof(locale));
|
throw new ArgumentException($"Invalid locale: {locale}", nameof(locale));
|
||||||
|
|
||||||
EnsureValidCommandDescription(description);
|
EnsureValidCommandDescription(description);
|
||||||
@@ -549,7 +549,7 @@ namespace Discord
|
|||||||
if (isIntType && MaxValue != null && MaxValue % 1 != 0)
|
if (isIntType && MaxValue != null && MaxValue % 1 != 0)
|
||||||
throw new InvalidOperationException("MaxValue cannot have decimals on Integer command options.");
|
throw new InvalidOperationException("MaxValue cannot have decimals on Integer command options.");
|
||||||
|
|
||||||
if(isStrType && MinLength is not null && MinLength < 0)
|
if (isStrType && MinLength is not null && MinLength < 0)
|
||||||
throw new InvalidOperationException("MinLength cannot be smaller than 0.");
|
throw new InvalidOperationException("MinLength cannot be smaller than 0.");
|
||||||
|
|
||||||
if (isStrType && MaxLength is not null && MaxLength < 1)
|
if (isStrType && MaxLength is not null && MaxLength < 1)
|
||||||
@@ -627,10 +627,10 @@ namespace Discord
|
|||||||
ChannelTypes = channelTypes,
|
ChannelTypes = channelTypes,
|
||||||
};
|
};
|
||||||
|
|
||||||
if(nameLocalizations is not null)
|
if (nameLocalizations is not null)
|
||||||
option.WithNameLocalizations(nameLocalizations);
|
option.WithNameLocalizations(nameLocalizations);
|
||||||
|
|
||||||
if(descriptionLocalizations is not null)
|
if (descriptionLocalizations is not null)
|
||||||
option.WithDescriptionLocalizations(descriptionLocalizations);
|
option.WithDescriptionLocalizations(descriptionLocalizations);
|
||||||
|
|
||||||
return AddOption(option);
|
return AddOption(option);
|
||||||
@@ -749,7 +749,7 @@ namespace Discord
|
|||||||
Preconditions.AtLeast(name.Length, 1, nameof(name));
|
Preconditions.AtLeast(name.Length, 1, nameof(name));
|
||||||
Preconditions.AtMost(name.Length, 100, nameof(name));
|
Preconditions.AtMost(name.Length, 100, nameof(name));
|
||||||
|
|
||||||
if(value is string str)
|
if (value is string str)
|
||||||
{
|
{
|
||||||
Preconditions.AtLeast(str.Length, 1, nameof(value));
|
Preconditions.AtLeast(str.Length, 1, nameof(value));
|
||||||
Preconditions.AtMost(str.Length, 100, nameof(value));
|
Preconditions.AtMost(str.Length, 100, nameof(value));
|
||||||
@@ -904,7 +904,7 @@ namespace Discord
|
|||||||
|
|
||||||
foreach (var (locale, name) in nameLocalizations)
|
foreach (var (locale, name) in nameLocalizations)
|
||||||
{
|
{
|
||||||
if(!Regex.IsMatch(locale, @"^\w{2}(?:-\w{2})?$"))
|
if (!Regex.IsMatch(locale, @"^\w{2}(?:-\w{2})?$"))
|
||||||
throw new ArgumentException($"Invalid locale: {locale}", nameof(locale));
|
throw new ArgumentException($"Invalid locale: {locale}", nameof(locale));
|
||||||
|
|
||||||
EnsureValidCommandOptionName(name);
|
EnsureValidCommandOptionName(name);
|
||||||
@@ -928,7 +928,7 @@ namespace Discord
|
|||||||
|
|
||||||
foreach (var (locale, description) in descriptionLocalizations)
|
foreach (var (locale, description) in descriptionLocalizations)
|
||||||
{
|
{
|
||||||
if(!Regex.IsMatch(locale, @"^\w{2}(?:-\w{2})?$"))
|
if (!Regex.IsMatch(locale, @"^\w{2}(?:-\w{2})?$"))
|
||||||
throw new ArgumentException($"Invalid locale: {locale}", nameof(locale));
|
throw new ArgumentException($"Invalid locale: {locale}", nameof(locale));
|
||||||
|
|
||||||
EnsureValidCommandOptionDescription(description);
|
EnsureValidCommandOptionDescription(description);
|
||||||
@@ -947,7 +947,7 @@ namespace Discord
|
|||||||
/// <exception cref="ArgumentException">Thrown if <paramref name="locale"/> is an invalid locale string.</exception>
|
/// <exception cref="ArgumentException">Thrown if <paramref name="locale"/> is an invalid locale string.</exception>
|
||||||
public SlashCommandOptionBuilder AddNameLocalization(string locale, string name)
|
public SlashCommandOptionBuilder AddNameLocalization(string locale, string name)
|
||||||
{
|
{
|
||||||
if(!Regex.IsMatch(locale, @"^\w{2}(?:-\w{2})?$"))
|
if (!Regex.IsMatch(locale, @"^\w{2}(?:-\w{2})?$"))
|
||||||
throw new ArgumentException($"Invalid locale: {locale}", nameof(locale));
|
throw new ArgumentException($"Invalid locale: {locale}", nameof(locale));
|
||||||
|
|
||||||
EnsureValidCommandOptionName(name);
|
EnsureValidCommandOptionName(name);
|
||||||
@@ -967,7 +967,7 @@ namespace Discord
|
|||||||
/// <exception cref="ArgumentException">Thrown if <paramref name="locale"/> is an invalid locale string.</exception>
|
/// <exception cref="ArgumentException">Thrown if <paramref name="locale"/> is an invalid locale string.</exception>
|
||||||
public SlashCommandOptionBuilder AddDescriptionLocalization(string locale, string description)
|
public SlashCommandOptionBuilder AddDescriptionLocalization(string locale, string description)
|
||||||
{
|
{
|
||||||
if(!Regex.IsMatch(locale, @"^\w{2}(?:-\w{2})?$"))
|
if (!Regex.IsMatch(locale, @"^\w{2}(?:-\w{2})?$"))
|
||||||
throw new ArgumentException($"Invalid locale: {locale}", nameof(locale));
|
throw new ArgumentException($"Invalid locale: {locale}", nameof(locale));
|
||||||
|
|
||||||
EnsureValidCommandOptionDescription(description);
|
EnsureValidCommandOptionDescription(description);
|
||||||
|
|||||||
@@ -128,7 +128,7 @@ namespace Discord
|
|||||||
{
|
{
|
||||||
var hash = 17;
|
var hash = 17;
|
||||||
hash = hash * 23 + (Type, Title, Description, Timestamp, Color, Image, Video, Author, Footer, Provider, Thumbnail).GetHashCode();
|
hash = hash * 23 + (Type, Title, Description, Timestamp, Color, Image, Video, Author, Footer, Provider, Thumbnail).GetHashCode();
|
||||||
foreach(var field in Fields)
|
foreach (var field in Fields)
|
||||||
hash = hash * 23 + field.GetHashCode();
|
hash = hash * 23 + field.GetHashCode();
|
||||||
return hash;
|
return hash;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
|
using Discord.Utils;
|
||||||
|
using Newtonsoft.Json;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Collections.Immutable;
|
using System.Collections.Immutable;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using Discord.Utils;
|
|
||||||
using Newtonsoft.Json;
|
|
||||||
|
|
||||||
namespace Discord
|
namespace Discord
|
||||||
{
|
{
|
||||||
@@ -50,7 +50,8 @@ namespace Discord
|
|||||||
get => _title;
|
get => _title;
|
||||||
set
|
set
|
||||||
{
|
{
|
||||||
if (value?.Length > MaxTitleLength) throw new ArgumentException(message: $"Title length must be less than or equal to {MaxTitleLength}.", paramName: nameof(Title));
|
if (value?.Length > MaxTitleLength)
|
||||||
|
throw new ArgumentException(message: $"Title length must be less than or equal to {MaxTitleLength}.", paramName: nameof(Title));
|
||||||
_title = value;
|
_title = value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -63,7 +64,8 @@ namespace Discord
|
|||||||
get => _description;
|
get => _description;
|
||||||
set
|
set
|
||||||
{
|
{
|
||||||
if (value?.Length > MaxDescriptionLength) throw new ArgumentException(message: $"Description length must be less than or equal to {MaxDescriptionLength}.", paramName: nameof(Description));
|
if (value?.Length > MaxDescriptionLength)
|
||||||
|
throw new ArgumentException(message: $"Description length must be less than or equal to {MaxDescriptionLength}.", paramName: nameof(Description));
|
||||||
_description = value;
|
_description = value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -100,8 +102,10 @@ namespace Discord
|
|||||||
get => _fields;
|
get => _fields;
|
||||||
set
|
set
|
||||||
{
|
{
|
||||||
if (value == null) throw new ArgumentNullException(paramName: nameof(Fields), message: "Cannot set an embed builder's fields collection to null.");
|
if (value == null)
|
||||||
if (value.Count > MaxFieldCount) throw new ArgumentException(message: $"Field count must be less than or equal to {MaxFieldCount}.", paramName: nameof(Fields));
|
throw new ArgumentNullException(paramName: nameof(Fields), message: "Cannot set an embed builder's fields collection to null.");
|
||||||
|
if (value.Count > MaxFieldCount)
|
||||||
|
throw new ArgumentException(message: $"Field count must be less than or equal to {MaxFieldCount}.", paramName: nameof(Fields));
|
||||||
_fields = value;
|
_fields = value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -470,7 +474,7 @@ namespace Discord
|
|||||||
if (!string.IsNullOrEmpty(Author.IconUrl))
|
if (!string.IsNullOrEmpty(Author.IconUrl))
|
||||||
UrlValidation.Validate(Author.IconUrl, true);
|
UrlValidation.Validate(Author.IconUrl, true);
|
||||||
}
|
}
|
||||||
if(Footer != null)
|
if (Footer != null)
|
||||||
{
|
{
|
||||||
if (!string.IsNullOrEmpty(Footer.IconUrl))
|
if (!string.IsNullOrEmpty(Footer.IconUrl))
|
||||||
UrlValidation.Validate(Footer.IconUrl, true);
|
UrlValidation.Validate(Footer.IconUrl, true);
|
||||||
@@ -564,8 +568,10 @@ namespace Discord
|
|||||||
get => _name;
|
get => _name;
|
||||||
set
|
set
|
||||||
{
|
{
|
||||||
if (string.IsNullOrWhiteSpace(value)) throw new ArgumentException(message: "Field name must not be null, empty or entirely whitespace.", paramName: nameof(Name));
|
if (string.IsNullOrWhiteSpace(value))
|
||||||
if (value.Length > MaxFieldNameLength) throw new ArgumentException(message: $"Field name length must be less than or equal to {MaxFieldNameLength}.", paramName: nameof(Name));
|
throw new ArgumentException(message: "Field name must not be null, empty or entirely whitespace.", paramName: nameof(Name));
|
||||||
|
if (value.Length > MaxFieldNameLength)
|
||||||
|
throw new ArgumentException(message: $"Field name length must be less than or equal to {MaxFieldNameLength}.", paramName: nameof(Name));
|
||||||
_name = value;
|
_name = value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -587,8 +593,10 @@ namespace Discord
|
|||||||
set
|
set
|
||||||
{
|
{
|
||||||
var stringValue = value?.ToString();
|
var stringValue = value?.ToString();
|
||||||
if (string.IsNullOrWhiteSpace(stringValue)) throw new ArgumentException(message: "Field value must not be null or empty.", paramName: nameof(Value));
|
if (string.IsNullOrWhiteSpace(stringValue))
|
||||||
if (stringValue.Length > MaxFieldValueLength) throw new ArgumentException(message: $"Field value length must be less than or equal to {MaxFieldValueLength}.", paramName: nameof(Value));
|
throw new ArgumentException(message: "Field value must not be null or empty.", paramName: nameof(Value));
|
||||||
|
if (stringValue.Length > MaxFieldValueLength)
|
||||||
|
throw new ArgumentException(message: $"Field value length must be less than or equal to {MaxFieldValueLength}.", paramName: nameof(Value));
|
||||||
_value = stringValue;
|
_value = stringValue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -704,7 +712,8 @@ namespace Discord
|
|||||||
get => _name;
|
get => _name;
|
||||||
set
|
set
|
||||||
{
|
{
|
||||||
if (value?.Length > MaxAuthorNameLength) throw new ArgumentException(message: $"Author name length must be less than or equal to {MaxAuthorNameLength}.", paramName: nameof(Name));
|
if (value?.Length > MaxAuthorNameLength)
|
||||||
|
throw new ArgumentException(message: $"Author name length must be less than or equal to {MaxAuthorNameLength}.", paramName: nameof(Name));
|
||||||
_name = value;
|
_name = value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -836,7 +845,8 @@ namespace Discord
|
|||||||
get => _text;
|
get => _text;
|
||||||
set
|
set
|
||||||
{
|
{
|
||||||
if (value?.Length > MaxFooterTextLength) throw new ArgumentException(message: $"Footer text length must be less than or equal to {MaxFooterTextLength}.", paramName: nameof(Text));
|
if (value?.Length > MaxFooterTextLength)
|
||||||
|
throw new ArgumentException(message: $"Footer text length must be less than or equal to {MaxFooterTextLength}.", paramName: nameof(Text));
|
||||||
_text = value;
|
_text = value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
namespace Discord
|
namespace Discord
|
||||||
{
|
{
|
||||||
public interface ITag
|
public interface ITag
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
|
|
||||||
namespace Discord
|
namespace Discord
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -225,7 +225,8 @@ namespace Discord
|
|||||||
embedLinks, attachFiles, readMessageHistory, mentionEveryone, useExternalEmojis, connect, speak, muteMembers, deafenMembers,
|
embedLinks, attachFiles, readMessageHistory, mentionEveryone, useExternalEmojis, connect, speak, muteMembers, deafenMembers,
|
||||||
moveMembers, useVoiceActivation, manageRoles, manageWebhooks, prioritySpeaker, stream, useSlashCommands, useApplicationCommands,
|
moveMembers, useVoiceActivation, manageRoles, manageWebhooks, prioritySpeaker, stream, useSlashCommands, useApplicationCommands,
|
||||||
requestToSpeak, manageThreads, createPublicThreads, createPrivateThreads, usePublicThreads, usePrivateThreads, useExternalStickers,
|
requestToSpeak, manageThreads, createPublicThreads, createPrivateThreads, usePublicThreads, usePrivateThreads, useExternalStickers,
|
||||||
sendMessagesInThreads, startEmbeddedActivities) { }
|
sendMessagesInThreads, startEmbeddedActivities)
|
||||||
|
{ }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Initializes a new <see cref="OverwritePermissions" /> from the current one, changing the provided
|
/// Initializes a new <see cref="OverwritePermissions" /> from the current one, changing the provided
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
namespace Discord
|
namespace Discord
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Threading.Tasks;
|
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
namespace Discord
|
namespace Discord
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
namespace Discord.Net.Rest
|
namespace Discord.Net.Rest
|
||||||
{
|
{
|
||||||
public delegate IRestClient RestClientProvider(string baseUrl);
|
public delegate IRestClient RestClientProvider(string baseUrl);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Net;
|
using System.Net;
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
namespace Discord.Net.Udp
|
namespace Discord.Net.Udp
|
||||||
{
|
{
|
||||||
public delegate IUdpSocket UdpSocketProvider();
|
public delegate IUdpSocket UdpSocketProvider();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
namespace Discord.Net.WebSockets
|
namespace Discord.Net.WebSockets
|
||||||
{
|
{
|
||||||
public delegate IWebSocketClient WebSocketProvider();
|
public delegate IWebSocketClient WebSocketProvider();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Collections.Immutable;
|
using System.Collections.Immutable;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ namespace Discord
|
|||||||
public TEntity Value { get; }
|
public TEntity Value { get; }
|
||||||
private Func<Task<TEntity>> DownloadFunc { get; }
|
private Func<Task<TEntity>> DownloadFunc { get; }
|
||||||
|
|
||||||
internal Cacheable(TEntity value, TId id, bool hasValue , Func<Task<TEntity>> downloadFunc)
|
internal Cacheable(TEntity value, TId id, bool hasValue, Func<Task<TEntity>> downloadFunc)
|
||||||
{
|
{
|
||||||
Value = value;
|
Value = value;
|
||||||
Id = id;
|
Id = id;
|
||||||
|
|||||||
@@ -161,7 +161,8 @@ namespace Discord
|
|||||||
public ConcurrentHashSet(IEnumerable<T> collection, IEqualityComparer<T> comparer)
|
public ConcurrentHashSet(IEnumerable<T> collection, IEqualityComparer<T> comparer)
|
||||||
: this(comparer)
|
: this(comparer)
|
||||||
{
|
{
|
||||||
if (collection == null) throw new ArgumentNullException(paramName: nameof(collection));
|
if (collection == null)
|
||||||
|
throw new ArgumentNullException(paramName: nameof(collection));
|
||||||
InitializeFromCollection(collection);
|
InitializeFromCollection(collection);
|
||||||
}
|
}
|
||||||
/// <exception cref="ArgumentNullException">
|
/// <exception cref="ArgumentNullException">
|
||||||
@@ -170,17 +171,22 @@ namespace Discord
|
|||||||
public ConcurrentHashSet(int concurrencyLevel, IEnumerable<T> collection, IEqualityComparer<T> comparer)
|
public ConcurrentHashSet(int concurrencyLevel, IEnumerable<T> collection, IEqualityComparer<T> comparer)
|
||||||
: this(concurrencyLevel, DefaultCapacity, false, comparer)
|
: this(concurrencyLevel, DefaultCapacity, false, comparer)
|
||||||
{
|
{
|
||||||
if (collection == null) throw new ArgumentNullException(paramName: nameof(collection));
|
if (collection == null)
|
||||||
if (comparer == null) throw new ArgumentNullException(paramName: nameof(comparer));
|
throw new ArgumentNullException(paramName: nameof(collection));
|
||||||
|
if (comparer == null)
|
||||||
|
throw new ArgumentNullException(paramName: nameof(comparer));
|
||||||
InitializeFromCollection(collection);
|
InitializeFromCollection(collection);
|
||||||
}
|
}
|
||||||
public ConcurrentHashSet(int concurrencyLevel, int capacity, IEqualityComparer<T> comparer)
|
public ConcurrentHashSet(int concurrencyLevel, int capacity, IEqualityComparer<T> comparer)
|
||||||
: this(concurrencyLevel, capacity, false, comparer) { }
|
: this(concurrencyLevel, capacity, false, comparer) { }
|
||||||
internal ConcurrentHashSet(int concurrencyLevel, int capacity, bool growLockArray, IEqualityComparer<T> comparer)
|
internal ConcurrentHashSet(int concurrencyLevel, int capacity, bool growLockArray, IEqualityComparer<T> comparer)
|
||||||
{
|
{
|
||||||
if (concurrencyLevel < 1) throw new ArgumentOutOfRangeException(paramName: nameof(concurrencyLevel));
|
if (concurrencyLevel < 1)
|
||||||
if (capacity < 0) throw new ArgumentOutOfRangeException(paramName: nameof(capacity));
|
throw new ArgumentOutOfRangeException(paramName: nameof(concurrencyLevel));
|
||||||
if (comparer == null) throw new ArgumentNullException(paramName: nameof(comparer));
|
if (capacity < 0)
|
||||||
|
throw new ArgumentOutOfRangeException(paramName: nameof(capacity));
|
||||||
|
if (comparer == null)
|
||||||
|
throw new ArgumentNullException(paramName: nameof(comparer));
|
||||||
|
|
||||||
if (capacity < concurrencyLevel)
|
if (capacity < concurrencyLevel)
|
||||||
capacity = concurrencyLevel;
|
capacity = concurrencyLevel;
|
||||||
@@ -201,7 +207,8 @@ namespace Discord
|
|||||||
{
|
{
|
||||||
foreach (var value in collection)
|
foreach (var value in collection)
|
||||||
{
|
{
|
||||||
if (value == null) throw new ArgumentNullException(paramName: "key");
|
if (value == null)
|
||||||
|
throw new ArgumentNullException(paramName: "key");
|
||||||
|
|
||||||
if (!TryAddInternal(value, _comparer.GetHashCode(value), false))
|
if (!TryAddInternal(value, _comparer.GetHashCode(value), false))
|
||||||
throw new ArgumentException();
|
throw new ArgumentException();
|
||||||
@@ -213,7 +220,8 @@ namespace Discord
|
|||||||
/// <exception cref="ArgumentNullException"><paramref name="value"/> is <c>null</c></exception>
|
/// <exception cref="ArgumentNullException"><paramref name="value"/> is <c>null</c></exception>
|
||||||
public bool ContainsKey(T value)
|
public bool ContainsKey(T value)
|
||||||
{
|
{
|
||||||
if (value == null) throw new ArgumentNullException(paramName: "key");
|
if (value == null)
|
||||||
|
throw new ArgumentNullException(paramName: "key");
|
||||||
return ContainsKeyInternal(value, _comparer.GetHashCode(value));
|
return ContainsKeyInternal(value, _comparer.GetHashCode(value));
|
||||||
}
|
}
|
||||||
private bool ContainsKeyInternal(T value, int hashcode)
|
private bool ContainsKeyInternal(T value, int hashcode)
|
||||||
@@ -237,7 +245,8 @@ namespace Discord
|
|||||||
/// <exception cref="ArgumentNullException"><paramref name="value"/> is <c>null</c></exception>
|
/// <exception cref="ArgumentNullException"><paramref name="value"/> is <c>null</c></exception>
|
||||||
public bool TryAdd(T value)
|
public bool TryAdd(T value)
|
||||||
{
|
{
|
||||||
if (value == null) throw new ArgumentNullException(paramName: "key");
|
if (value == null)
|
||||||
|
throw new ArgumentNullException(paramName: "key");
|
||||||
return TryAddInternal(value, _comparer.GetHashCode(value), true);
|
return TryAddInternal(value, _comparer.GetHashCode(value), true);
|
||||||
}
|
}
|
||||||
private bool TryAddInternal(T value, int hashcode, bool acquireLock)
|
private bool TryAddInternal(T value, int hashcode, bool acquireLock)
|
||||||
@@ -266,7 +275,8 @@ namespace Discord
|
|||||||
}
|
}
|
||||||
|
|
||||||
Volatile.Write(ref tables._buckets[bucketNo], new Node(value, hashcode, tables._buckets[bucketNo]));
|
Volatile.Write(ref tables._buckets[bucketNo], new Node(value, hashcode, tables._buckets[bucketNo]));
|
||||||
checked { tables._countPerLock[lockNo]++; }
|
checked
|
||||||
|
{ tables._countPerLock[lockNo]++; }
|
||||||
|
|
||||||
if (tables._countPerLock[lockNo] > _budget)
|
if (tables._countPerLock[lockNo] > _budget)
|
||||||
resizeDesired = true;
|
resizeDesired = true;
|
||||||
@@ -287,7 +297,8 @@ namespace Discord
|
|||||||
/// <exception cref="ArgumentNullException"><paramref name="value"/> is <c>null</c></exception>
|
/// <exception cref="ArgumentNullException"><paramref name="value"/> is <c>null</c></exception>
|
||||||
public bool TryRemove(T value)
|
public bool TryRemove(T value)
|
||||||
{
|
{
|
||||||
if (value == null) throw new ArgumentNullException(paramName: "key");
|
if (value == null)
|
||||||
|
throw new ArgumentNullException(paramName: "key");
|
||||||
return TryRemoveInternal(value);
|
return TryRemoveInternal(value);
|
||||||
}
|
}
|
||||||
private bool TryRemoveInternal(T value)
|
private bool TryRemoveInternal(T value)
|
||||||
@@ -432,7 +443,8 @@ namespace Discord
|
|||||||
|
|
||||||
newBuckets[newBucketNo] = new Node(current._value, current._hashcode, newBuckets[newBucketNo]);
|
newBuckets[newBucketNo] = new Node(current._value, current._hashcode, newBuckets[newBucketNo]);
|
||||||
|
|
||||||
checked { newCountPerLock[newLockNo]++; }
|
checked
|
||||||
|
{ newCountPerLock[newLockNo]++; }
|
||||||
|
|
||||||
current = next;
|
current = next;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -136,27 +136,33 @@ namespace Discord
|
|||||||
switch (tag.Type)
|
switch (tag.Type)
|
||||||
{
|
{
|
||||||
case TagType.UserMention:
|
case TagType.UserMention:
|
||||||
if (userHandling == TagHandling.Ignore) continue;
|
if (userHandling == TagHandling.Ignore)
|
||||||
|
continue;
|
||||||
newText = ResolveUserMention(tag, userHandling);
|
newText = ResolveUserMention(tag, userHandling);
|
||||||
break;
|
break;
|
||||||
case TagType.ChannelMention:
|
case TagType.ChannelMention:
|
||||||
if (channelHandling == TagHandling.Ignore) continue;
|
if (channelHandling == TagHandling.Ignore)
|
||||||
|
continue;
|
||||||
newText = ResolveChannelMention(tag, channelHandling);
|
newText = ResolveChannelMention(tag, channelHandling);
|
||||||
break;
|
break;
|
||||||
case TagType.RoleMention:
|
case TagType.RoleMention:
|
||||||
if (roleHandling == TagHandling.Ignore) continue;
|
if (roleHandling == TagHandling.Ignore)
|
||||||
|
continue;
|
||||||
newText = ResolveRoleMention(tag, roleHandling);
|
newText = ResolveRoleMention(tag, roleHandling);
|
||||||
break;
|
break;
|
||||||
case TagType.EveryoneMention:
|
case TagType.EveryoneMention:
|
||||||
if (everyoneHandling == TagHandling.Ignore) continue;
|
if (everyoneHandling == TagHandling.Ignore)
|
||||||
|
continue;
|
||||||
newText = ResolveEveryoneMention(tag, everyoneHandling);
|
newText = ResolveEveryoneMention(tag, everyoneHandling);
|
||||||
break;
|
break;
|
||||||
case TagType.HereMention:
|
case TagType.HereMention:
|
||||||
if (everyoneHandling == TagHandling.Ignore) continue;
|
if (everyoneHandling == TagHandling.Ignore)
|
||||||
|
continue;
|
||||||
newText = ResolveHereMention(tag, everyoneHandling);
|
newText = ResolveHereMention(tag, everyoneHandling);
|
||||||
break;
|
break;
|
||||||
case TagType.Emoji:
|
case TagType.Emoji:
|
||||||
if (emojiHandling == TagHandling.Ignore) continue;
|
if (emojiHandling == TagHandling.Ignore)
|
||||||
|
continue;
|
||||||
newText = ResolveEmoji(tag, emojiHandling);
|
newText = ResolveEmoji(tag, emojiHandling);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -36,8 +36,10 @@ namespace Discord
|
|||||||
|
|
||||||
public override bool Equals(object other)
|
public override bool Equals(object other)
|
||||||
{
|
{
|
||||||
if (!IsSpecified) return other == null;
|
if (!IsSpecified)
|
||||||
if (other == null) return false;
|
return other == null;
|
||||||
|
if (other == null)
|
||||||
|
return false;
|
||||||
return _value.Equals(other);
|
return _value.Equals(other);
|
||||||
}
|
}
|
||||||
public override int GetHashCode() => IsSpecified ? _value.GetHashCode() : 0;
|
public override int GetHashCode() => IsSpecified ? _value.GetHashCode() : 0;
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
using System.Collections;
|
using System.Collections;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Collections.Immutable;
|
using System.Collections.Immutable;
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
namespace Discord
|
namespace Discord
|
||||||
{
|
{
|
||||||
internal class PageInfo
|
internal class PageInfo
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -12,8 +12,10 @@ namespace Discord
|
|||||||
|
|
||||||
private static ArgumentNullException CreateNotNullException(string name, string msg)
|
private static ArgumentNullException CreateNotNullException(string name, string msg)
|
||||||
{
|
{
|
||||||
if (msg == null) return new ArgumentNullException(paramName: name);
|
if (msg == null)
|
||||||
else return new ArgumentNullException(paramName: name, message: msg);
|
return new ArgumentNullException(paramName: name);
|
||||||
|
else
|
||||||
|
return new ArgumentNullException(paramName: name, message: msg);
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
@@ -26,8 +28,10 @@ namespace Discord
|
|||||||
/// <exception cref="ArgumentNullException"><paramref name="obj"/> must not be <see langword="null"/>.</exception>
|
/// <exception cref="ArgumentNullException"><paramref name="obj"/> must not be <see langword="null"/>.</exception>
|
||||||
public static void NotNullOrEmpty(string obj, string name, string msg = null)
|
public static void NotNullOrEmpty(string obj, string name, string msg = null)
|
||||||
{
|
{
|
||||||
if (obj == null) throw CreateNotNullException(name, msg);
|
if (obj == null)
|
||||||
if (obj.Length == 0) throw CreateNotEmptyException(name, msg);
|
throw CreateNotNullException(name, msg);
|
||||||
|
if (obj.Length == 0)
|
||||||
|
throw CreateNotEmptyException(name, msg);
|
||||||
}
|
}
|
||||||
/// <exception cref="ArgumentException"><paramref name="obj"/> cannot be blank.</exception>
|
/// <exception cref="ArgumentException"><paramref name="obj"/> cannot be blank.</exception>
|
||||||
/// <exception cref="ArgumentNullException"><paramref name="obj"/> must not be <see langword="null"/>.</exception>
|
/// <exception cref="ArgumentNullException"><paramref name="obj"/> must not be <see langword="null"/>.</exception>
|
||||||
@@ -35,16 +39,20 @@ namespace Discord
|
|||||||
{
|
{
|
||||||
if (obj.IsSpecified)
|
if (obj.IsSpecified)
|
||||||
{
|
{
|
||||||
if (obj.Value == null) throw CreateNotNullException(name, msg);
|
if (obj.Value == null)
|
||||||
if (obj.Value.Length == 0) throw CreateNotEmptyException(name, msg);
|
throw CreateNotNullException(name, msg);
|
||||||
|
if (obj.Value.Length == 0)
|
||||||
|
throw CreateNotEmptyException(name, msg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/// <exception cref="ArgumentException"><paramref name="obj"/> cannot be blank.</exception>
|
/// <exception cref="ArgumentException"><paramref name="obj"/> cannot be blank.</exception>
|
||||||
/// <exception cref="ArgumentNullException"><paramref name="obj"/> must not be <see langword="null"/>.</exception>
|
/// <exception cref="ArgumentNullException"><paramref name="obj"/> must not be <see langword="null"/>.</exception>
|
||||||
public static void NotNullOrWhitespace(string obj, string name, string msg = null)
|
public static void NotNullOrWhitespace(string obj, string name, string msg = null)
|
||||||
{
|
{
|
||||||
if (obj == null) throw CreateNotNullException(name, msg);
|
if (obj == null)
|
||||||
if (obj.Trim().Length == 0) throw CreateNotEmptyException(name, msg);
|
throw CreateNotNullException(name, msg);
|
||||||
|
if (obj.Trim().Length == 0)
|
||||||
|
throw CreateNotEmptyException(name, msg);
|
||||||
}
|
}
|
||||||
/// <exception cref="ArgumentException"><paramref name="obj"/> cannot be blank.</exception>
|
/// <exception cref="ArgumentException"><paramref name="obj"/> cannot be blank.</exception>
|
||||||
/// <exception cref="ArgumentNullException"><paramref name="obj"/> must not be <see langword="null"/>.</exception>
|
/// <exception cref="ArgumentNullException"><paramref name="obj"/> must not be <see langword="null"/>.</exception>
|
||||||
@@ -52,8 +60,10 @@ namespace Discord
|
|||||||
{
|
{
|
||||||
if (obj.IsSpecified)
|
if (obj.IsSpecified)
|
||||||
{
|
{
|
||||||
if (obj.Value == null) throw CreateNotNullException(name, msg);
|
if (obj.Value == null)
|
||||||
if (obj.Value.Trim().Length == 0) throw CreateNotEmptyException(name, msg);
|
throw CreateNotNullException(name, msg);
|
||||||
|
if (obj.Value.Trim().Length == 0)
|
||||||
|
throw CreateNotEmptyException(name, msg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -282,7 +292,8 @@ namespace Discord
|
|||||||
var minimum = SnowflakeUtils.ToSnowflake(DateTimeOffset.UtcNow.Subtract(TimeSpan.FromDays(14)));
|
var minimum = SnowflakeUtils.ToSnowflake(DateTimeOffset.UtcNow.Subtract(TimeSpan.FromDays(14)));
|
||||||
for (var i = 0; i < collection.Length; i++)
|
for (var i = 0; i < collection.Length; i++)
|
||||||
{
|
{
|
||||||
if (collection[i] == 0) continue;
|
if (collection[i] == 0)
|
||||||
|
continue;
|
||||||
if (collection[i] <= minimum)
|
if (collection[i] <= minimum)
|
||||||
throw new ArgumentOutOfRangeException(name, "Messages must be younger than two weeks old.");
|
throw new ArgumentOutOfRangeException(name, "Messages must be younger than two weeks old.");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ namespace Discord.Interactions
|
|||||||
/// Specify the target channel types for a <see cref="ApplicationCommandOptionType.Channel"/> option.
|
/// Specify the target channel types for a <see cref="ApplicationCommandOptionType.Channel"/> option.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="channelTypes">The allowed channel types for this option.</param>
|
/// <param name="channelTypes">The allowed channel types for this option.</param>
|
||||||
public ChannelTypesAttribute (params ChannelType[] channelTypes)
|
public ChannelTypesAttribute(params ChannelType[] channelTypes)
|
||||||
{
|
{
|
||||||
if (channelTypes is null)
|
if (channelTypes is null)
|
||||||
throw new ArgumentNullException(nameof(channelTypes));
|
throw new ArgumentNullException(nameof(channelTypes));
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ namespace Discord.Interactions
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public object Value { get; }
|
public object Value { get; }
|
||||||
|
|
||||||
private ChoiceAttribute (string name)
|
private ChoiceAttribute(string name)
|
||||||
{
|
{
|
||||||
Name = name;
|
Name = name;
|
||||||
}
|
}
|
||||||
@@ -33,7 +33,7 @@ namespace Discord.Interactions
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="name">Name of the choice.</param>
|
/// <param name="name">Name of the choice.</param>
|
||||||
/// <param name="value">Predefined value of the choice.</param>
|
/// <param name="value">Predefined value of the choice.</param>
|
||||||
public ChoiceAttribute (string name, string value) : this(name)
|
public ChoiceAttribute(string name, string value) : this(name)
|
||||||
{
|
{
|
||||||
Type = SlashCommandChoiceType.String;
|
Type = SlashCommandChoiceType.String;
|
||||||
Value = value;
|
Value = value;
|
||||||
@@ -44,7 +44,7 @@ namespace Discord.Interactions
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="name">Name of the choice.</param>
|
/// <param name="name">Name of the choice.</param>
|
||||||
/// <param name="value">Predefined value of the choice.</param>
|
/// <param name="value">Predefined value of the choice.</param>
|
||||||
public ChoiceAttribute (string name, int value) : this(name)
|
public ChoiceAttribute(string name, int value) : this(name)
|
||||||
{
|
{
|
||||||
Type = SlashCommandChoiceType.Integer;
|
Type = SlashCommandChoiceType.Integer;
|
||||||
Value = value;
|
Value = value;
|
||||||
@@ -55,7 +55,7 @@ namespace Discord.Interactions
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="name">Name of the choice.</param>
|
/// <param name="name">Name of the choice.</param>
|
||||||
/// <param name="value">Predefined value of the choice.</param>
|
/// <param name="value">Predefined value of the choice.</param>
|
||||||
public ChoiceAttribute (string name, double value) : this(name)
|
public ChoiceAttribute(string name, double value) : this(name)
|
||||||
{
|
{
|
||||||
Type = SlashCommandChoiceType.Number;
|
Type = SlashCommandChoiceType.Number;
|
||||||
Value = value;
|
Value = value;
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ namespace Discord.Interactions
|
|||||||
/// <param name="customId">String to compare the Message Component CustomIDs with.</param>
|
/// <param name="customId">String to compare the Message Component CustomIDs with.</param>
|
||||||
/// <param name="ignoreGroupNames">If <see langword="true"/> <see cref="GroupAttribute"/>s will be ignored while creating this command and this method will be treated as a top level command.</param>
|
/// <param name="ignoreGroupNames">If <see langword="true"/> <see cref="GroupAttribute"/>s will be ignored while creating this command and this method will be treated as a top level command.</param>
|
||||||
/// <param name="runMode">Set the run mode of the command.</param>
|
/// <param name="runMode">Set the run mode of the command.</param>
|
||||||
public ComponentInteractionAttribute (string customId, bool ignoreGroupNames = false, RunMode runMode = RunMode.Default)
|
public ComponentInteractionAttribute(string customId, bool ignoreGroupNames = false, RunMode runMode = RunMode.Default)
|
||||||
{
|
{
|
||||||
CustomId = customId;
|
CustomId = customId;
|
||||||
IgnoreGroupNames = ignoreGroupNames;
|
IgnoreGroupNames = ignoreGroupNames;
|
||||||
|
|||||||
@@ -24,13 +24,13 @@ namespace Discord.Interactions
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public RunMode RunMode { get; }
|
public RunMode RunMode { get; }
|
||||||
|
|
||||||
internal ContextCommandAttribute (string name, ApplicationCommandType commandType, RunMode runMode = RunMode.Default)
|
internal ContextCommandAttribute(string name, ApplicationCommandType commandType, RunMode runMode = RunMode.Default)
|
||||||
{
|
{
|
||||||
Name = name;
|
Name = name;
|
||||||
CommandType = commandType;
|
CommandType = commandType;
|
||||||
RunMode = runMode;
|
RunMode = runMode;
|
||||||
}
|
}
|
||||||
|
|
||||||
internal virtual void CheckMethodDefinition (MethodInfo methodInfo) { }
|
internal virtual void CheckMethodDefinition(MethodInfo methodInfo) { }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,9 +16,9 @@ namespace Discord.Interactions
|
|||||||
/// Register a method as a Message Context Command.
|
/// Register a method as a Message Context Command.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="name">Name of the context command.</param>
|
/// <param name="name">Name of the context command.</param>
|
||||||
public MessageCommandAttribute (string name) : base(name, ApplicationCommandType.Message) { }
|
public MessageCommandAttribute(string name) : base(name, ApplicationCommandType.Message) { }
|
||||||
|
|
||||||
internal override void CheckMethodDefinition (MethodInfo methodInfo)
|
internal override void CheckMethodDefinition(MethodInfo methodInfo)
|
||||||
{
|
{
|
||||||
var parameters = methodInfo.GetParameters();
|
var parameters = methodInfo.GetParameters();
|
||||||
|
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ namespace Discord.Interactions
|
|||||||
/// <param name="description">Description of the command.</param>
|
/// <param name="description">Description of the command.</param>
|
||||||
/// <param name="ignoreGroupNames"> If <see langword="true"/>, <see cref="GroupAttribute"/>s will be ignored while creating this command and this method will be treated as a top level command.</param>
|
/// <param name="ignoreGroupNames"> If <see langword="true"/>, <see cref="GroupAttribute"/>s will be ignored while creating this command and this method will be treated as a top level command.</param>
|
||||||
/// <param name="runMode">Set the run mode of the command.</param>
|
/// <param name="runMode">Set the run mode of the command.</param>
|
||||||
public SlashCommandAttribute (string name, string description, bool ignoreGroupNames = false, RunMode runMode = RunMode.Default)
|
public SlashCommandAttribute(string name, string description, bool ignoreGroupNames = false, RunMode runMode = RunMode.Default)
|
||||||
{
|
{
|
||||||
Name = name;
|
Name = name;
|
||||||
Description = description;
|
Description = description;
|
||||||
|
|||||||
@@ -16,9 +16,9 @@ namespace Discord.Interactions
|
|||||||
/// Register a command as a User Context Command.
|
/// Register a command as a User Context Command.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="name">Name of this User Context Command.</param>
|
/// <param name="name">Name of this User Context Command.</param>
|
||||||
public UserCommandAttribute (string name) : base(name, ApplicationCommandType.User) { }
|
public UserCommandAttribute(string name) : base(name, ApplicationCommandType.User) { }
|
||||||
|
|
||||||
internal override void CheckMethodDefinition (MethodInfo methodInfo)
|
internal override void CheckMethodDefinition(MethodInfo methodInfo)
|
||||||
{
|
{
|
||||||
var parameters = methodInfo.GetParameters();
|
var parameters = methodInfo.GetParameters();
|
||||||
|
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ namespace Discord.Interactions
|
|||||||
/// Set the default permission of a Slash Command.
|
/// Set the default permission of a Slash Command.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="isDefaultPermission"><see langword="true"/> if the users are allowed to use this command.</param>
|
/// <param name="isDefaultPermission"><see langword="true"/> if the users are allowed to use this command.</param>
|
||||||
public DefaultPermissionAttribute (bool isDefaultPermission)
|
public DefaultPermissionAttribute(bool isDefaultPermission)
|
||||||
{
|
{
|
||||||
IsDefaultPermission = isDefaultPermission;
|
IsDefaultPermission = isDefaultPermission;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ namespace Discord.Interactions
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="name">Name of the group.</param>
|
/// <param name="name">Name of the group.</param>
|
||||||
/// <param name="description">Description of the group.</param>
|
/// <param name="description">Description of the group.</param>
|
||||||
public GroupAttribute (string name, string description)
|
public GroupAttribute(string name, string description)
|
||||||
{
|
{
|
||||||
Name = name;
|
Name = name;
|
||||||
Description = description;
|
Description = description;
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ namespace Discord.Interactions
|
|||||||
/// <param name="parameterInfo">The parameter of the command being checked against.</param>
|
/// <param name="parameterInfo">The parameter of the command being checked against.</param>
|
||||||
/// <param name="value">The raw value of the parameter.</param>
|
/// <param name="value">The raw value of the parameter.</param>
|
||||||
/// <param name="services">The service collection used for dependency injection.</param>
|
/// <param name="services">The service collection used for dependency injection.</param>
|
||||||
public abstract Task<PreconditionResult> CheckRequirementsAsync (IInteractionContext context, IParameterInfo parameterInfo, object value,
|
public abstract Task<PreconditionResult> CheckRequirementsAsync(IInteractionContext context, IParameterInfo parameterInfo, object value,
|
||||||
IServiceProvider services);
|
IServiceProvider services);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -37,6 +37,6 @@ namespace Discord.Interactions
|
|||||||
/// <param name="context">The context of the command.</param>
|
/// <param name="context">The context of the command.</param>
|
||||||
/// <param name="commandInfo">The command being executed.</param>
|
/// <param name="commandInfo">The command being executed.</param>
|
||||||
/// <param name="services">The service collection used for dependency injection.</param>
|
/// <param name="services">The service collection used for dependency injection.</param>
|
||||||
public abstract Task<PreconditionResult> CheckRequirementsAsync (IInteractionContext context, ICommandInfo commandInfo, IServiceProvider services);
|
public abstract Task<PreconditionResult> CheckRequirementsAsync(IInteractionContext context, ICommandInfo commandInfo, IServiceProvider services);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ namespace Discord.Interactions
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="name">Name of the parameter.</param>
|
/// <param name="name">Name of the parameter.</param>
|
||||||
/// <param name="description">Description of the parameter.</param>
|
/// <param name="description">Description of the parameter.</param>
|
||||||
public SummaryAttribute (string name = null, string description = null)
|
public SummaryAttribute(string name = null, string description = null)
|
||||||
{
|
{
|
||||||
Name = name;
|
Name = name;
|
||||||
Description = description;
|
Description = description;
|
||||||
|
|||||||
@@ -53,7 +53,7 @@ namespace Discord.Interactions.Builders
|
|||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
IReadOnlyList<IParameterBuilder> ICommandBuilder.Parameters => Parameters;
|
IReadOnlyList<IParameterBuilder> ICommandBuilder.Parameters => Parameters;
|
||||||
|
|
||||||
internal CommandBuilder (ModuleBuilder module)
|
internal CommandBuilder(ModuleBuilder module)
|
||||||
{
|
{
|
||||||
_attributes = new List<Attribute>();
|
_attributes = new List<Attribute>();
|
||||||
_preconditions = new List<PreconditionAttribute>();
|
_preconditions = new List<PreconditionAttribute>();
|
||||||
@@ -62,7 +62,7 @@ namespace Discord.Interactions.Builders
|
|||||||
Module = module;
|
Module = module;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected CommandBuilder (ModuleBuilder module, string name, ExecuteCallback callback) : this(module)
|
protected CommandBuilder(ModuleBuilder module, string name, ExecuteCallback callback) : this(module)
|
||||||
{
|
{
|
||||||
Name = name;
|
Name = name;
|
||||||
Callback = callback;
|
Callback = callback;
|
||||||
@@ -75,7 +75,7 @@ namespace Discord.Interactions.Builders
|
|||||||
/// <returns>
|
/// <returns>
|
||||||
/// The builder instance.
|
/// The builder instance.
|
||||||
/// </returns>
|
/// </returns>
|
||||||
public TBuilder WithName (string name)
|
public TBuilder WithName(string name)
|
||||||
{
|
{
|
||||||
Name = name;
|
Name = name;
|
||||||
return Instance;
|
return Instance;
|
||||||
@@ -88,7 +88,7 @@ namespace Discord.Interactions.Builders
|
|||||||
/// <returns>
|
/// <returns>
|
||||||
/// The builder instance.
|
/// The builder instance.
|
||||||
/// </returns>
|
/// </returns>
|
||||||
public TBuilder WithMethodName (string name)
|
public TBuilder WithMethodName(string name)
|
||||||
{
|
{
|
||||||
MethodName = name;
|
MethodName = name;
|
||||||
return Instance;
|
return Instance;
|
||||||
@@ -101,7 +101,7 @@ namespace Discord.Interactions.Builders
|
|||||||
/// <returns>
|
/// <returns>
|
||||||
/// The builder instance.
|
/// The builder instance.
|
||||||
/// </returns>
|
/// </returns>
|
||||||
public TBuilder WithAttributes (params Attribute[] attributes)
|
public TBuilder WithAttributes(params Attribute[] attributes)
|
||||||
{
|
{
|
||||||
_attributes.AddRange(attributes);
|
_attributes.AddRange(attributes);
|
||||||
return Instance;
|
return Instance;
|
||||||
@@ -114,7 +114,7 @@ namespace Discord.Interactions.Builders
|
|||||||
/// <returns>
|
/// <returns>
|
||||||
/// The builder instance.
|
/// The builder instance.
|
||||||
/// </returns>
|
/// </returns>
|
||||||
public TBuilder SetRunMode (RunMode runMode)
|
public TBuilder SetRunMode(RunMode runMode)
|
||||||
{
|
{
|
||||||
RunMode = runMode;
|
RunMode = runMode;
|
||||||
return Instance;
|
return Instance;
|
||||||
@@ -127,7 +127,7 @@ namespace Discord.Interactions.Builders
|
|||||||
/// <returns>
|
/// <returns>
|
||||||
/// The builder instance.
|
/// The builder instance.
|
||||||
/// </returns>
|
/// </returns>
|
||||||
public TBuilder WithNameAsRegex (bool value)
|
public TBuilder WithNameAsRegex(bool value)
|
||||||
{
|
{
|
||||||
TreatNameAsRegex = value;
|
TreatNameAsRegex = value;
|
||||||
return Instance;
|
return Instance;
|
||||||
@@ -140,7 +140,7 @@ namespace Discord.Interactions.Builders
|
|||||||
/// <returns>
|
/// <returns>
|
||||||
/// The builder instance.
|
/// The builder instance.
|
||||||
/// </returns>
|
/// </returns>
|
||||||
public TBuilder AddParameters (params TParamBuilder[] parameters)
|
public TBuilder AddParameters(params TParamBuilder[] parameters)
|
||||||
{
|
{
|
||||||
_parameters.AddRange(parameters);
|
_parameters.AddRange(parameters);
|
||||||
return Instance;
|
return Instance;
|
||||||
@@ -153,30 +153,30 @@ namespace Discord.Interactions.Builders
|
|||||||
/// <returns>
|
/// <returns>
|
||||||
/// The builder instance.
|
/// The builder instance.
|
||||||
/// </returns>
|
/// </returns>
|
||||||
public TBuilder WithPreconditions (params PreconditionAttribute[] preconditions)
|
public TBuilder WithPreconditions(params PreconditionAttribute[] preconditions)
|
||||||
{
|
{
|
||||||
_preconditions.AddRange(preconditions);
|
_preconditions.AddRange(preconditions);
|
||||||
return Instance;
|
return Instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
public abstract TBuilder AddParameter (Action<TParamBuilder> configure);
|
public abstract TBuilder AddParameter(Action<TParamBuilder> configure);
|
||||||
|
|
||||||
internal abstract TInfo Build (ModuleInfo module, InteractionService commandService);
|
internal abstract TInfo Build(ModuleInfo module, InteractionService commandService);
|
||||||
|
|
||||||
//ICommandBuilder
|
//ICommandBuilder
|
||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
ICommandBuilder ICommandBuilder.WithName (string name) =>
|
ICommandBuilder ICommandBuilder.WithName(string name) =>
|
||||||
WithName(name);
|
WithName(name);
|
||||||
|
|
||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
ICommandBuilder ICommandBuilder.WithMethodName (string name) =>
|
ICommandBuilder ICommandBuilder.WithMethodName(string name) =>
|
||||||
WithMethodName(name);
|
WithMethodName(name);
|
||||||
ICommandBuilder ICommandBuilder.WithAttributes (params Attribute[] attributes) =>
|
ICommandBuilder ICommandBuilder.WithAttributes(params Attribute[] attributes) =>
|
||||||
WithAttributes(attributes);
|
WithAttributes(attributes);
|
||||||
|
|
||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
ICommandBuilder ICommandBuilder.SetRunMode (RunMode runMode) =>
|
ICommandBuilder ICommandBuilder.SetRunMode(RunMode runMode) =>
|
||||||
SetRunMode(runMode);
|
SetRunMode(runMode);
|
||||||
|
|
||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
@@ -184,11 +184,11 @@ namespace Discord.Interactions.Builders
|
|||||||
WithNameAsRegex(value);
|
WithNameAsRegex(value);
|
||||||
|
|
||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
ICommandBuilder ICommandBuilder.AddParameters (params IParameterBuilder[] parameters) =>
|
ICommandBuilder ICommandBuilder.AddParameters(params IParameterBuilder[] parameters) =>
|
||||||
AddParameters(parameters as TParamBuilder);
|
AddParameters(parameters as TParamBuilder);
|
||||||
|
|
||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
ICommandBuilder ICommandBuilder.WithPreconditions (params PreconditionAttribute[] preconditions) =>
|
ICommandBuilder ICommandBuilder.WithPreconditions(params PreconditionAttribute[] preconditions) =>
|
||||||
WithPreconditions(preconditions);
|
WithPreconditions(preconditions);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ namespace Discord.Interactions.Builders
|
|||||||
{
|
{
|
||||||
protected override ComponentCommandBuilder Instance => this;
|
protected override ComponentCommandBuilder Instance => this;
|
||||||
|
|
||||||
internal ComponentCommandBuilder (ModuleBuilder module) : base(module) { }
|
internal ComponentCommandBuilder(ModuleBuilder module) : base(module) { }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Initializes a new <see cref="ComponentBuilder"/>.
|
/// Initializes a new <see cref="ComponentBuilder"/>.
|
||||||
@@ -17,7 +17,7 @@ namespace Discord.Interactions.Builders
|
|||||||
/// <param name="module">Parent module of this command.</param>
|
/// <param name="module">Parent module of this command.</param>
|
||||||
/// <param name="name">Name of this command.</param>
|
/// <param name="name">Name of this command.</param>
|
||||||
/// <param name="callback">Execution callback of this command.</param>
|
/// <param name="callback">Execution callback of this command.</param>
|
||||||
public ComponentCommandBuilder (ModuleBuilder module, string name, ExecuteCallback callback) : base(module, name, callback) { }
|
public ComponentCommandBuilder(ModuleBuilder module, string name, ExecuteCallback callback) : base(module, name, callback) { }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Adds a command parameter to the parameters collection.
|
/// Adds a command parameter to the parameters collection.
|
||||||
@@ -26,7 +26,7 @@ namespace Discord.Interactions.Builders
|
|||||||
/// <returns>
|
/// <returns>
|
||||||
/// The builder instance.
|
/// The builder instance.
|
||||||
/// </returns>
|
/// </returns>
|
||||||
public override ComponentCommandBuilder AddParameter (Action<ComponentCommandParameterBuilder> configure)
|
public override ComponentCommandBuilder AddParameter(Action<ComponentCommandParameterBuilder> configure)
|
||||||
{
|
{
|
||||||
var parameter = new ComponentCommandParameterBuilder(this);
|
var parameter = new ComponentCommandParameterBuilder(this);
|
||||||
configure(parameter);
|
configure(parameter);
|
||||||
@@ -34,7 +34,7 @@ namespace Discord.Interactions.Builders
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
internal override ComponentCommandInfo Build (ModuleInfo module, InteractionService commandService) =>
|
internal override ComponentCommandInfo Build(ModuleInfo module, InteractionService commandService) =>
|
||||||
new ComponentCommandInfo(this, module, commandService);
|
new ComponentCommandInfo(this, module, commandService);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ namespace Discord.Interactions.Builders
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public GuildPermission? DefaultMemberPermissions { get; set; } = null;
|
public GuildPermission? DefaultMemberPermissions { get; set; } = null;
|
||||||
|
|
||||||
internal ContextCommandBuilder (ModuleBuilder module) : base(module) { }
|
internal ContextCommandBuilder(ModuleBuilder module) : base(module) { }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Initializes a new <see cref="ContextCommandBuilder"/>.
|
/// Initializes a new <see cref="ContextCommandBuilder"/>.
|
||||||
@@ -43,7 +43,7 @@ namespace Discord.Interactions.Builders
|
|||||||
/// <param name="module">Parent module of this command.</param>
|
/// <param name="module">Parent module of this command.</param>
|
||||||
/// <param name="name">Name of this command.</param>
|
/// <param name="name">Name of this command.</param>
|
||||||
/// <param name="callback">Execution callback of this command.</param>
|
/// <param name="callback">Execution callback of this command.</param>
|
||||||
public ContextCommandBuilder (ModuleBuilder module, string name, ExecuteCallback callback) : base(module, name, callback) { }
|
public ContextCommandBuilder(ModuleBuilder module, string name, ExecuteCallback callback) : base(module, name, callback) { }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Sets <see cref="CommandType"/>.
|
/// Sets <see cref="CommandType"/>.
|
||||||
@@ -52,7 +52,7 @@ namespace Discord.Interactions.Builders
|
|||||||
/// <returns>
|
/// <returns>
|
||||||
/// The builder instance.
|
/// The builder instance.
|
||||||
/// </returns>
|
/// </returns>
|
||||||
public ContextCommandBuilder SetType (ApplicationCommandType commandType)
|
public ContextCommandBuilder SetType(ApplicationCommandType commandType)
|
||||||
{
|
{
|
||||||
CommandType = commandType;
|
CommandType = commandType;
|
||||||
return this;
|
return this;
|
||||||
@@ -66,7 +66,7 @@ namespace Discord.Interactions.Builders
|
|||||||
/// The builder instance.
|
/// The builder instance.
|
||||||
/// </returns>
|
/// </returns>
|
||||||
[Obsolete($"To be deprecated soon, use {nameof(SetEnabledInDm)} and {nameof(WithDefaultMemberPermissions)} instead.")]
|
[Obsolete($"To be deprecated soon, use {nameof(SetEnabledInDm)} and {nameof(WithDefaultMemberPermissions)} instead.")]
|
||||||
public ContextCommandBuilder SetDefaultPermission (bool defaultPermision)
|
public ContextCommandBuilder SetDefaultPermission(bool defaultPermision)
|
||||||
{
|
{
|
||||||
DefaultPermission = defaultPermision;
|
DefaultPermission = defaultPermision;
|
||||||
return this;
|
return this;
|
||||||
@@ -79,7 +79,7 @@ namespace Discord.Interactions.Builders
|
|||||||
/// <returns>
|
/// <returns>
|
||||||
/// The builder instance.
|
/// The builder instance.
|
||||||
/// </returns>
|
/// </returns>
|
||||||
public override ContextCommandBuilder AddParameter (Action<CommandParameterBuilder> configure)
|
public override ContextCommandBuilder AddParameter(Action<CommandParameterBuilder> configure)
|
||||||
{
|
{
|
||||||
var parameter = new CommandParameterBuilder(this);
|
var parameter = new CommandParameterBuilder(this);
|
||||||
configure(parameter);
|
configure(parameter);
|
||||||
@@ -126,7 +126,7 @@ namespace Discord.Interactions.Builders
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
internal override ContextCommandInfo Build (ModuleInfo module, InteractionService commandService) =>
|
internal override ContextCommandInfo Build(ModuleInfo module, InteractionService commandService) =>
|
||||||
ContextCommandInfo.Create(this, module, commandService);
|
ContextCommandInfo.Create(this, module, commandService);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -66,7 +66,7 @@ namespace Discord.Interactions.Builders
|
|||||||
/// <returns>
|
/// <returns>
|
||||||
/// The builder instance.
|
/// The builder instance.
|
||||||
/// </returns>
|
/// </returns>
|
||||||
ICommandBuilder WithName (string name);
|
ICommandBuilder WithName(string name);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Sets <see cref="MethodName"/>.
|
/// Sets <see cref="MethodName"/>.
|
||||||
@@ -75,7 +75,7 @@ namespace Discord.Interactions.Builders
|
|||||||
/// <returns>
|
/// <returns>
|
||||||
/// The builder instance.
|
/// The builder instance.
|
||||||
/// </returns>
|
/// </returns>
|
||||||
ICommandBuilder WithMethodName (string name);
|
ICommandBuilder WithMethodName(string name);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Adds attributes to <see cref="Attributes"/>.
|
/// Adds attributes to <see cref="Attributes"/>.
|
||||||
@@ -84,7 +84,7 @@ namespace Discord.Interactions.Builders
|
|||||||
/// <returns>
|
/// <returns>
|
||||||
/// The builder instance.
|
/// The builder instance.
|
||||||
/// </returns>
|
/// </returns>
|
||||||
ICommandBuilder WithAttributes (params Attribute[] attributes);
|
ICommandBuilder WithAttributes(params Attribute[] attributes);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Sets <see cref="RunMode"/>.
|
/// Sets <see cref="RunMode"/>.
|
||||||
@@ -93,7 +93,7 @@ namespace Discord.Interactions.Builders
|
|||||||
/// <returns>
|
/// <returns>
|
||||||
/// The builder instance.
|
/// The builder instance.
|
||||||
/// </returns>
|
/// </returns>
|
||||||
ICommandBuilder SetRunMode (RunMode runMode);
|
ICommandBuilder SetRunMode(RunMode runMode);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Sets <see cref="TreatNameAsRegex"/>.
|
/// Sets <see cref="TreatNameAsRegex"/>.
|
||||||
@@ -111,7 +111,7 @@ namespace Discord.Interactions.Builders
|
|||||||
/// <returns>
|
/// <returns>
|
||||||
/// The builder instance.
|
/// The builder instance.
|
||||||
/// </returns>
|
/// </returns>
|
||||||
ICommandBuilder AddParameters (params IParameterBuilder[] parameters);
|
ICommandBuilder AddParameters(params IParameterBuilder[] parameters);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Adds preconditions to <see cref="Preconditions"/>.
|
/// Adds preconditions to <see cref="Preconditions"/>.
|
||||||
@@ -120,6 +120,6 @@ namespace Discord.Interactions.Builders
|
|||||||
/// <returns>
|
/// <returns>
|
||||||
/// The builder instance.
|
/// The builder instance.
|
||||||
/// </returns>
|
/// </returns>
|
||||||
ICommandBuilder WithPreconditions (params PreconditionAttribute[] preconditions);
|
ICommandBuilder WithPreconditions(params PreconditionAttribute[] preconditions);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ namespace Discord.Interactions.Builders
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public GuildPermission? DefaultMemberPermissions { get; set; } = null;
|
public GuildPermission? DefaultMemberPermissions { get; set; } = null;
|
||||||
|
|
||||||
internal SlashCommandBuilder (ModuleBuilder module) : base(module) { }
|
internal SlashCommandBuilder(ModuleBuilder module) : base(module) { }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Initializes a new <see cref="SlashCommandBuilder"/>.
|
/// Initializes a new <see cref="SlashCommandBuilder"/>.
|
||||||
@@ -43,7 +43,7 @@ namespace Discord.Interactions.Builders
|
|||||||
/// <param name="module">Parent module of this command.</param>
|
/// <param name="module">Parent module of this command.</param>
|
||||||
/// <param name="name">Name of this command.</param>
|
/// <param name="name">Name of this command.</param>
|
||||||
/// <param name="callback">Execution callback of this command.</param>
|
/// <param name="callback">Execution callback of this command.</param>
|
||||||
public SlashCommandBuilder (ModuleBuilder module, string name, ExecuteCallback callback) : base(module, name, callback) { }
|
public SlashCommandBuilder(ModuleBuilder module, string name, ExecuteCallback callback) : base(module, name, callback) { }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Sets <see cref="Description"/>.
|
/// Sets <see cref="Description"/>.
|
||||||
@@ -52,7 +52,7 @@ namespace Discord.Interactions.Builders
|
|||||||
/// <returns>
|
/// <returns>
|
||||||
/// The builder instance.
|
/// The builder instance.
|
||||||
/// </returns>
|
/// </returns>
|
||||||
public SlashCommandBuilder WithDescription (string description)
|
public SlashCommandBuilder WithDescription(string description)
|
||||||
{
|
{
|
||||||
Description = description;
|
Description = description;
|
||||||
return this;
|
return this;
|
||||||
@@ -66,7 +66,7 @@ namespace Discord.Interactions.Builders
|
|||||||
/// The builder instance.
|
/// The builder instance.
|
||||||
/// </returns>
|
/// </returns>
|
||||||
[Obsolete($"To be deprecated soon, use {nameof(SetEnabledInDm)} and {nameof(WithDefaultMemberPermissions)} instead.")]
|
[Obsolete($"To be deprecated soon, use {nameof(SetEnabledInDm)} and {nameof(WithDefaultMemberPermissions)} instead.")]
|
||||||
public SlashCommandBuilder WithDefaultPermission (bool permission)
|
public SlashCommandBuilder WithDefaultPermission(bool permission)
|
||||||
{
|
{
|
||||||
DefaultPermission = permission;
|
DefaultPermission = permission;
|
||||||
return Instance;
|
return Instance;
|
||||||
@@ -79,7 +79,7 @@ namespace Discord.Interactions.Builders
|
|||||||
/// <returns>
|
/// <returns>
|
||||||
/// The builder instance.
|
/// The builder instance.
|
||||||
/// </returns>
|
/// </returns>
|
||||||
public override SlashCommandBuilder AddParameter (Action<SlashCommandParameterBuilder> configure)
|
public override SlashCommandBuilder AddParameter(Action<SlashCommandParameterBuilder> configure)
|
||||||
{
|
{
|
||||||
var parameter = new SlashCommandParameterBuilder(this);
|
var parameter = new SlashCommandParameterBuilder(this);
|
||||||
configure(parameter);
|
configure(parameter);
|
||||||
@@ -126,7 +126,7 @@ namespace Discord.Interactions.Builders
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
internal override SlashCommandInfo Build (ModuleInfo module, InteractionService commandService) =>
|
internal override SlashCommandInfo Build(ModuleInfo module, InteractionService commandService) =>
|
||||||
new SlashCommandInfo(this, module, commandService);
|
new SlashCommandInfo(this, module, commandService);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -116,7 +116,7 @@ namespace Discord.Interactions.Builders
|
|||||||
|
|
||||||
internal TypeInfo TypeInfo { get; set; }
|
internal TypeInfo TypeInfo { get; set; }
|
||||||
|
|
||||||
internal ModuleBuilder (InteractionService interactionService, ModuleBuilder parent = null)
|
internal ModuleBuilder(InteractionService interactionService, ModuleBuilder parent = null)
|
||||||
{
|
{
|
||||||
InteractionService = interactionService;
|
InteractionService = interactionService;
|
||||||
Parent = parent;
|
Parent = parent;
|
||||||
@@ -127,7 +127,7 @@ namespace Discord.Interactions.Builders
|
|||||||
_contextCommands = new List<ContextCommandBuilder>();
|
_contextCommands = new List<ContextCommandBuilder>();
|
||||||
_componentCommands = new List<ComponentCommandBuilder>();
|
_componentCommands = new List<ComponentCommandBuilder>();
|
||||||
_autocompleteCommands = new List<AutocompleteCommandBuilder>();
|
_autocompleteCommands = new List<AutocompleteCommandBuilder>();
|
||||||
_modalCommands = new List<ModalCommandBuilder> ();
|
_modalCommands = new List<ModalCommandBuilder>();
|
||||||
_preconditions = new List<PreconditionAttribute>();
|
_preconditions = new List<PreconditionAttribute>();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -137,7 +137,7 @@ namespace Discord.Interactions.Builders
|
|||||||
/// <param name="interactionService">The underlying Interaction Service.</param>
|
/// <param name="interactionService">The underlying Interaction Service.</param>
|
||||||
/// <param name="name">Name of this module.</param>
|
/// <param name="name">Name of this module.</param>
|
||||||
/// <param name="parent">Parent module of this sub-module.</param>
|
/// <param name="parent">Parent module of this sub-module.</param>
|
||||||
public ModuleBuilder (InteractionService interactionService, string name, ModuleBuilder parent = null) : this(interactionService, parent)
|
public ModuleBuilder(InteractionService interactionService, string name, ModuleBuilder parent = null) : this(interactionService, parent)
|
||||||
{
|
{
|
||||||
Name = name;
|
Name = name;
|
||||||
}
|
}
|
||||||
@@ -149,7 +149,7 @@ namespace Discord.Interactions.Builders
|
|||||||
/// <returns>
|
/// <returns>
|
||||||
/// The builder instance.
|
/// The builder instance.
|
||||||
/// </returns>
|
/// </returns>
|
||||||
public ModuleBuilder WithGroupName (string name)
|
public ModuleBuilder WithGroupName(string name)
|
||||||
{
|
{
|
||||||
SlashGroupName = name;
|
SlashGroupName = name;
|
||||||
return this;
|
return this;
|
||||||
@@ -162,7 +162,7 @@ namespace Discord.Interactions.Builders
|
|||||||
/// <returns>
|
/// <returns>
|
||||||
/// The builder instance.
|
/// The builder instance.
|
||||||
/// </returns>
|
/// </returns>
|
||||||
public ModuleBuilder WithDescription (string description)
|
public ModuleBuilder WithDescription(string description)
|
||||||
{
|
{
|
||||||
Description = description;
|
Description = description;
|
||||||
return this;
|
return this;
|
||||||
@@ -176,7 +176,7 @@ namespace Discord.Interactions.Builders
|
|||||||
/// The builder instance.
|
/// The builder instance.
|
||||||
/// </returns>
|
/// </returns>
|
||||||
[Obsolete($"To be deprecated soon, use {nameof(SetEnabledInDm)} and {nameof(WithDefaultMemberPermissions)} instead.")]
|
[Obsolete($"To be deprecated soon, use {nameof(SetEnabledInDm)} and {nameof(WithDefaultMemberPermissions)} instead.")]
|
||||||
public ModuleBuilder WithDefaultPermission (bool permission)
|
public ModuleBuilder WithDefaultPermission(bool permission)
|
||||||
{
|
{
|
||||||
DefaultPermission = permission;
|
DefaultPermission = permission;
|
||||||
return this;
|
return this;
|
||||||
@@ -228,7 +228,7 @@ namespace Discord.Interactions.Builders
|
|||||||
/// <returns>
|
/// <returns>
|
||||||
/// The builder instance.
|
/// The builder instance.
|
||||||
/// </returns>
|
/// </returns>
|
||||||
public ModuleBuilder AddAttributes (params Attribute[] attributes)
|
public ModuleBuilder AddAttributes(params Attribute[] attributes)
|
||||||
{
|
{
|
||||||
_attributes.AddRange(attributes);
|
_attributes.AddRange(attributes);
|
||||||
return this;
|
return this;
|
||||||
@@ -241,7 +241,7 @@ namespace Discord.Interactions.Builders
|
|||||||
/// <returns>
|
/// <returns>
|
||||||
/// The builder instance.
|
/// The builder instance.
|
||||||
/// </returns>
|
/// </returns>
|
||||||
public ModuleBuilder AddPreconditions (params PreconditionAttribute[] preconditions)
|
public ModuleBuilder AddPreconditions(params PreconditionAttribute[] preconditions)
|
||||||
{
|
{
|
||||||
_preconditions.AddRange(preconditions);
|
_preconditions.AddRange(preconditions);
|
||||||
return this;
|
return this;
|
||||||
@@ -254,7 +254,7 @@ namespace Discord.Interactions.Builders
|
|||||||
/// <returns>
|
/// <returns>
|
||||||
/// The builder instance.
|
/// The builder instance.
|
||||||
/// </returns>
|
/// </returns>
|
||||||
public ModuleBuilder AddSlashCommand (Action<SlashCommandBuilder> configure)
|
public ModuleBuilder AddSlashCommand(Action<SlashCommandBuilder> configure)
|
||||||
{
|
{
|
||||||
var command = new SlashCommandBuilder(this);
|
var command = new SlashCommandBuilder(this);
|
||||||
configure(command);
|
configure(command);
|
||||||
@@ -286,7 +286,7 @@ namespace Discord.Interactions.Builders
|
|||||||
/// <returns>
|
/// <returns>
|
||||||
/// The builder instance.
|
/// The builder instance.
|
||||||
/// </returns>
|
/// </returns>
|
||||||
public ModuleBuilder AddContextCommand (Action<ContextCommandBuilder> configure)
|
public ModuleBuilder AddContextCommand(Action<ContextCommandBuilder> configure)
|
||||||
{
|
{
|
||||||
var command = new ContextCommandBuilder(this);
|
var command = new ContextCommandBuilder(this);
|
||||||
configure(command);
|
configure(command);
|
||||||
@@ -318,7 +318,7 @@ namespace Discord.Interactions.Builders
|
|||||||
/// <returns>
|
/// <returns>
|
||||||
/// The builder instance.
|
/// The builder instance.
|
||||||
/// </returns>
|
/// </returns>
|
||||||
public ModuleBuilder AddComponentCommand (Action<ComponentCommandBuilder> configure)
|
public ModuleBuilder AddComponentCommand(Action<ComponentCommandBuilder> configure)
|
||||||
{
|
{
|
||||||
var command = new ComponentCommandBuilder(this);
|
var command = new ComponentCommandBuilder(this);
|
||||||
configure(command);
|
configure(command);
|
||||||
@@ -398,7 +398,7 @@ namespace Discord.Interactions.Builders
|
|||||||
/// <returns>
|
/// <returns>
|
||||||
/// The builder instance.
|
/// The builder instance.
|
||||||
/// </returns>
|
/// </returns>
|
||||||
public ModuleBuilder AddModule (Action<ModuleBuilder> configure)
|
public ModuleBuilder AddModule(Action<ModuleBuilder> configure)
|
||||||
{
|
{
|
||||||
var subModule = new ModuleBuilder(InteractionService, this);
|
var subModule = new ModuleBuilder(InteractionService, this);
|
||||||
configure(subModule);
|
configure(subModule);
|
||||||
@@ -406,7 +406,7 @@ namespace Discord.Interactions.Builders
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
internal ModuleInfo Build (InteractionService interactionService, IServiceProvider services, ModuleInfo parent = null)
|
internal ModuleInfo Build(InteractionService interactionService, IServiceProvider services, ModuleInfo parent = null)
|
||||||
{
|
{
|
||||||
if (TypeInfo is not null && ModuleClassBuilder.IsValidModuleDefinition(TypeInfo))
|
if (TypeInfo is not null && ModuleClassBuilder.IsValidModuleDefinition(TypeInfo))
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -13,9 +13,9 @@ namespace Discord.Interactions.Builders
|
|||||||
|
|
||||||
public const int MaxCommandDepth = 3;
|
public const int MaxCommandDepth = 3;
|
||||||
|
|
||||||
public static async Task<IEnumerable<TypeInfo>> SearchAsync (Assembly assembly, InteractionService commandService)
|
public static async Task<IEnumerable<TypeInfo>> SearchAsync(Assembly assembly, InteractionService commandService)
|
||||||
{
|
{
|
||||||
static bool IsLoadableModule (TypeInfo info)
|
static bool IsLoadableModule(TypeInfo info)
|
||||||
{
|
{
|
||||||
return info.DeclaredMethods.Any(x => x.GetCustomAttribute<SlashCommandAttribute>() != null);
|
return info.DeclaredMethods.Any(x => x.GetCustomAttribute<SlashCommandAttribute>() != null);
|
||||||
}
|
}
|
||||||
@@ -24,7 +24,7 @@ namespace Discord.Interactions.Builders
|
|||||||
|
|
||||||
foreach (var type in assembly.DefinedTypes)
|
foreach (var type in assembly.DefinedTypes)
|
||||||
{
|
{
|
||||||
if (( type.IsPublic || type.IsNestedPublic ) && IsValidModuleDefinition(type))
|
if ((type.IsPublic || type.IsNestedPublic) && IsValidModuleDefinition(type))
|
||||||
{
|
{
|
||||||
result.Add(type);
|
result.Add(type);
|
||||||
}
|
}
|
||||||
@@ -36,7 +36,7 @@ namespace Discord.Interactions.Builders
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static async Task<Dictionary<Type, ModuleInfo>> BuildAsync (IEnumerable<TypeInfo> validTypes, InteractionService commandService,
|
public static async Task<Dictionary<Type, ModuleInfo>> BuildAsync(IEnumerable<TypeInfo> validTypes, InteractionService commandService,
|
||||||
IServiceProvider services)
|
IServiceProvider services)
|
||||||
{
|
{
|
||||||
var topLevelGroups = validTypes.Where(x => x.DeclaringType == null || !IsValidModuleDefinition(x.DeclaringType.GetTypeInfo()));
|
var topLevelGroups = validTypes.Where(x => x.DeclaringType == null || !IsValidModuleDefinition(x.DeclaringType.GetTypeInfo()));
|
||||||
@@ -62,7 +62,7 @@ namespace Discord.Interactions.Builders
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void BuildModule (ModuleBuilder builder, TypeInfo typeInfo, InteractionService commandService,
|
private static void BuildModule(ModuleBuilder builder, TypeInfo typeInfo, InteractionService commandService,
|
||||||
IServiceProvider services)
|
IServiceProvider services)
|
||||||
{
|
{
|
||||||
var attributes = typeInfo.GetCustomAttributes();
|
var attributes = typeInfo.GetCustomAttributes();
|
||||||
@@ -130,14 +130,14 @@ namespace Discord.Interactions.Builders
|
|||||||
foreach (var method in validInteractions)
|
foreach (var method in validInteractions)
|
||||||
builder.AddComponentCommand(x => BuildComponentCommand(x, createInstance, method, commandService, services));
|
builder.AddComponentCommand(x => BuildComponentCommand(x, createInstance, method, commandService, services));
|
||||||
|
|
||||||
foreach(var method in validAutocompleteCommands)
|
foreach (var method in validAutocompleteCommands)
|
||||||
builder.AddAutocompleteCommand(x => BuildAutocompleteCommand(x, createInstance, method, commandService, services));
|
builder.AddAutocompleteCommand(x => BuildAutocompleteCommand(x, createInstance, method, commandService, services));
|
||||||
|
|
||||||
foreach(var method in validModalCommands)
|
foreach (var method in validModalCommands)
|
||||||
builder.AddModalCommand(x => BuildModalCommand(x, createInstance, method, commandService, services));
|
builder.AddModalCommand(x => BuildModalCommand(x, createInstance, method, commandService, services));
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void BuildSubModules (ModuleBuilder parent, IEnumerable<TypeInfo> subModules, IList<TypeInfo> builtTypes, InteractionService commandService,
|
private static void BuildSubModules(ModuleBuilder parent, IEnumerable<TypeInfo> subModules, IList<TypeInfo> builtTypes, InteractionService commandService,
|
||||||
IServiceProvider services, int slashGroupDepth = 0)
|
IServiceProvider services, int slashGroupDepth = 0)
|
||||||
{
|
{
|
||||||
foreach (var submodule in subModules.Where(IsValidModuleDefinition))
|
foreach (var submodule in subModules.Where(IsValidModuleDefinition))
|
||||||
@@ -158,7 +158,7 @@ namespace Discord.Interactions.Builders
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void BuildSlashCommand (SlashCommandBuilder builder, Func<IServiceProvider, IInteractionModuleBase> createInstance, MethodInfo methodInfo,
|
private static void BuildSlashCommand(SlashCommandBuilder builder, Func<IServiceProvider, IInteractionModuleBase> createInstance, MethodInfo methodInfo,
|
||||||
InteractionService commandService, IServiceProvider services)
|
InteractionService commandService, IServiceProvider services)
|
||||||
{
|
{
|
||||||
var attributes = methodInfo.GetCustomAttributes();
|
var attributes = methodInfo.GetCustomAttributes();
|
||||||
@@ -212,7 +212,7 @@ namespace Discord.Interactions.Builders
|
|||||||
builder.Callback = CreateCallback(createInstance, methodInfo, commandService);
|
builder.Callback = CreateCallback(createInstance, methodInfo, commandService);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void BuildContextCommand (ContextCommandBuilder builder, Func<IServiceProvider, IInteractionModuleBase> createInstance, MethodInfo methodInfo,
|
private static void BuildContextCommand(ContextCommandBuilder builder, Func<IServiceProvider, IInteractionModuleBase> createInstance, MethodInfo methodInfo,
|
||||||
InteractionService commandService, IServiceProvider services)
|
InteractionService commandService, IServiceProvider services)
|
||||||
{
|
{
|
||||||
var attributes = methodInfo.GetCustomAttributes();
|
var attributes = methodInfo.GetCustomAttributes();
|
||||||
@@ -267,7 +267,7 @@ namespace Discord.Interactions.Builders
|
|||||||
builder.Callback = CreateCallback(createInstance, methodInfo, commandService);
|
builder.Callback = CreateCallback(createInstance, methodInfo, commandService);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void BuildComponentCommand (ComponentCommandBuilder builder, Func<IServiceProvider, IInteractionModuleBase> createInstance, MethodInfo methodInfo,
|
private static void BuildComponentCommand(ComponentCommandBuilder builder, Func<IServiceProvider, IInteractionModuleBase> createInstance, MethodInfo methodInfo,
|
||||||
InteractionService commandService, IServiceProvider services)
|
InteractionService commandService, IServiceProvider services)
|
||||||
{
|
{
|
||||||
var attributes = methodInfo.GetCustomAttributes();
|
var attributes = methodInfo.GetCustomAttributes();
|
||||||
@@ -312,7 +312,7 @@ namespace Discord.Interactions.Builders
|
|||||||
|
|
||||||
builder.MethodName = methodInfo.Name;
|
builder.MethodName = methodInfo.Name;
|
||||||
|
|
||||||
foreach(var attribute in attributes)
|
foreach (var attribute in attributes)
|
||||||
{
|
{
|
||||||
switch (attribute)
|
switch (attribute)
|
||||||
{
|
{
|
||||||
@@ -383,13 +383,13 @@ namespace Discord.Interactions.Builders
|
|||||||
builder.Callback = CreateCallback(createInstance, methodInfo, commandService);
|
builder.Callback = CreateCallback(createInstance, methodInfo, commandService);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static ExecuteCallback CreateCallback (Func<IServiceProvider, IInteractionModuleBase> createInstance,
|
private static ExecuteCallback CreateCallback(Func<IServiceProvider, IInteractionModuleBase> createInstance,
|
||||||
MethodInfo methodInfo, InteractionService commandService)
|
MethodInfo methodInfo, InteractionService commandService)
|
||||||
{
|
{
|
||||||
Func<IInteractionModuleBase, object[], Task> commandInvoker = commandService._useCompiledLambda ?
|
Func<IInteractionModuleBase, object[], Task> commandInvoker = commandService._useCompiledLambda ?
|
||||||
ReflectionUtils<IInteractionModuleBase>.CreateMethodInvoker(methodInfo) : (module, args) => methodInfo.Invoke(module, args) as Task;
|
ReflectionUtils<IInteractionModuleBase>.CreateMethodInvoker(methodInfo) : (module, args) => methodInfo.Invoke(module, args) as Task;
|
||||||
|
|
||||||
async Task<IResult> ExecuteCallback (IInteractionContext context, object[] args, IServiceProvider serviceProvider, ICommandInfo commandInfo)
|
async Task<IResult> ExecuteCallback(IInteractionContext context, object[] args, IServiceProvider serviceProvider, ICommandInfo commandInfo)
|
||||||
{
|
{
|
||||||
var instance = createInstance(serviceProvider);
|
var instance = createInstance(serviceProvider);
|
||||||
instance.SetContext(context);
|
instance.SetContext(context);
|
||||||
@@ -420,7 +420,7 @@ namespace Discord.Interactions.Builders
|
|||||||
{
|
{
|
||||||
await instance.AfterExecuteAsync(commandInfo).ConfigureAwait(false);
|
await instance.AfterExecuteAsync(commandInfo).ConfigureAwait(false);
|
||||||
instance.AfterExecute(commandInfo);
|
instance.AfterExecute(commandInfo);
|
||||||
( instance as IDisposable )?.Dispose();
|
(instance as IDisposable)?.Dispose();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -428,7 +428,7 @@ namespace Discord.Interactions.Builders
|
|||||||
}
|
}
|
||||||
|
|
||||||
#region Parameters
|
#region Parameters
|
||||||
private static void BuildSlashParameter (SlashCommandParameterBuilder builder, ParameterInfo paramInfo, IServiceProvider services)
|
private static void BuildSlashParameter(SlashCommandParameterBuilder builder, ParameterInfo paramInfo, IServiceProvider services)
|
||||||
{
|
{
|
||||||
var attributes = paramInfo.GetCustomAttributes();
|
var attributes = paramInfo.GetCustomAttributes();
|
||||||
var paramType = paramInfo.ParameterType;
|
var paramType = paramInfo.ParameterType;
|
||||||
@@ -465,7 +465,7 @@ namespace Discord.Interactions.Builders
|
|||||||
break;
|
break;
|
||||||
case AutocompleteAttribute autocomplete:
|
case AutocompleteAttribute autocomplete:
|
||||||
builder.Autocomplete = true;
|
builder.Autocomplete = true;
|
||||||
if(autocomplete.AutocompleteHandlerType is not null)
|
if (autocomplete.AutocompleteHandlerType is not null)
|
||||||
builder.WithAutocompleteHandler(autocomplete.AutocompleteHandlerType, services);
|
builder.WithAutocompleteHandler(autocomplete.AutocompleteHandlerType, services);
|
||||||
break;
|
break;
|
||||||
case MaxValueAttribute maxValue:
|
case MaxValueAttribute maxValue:
|
||||||
@@ -516,7 +516,7 @@ namespace Discord.Interactions.Builders
|
|||||||
BuildParameter(builder, paramInfo);
|
BuildParameter(builder, paramInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void BuildParameter<TInfo, TBuilder> (ParameterBuilder<TInfo, TBuilder> builder, ParameterInfo paramInfo)
|
private static void BuildParameter<TInfo, TBuilder>(ParameterBuilder<TInfo, TBuilder> builder, ParameterInfo paramInfo)
|
||||||
where TInfo : class, IParameterInfo
|
where TInfo : class, IParameterInfo
|
||||||
where TBuilder : ParameterBuilder<TInfo, TBuilder>
|
where TBuilder : ParameterBuilder<TInfo, TBuilder>
|
||||||
{
|
{
|
||||||
@@ -598,7 +598,7 @@ namespace Discord.Interactions.Builders
|
|||||||
builder.WithType(propertyInfo.PropertyType);
|
builder.WithType(propertyInfo.PropertyType);
|
||||||
builder.PropertyInfo = propertyInfo;
|
builder.PropertyInfo = propertyInfo;
|
||||||
|
|
||||||
foreach(var attribute in attributes)
|
foreach (var attribute in attributes)
|
||||||
{
|
{
|
||||||
switch (attribute)
|
switch (attribute)
|
||||||
{
|
{
|
||||||
@@ -625,30 +625,30 @@ namespace Discord.Interactions.Builders
|
|||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
internal static bool IsValidModuleDefinition (TypeInfo typeInfo)
|
internal static bool IsValidModuleDefinition(TypeInfo typeInfo)
|
||||||
{
|
{
|
||||||
return ModuleTypeInfo.IsAssignableFrom(typeInfo) &&
|
return ModuleTypeInfo.IsAssignableFrom(typeInfo) &&
|
||||||
!typeInfo.IsAbstract &&
|
!typeInfo.IsAbstract &&
|
||||||
!typeInfo.ContainsGenericParameters;
|
!typeInfo.ContainsGenericParameters;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static bool IsValidSlashCommandDefinition (MethodInfo methodInfo)
|
private static bool IsValidSlashCommandDefinition(MethodInfo methodInfo)
|
||||||
{
|
{
|
||||||
return methodInfo.IsDefined(typeof(SlashCommandAttribute)) &&
|
return methodInfo.IsDefined(typeof(SlashCommandAttribute)) &&
|
||||||
( methodInfo.ReturnType == typeof(Task) || methodInfo.ReturnType == typeof(Task<RuntimeResult>) ) &&
|
(methodInfo.ReturnType == typeof(Task) || methodInfo.ReturnType == typeof(Task<RuntimeResult>)) &&
|
||||||
!methodInfo.IsStatic &&
|
!methodInfo.IsStatic &&
|
||||||
!methodInfo.IsGenericMethod;
|
!methodInfo.IsGenericMethod;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static bool IsValidContextCommandDefinition (MethodInfo methodInfo)
|
private static bool IsValidContextCommandDefinition(MethodInfo methodInfo)
|
||||||
{
|
{
|
||||||
return methodInfo.IsDefined(typeof(ContextCommandAttribute)) &&
|
return methodInfo.IsDefined(typeof(ContextCommandAttribute)) &&
|
||||||
( methodInfo.ReturnType == typeof(Task) || methodInfo.ReturnType == typeof(Task<RuntimeResult>) ) &&
|
(methodInfo.ReturnType == typeof(Task) || methodInfo.ReturnType == typeof(Task<RuntimeResult>)) &&
|
||||||
!methodInfo.IsStatic &&
|
!methodInfo.IsStatic &&
|
||||||
!methodInfo.IsGenericMethod;
|
!methodInfo.IsGenericMethod;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static bool IsValidComponentCommandDefinition (MethodInfo methodInfo)
|
private static bool IsValidComponentCommandDefinition(MethodInfo methodInfo)
|
||||||
{
|
{
|
||||||
return methodInfo.IsDefined(typeof(ComponentInteractionAttribute)) &&
|
return methodInfo.IsDefined(typeof(ComponentInteractionAttribute)) &&
|
||||||
(methodInfo.ReturnType == typeof(Task) || methodInfo.ReturnType == typeof(Task<RuntimeResult>)) &&
|
(methodInfo.ReturnType == typeof(Task) || methodInfo.ReturnType == typeof(Task<RuntimeResult>)) &&
|
||||||
@@ -656,7 +656,7 @@ namespace Discord.Interactions.Builders
|
|||||||
!methodInfo.IsGenericMethod;
|
!methodInfo.IsGenericMethod;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static bool IsValidAutocompleteCommandDefinition (MethodInfo methodInfo)
|
private static bool IsValidAutocompleteCommandDefinition(MethodInfo methodInfo)
|
||||||
{
|
{
|
||||||
return methodInfo.IsDefined(typeof(AutocompleteCommandAttribute)) &&
|
return methodInfo.IsDefined(typeof(AutocompleteCommandAttribute)) &&
|
||||||
(methodInfo.ReturnType == typeof(Task) || methodInfo.ReturnType == typeof(Task<RuntimeResult>)) &&
|
(methodInfo.ReturnType == typeof(Task) || methodInfo.ReturnType == typeof(Task<RuntimeResult>)) &&
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ namespace Discord.Interactions.Builders
|
|||||||
{
|
{
|
||||||
protected override CommandParameterBuilder Instance => this;
|
protected override CommandParameterBuilder Instance => this;
|
||||||
|
|
||||||
internal CommandParameterBuilder (ICommandBuilder command) : base(command) { }
|
internal CommandParameterBuilder(ICommandBuilder command) : base(command) { }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Initializes a new <see cref="CommandParameterInfo"/>.
|
/// Initializes a new <see cref="CommandParameterInfo"/>.
|
||||||
@@ -17,9 +17,9 @@ namespace Discord.Interactions.Builders
|
|||||||
/// <param name="command">Parent command of this parameter.</param>
|
/// <param name="command">Parent command of this parameter.</param>
|
||||||
/// <param name="name">Name of this command.</param>
|
/// <param name="name">Name of this command.</param>
|
||||||
/// <param name="type">Type of this parameter.</param>
|
/// <param name="type">Type of this parameter.</param>
|
||||||
public CommandParameterBuilder (ICommandBuilder command, string name, Type type) : base(command, name, type) { }
|
public CommandParameterBuilder(ICommandBuilder command, string name, Type type) : base(command, name, type) { }
|
||||||
|
|
||||||
internal override CommandParameterInfo Build (ICommandInfo command) =>
|
internal override CommandParameterInfo Build(ICommandInfo command) =>
|
||||||
new CommandParameterInfo(this, command);
|
new CommandParameterInfo(this, command);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -55,7 +55,7 @@ namespace Discord.Interactions.Builders
|
|||||||
/// <returns>
|
/// <returns>
|
||||||
/// The builder instance.
|
/// The builder instance.
|
||||||
/// </returns>
|
/// </returns>
|
||||||
IParameterBuilder WithName (string name);
|
IParameterBuilder WithName(string name);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Sets <see cref="ParameterType"/>.
|
/// Sets <see cref="ParameterType"/>.
|
||||||
@@ -64,7 +64,7 @@ namespace Discord.Interactions.Builders
|
|||||||
/// <returns>
|
/// <returns>
|
||||||
/// The builder instance.
|
/// The builder instance.
|
||||||
/// </returns>
|
/// </returns>
|
||||||
IParameterBuilder SetParameterType (Type type);
|
IParameterBuilder SetParameterType(Type type);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Sets <see cref="IsRequired"/>.
|
/// Sets <see cref="IsRequired"/>.
|
||||||
@@ -73,7 +73,7 @@ namespace Discord.Interactions.Builders
|
|||||||
/// <returns>
|
/// <returns>
|
||||||
/// The builder instance.
|
/// The builder instance.
|
||||||
/// </returns>
|
/// </returns>
|
||||||
IParameterBuilder SetRequired (bool isRequired);
|
IParameterBuilder SetRequired(bool isRequired);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Sets <see cref="DefaultValue"/>.
|
/// Sets <see cref="DefaultValue"/>.
|
||||||
@@ -82,7 +82,7 @@ namespace Discord.Interactions.Builders
|
|||||||
/// <returns>
|
/// <returns>
|
||||||
/// The builder instance.
|
/// The builder instance.
|
||||||
/// </returns>
|
/// </returns>
|
||||||
IParameterBuilder SetDefaultValue (object defaultValue);
|
IParameterBuilder SetDefaultValue(object defaultValue);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Adds attributes to <see cref="Attributes"/>.
|
/// Adds attributes to <see cref="Attributes"/>.
|
||||||
@@ -91,7 +91,7 @@ namespace Discord.Interactions.Builders
|
|||||||
/// <returns>
|
/// <returns>
|
||||||
/// The builder instance.
|
/// The builder instance.
|
||||||
/// </returns>
|
/// </returns>
|
||||||
IParameterBuilder AddAttributes (params Attribute[] attributes);
|
IParameterBuilder AddAttributes(params Attribute[] attributes);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Adds preconditions to <see cref="Preconditions"/>.
|
/// Adds preconditions to <see cref="Preconditions"/>.
|
||||||
@@ -100,6 +100,6 @@ namespace Discord.Interactions.Builders
|
|||||||
/// <returns>
|
/// <returns>
|
||||||
/// The builder instance.
|
/// The builder instance.
|
||||||
/// </returns>
|
/// </returns>
|
||||||
IParameterBuilder AddPreconditions (params ParameterPreconditionAttribute[] preconditions);
|
IParameterBuilder AddPreconditions(params ParameterPreconditionAttribute[] preconditions);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ namespace Discord.Interactions.Builders
|
|||||||
public IReadOnlyCollection<ParameterPreconditionAttribute> Preconditions => _preconditions;
|
public IReadOnlyCollection<ParameterPreconditionAttribute> Preconditions => _preconditions;
|
||||||
protected abstract TBuilder Instance { get; }
|
protected abstract TBuilder Instance { get; }
|
||||||
|
|
||||||
internal ParameterBuilder (ICommandBuilder command)
|
internal ParameterBuilder(ICommandBuilder command)
|
||||||
{
|
{
|
||||||
_attributes = new List<Attribute>();
|
_attributes = new List<Attribute>();
|
||||||
_preconditions = new List<ParameterPreconditionAttribute>();
|
_preconditions = new List<ParameterPreconditionAttribute>();
|
||||||
@@ -48,7 +48,7 @@ namespace Discord.Interactions.Builders
|
|||||||
Command = command;
|
Command = command;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected ParameterBuilder (ICommandBuilder command, string name, Type type) : this(command)
|
protected ParameterBuilder(ICommandBuilder command, string name, Type type) : this(command)
|
||||||
{
|
{
|
||||||
Name = name;
|
Name = name;
|
||||||
SetParameterType(type);
|
SetParameterType(type);
|
||||||
@@ -61,7 +61,7 @@ namespace Discord.Interactions.Builders
|
|||||||
/// <returns>
|
/// <returns>
|
||||||
/// The builder instance.
|
/// The builder instance.
|
||||||
/// </returns>
|
/// </returns>
|
||||||
public virtual TBuilder WithName (string name)
|
public virtual TBuilder WithName(string name)
|
||||||
{
|
{
|
||||||
Name = name;
|
Name = name;
|
||||||
return Instance;
|
return Instance;
|
||||||
@@ -74,7 +74,7 @@ namespace Discord.Interactions.Builders
|
|||||||
/// <returns>
|
/// <returns>
|
||||||
/// The builder instance.
|
/// The builder instance.
|
||||||
/// </returns>
|
/// </returns>
|
||||||
public virtual TBuilder SetParameterType (Type type)
|
public virtual TBuilder SetParameterType(Type type)
|
||||||
{
|
{
|
||||||
ParameterType = type;
|
ParameterType = type;
|
||||||
return Instance;
|
return Instance;
|
||||||
@@ -87,7 +87,7 @@ namespace Discord.Interactions.Builders
|
|||||||
/// <returns>
|
/// <returns>
|
||||||
/// The builder instance.
|
/// The builder instance.
|
||||||
/// </returns>
|
/// </returns>
|
||||||
public virtual TBuilder SetRequired (bool isRequired)
|
public virtual TBuilder SetRequired(bool isRequired)
|
||||||
{
|
{
|
||||||
IsRequired = isRequired;
|
IsRequired = isRequired;
|
||||||
return Instance;
|
return Instance;
|
||||||
@@ -100,7 +100,7 @@ namespace Discord.Interactions.Builders
|
|||||||
/// <returns>
|
/// <returns>
|
||||||
/// The builder instance.
|
/// The builder instance.
|
||||||
/// </returns>
|
/// </returns>
|
||||||
public virtual TBuilder SetDefaultValue (object defaultValue)
|
public virtual TBuilder SetDefaultValue(object defaultValue)
|
||||||
{
|
{
|
||||||
DefaultValue = defaultValue;
|
DefaultValue = defaultValue;
|
||||||
return Instance;
|
return Instance;
|
||||||
@@ -113,7 +113,7 @@ namespace Discord.Interactions.Builders
|
|||||||
/// <returns>
|
/// <returns>
|
||||||
/// The builder instance.
|
/// The builder instance.
|
||||||
/// </returns>
|
/// </returns>
|
||||||
public virtual TBuilder AddAttributes (params Attribute[] attributes)
|
public virtual TBuilder AddAttributes(params Attribute[] attributes)
|
||||||
{
|
{
|
||||||
_attributes.AddRange(attributes);
|
_attributes.AddRange(attributes);
|
||||||
return Instance;
|
return Instance;
|
||||||
@@ -126,37 +126,37 @@ namespace Discord.Interactions.Builders
|
|||||||
/// <returns>
|
/// <returns>
|
||||||
/// The builder instance.
|
/// The builder instance.
|
||||||
/// </returns>
|
/// </returns>
|
||||||
public virtual TBuilder AddPreconditions (params ParameterPreconditionAttribute[] attributes)
|
public virtual TBuilder AddPreconditions(params ParameterPreconditionAttribute[] attributes)
|
||||||
{
|
{
|
||||||
_preconditions.AddRange(attributes);
|
_preconditions.AddRange(attributes);
|
||||||
return Instance;
|
return Instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
internal abstract TInfo Build (ICommandInfo command);
|
internal abstract TInfo Build(ICommandInfo command);
|
||||||
|
|
||||||
//IParameterBuilder
|
//IParameterBuilder
|
||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
IParameterBuilder IParameterBuilder.WithName (string name) =>
|
IParameterBuilder IParameterBuilder.WithName(string name) =>
|
||||||
WithName(name);
|
WithName(name);
|
||||||
|
|
||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
IParameterBuilder IParameterBuilder.SetParameterType (Type type) =>
|
IParameterBuilder IParameterBuilder.SetParameterType(Type type) =>
|
||||||
SetParameterType(type);
|
SetParameterType(type);
|
||||||
|
|
||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
IParameterBuilder IParameterBuilder.SetRequired (bool isRequired) =>
|
IParameterBuilder IParameterBuilder.SetRequired(bool isRequired) =>
|
||||||
SetRequired(isRequired);
|
SetRequired(isRequired);
|
||||||
|
|
||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
IParameterBuilder IParameterBuilder.SetDefaultValue (object defaultValue) =>
|
IParameterBuilder IParameterBuilder.SetDefaultValue(object defaultValue) =>
|
||||||
SetDefaultValue(defaultValue);
|
SetDefaultValue(defaultValue);
|
||||||
|
|
||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
IParameterBuilder IParameterBuilder.AddAttributes (params Attribute[] attributes) =>
|
IParameterBuilder IParameterBuilder.AddAttributes(params Attribute[] attributes) =>
|
||||||
AddAttributes(attributes);
|
AddAttributes(attributes);
|
||||||
|
|
||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
IParameterBuilder IParameterBuilder.AddPreconditions (params ParameterPreconditionAttribute[] preconditions) =>
|
IParameterBuilder IParameterBuilder.AddPreconditions(params ParameterPreconditionAttribute[] preconditions) =>
|
||||||
AddPreconditions(preconditions);
|
AddPreconditions(preconditions);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -229,7 +229,7 @@ namespace Discord.Interactions.Builders
|
|||||||
{
|
{
|
||||||
base.SetParameterType(type);
|
base.SetParameterType(type);
|
||||||
|
|
||||||
if(!IsComplexParameter)
|
if (!IsComplexParameter)
|
||||||
TypeConverter = Command.Module.InteractionService.GetTypeConverter(ParameterType, services);
|
TypeConverter = Command.Module.InteractionService.GetTypeConverter(ParameterType, services);
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
@@ -248,7 +248,7 @@ namespace Discord.Interactions.Builders
|
|||||||
SlashCommandParameterBuilder builder = new(Command);
|
SlashCommandParameterBuilder builder = new(Command);
|
||||||
configure(builder);
|
configure(builder);
|
||||||
|
|
||||||
if(builder.IsComplexParameter)
|
if (builder.IsComplexParameter)
|
||||||
throw new InvalidOperationException("You cannot create nested complex parameters.");
|
throw new InvalidOperationException("You cannot create nested complex parameters.");
|
||||||
|
|
||||||
_complexParameterFields.Add(builder);
|
_complexParameterFields.Add(builder);
|
||||||
@@ -265,7 +265,7 @@ namespace Discord.Interactions.Builders
|
|||||||
/// <exception cref="InvalidOperationException">Thrown if the added field has a <see cref="ComplexParameterAttribute"/>.</exception>
|
/// <exception cref="InvalidOperationException">Thrown if the added field has a <see cref="ComplexParameterAttribute"/>.</exception>
|
||||||
public SlashCommandParameterBuilder AddComplexParameterFields(params SlashCommandParameterBuilder[] fields)
|
public SlashCommandParameterBuilder AddComplexParameterFields(params SlashCommandParameterBuilder[] fields)
|
||||||
{
|
{
|
||||||
if(fields.Any(x => x.IsComplexParameter))
|
if (fields.Any(x => x.IsComplexParameter))
|
||||||
throw new InvalidOperationException("You cannot create nested complex parameters.");
|
throw new InvalidOperationException("You cannot create nested complex parameters.");
|
||||||
|
|
||||||
_complexParameterFields.AddRange(fields);
|
_complexParameterFields.AddRange(fields);
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ namespace Discord.Interactions
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public object Value { get; }
|
public object Value { get; }
|
||||||
|
|
||||||
internal ParameterChoice (string name, object value)
|
internal ParameterChoice(string name, object value)
|
||||||
{
|
{
|
||||||
Name = name;
|
Name = name;
|
||||||
Value = value;
|
Value = value;
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ namespace Discord.Interactions
|
|||||||
/// Sets the context of this module.
|
/// Sets the context of this module.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="context"></param>
|
/// <param name="context"></param>
|
||||||
void SetContext (IInteractionContext context);
|
void SetContext(IInteractionContext context);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Method body to be executed asynchronously before executing an application command.
|
/// Method body to be executed asynchronously before executing an application command.
|
||||||
@@ -35,14 +35,14 @@ namespace Discord.Interactions
|
|||||||
/// Method body to be executed after an application command execution.
|
/// Method body to be executed after an application command execution.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="command">Command information related to the Discord Application Command.</param>
|
/// <param name="command">Command information related to the Discord Application Command.</param>
|
||||||
void AfterExecute (ICommandInfo command);
|
void AfterExecute(ICommandInfo command);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Method body to be executed when <see cref="Builders.ModuleBuilder.Build(InteractionService, System.IServiceProvider, ModuleInfo)"/> is called.
|
/// Method body to be executed when <see cref="Builders.ModuleBuilder.Build(InteractionService, System.IServiceProvider, ModuleInfo)"/> is called.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="commandService">Command Service instance that built this module.</param>
|
/// <param name="commandService">Command Service instance that built this module.</param>
|
||||||
/// <param name="module">Info class of this module.</param>
|
/// <param name="module">Info class of this module.</param>
|
||||||
void OnModuleBuilding (InteractionService commandService, ModuleInfo module);
|
void OnModuleBuilding(InteractionService commandService, ModuleInfo module);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Method body to be executed after the automated module creation is completed and before <see cref="Builders.ModuleBuilder.Build(InteractionService, System.IServiceProvider, ModuleInfo)"/> is called.
|
/// Method body to be executed after the automated module creation is completed and before <see cref="Builders.ModuleBuilder.Build(InteractionService, System.IServiceProvider, ModuleInfo)"/> is called.
|
||||||
|
|||||||
@@ -64,7 +64,7 @@ namespace Discord.Interactions
|
|||||||
{
|
{
|
||||||
var keywords = new List<string>() { ParameterName, CommandName };
|
var keywords = new List<string>() { ParameterName, CommandName };
|
||||||
|
|
||||||
if(!IgnoreGroupNames)
|
if (!IgnoreGroupNames)
|
||||||
{
|
{
|
||||||
var currentParent = Module;
|
var currentParent = Module;
|
||||||
|
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ namespace Discord.Interactions
|
|||||||
/// <returns>
|
/// <returns>
|
||||||
/// A task representing the execution operation.
|
/// A task representing the execution operation.
|
||||||
/// </returns>
|
/// </returns>
|
||||||
public delegate Task ExecuteCallback (IInteractionContext context, object[] args, IServiceProvider serviceProvider, ICommandInfo commandInfo);
|
public delegate Task ExecuteCallback(IInteractionContext context, object[] args, IServiceProvider serviceProvider, ICommandInfo commandInfo);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The base information class for <see cref="InteractionService"/> commands.
|
/// The base information class for <see cref="InteractionService"/> commands.
|
||||||
@@ -129,7 +129,7 @@ namespace Discord.Interactions
|
|||||||
if (!argsResult.IsSuccess)
|
if (!argsResult.IsSuccess)
|
||||||
return await InvokeEventAndReturn(context, argsResult).ConfigureAwait(false);
|
return await InvokeEventAndReturn(context, argsResult).ConfigureAwait(false);
|
||||||
|
|
||||||
if(argsResult is not ParseResult parseResult)
|
if (argsResult is not ParseResult parseResult)
|
||||||
return ExecuteResult.FromError(InteractionCommandError.BadArgs, "Complex command parsing failed for an unknown reason.");
|
return ExecuteResult.FromError(InteractionCommandError.BadArgs, "Complex command parsing failed for an unknown reason.");
|
||||||
|
|
||||||
var args = parseResult.Args;
|
var args = parseResult.Args;
|
||||||
|
|||||||
@@ -42,7 +42,7 @@ namespace Discord.Interactions
|
|||||||
var data = (context.Interaction as IComponentInteraction).Data;
|
var data = (context.Interaction as IComponentInteraction).Data;
|
||||||
var args = new object[Parameters.Count];
|
var args = new object[Parameters.Count];
|
||||||
|
|
||||||
for(var i = 0; i < Parameters.Count; i++)
|
for (var i = 0; i < Parameters.Count; i++)
|
||||||
{
|
{
|
||||||
var parameter = Parameters[i];
|
var parameter = Parameters[i];
|
||||||
var isCapture = i < captureCount;
|
var isCapture = i < captureCount;
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ namespace Discord.Interactions
|
|||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
public override bool IgnoreGroupNames => true;
|
public override bool IgnoreGroupNames => true;
|
||||||
|
|
||||||
internal ContextCommandInfo (Builders.ContextCommandBuilder builder, ModuleInfo module, InteractionService commandService)
|
internal ContextCommandInfo(Builders.ContextCommandBuilder builder, ModuleInfo module, InteractionService commandService)
|
||||||
: base(builder, module, commandService)
|
: base(builder, module, commandService)
|
||||||
{
|
{
|
||||||
CommandType = builder.CommandType;
|
CommandType = builder.CommandType;
|
||||||
@@ -46,7 +46,7 @@ namespace Discord.Interactions
|
|||||||
Parameters = builder.Parameters.Select(x => x.Build(this)).ToImmutableArray();
|
Parameters = builder.Parameters.Select(x => x.Build(this)).ToImmutableArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
internal static ContextCommandInfo Create (Builders.ContextCommandBuilder builder, ModuleInfo module, InteractionService commandService)
|
internal static ContextCommandInfo Create(Builders.ContextCommandBuilder builder, ModuleInfo module, InteractionService commandService)
|
||||||
{
|
{
|
||||||
return builder.CommandType switch
|
return builder.CommandType switch
|
||||||
{
|
{
|
||||||
@@ -57,7 +57,7 @@ namespace Discord.Interactions
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
protected override Task InvokeModuleEvent (IInteractionContext context, IResult result)
|
protected override Task InvokeModuleEvent(IInteractionContext context, IResult result)
|
||||||
=> CommandService._contextCommandExecutedEvent.InvokeAsync(this, context, result);
|
=> CommandService._contextCommandExecutedEvent.InvokeAsync(this, context, result);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -86,7 +86,7 @@ namespace Discord.Interactions
|
|||||||
|
|
||||||
var options = GetOptions();
|
var options = GetOptions();
|
||||||
var args = new object[Parameters.Count];
|
var args = new object[Parameters.Count];
|
||||||
for(var i = 0; i < Parameters.Count; i++)
|
for (var i = 0; i < Parameters.Count; i++)
|
||||||
{
|
{
|
||||||
var parameter = Parameters[i];
|
var parameter = Parameters[i];
|
||||||
var result = await ParseArgumentAsync(parameter, context, options, services).ConfigureAwait(false);
|
var result = await ParseArgumentAsync(parameter, context, options, services).ConfigureAwait(false);
|
||||||
@@ -136,10 +136,10 @@ namespace Discord.Interactions
|
|||||||
return readResult;
|
return readResult;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override Task InvokeModuleEvent (IInteractionContext context, IResult result)
|
protected override Task InvokeModuleEvent(IInteractionContext context, IResult result)
|
||||||
=> CommandService._slashCommandExecutedEvent.InvokeAsync(this, context, result);
|
=> CommandService._slashCommandExecutedEvent.InvokeAsync(this, context, result);
|
||||||
|
|
||||||
protected override string GetLogString (IInteractionContext context)
|
protected override string GetLogString(IInteractionContext context)
|
||||||
{
|
{
|
||||||
if (context.Guild != null)
|
if (context.Guild != null)
|
||||||
return $"Slash Command: \"{base.ToString()}\" for {context.User} in {context.Guild}/{context.Channel}";
|
return $"Slash Command: \"{base.ToString()}\" for {context.User} in {context.Guild}/{context.Channel}";
|
||||||
@@ -153,7 +153,7 @@ namespace Discord.Interactions
|
|||||||
if (!parameter.IsComplexParameter)
|
if (!parameter.IsComplexParameter)
|
||||||
yield return parameter;
|
yield return parameter;
|
||||||
else
|
else
|
||||||
foreach(var complexParameterField in parameter.ComplexParameterFields)
|
foreach (var complexParameterField in parameter.ComplexParameterFields)
|
||||||
yield return complexParameterField;
|
yield return complexParameterField;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -75,11 +75,11 @@ namespace Discord.Interactions
|
|||||||
/// <returns>
|
/// <returns>
|
||||||
/// A task representing the execution process. The task result contains the execution result.
|
/// A task representing the execution process. The task result contains the execution result.
|
||||||
/// </returns>
|
/// </returns>
|
||||||
Task<IResult> ExecuteAsync (IInteractionContext context, IServiceProvider services);
|
Task<IResult> ExecuteAsync(IInteractionContext context, IServiceProvider services);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Check if an execution context meets the command precondition requirements.
|
/// Check if an execution context meets the command precondition requirements.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
Task<PreconditionResult> CheckPreconditionsAsync (IInteractionContext context, IServiceProvider services);
|
Task<PreconditionResult> CheckPreconditionsAsync(IInteractionContext context, IServiceProvider services);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -52,6 +52,6 @@ namespace Discord.Interactions
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Check if an execution context meets the parameter precondition requirements.
|
/// Check if an execution context meets the parameter precondition requirements.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
Task<PreconditionResult> CheckPreconditionsAsync (IInteractionContext context, object value, IServiceProvider services);
|
Task<PreconditionResult> CheckPreconditionsAsync(IInteractionContext context, object value, IServiceProvider services);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -117,7 +117,7 @@ namespace Discord.Interactions
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public bool DontAutoRegister { get; }
|
public bool DontAutoRegister { get; }
|
||||||
|
|
||||||
internal ModuleInfo (ModuleBuilder builder, InteractionService commandService, IServiceProvider services, ModuleInfo parent = null)
|
internal ModuleInfo(ModuleBuilder builder, InteractionService commandService, IServiceProvider services, ModuleInfo parent = null)
|
||||||
{
|
{
|
||||||
CommandService = commandService;
|
CommandService = commandService;
|
||||||
|
|
||||||
@@ -143,7 +143,7 @@ namespace Discord.Interactions
|
|||||||
GroupedPreconditions = Preconditions.ToLookup(x => x.Group, x => x, StringComparer.Ordinal);
|
GroupedPreconditions = Preconditions.ToLookup(x => x.Group, x => x, StringComparer.Ordinal);
|
||||||
}
|
}
|
||||||
|
|
||||||
private IEnumerable<ModuleInfo> BuildSubModules (ModuleBuilder builder, InteractionService commandService, IServiceProvider services)
|
private IEnumerable<ModuleInfo> BuildSubModules(ModuleBuilder builder, InteractionService commandService, IServiceProvider services)
|
||||||
{
|
{
|
||||||
var result = new List<ModuleInfo>();
|
var result = new List<ModuleInfo>();
|
||||||
|
|
||||||
@@ -153,7 +153,7 @@ namespace Discord.Interactions
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
private IEnumerable<SlashCommandInfo> BuildSlashCommands (ModuleBuilder builder)
|
private IEnumerable<SlashCommandInfo> BuildSlashCommands(ModuleBuilder builder)
|
||||||
{
|
{
|
||||||
var result = new List<SlashCommandInfo>();
|
var result = new List<SlashCommandInfo>();
|
||||||
|
|
||||||
@@ -163,7 +163,7 @@ namespace Discord.Interactions
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
private IEnumerable<ContextCommandInfo> BuildContextCommands (ModuleBuilder builder)
|
private IEnumerable<ContextCommandInfo> BuildContextCommands(ModuleBuilder builder)
|
||||||
{
|
{
|
||||||
var result = new List<ContextCommandInfo>();
|
var result = new List<ContextCommandInfo>();
|
||||||
|
|
||||||
@@ -173,7 +173,7 @@ namespace Discord.Interactions
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
private IEnumerable<ComponentCommandInfo> BuildComponentCommands (ModuleBuilder builder)
|
private IEnumerable<ComponentCommandInfo> BuildComponentCommands(ModuleBuilder builder)
|
||||||
{
|
{
|
||||||
var result = new List<ComponentCommandInfo>();
|
var result = new List<ComponentCommandInfo>();
|
||||||
|
|
||||||
@@ -183,7 +183,7 @@ namespace Discord.Interactions
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
private IEnumerable<AutocompleteCommandInfo> BuildAutocompleteCommands( ModuleBuilder builder)
|
private IEnumerable<AutocompleteCommandInfo> BuildAutocompleteCommands(ModuleBuilder builder)
|
||||||
{
|
{
|
||||||
var result = new List<AutocompleteCommandInfo>();
|
var result = new List<AutocompleteCommandInfo>();
|
||||||
|
|
||||||
@@ -203,7 +203,7 @@ namespace Discord.Interactions
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
private IEnumerable<Attribute> BuildAttributes (ModuleBuilder builder)
|
private IEnumerable<Attribute> BuildAttributes(ModuleBuilder builder)
|
||||||
{
|
{
|
||||||
var result = new List<Attribute>();
|
var result = new List<Attribute>();
|
||||||
var currentParent = builder;
|
var currentParent = builder;
|
||||||
@@ -217,7 +217,7 @@ namespace Discord.Interactions
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static IEnumerable<PreconditionAttribute> BuildPreconditions (ModuleBuilder builder)
|
private static IEnumerable<PreconditionAttribute> BuildPreconditions(ModuleBuilder builder)
|
||||||
{
|
{
|
||||||
var preconditions = new List<PreconditionAttribute>();
|
var preconditions = new List<PreconditionAttribute>();
|
||||||
|
|
||||||
@@ -232,7 +232,7 @@ namespace Discord.Interactions
|
|||||||
return preconditions;
|
return preconditions;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static bool CheckTopLevel (ModuleInfo parent)
|
private static bool CheckTopLevel(ModuleInfo parent)
|
||||||
{
|
{
|
||||||
var currentParent = parent;
|
var currentParent = parent;
|
||||||
|
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ namespace Discord.Interactions
|
|||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
public IReadOnlyCollection<ParameterPreconditionAttribute> Preconditions { get; }
|
public IReadOnlyCollection<ParameterPreconditionAttribute> Preconditions { get; }
|
||||||
|
|
||||||
internal CommandParameterInfo (Builders.IParameterBuilder builder, ICommandInfo command)
|
internal CommandParameterInfo(Builders.IParameterBuilder builder, ICommandInfo command)
|
||||||
{
|
{
|
||||||
Command = command;
|
Command = command;
|
||||||
Name = builder.Name;
|
Name = builder.Name;
|
||||||
@@ -47,7 +47,7 @@ namespace Discord.Interactions
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
public async Task<PreconditionResult> CheckPreconditionsAsync (IInteractionContext context, object value, IServiceProvider services)
|
public async Task<PreconditionResult> CheckPreconditionsAsync(IInteractionContext context, object value, IServiceProvider services)
|
||||||
{
|
{
|
||||||
foreach (var precondition in Preconditions)
|
foreach (var precondition in Preconditions)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -18,10 +18,10 @@ namespace Discord.Interactions
|
|||||||
public T Context { get; private set; }
|
public T Context { get; private set; }
|
||||||
|
|
||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
public virtual void AfterExecute (ICommandInfo command) { }
|
public virtual void AfterExecute(ICommandInfo command) { }
|
||||||
|
|
||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
public virtual void BeforeExecute (ICommandInfo command) { }
|
public virtual void BeforeExecute(ICommandInfo command) { }
|
||||||
|
|
||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
public virtual Task BeforeExecuteAsync(ICommandInfo command) => Task.CompletedTask;
|
public virtual Task BeforeExecuteAsync(ICommandInfo command) => Task.CompletedTask;
|
||||||
@@ -30,12 +30,12 @@ namespace Discord.Interactions
|
|||||||
public virtual Task AfterExecuteAsync(ICommandInfo command) => Task.CompletedTask;
|
public virtual Task AfterExecuteAsync(ICommandInfo command) => Task.CompletedTask;
|
||||||
|
|
||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
public virtual void OnModuleBuilding (InteractionService commandService, ModuleInfo module) { }
|
public virtual void OnModuleBuilding(InteractionService commandService, ModuleInfo module) { }
|
||||||
|
|
||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
public virtual void Construct (Builders.ModuleBuilder builder, InteractionService commandService) { }
|
public virtual void Construct(Builders.ModuleBuilder builder, InteractionService commandService) { }
|
||||||
|
|
||||||
internal void SetContext (IInteractionContext context)
|
internal void SetContext(IInteractionContext context)
|
||||||
{
|
{
|
||||||
var newValue = context as T;
|
var newValue = context as T;
|
||||||
Context = newValue ?? throw new InvalidOperationException($"Invalid context type. Expected {typeof(T).Name}, got {context.GetType().Name}.");
|
Context = newValue ?? throw new InvalidOperationException($"Invalid context type. Expected {typeof(T).Name}, got {context.GetType().Name}.");
|
||||||
@@ -46,7 +46,7 @@ namespace Discord.Interactions
|
|||||||
await Context.Interaction.DeferAsync(ephemeral, options).ConfigureAwait(false);
|
await Context.Interaction.DeferAsync(ephemeral, options).ConfigureAwait(false);
|
||||||
|
|
||||||
/// <inheritdoc cref="IDiscordInteraction.RespondAsync(string, Embed[], bool, bool, AllowedMentions, MessageComponent, Embed, RequestOptions)"/>
|
/// <inheritdoc cref="IDiscordInteraction.RespondAsync(string, Embed[], bool, bool, AllowedMentions, MessageComponent, Embed, RequestOptions)"/>
|
||||||
protected virtual async Task RespondAsync (string text = null, Embed[] embeds = null, bool isTTS = false, bool ephemeral = false,
|
protected virtual async Task RespondAsync(string text = null, Embed[] embeds = null, bool isTTS = false, bool ephemeral = false,
|
||||||
AllowedMentions allowedMentions = null, RequestOptions options = null, MessageComponent components = null, Embed embed = null) =>
|
AllowedMentions allowedMentions = null, RequestOptions options = null, MessageComponent components = null, Embed embed = null) =>
|
||||||
await Context.Interaction.RespondAsync(text, embeds, isTTS, ephemeral, allowedMentions, components, embed, options).ConfigureAwait(false);
|
await Context.Interaction.RespondAsync(text, embeds, isTTS, ephemeral, allowedMentions, components, embed, options).ConfigureAwait(false);
|
||||||
|
|
||||||
@@ -71,7 +71,7 @@ namespace Discord.Interactions
|
|||||||
=> Context.Interaction.RespondWithFilesAsync(attachments, text, embeds, isTTS, ephemeral, allowedMentions, components, embed, options);
|
=> Context.Interaction.RespondWithFilesAsync(attachments, text, embeds, isTTS, ephemeral, allowedMentions, components, embed, options);
|
||||||
|
|
||||||
/// <inheritdoc cref="IDiscordInteraction.FollowupAsync(string, Embed[], bool, bool, AllowedMentions, MessageComponent, Embed, RequestOptions)"/>
|
/// <inheritdoc cref="IDiscordInteraction.FollowupAsync(string, Embed[], bool, bool, AllowedMentions, MessageComponent, Embed, RequestOptions)"/>
|
||||||
protected virtual async Task<IUserMessage> FollowupAsync (string text = null, Embed[] embeds = null, bool isTTS = false, bool ephemeral = false,
|
protected virtual async Task<IUserMessage> FollowupAsync(string text = null, Embed[] embeds = null, bool isTTS = false, bool ephemeral = false,
|
||||||
AllowedMentions allowedMentions = null, RequestOptions options = null, MessageComponent components = null, Embed embed = null) =>
|
AllowedMentions allowedMentions = null, RequestOptions options = null, MessageComponent components = null, Embed embed = null) =>
|
||||||
await Context.Interaction.FollowupAsync(text, embeds, isTTS, ephemeral, allowedMentions, components, embed, options).ConfigureAwait(false);
|
await Context.Interaction.FollowupAsync(text, embeds, isTTS, ephemeral, allowedMentions, components, embed, options).ConfigureAwait(false);
|
||||||
|
|
||||||
@@ -96,7 +96,7 @@ namespace Discord.Interactions
|
|||||||
=> Context.Interaction.FollowupWithFilesAsync(attachments, text, embeds, isTTS, ephemeral, allowedMentions, components, embed, options);
|
=> Context.Interaction.FollowupWithFilesAsync(attachments, text, embeds, isTTS, ephemeral, allowedMentions, components, embed, options);
|
||||||
|
|
||||||
/// <inheritdoc cref="IMessageChannel.SendMessageAsync(string, bool, Embed, RequestOptions, AllowedMentions, MessageReference, MessageComponent, ISticker[], Embed[], MessageFlags)"/>
|
/// <inheritdoc cref="IMessageChannel.SendMessageAsync(string, bool, Embed, RequestOptions, AllowedMentions, MessageReference, MessageComponent, ISticker[], Embed[], MessageFlags)"/>
|
||||||
protected virtual async Task<IUserMessage> ReplyAsync (string text = null, bool isTTS = false, Embed embed = null, RequestOptions options = null,
|
protected virtual async Task<IUserMessage> ReplyAsync(string text = null, bool isTTS = false, Embed embed = null, RequestOptions options = null,
|
||||||
AllowedMentions allowedMentions = null, MessageReference messageReference = null, MessageComponent components = null) =>
|
AllowedMentions allowedMentions = null, MessageReference messageReference = null, MessageComponent components = null) =>
|
||||||
await Context.Channel.SendMessageAsync(text, false, embed, options, allowedMentions, messageReference, components).ConfigureAwait(false);
|
await Context.Channel.SendMessageAsync(text, false, embed, options, allowedMentions, messageReference, components).ConfigureAwait(false);
|
||||||
|
|
||||||
@@ -125,7 +125,7 @@ namespace Discord.Interactions
|
|||||||
//IInteractionModuleBase
|
//IInteractionModuleBase
|
||||||
|
|
||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
void IInteractionModuleBase.SetContext (IInteractionContext context) => SetContext(context);
|
void IInteractionModuleBase.SetContext(IInteractionContext context) => SetContext(context);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ namespace Discord.Interactions
|
|||||||
/// Occurs when a Slash Command related information is recieved.
|
/// Occurs when a Slash Command related information is recieved.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public event Func<LogMessage, Task> Log { add { _logEvent.Add(value); } remove { _logEvent.Remove(value); } }
|
public event Func<LogMessage, Task> Log { add { _logEvent.Add(value); } remove { _logEvent.Remove(value); } }
|
||||||
internal readonly AsyncEvent<Func<LogMessage, Task>> _logEvent = new ();
|
internal readonly AsyncEvent<Func<LogMessage, Task>> _logEvent = new();
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Occurs when any type of interaction is executed.
|
/// Occurs when any type of interaction is executed.
|
||||||
@@ -51,19 +51,19 @@ namespace Discord.Interactions
|
|||||||
/// Occurs when a Slash Command is executed.
|
/// Occurs when a Slash Command is executed.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public event Func<SlashCommandInfo, IInteractionContext, IResult, Task> SlashCommandExecuted { add { _slashCommandExecutedEvent.Add(value); } remove { _slashCommandExecutedEvent.Remove(value); } }
|
public event Func<SlashCommandInfo, IInteractionContext, IResult, Task> SlashCommandExecuted { add { _slashCommandExecutedEvent.Add(value); } remove { _slashCommandExecutedEvent.Remove(value); } }
|
||||||
internal readonly AsyncEvent<Func<SlashCommandInfo, IInteractionContext, IResult, Task>> _slashCommandExecutedEvent = new ();
|
internal readonly AsyncEvent<Func<SlashCommandInfo, IInteractionContext, IResult, Task>> _slashCommandExecutedEvent = new();
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Occurs when a Context Command is executed.
|
/// Occurs when a Context Command is executed.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public event Func<ContextCommandInfo, IInteractionContext, IResult, Task> ContextCommandExecuted { add { _contextCommandExecutedEvent.Add(value); } remove { _contextCommandExecutedEvent.Remove(value); } }
|
public event Func<ContextCommandInfo, IInteractionContext, IResult, Task> ContextCommandExecuted { add { _contextCommandExecutedEvent.Add(value); } remove { _contextCommandExecutedEvent.Remove(value); } }
|
||||||
internal readonly AsyncEvent<Func<ContextCommandInfo, IInteractionContext, IResult, Task>> _contextCommandExecutedEvent = new ();
|
internal readonly AsyncEvent<Func<ContextCommandInfo, IInteractionContext, IResult, Task>> _contextCommandExecutedEvent = new();
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Occurs when a Message Component command is executed.
|
/// Occurs when a Message Component command is executed.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public event Func<ComponentCommandInfo, IInteractionContext, IResult, Task> ComponentCommandExecuted { add { _componentCommandExecutedEvent.Add(value); } remove { _componentCommandExecutedEvent.Remove(value); } }
|
public event Func<ComponentCommandInfo, IInteractionContext, IResult, Task> ComponentCommandExecuted { add { _componentCommandExecutedEvent.Add(value); } remove { _componentCommandExecutedEvent.Remove(value); } }
|
||||||
internal readonly AsyncEvent<Func<ComponentCommandInfo, IInteractionContext, IResult, Task>> _componentCommandExecutedEvent = new ();
|
internal readonly AsyncEvent<Func<ComponentCommandInfo, IInteractionContext, IResult, Task>> _componentCommandExecutedEvent = new();
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Occurs when a Autocomplete command is executed.
|
/// Occurs when a Autocomplete command is executed.
|
||||||
@@ -150,7 +150,7 @@ namespace Discord.Interactions
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="discord">The discord client.</param>
|
/// <param name="discord">The discord client.</param>
|
||||||
/// <param name="config">The configuration class.</param>
|
/// <param name="config">The configuration class.</param>
|
||||||
public InteractionService (DiscordSocketClient discord, InteractionServiceConfig config = null)
|
public InteractionService(DiscordSocketClient discord, InteractionServiceConfig config = null)
|
||||||
: this(() => discord.Rest, config ?? new InteractionServiceConfig()) { }
|
: this(() => discord.Rest, config ?? new InteractionServiceConfig()) { }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -158,7 +158,7 @@ namespace Discord.Interactions
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="discord">The discord client.</param>
|
/// <param name="discord">The discord client.</param>
|
||||||
/// <param name="config">The configuration class.</param>
|
/// <param name="config">The configuration class.</param>
|
||||||
public InteractionService (DiscordShardedClient discord, InteractionServiceConfig config = null)
|
public InteractionService(DiscordShardedClient discord, InteractionServiceConfig config = null)
|
||||||
: this(() => discord.Rest, config ?? new InteractionServiceConfig()) { }
|
: this(() => discord.Rest, config ?? new InteractionServiceConfig()) { }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -166,18 +166,18 @@ namespace Discord.Interactions
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="discord">The discord client.</param>
|
/// <param name="discord">The discord client.</param>
|
||||||
/// <param name="config">The configuration class.</param>
|
/// <param name="config">The configuration class.</param>
|
||||||
public InteractionService (BaseSocketClient discord, InteractionServiceConfig config = null)
|
public InteractionService(BaseSocketClient discord, InteractionServiceConfig config = null)
|
||||||
:this(() => discord.Rest, config ?? new InteractionServiceConfig()) { }
|
: this(() => discord.Rest, config ?? new InteractionServiceConfig()) { }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Initialize a <see cref="InteractionService"/> with provided configurations.
|
/// Initialize a <see cref="InteractionService"/> with provided configurations.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="discord">The discord client.</param>
|
/// <param name="discord">The discord client.</param>
|
||||||
/// <param name="config">The configuration class.</param>
|
/// <param name="config">The configuration class.</param>
|
||||||
public InteractionService (DiscordRestClient discord, InteractionServiceConfig config = null)
|
public InteractionService(DiscordRestClient discord, InteractionServiceConfig config = null)
|
||||||
:this(() => discord, config ?? new InteractionServiceConfig()) { }
|
: this(() => discord, config ?? new InteractionServiceConfig()) { }
|
||||||
|
|
||||||
private InteractionService (Func<DiscordRestClient> getRestClient, InteractionServiceConfig config = null)
|
private InteractionService(Func<DiscordRestClient> getRestClient, InteractionServiceConfig config = null)
|
||||||
{
|
{
|
||||||
config ??= new InteractionServiceConfig();
|
config ??= new InteractionServiceConfig();
|
||||||
|
|
||||||
@@ -284,7 +284,7 @@ namespace Discord.Interactions
|
|||||||
/// <returns>
|
/// <returns>
|
||||||
/// A task representing the operation for adding modules. The task result contains a collection of the modules added.
|
/// A task representing the operation for adding modules. The task result contains a collection of the modules added.
|
||||||
/// </returns>
|
/// </returns>
|
||||||
public async Task<IEnumerable<ModuleInfo>> AddModulesAsync (Assembly assembly, IServiceProvider services)
|
public async Task<IEnumerable<ModuleInfo>> AddModulesAsync(Assembly assembly, IServiceProvider services)
|
||||||
{
|
{
|
||||||
services ??= EmptyServiceProvider.Instance;
|
services ??= EmptyServiceProvider.Instance;
|
||||||
|
|
||||||
@@ -322,7 +322,7 @@ namespace Discord.Interactions
|
|||||||
/// <exception cref="InvalidOperationException">
|
/// <exception cref="InvalidOperationException">
|
||||||
/// Thrown when the <typeparamref name="T"/> is not a valid module definition.
|
/// Thrown when the <typeparamref name="T"/> is not a valid module definition.
|
||||||
/// </exception>
|
/// </exception>
|
||||||
public Task<ModuleInfo> AddModuleAsync<T> (IServiceProvider services) where T : class =>
|
public Task<ModuleInfo> AddModuleAsync<T>(IServiceProvider services) where T : class =>
|
||||||
AddModuleAsync(typeof(T), services);
|
AddModuleAsync(typeof(T), services);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -339,7 +339,7 @@ namespace Discord.Interactions
|
|||||||
/// <exception cref="InvalidOperationException">
|
/// <exception cref="InvalidOperationException">
|
||||||
/// Thrown when the <paramref name="type"/> is not a valid module definition.
|
/// Thrown when the <paramref name="type"/> is not a valid module definition.
|
||||||
/// </exception>
|
/// </exception>
|
||||||
public async Task<ModuleInfo> AddModuleAsync (Type type, IServiceProvider services)
|
public async Task<ModuleInfo> AddModuleAsync(Type type, IServiceProvider services)
|
||||||
{
|
{
|
||||||
if (!typeof(IInteractionModuleBase).IsAssignableFrom(type))
|
if (!typeof(IInteractionModuleBase).IsAssignableFrom(type))
|
||||||
throw new ArgumentException("Type parameter must be a type of Slash Module", nameof(type));
|
throw new ArgumentException("Type parameter must be a type of Slash Module", nameof(type));
|
||||||
@@ -355,7 +355,7 @@ namespace Discord.Interactions
|
|||||||
if (_typedModuleDefs.ContainsKey(typeInfo))
|
if (_typedModuleDefs.ContainsKey(typeInfo))
|
||||||
throw new ArgumentException("Module definition for this type already exists.");
|
throw new ArgumentException("Module definition for this type already exists.");
|
||||||
|
|
||||||
var moduleDef = ( await ModuleClassBuilder.BuildAsync(new List<TypeInfo> { typeInfo }, this, services).ConfigureAwait(false) ).FirstOrDefault();
|
var moduleDef = (await ModuleClassBuilder.BuildAsync(new List<TypeInfo> { typeInfo }, this, services).ConfigureAwait(false)).FirstOrDefault();
|
||||||
|
|
||||||
if (moduleDef.Value == default)
|
if (moduleDef.Value == default)
|
||||||
throw new InvalidOperationException($"Could not build the module {typeInfo.FullName}, did you pass an invalid type?");
|
throw new InvalidOperationException($"Could not build the module {typeInfo.FullName}, did you pass an invalid type?");
|
||||||
@@ -382,7 +382,7 @@ namespace Discord.Interactions
|
|||||||
/// <returns>
|
/// <returns>
|
||||||
/// A task representing the command registration process. The task result contains the active application commands of the target guild.
|
/// A task representing the command registration process. The task result contains the active application commands of the target guild.
|
||||||
/// </returns>
|
/// </returns>
|
||||||
public async Task<IReadOnlyCollection<RestGuildCommand>> RegisterCommandsToGuildAsync (ulong guildId, bool deleteMissing = true)
|
public async Task<IReadOnlyCollection<RestGuildCommand>> RegisterCommandsToGuildAsync(ulong guildId, bool deleteMissing = true)
|
||||||
{
|
{
|
||||||
EnsureClientReady();
|
EnsureClientReady();
|
||||||
|
|
||||||
@@ -407,7 +407,7 @@ namespace Discord.Interactions
|
|||||||
/// <returns>
|
/// <returns>
|
||||||
/// A task representing the command registration process. The task result contains the active global application commands of bot.
|
/// A task representing the command registration process. The task result contains the active global application commands of bot.
|
||||||
/// </returns>
|
/// </returns>
|
||||||
public async Task<IReadOnlyCollection<RestGlobalCommand>> RegisterCommandsGloballyAsync (bool deleteMissing = true)
|
public async Task<IReadOnlyCollection<RestGlobalCommand>> RegisterCommandsGloballyAsync(bool deleteMissing = true)
|
||||||
{
|
{
|
||||||
EnsureClientReady();
|
EnsureClientReady();
|
||||||
|
|
||||||
@@ -598,7 +598,7 @@ namespace Discord.Interactions
|
|||||||
return await RestClient.BulkOverwriteGlobalCommands(props.ToArray()).ConfigureAwait(false);
|
return await RestClient.BulkOverwriteGlobalCommands(props.ToArray()).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void LoadModuleInternal (ModuleInfo module)
|
private void LoadModuleInternal(ModuleInfo module)
|
||||||
{
|
{
|
||||||
_moduleDefs.Add(module);
|
_moduleDefs.Add(module);
|
||||||
|
|
||||||
@@ -629,7 +629,7 @@ namespace Discord.Interactions
|
|||||||
/// A task that represents the asynchronous removal operation. The task result contains a value that
|
/// A task that represents the asynchronous removal operation. The task result contains a value that
|
||||||
/// indicates whether the module is successfully removed.
|
/// indicates whether the module is successfully removed.
|
||||||
/// </returns>
|
/// </returns>
|
||||||
public Task<bool> RemoveModuleAsync<T> ( ) =>
|
public Task<bool> RemoveModuleAsync<T>() =>
|
||||||
RemoveModuleAsync(typeof(T));
|
RemoveModuleAsync(typeof(T));
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -640,7 +640,7 @@ namespace Discord.Interactions
|
|||||||
/// A task that represents the asynchronous removal operation. The task result contains a value that
|
/// A task that represents the asynchronous removal operation. The task result contains a value that
|
||||||
/// indicates whether the module is successfully removed.
|
/// indicates whether the module is successfully removed.
|
||||||
/// </returns>
|
/// </returns>
|
||||||
public async Task<bool> RemoveModuleAsync (Type type)
|
public async Task<bool> RemoveModuleAsync(Type type)
|
||||||
{
|
{
|
||||||
await _lock.WaitAsync().ConfigureAwait(false);
|
await _lock.WaitAsync().ConfigureAwait(false);
|
||||||
|
|
||||||
@@ -720,7 +720,7 @@ namespace Discord.Interactions
|
|||||||
return await RestClient.BulkOverwriteGuildCommands(props.ToArray(), guildId).ConfigureAwait(false);
|
return await RestClient.BulkOverwriteGuildCommands(props.ToArray(), guildId).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
private bool RemoveModuleInternal (ModuleInfo moduleInfo)
|
private bool RemoveModuleInternal(ModuleInfo moduleInfo)
|
||||||
{
|
{
|
||||||
if (!_moduleDefs.Remove(moduleInfo))
|
if (!_moduleDefs.Remove(moduleInfo))
|
||||||
return false;
|
return false;
|
||||||
@@ -795,7 +795,7 @@ namespace Discord.Interactions
|
|||||||
/// <returns>
|
/// <returns>
|
||||||
/// A task representing the command execution process. The task result contains the result of the execution.
|
/// A task representing the command execution process. The task result contains the result of the execution.
|
||||||
/// </returns>
|
/// </returns>
|
||||||
public async Task<IResult> ExecuteCommandAsync (IInteractionContext context, IServiceProvider services)
|
public async Task<IResult> ExecuteCommandAsync(IInteractionContext context, IServiceProvider services)
|
||||||
{
|
{
|
||||||
var interaction = context.Interaction;
|
var interaction = context.Interaction;
|
||||||
|
|
||||||
@@ -811,7 +811,7 @@ namespace Discord.Interactions
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task<IResult> ExecuteSlashCommandAsync (IInteractionContext context, ISlashCommandInteraction interaction, IServiceProvider services)
|
private async Task<IResult> ExecuteSlashCommandAsync(IInteractionContext context, ISlashCommandInteraction interaction, IServiceProvider services)
|
||||||
{
|
{
|
||||||
var keywords = interaction.Data.GetCommandKeywords();
|
var keywords = interaction.Data.GetCommandKeywords();
|
||||||
|
|
||||||
@@ -827,7 +827,7 @@ namespace Discord.Interactions
|
|||||||
return await result.Command.ExecuteAsync(context, services).ConfigureAwait(false);
|
return await result.Command.ExecuteAsync(context, services).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task<IResult> ExecuteContextCommandAsync (IInteractionContext context, string input, ApplicationCommandType commandType, IServiceProvider services)
|
private async Task<IResult> ExecuteContextCommandAsync(IInteractionContext context, string input, ApplicationCommandType commandType, IServiceProvider services)
|
||||||
{
|
{
|
||||||
if (!_contextCommandMaps.TryGetValue(commandType, out var map))
|
if (!_contextCommandMaps.TryGetValue(commandType, out var map))
|
||||||
return SearchResult<ContextCommandInfo>.FromError(input, InteractionCommandError.UnknownCommand, $"No {commandType} command found.");
|
return SearchResult<ContextCommandInfo>.FromError(input, InteractionCommandError.UnknownCommand, $"No {commandType} command found.");
|
||||||
@@ -844,7 +844,7 @@ namespace Discord.Interactions
|
|||||||
return await result.Command.ExecuteAsync(context, services).ConfigureAwait(false);
|
return await result.Command.ExecuteAsync(context, services).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task<IResult> ExecuteComponentCommandAsync (IInteractionContext context, string input, IServiceProvider services)
|
private async Task<IResult> ExecuteComponentCommandAsync(IInteractionContext context, string input, IServiceProvider services)
|
||||||
{
|
{
|
||||||
var result = _componentCommandMap.GetCommand(input);
|
var result = _componentCommandMap.GetCommand(input);
|
||||||
|
|
||||||
@@ -861,15 +861,15 @@ namespace Discord.Interactions
|
|||||||
return await result.Command.ExecuteAsync(context, services).ConfigureAwait(false);
|
return await result.Command.ExecuteAsync(context, services).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task<IResult> ExecuteAutocompleteAsync (IInteractionContext context, IAutocompleteInteraction interaction, IServiceProvider services )
|
private async Task<IResult> ExecuteAutocompleteAsync(IInteractionContext context, IAutocompleteInteraction interaction, IServiceProvider services)
|
||||||
{
|
{
|
||||||
var keywords = interaction.Data.GetCommandKeywords();
|
var keywords = interaction.Data.GetCommandKeywords();
|
||||||
|
|
||||||
if(_enableAutocompleteHandlers)
|
if (_enableAutocompleteHandlers)
|
||||||
{
|
{
|
||||||
var autocompleteHandlerResult = _slashCommandMap.GetCommand(keywords);
|
var autocompleteHandlerResult = _slashCommandMap.GetCommand(keywords);
|
||||||
|
|
||||||
if(autocompleteHandlerResult.IsSuccess)
|
if (autocompleteHandlerResult.IsSuccess)
|
||||||
{
|
{
|
||||||
if (autocompleteHandlerResult.Command._flattenedParameterDictionary.TryGetValue(interaction.Data.Current.Name, out var parameter) && parameter?.AutocompleteHandler is not null)
|
if (autocompleteHandlerResult.Command._flattenedParameterDictionary.TryGetValue(interaction.Data.Current.Name, out var parameter) && parameter?.AutocompleteHandler is not null)
|
||||||
return await parameter.AutocompleteHandler.ExecuteAsync(context, interaction, parameter, services).ConfigureAwait(false);
|
return await parameter.AutocompleteHandler.ExecuteAsync(context, interaction, parameter, services).ConfigureAwait(false);
|
||||||
@@ -880,7 +880,7 @@ namespace Discord.Interactions
|
|||||||
|
|
||||||
var commandResult = _autocompleteCommandMap.GetCommand(keywords);
|
var commandResult = _autocompleteCommandMap.GetCommand(keywords);
|
||||||
|
|
||||||
if(!commandResult.IsSuccess)
|
if (!commandResult.IsSuccess)
|
||||||
{
|
{
|
||||||
await _cmdLogger.DebugAsync($"Unknown command name, skipping autocomplete process ({interaction.Data.CommandName.ToUpper()})");
|
await _cmdLogger.DebugAsync($"Unknown command name, skipping autocomplete process ({interaction.Data.CommandName.ToUpper()})");
|
||||||
|
|
||||||
@@ -1109,7 +1109,7 @@ namespace Discord.Interactions
|
|||||||
{
|
{
|
||||||
var serializedValues = new string[args.Length];
|
var serializedValues = new string[args.Length];
|
||||||
|
|
||||||
for(var i = 0; i < args.Length; i++)
|
for (var i = 0; i < args.Length; i++)
|
||||||
{
|
{
|
||||||
var arg = args[i];
|
var arg = args[i];
|
||||||
var typeReader = _typeReaderMap.Get(arg.GetType(), null);
|
var typeReader = _typeReaderMap.Get(arg.GetType(), null);
|
||||||
@@ -1269,7 +1269,7 @@ namespace Discord.Interactions
|
|||||||
public async Task<GuildApplicationCommandPermission> ModifyContextCommandPermissionsAsync(ContextCommandInfo command, ulong guildId,
|
public async Task<GuildApplicationCommandPermission> ModifyContextCommandPermissionsAsync(ContextCommandInfo command, ulong guildId,
|
||||||
params ApplicationCommandPermission[] permissions) => await ModifyApplicationCommandPermissionsAsync(command, guildId, permissions).ConfigureAwait(false);
|
params ApplicationCommandPermission[] permissions) => await ModifyApplicationCommandPermissionsAsync(command, guildId, permissions).ConfigureAwait(false);
|
||||||
|
|
||||||
private async Task<GuildApplicationCommandPermission> ModifyApplicationCommandPermissionsAsync<T> (T command, ulong guildId,
|
private async Task<GuildApplicationCommandPermission> ModifyApplicationCommandPermissionsAsync<T>(T command, ulong guildId,
|
||||||
params ApplicationCommandPermission[] permissions) where T : class, IApplicationCommandInfo, ICommandInfo
|
params ApplicationCommandPermission[] permissions) where T : class, IApplicationCommandInfo, ICommandInfo
|
||||||
{
|
{
|
||||||
if (command is null)
|
if (command is null)
|
||||||
@@ -1279,7 +1279,7 @@ namespace Discord.Interactions
|
|||||||
throw new InvalidOperationException("This command is not a top level application command. You cannot change its permissions");
|
throw new InvalidOperationException("This command is not a top level application command. You cannot change its permissions");
|
||||||
|
|
||||||
var commands = await RestClient.GetGuildApplicationCommands(guildId).ConfigureAwait(false);
|
var commands = await RestClient.GetGuildApplicationCommands(guildId).ConfigureAwait(false);
|
||||||
var appCommand = commands.First(x => x.Name == ( command as IApplicationCommandInfo ).Name);
|
var appCommand = commands.First(x => x.Name == (command as IApplicationCommandInfo).Name);
|
||||||
|
|
||||||
return await appCommand.ModifyCommandPermissions(permissions).ConfigureAwait(false);
|
return await appCommand.ModifyCommandPermissions(permissions).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
@@ -1293,7 +1293,7 @@ namespace Discord.Interactions
|
|||||||
/// <see cref="SlashCommandInfo"/> instance for this command.
|
/// <see cref="SlashCommandInfo"/> instance for this command.
|
||||||
/// </returns>
|
/// </returns>
|
||||||
/// <exception cref="InvalidOperationException">Module or Slash Command couldn't be found.</exception>
|
/// <exception cref="InvalidOperationException">Module or Slash Command couldn't be found.</exception>
|
||||||
public SlashCommandInfo GetSlashCommandInfo<TModule> (string methodName) where TModule : class
|
public SlashCommandInfo GetSlashCommandInfo<TModule>(string methodName) where TModule : class
|
||||||
{
|
{
|
||||||
var module = GetModuleInfo<TModule>();
|
var module = GetModuleInfo<TModule>();
|
||||||
|
|
||||||
@@ -1309,7 +1309,7 @@ namespace Discord.Interactions
|
|||||||
/// <see cref="ContextCommandInfo"/> instance for this command.
|
/// <see cref="ContextCommandInfo"/> instance for this command.
|
||||||
/// </returns>
|
/// </returns>
|
||||||
/// <exception cref="InvalidOperationException">Module or Context Command couldn't be found.</exception>
|
/// <exception cref="InvalidOperationException">Module or Context Command couldn't be found.</exception>
|
||||||
public ContextCommandInfo GetContextCommandInfo<TModule> (string methodName) where TModule : class
|
public ContextCommandInfo GetContextCommandInfo<TModule>(string methodName) where TModule : class
|
||||||
{
|
{
|
||||||
var module = GetModuleInfo<TModule>();
|
var module = GetModuleInfo<TModule>();
|
||||||
|
|
||||||
@@ -1325,7 +1325,7 @@ namespace Discord.Interactions
|
|||||||
/// <see cref="ComponentCommandInfo"/> instance for this command.
|
/// <see cref="ComponentCommandInfo"/> instance for this command.
|
||||||
/// </returns>
|
/// </returns>
|
||||||
/// <exception cref="InvalidOperationException">Module or Component Command couldn't be found.</exception>
|
/// <exception cref="InvalidOperationException">Module or Component Command couldn't be found.</exception>
|
||||||
public ComponentCommandInfo GetComponentCommandInfo<TModule> (string methodName) where TModule : class
|
public ComponentCommandInfo GetComponentCommandInfo<TModule>(string methodName) where TModule : class
|
||||||
{
|
{
|
||||||
var module = GetModuleInfo<TModule>();
|
var module = GetModuleInfo<TModule>();
|
||||||
|
|
||||||
@@ -1339,7 +1339,7 @@ namespace Discord.Interactions
|
|||||||
/// <returns>
|
/// <returns>
|
||||||
/// <see cref="ModuleInfo"/> instance for this module.
|
/// <see cref="ModuleInfo"/> instance for this module.
|
||||||
/// </returns>
|
/// </returns>
|
||||||
public ModuleInfo GetModuleInfo<TModule> ( ) where TModule : class
|
public ModuleInfo GetModuleInfo<TModule>() where TModule : class
|
||||||
{
|
{
|
||||||
if (!typeof(IInteractionModuleBase).IsAssignableFrom(typeof(TModule)))
|
if (!typeof(IInteractionModuleBase).IsAssignableFrom(typeof(TModule)))
|
||||||
throw new ArgumentException("Type parameter must be a type of Slash Module", nameof(TModule));
|
throw new ArgumentException("Type parameter must be a type of Slash Module", nameof(TModule));
|
||||||
@@ -1353,7 +1353,7 @@ namespace Discord.Interactions
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
public void Dispose ( )
|
public void Dispose()
|
||||||
{
|
{
|
||||||
_lock.Dispose();
|
_lock.Dispose();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -49,7 +49,7 @@ namespace Discord.Interactions
|
|||||||
|
|
||||||
public SearchResult<T> GetCommand(string input)
|
public SearchResult<T> GetCommand(string input)
|
||||||
{
|
{
|
||||||
if(_seperators.Any())
|
if (_seperators.Any())
|
||||||
return GetCommand(input.Split(_seperators));
|
return GetCommand(input.Split(_seperators));
|
||||||
else
|
else
|
||||||
return GetCommand(new string[] { input });
|
return GetCommand(new string[] { input });
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ namespace Discord.Interactions
|
|||||||
public IReadOnlyDictionary<Regex, T> WildCardCommands => _wildCardCommands;
|
public IReadOnlyDictionary<Regex, T> WildCardCommands => _wildCardCommands;
|
||||||
public string Name { get; }
|
public string Name { get; }
|
||||||
|
|
||||||
public CommandMapNode (string name, string wildCardExp = null)
|
public CommandMapNode(string name, string wildCardExp = null)
|
||||||
{
|
{
|
||||||
Name = name;
|
Name = name;
|
||||||
_nodes = new ConcurrentDictionary<string, CommandMapNode<T>>();
|
_nodes = new ConcurrentDictionary<string, CommandMapNode<T>>();
|
||||||
@@ -30,7 +30,7 @@ namespace Discord.Interactions
|
|||||||
_wildCardStr = wildCardExp;
|
_wildCardStr = wildCardExp;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void AddCommand (IList<string> keywords, int index, T commandInfo)
|
public void AddCommand(IList<string> keywords, int index, T commandInfo)
|
||||||
{
|
{
|
||||||
if (keywords.Count == index + 1)
|
if (keywords.Count == index + 1)
|
||||||
{
|
{
|
||||||
@@ -54,7 +54,7 @@ namespace Discord.Interactions
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool RemoveCommand (IList<string> keywords, int index)
|
public bool RemoveCommand(IList<string> keywords, int index)
|
||||||
{
|
{
|
||||||
if (keywords.Count == index + 1)
|
if (keywords.Count == index + 1)
|
||||||
return _commands.TryRemove(keywords[index], out var _);
|
return _commands.TryRemove(keywords[index], out var _);
|
||||||
@@ -67,7 +67,7 @@ namespace Discord.Interactions
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public SearchResult<T> GetCommand (IList<string> keywords, int index)
|
public SearchResult<T> GetCommand(IList<string> keywords, int index)
|
||||||
{
|
{
|
||||||
string name = string.Join(" ", keywords);
|
string name = string.Join(" ", keywords);
|
||||||
|
|
||||||
@@ -101,7 +101,7 @@ namespace Discord.Interactions
|
|||||||
return SearchResult<T>.FromError(name, InteractionCommandError.UnknownCommand, $"No {typeof(T).FullName} found for {name}");
|
return SearchResult<T>.FromError(name, InteractionCommandError.UnknownCommand, $"No {typeof(T).FullName} found for {name}");
|
||||||
}
|
}
|
||||||
|
|
||||||
public SearchResult<T> GetCommand (string text, int index, char[] seperators)
|
public SearchResult<T> GetCommand(string text, int index, char[] seperators)
|
||||||
{
|
{
|
||||||
var keywords = text.Split(seperators);
|
var keywords = text.Split(seperators);
|
||||||
return GetCommand(keywords, index);
|
return GetCommand(keywords, index);
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ namespace Discord.Interactions
|
|||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
public bool IsSuccess => !Error.HasValue;
|
public bool IsSuccess => !Error.HasValue;
|
||||||
|
|
||||||
private ExecuteResult (Exception exception, InteractionCommandError? commandError, string errorReason)
|
private ExecuteResult(Exception exception, InteractionCommandError? commandError, string errorReason)
|
||||||
{
|
{
|
||||||
Exception = exception;
|
Exception = exception;
|
||||||
Error = commandError;
|
Error = commandError;
|
||||||
@@ -34,7 +34,7 @@ namespace Discord.Interactions
|
|||||||
/// <returns>
|
/// <returns>
|
||||||
/// A <see cref="ExecuteResult" /> that does not contain any errors.
|
/// A <see cref="ExecuteResult" /> that does not contain any errors.
|
||||||
/// </returns>
|
/// </returns>
|
||||||
public static ExecuteResult FromSuccess ( ) =>
|
public static ExecuteResult FromSuccess() =>
|
||||||
new ExecuteResult(null, null, null);
|
new ExecuteResult(null, null, null);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -46,7 +46,7 @@ namespace Discord.Interactions
|
|||||||
/// <returns>
|
/// <returns>
|
||||||
/// A <see cref="ExecuteResult" /> that contains a <see cref="InteractionCommandError" /> and reason.
|
/// A <see cref="ExecuteResult" /> that contains a <see cref="InteractionCommandError" /> and reason.
|
||||||
/// </returns>
|
/// </returns>
|
||||||
public static ExecuteResult FromError (InteractionCommandError commandError, string reason) =>
|
public static ExecuteResult FromError(InteractionCommandError commandError, string reason) =>
|
||||||
new ExecuteResult(null, commandError, reason);
|
new ExecuteResult(null, commandError, reason);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -59,7 +59,7 @@ namespace Discord.Interactions
|
|||||||
/// with a <see cref="InteractionCommandError" /> of type <c>Exception</c> as well as the exception message as the
|
/// with a <see cref="InteractionCommandError" /> of type <c>Exception</c> as well as the exception message as the
|
||||||
/// reason.
|
/// reason.
|
||||||
/// </returns>
|
/// </returns>
|
||||||
public static ExecuteResult FromError (Exception exception) =>
|
public static ExecuteResult FromError(Exception exception) =>
|
||||||
new ExecuteResult(exception, InteractionCommandError.Exception, exception.Message);
|
new ExecuteResult(exception, InteractionCommandError.Exception, exception.Message);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -71,7 +71,7 @@ namespace Discord.Interactions
|
|||||||
/// <returns>
|
/// <returns>
|
||||||
/// A <see cref="ExecuteResult"/> that inherits the <see cref="IResult"/> error type and reason.
|
/// A <see cref="ExecuteResult"/> that inherits the <see cref="IResult"/> error type and reason.
|
||||||
/// </returns>
|
/// </returns>
|
||||||
public static ExecuteResult FromError (IResult result) =>
|
public static ExecuteResult FromError(IResult result) =>
|
||||||
new ExecuteResult(null, result.Error, result.ErrorReason);
|
new ExecuteResult(null, result.Error, result.ErrorReason);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -81,6 +81,6 @@ namespace Discord.Interactions
|
|||||||
/// <c>Success</c> if <see cref="IsSuccess"/> is <see langword="true"/>; otherwise "<see cref="Error"/>:
|
/// <c>Success</c> if <see cref="IsSuccess"/> is <see langword="true"/>; otherwise "<see cref="Error"/>:
|
||||||
/// <see cref="ErrorReason"/>".
|
/// <see cref="ErrorReason"/>".
|
||||||
/// </returns>
|
/// </returns>
|
||||||
public override string ToString ( ) => IsSuccess ? "Success" : $"{Error}: {ErrorReason}";
|
public override string ToString() => IsSuccess ? "Success" : $"{Error}: {ErrorReason}";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ namespace Discord.Interactions
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public IReadOnlyCollection<PreconditionResult> Results { get; }
|
public IReadOnlyCollection<PreconditionResult> Results { get; }
|
||||||
|
|
||||||
private PreconditionGroupResult (InteractionCommandError? error, string reason, IEnumerable<PreconditionResult> results) : base(error, reason)
|
private PreconditionGroupResult(InteractionCommandError? error, string reason, IEnumerable<PreconditionResult> results) : base(error, reason)
|
||||||
{
|
{
|
||||||
Results = results?.ToImmutableArray();
|
Results = results?.ToImmutableArray();
|
||||||
}
|
}
|
||||||
@@ -22,21 +22,21 @@ namespace Discord.Interactions
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Returns a <see cref="PreconditionGroupResult" /> with no errors.
|
/// Returns a <see cref="PreconditionGroupResult" /> with no errors.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static new PreconditionGroupResult FromSuccess ( ) =>
|
public static new PreconditionGroupResult FromSuccess() =>
|
||||||
new PreconditionGroupResult(null, null, null);
|
new PreconditionGroupResult(null, null, null);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Returns a <see cref="PreconditionGroupResult" /> with <see cref="InteractionCommandError.Exception" /> and the <see cref="Exception.Message"/>.
|
/// Returns a <see cref="PreconditionGroupResult" /> with <see cref="InteractionCommandError.Exception" /> and the <see cref="Exception.Message"/>.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="exception">The exception that caused the precondition check to fail.</param>
|
/// <param name="exception">The exception that caused the precondition check to fail.</param>
|
||||||
public static new PreconditionGroupResult FromError (Exception exception) =>
|
public static new PreconditionGroupResult FromError(Exception exception) =>
|
||||||
new PreconditionGroupResult(InteractionCommandError.Exception, exception.Message, null);
|
new PreconditionGroupResult(InteractionCommandError.Exception, exception.Message, null);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Returns a <see cref="PreconditionGroupResult" /> with the specified <paramref name="result"/> type.
|
/// Returns a <see cref="PreconditionGroupResult" /> with the specified <paramref name="result"/> type.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="result">The result of failure.</param>
|
/// <param name="result">The result of failure.</param>
|
||||||
public static new PreconditionGroupResult FromError (IResult result) =>
|
public static new PreconditionGroupResult FromError(IResult result) =>
|
||||||
new PreconditionGroupResult(result.Error, result.ErrorReason, null);
|
new PreconditionGroupResult(result.Error, result.ErrorReason, null);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -45,7 +45,7 @@ namespace Discord.Interactions
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="reason">The reason of failure.</param>
|
/// <param name="reason">The reason of failure.</param>
|
||||||
/// <param name="results">Precondition results of this group</param>
|
/// <param name="results">Precondition results of this group</param>
|
||||||
public static PreconditionGroupResult FromError (string reason, IEnumerable<PreconditionResult> results) =>
|
public static PreconditionGroupResult FromError(string reason, IEnumerable<PreconditionResult> results) =>
|
||||||
new PreconditionGroupResult(InteractionCommandError.UnmetPrecondition, reason, results);
|
new PreconditionGroupResult(InteractionCommandError.UnmetPrecondition, reason, results);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ namespace Discord.Interactions
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="error">The type of failure.</param>
|
/// <param name="error">The type of failure.</param>
|
||||||
/// <param name="reason">The reason of failure.</param>
|
/// <param name="reason">The reason of failure.</param>
|
||||||
protected PreconditionResult (InteractionCommandError? error, string reason)
|
protected PreconditionResult(InteractionCommandError? error, string reason)
|
||||||
{
|
{
|
||||||
Error = error;
|
Error = error;
|
||||||
ErrorReason = reason;
|
ErrorReason = reason;
|
||||||
@@ -31,21 +31,21 @@ namespace Discord.Interactions
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Returns a <see cref="PreconditionResult" /> with no errors.
|
/// Returns a <see cref="PreconditionResult" /> with no errors.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static PreconditionResult FromSuccess ( ) =>
|
public static PreconditionResult FromSuccess() =>
|
||||||
new PreconditionResult(null, null);
|
new PreconditionResult(null, null);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Returns a <see cref="PreconditionResult" /> with <see cref="InteractionCommandError.Exception" /> and the <see cref="Exception.Message"/>.
|
/// Returns a <see cref="PreconditionResult" /> with <see cref="InteractionCommandError.Exception" /> and the <see cref="Exception.Message"/>.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="exception">The exception that caused the precondition check to fail.</param>
|
/// <param name="exception">The exception that caused the precondition check to fail.</param>
|
||||||
public static PreconditionResult FromError (Exception exception) =>
|
public static PreconditionResult FromError(Exception exception) =>
|
||||||
new PreconditionResult(InteractionCommandError.Exception, exception.Message);
|
new PreconditionResult(InteractionCommandError.Exception, exception.Message);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Returns a <see cref="PreconditionResult" /> with the specified <paramref name="result"/> type.
|
/// Returns a <see cref="PreconditionResult" /> with the specified <paramref name="result"/> type.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="result">The result of failure.</param>
|
/// <param name="result">The result of failure.</param>
|
||||||
public static PreconditionResult FromError (IResult result) =>
|
public static PreconditionResult FromError(IResult result) =>
|
||||||
new PreconditionResult(result.Error, result.ErrorReason);
|
new PreconditionResult(result.Error, result.ErrorReason);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -53,7 +53,7 @@ namespace Discord.Interactions
|
|||||||
/// specified reason.
|
/// specified reason.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="reason">The reason of failure.</param>
|
/// <param name="reason">The reason of failure.</param>
|
||||||
public static PreconditionResult FromError (string reason) =>
|
public static PreconditionResult FromError(string reason) =>
|
||||||
new PreconditionResult(InteractionCommandError.UnmetPrecondition, reason);
|
new PreconditionResult(InteractionCommandError.UnmetPrecondition, reason);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ namespace Discord.Interactions
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="error">The type of failure, or <c>null</c> if none.</param>
|
/// <param name="error">The type of failure, or <c>null</c> if none.</param>
|
||||||
/// <param name="reason">The reason of failure.</param>
|
/// <param name="reason">The reason of failure.</param>
|
||||||
protected RuntimeResult (InteractionCommandError? error, string reason)
|
protected RuntimeResult(InteractionCommandError? error, string reason)
|
||||||
{
|
{
|
||||||
Error = error;
|
Error = error;
|
||||||
ErrorReason = reason;
|
ErrorReason = reason;
|
||||||
@@ -32,6 +32,6 @@ namespace Discord.Interactions
|
|||||||
/// <c>Success</c> if <see cref="IsSuccess"/> is <c>true</c>; otherwise "<see cref="Error"/>:
|
/// <c>Success</c> if <see cref="IsSuccess"/> is <c>true</c>; otherwise "<see cref="Error"/>:
|
||||||
/// <see cref="ErrorReason"/>".
|
/// <see cref="ErrorReason"/>".
|
||||||
/// </returns>
|
/// </returns>
|
||||||
public override string ToString ( ) => ErrorReason ?? ( IsSuccess ? "Successful" : "Unsuccessful" );
|
public override string ToString() => ErrorReason ?? (IsSuccess ? "Successful" : "Unsuccessful");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ namespace Discord.Interactions
|
|||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
public bool IsSuccess => !Error.HasValue;
|
public bool IsSuccess => !Error.HasValue;
|
||||||
|
|
||||||
private SearchResult (string text, T commandInfo, string[] captureGroups, InteractionCommandError? error, string reason)
|
private SearchResult(string text, T commandInfo, string[] captureGroups, InteractionCommandError? error, string reason)
|
||||||
{
|
{
|
||||||
Text = text;
|
Text = text;
|
||||||
Error = error;
|
Error = error;
|
||||||
@@ -47,7 +47,7 @@ namespace Discord.Interactions
|
|||||||
/// <returns>
|
/// <returns>
|
||||||
/// A <see cref="SearchResult{T}" /> that does not contain any errors.
|
/// A <see cref="SearchResult{T}" /> that does not contain any errors.
|
||||||
/// </returns>
|
/// </returns>
|
||||||
public static SearchResult<T> FromSuccess (string text, T commandInfo, string[] wildCardMatch = null) =>
|
public static SearchResult<T> FromSuccess(string text, T commandInfo, string[] wildCardMatch = null) =>
|
||||||
new SearchResult<T>(text, commandInfo, wildCardMatch, null, null);
|
new SearchResult<T>(text, commandInfo, wildCardMatch, null, null);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -59,7 +59,7 @@ namespace Discord.Interactions
|
|||||||
/// <returns>
|
/// <returns>
|
||||||
/// A <see cref="SearchResult{T}" /> that contains a <see cref="InteractionCommandError" /> and reason.
|
/// A <see cref="SearchResult{T}" /> that contains a <see cref="InteractionCommandError" /> and reason.
|
||||||
/// </returns>
|
/// </returns>
|
||||||
public static SearchResult<T> FromError (string text, InteractionCommandError error, string reason) =>
|
public static SearchResult<T> FromError(string text, InteractionCommandError error, string reason) =>
|
||||||
new SearchResult<T>(text, null, null, error, reason);
|
new SearchResult<T>(text, null, null, error, reason);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -72,7 +72,7 @@ namespace Discord.Interactions
|
|||||||
/// with a <see cref="InteractionCommandError" /> of type <c>Exception</c> as well as the exception message as the
|
/// with a <see cref="InteractionCommandError" /> of type <c>Exception</c> as well as the exception message as the
|
||||||
/// reason.
|
/// reason.
|
||||||
/// </returns>
|
/// </returns>
|
||||||
public static SearchResult<T> FromError (Exception ex) =>
|
public static SearchResult<T> FromError(Exception ex) =>
|
||||||
new SearchResult<T>(null, null, null, InteractionCommandError.Exception, ex.Message);
|
new SearchResult<T>(null, null, null, InteractionCommandError.Exception, ex.Message);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -84,10 +84,10 @@ namespace Discord.Interactions
|
|||||||
/// <returns>
|
/// <returns>
|
||||||
/// A <see cref="SearchResult{T}"/> that inherits the <see cref="IResult"/> error type and reason.
|
/// A <see cref="SearchResult{T}"/> that inherits the <see cref="IResult"/> error type and reason.
|
||||||
/// </returns>
|
/// </returns>
|
||||||
public static SearchResult<T> FromError (IResult result) =>
|
public static SearchResult<T> FromError(IResult result) =>
|
||||||
new SearchResult<T>(null, null, null, result.Error, result.ErrorReason);
|
new SearchResult<T>(null, null, null, result.Error, result.ErrorReason);
|
||||||
|
|
||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
public override string ToString ( ) => IsSuccess ? "Success" : $"{Error}: {ErrorReason}";
|
public override string ToString() => IsSuccess ? "Success" : $"{Error}: {ErrorReason}";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ namespace Discord.Interactions
|
|||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
public bool IsSuccess => !Error.HasValue;
|
public bool IsSuccess => !Error.HasValue;
|
||||||
|
|
||||||
private TypeConverterResult (object value, InteractionCommandError? error, string reason)
|
private TypeConverterResult(object value, InteractionCommandError? error, string reason)
|
||||||
{
|
{
|
||||||
Value = value;
|
Value = value;
|
||||||
Error = error;
|
Error = error;
|
||||||
@@ -31,14 +31,14 @@ namespace Discord.Interactions
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Returns a <see cref="TypeConverterResult" /> with no errors.
|
/// Returns a <see cref="TypeConverterResult" /> with no errors.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static TypeConverterResult FromSuccess (object value) =>
|
public static TypeConverterResult FromSuccess(object value) =>
|
||||||
new TypeConverterResult(value, null, null);
|
new TypeConverterResult(value, null, null);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Returns a <see cref="TypeConverterResult" /> with <see cref="InteractionCommandError.Exception" /> and the <see cref="Exception.Message"/>.
|
/// Returns a <see cref="TypeConverterResult" /> with <see cref="InteractionCommandError.Exception" /> and the <see cref="Exception.Message"/>.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="exception">The exception that caused the type convertion to fail.</param>
|
/// <param name="exception">The exception that caused the type convertion to fail.</param>
|
||||||
public static TypeConverterResult FromError (Exception exception) =>
|
public static TypeConverterResult FromError(Exception exception) =>
|
||||||
new TypeConverterResult(null, InteractionCommandError.Exception, exception.Message);
|
new TypeConverterResult(null, InteractionCommandError.Exception, exception.Message);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -46,16 +46,16 @@ namespace Discord.Interactions
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="error">The type of error.</param>
|
/// <param name="error">The type of error.</param>
|
||||||
/// <param name="reason">The reason of failure.</param>
|
/// <param name="reason">The reason of failure.</param>
|
||||||
public static TypeConverterResult FromError (InteractionCommandError error, string reason) =>
|
public static TypeConverterResult FromError(InteractionCommandError error, string reason) =>
|
||||||
new TypeConverterResult(null, error, reason);
|
new TypeConverterResult(null, error, reason);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Returns a <see cref="PreconditionResult" /> with the specified <paramref name="result"/> type.
|
/// Returns a <see cref="PreconditionResult" /> with the specified <paramref name="result"/> type.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="result">The result of failure.</param>
|
/// <param name="result">The result of failure.</param>
|
||||||
public static TypeConverterResult FromError (IResult result) =>
|
public static TypeConverterResult FromError(IResult result) =>
|
||||||
new TypeConverterResult(null, result.Error, result.ErrorReason);
|
new TypeConverterResult(null, result.Error, result.ErrorReason);
|
||||||
|
|
||||||
public override string ToString ( ) => IsSuccess ? "Success" : $"{Error}: {ErrorReason}";
|
public override string ToString() => IsSuccess ? "Success" : $"{Error}: {ErrorReason}";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ namespace Discord.Interactions
|
|||||||
{
|
{
|
||||||
var objs = new List<object>();
|
var objs = new List<object>();
|
||||||
|
|
||||||
if(_typeReader is not null && option.Values.Count > 0)
|
if (_typeReader is not null && option.Values.Count > 0)
|
||||||
foreach (var value in option.Values)
|
foreach (var value in option.Values)
|
||||||
{
|
{
|
||||||
var result = await _typeReader.ReadAsync(context, value, services).ConfigureAwait(false);
|
var result = await _typeReader.ReadAsync(context, value, services).ConfigureAwait(false);
|
||||||
@@ -52,13 +52,13 @@ namespace Discord.Interactions
|
|||||||
foreach (var user in option.Users)
|
foreach (var user in option.Users)
|
||||||
users[user.Id] = user;
|
users[user.Id] = user;
|
||||||
|
|
||||||
if(option.Members is not null)
|
if (option.Members is not null)
|
||||||
foreach(var member in option.Members)
|
foreach (var member in option.Members)
|
||||||
users[member.Id] = member;
|
users[member.Id] = member;
|
||||||
|
|
||||||
objs.AddRange(users.Values);
|
objs.AddRange(users.Values);
|
||||||
|
|
||||||
if(option.Roles is not null)
|
if (option.Roles is not null)
|
||||||
objs.AddRange(option.Roles);
|
objs.AddRange(option.Roles);
|
||||||
|
|
||||||
if (option.Channels is not null)
|
if (option.Channels is not null)
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user