Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
b98f62a
Change GuildMemberUpdatedEventArgs to contain before and after Discor…
selfdocumentingcode Jul 28, 2022
168dbf9
Fix #1325 - WebhookBuilder Throws Bad Request (#1363)
waffle-lord Aug 5, 2022
254ba1d
Implemented PATCH /guilds/:guild_id/roles (tested) (#1311)
OoLunar Aug 5, 2022
570040e
Fix compile errors caused by #1333
OoLunar Aug 5, 2022
e2bfeef
Update hosting.md
OoLunar Aug 5, 2022
2bcabe3
Remove unused DSharpPlus.MSTest folder
OoLunar Aug 5, 2022
f85c91f
Cache threads upon thread creation (#1366)
OoLunar Aug 5, 2022
00530ed
categorization for the cnext default help command (#1371)
akiraveliara Aug 8, 2022
8447942
Fix memberBefore missing roles in GuildMemberUpdateEventArgs when not…
selfdocumentingcode Aug 9, 2022
eba2fba
Ported CommandsNext cooldown attribute to Slash Commands (#1375)
OoLunar Aug 15, 2022
da296c0
Made all exceptions inherit from ApplicationCommandExecutionChecksFai…
OoLunar Aug 19, 2022
c9b68f1
Start on converters
OoLunar Aug 25, 2022
4fc014a
Added custom converter support:
OoLunar Aug 29, 2022
c79c9e0
Fixed startup errors; Added DiscordMessageArgumentConverter; Added (u…
OoLunar Oct 27, 2022
7bdeb7b
Fix registering converters
OoLunar Oct 30, 2022
616b171
(untested) Add number converters; Fix enums not registering choices c…
OoLunar Nov 1, 2022
bddacc8
Add DiscordMember converter; Switch from ArgumentException to new Mis…
OoLunar Nov 1, 2022
7035214
Actually fix Nullable and update TimeSpan converter to match with CNext
OoLunar Nov 2, 2022
299cafd
Add params/array support
OoLunar Nov 2, 2022
f9e5729
Boundry checks
OoLunar Nov 4, 2022
c2fd5e9
[ci-skip] Resolve naming errors
OoLunar Nov 17, 2022
7bfcada
"One less variable allocation"
OoLunar Nov 17, 2022
6056f6b
Remove unsupport NETSTANDARD1_3 support; Un-Emziware those variable n…
OoLunar Nov 17, 2022
060763d
Remove unused property
OoLunar Nov 17, 2022
7994dd6
Extra parameter limit attribute check
OoLunar Nov 17, 2022
7299df0
Remove UnregisterConverter(s) methods
OoLunar Nov 17, 2022
19c4afa
Changed BCL types to use framework names
OoLunar Nov 17, 2022
cd650a5
Pass InnerException to prevent passing TargetInvocationException
OoLunar Nov 18, 2022
06446b7
Fix enum support (again)
OoLunar Nov 21, 2022
3456d6b
Merge branch 'master' into fix/v4/slashies-cleanup
OoLunar Nov 27, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions DSharpPlus.CommandsNext/Attributes/CategoryAttribute.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// This file is part of the DSharpPlus project.
//
// Copyright (c) 2015 Mike Santiago
// Copyright (c) 2016-2022 DSharpPlus Contributors
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.

using System;
using System.Collections.Generic;
using System.Text;

namespace DSharpPlus.CommandsNext.Attributes
{
[AttributeUsage(AttributeTargets.Method, AllowMultiple = false, Inherited = true)]
public sealed class CategoryAttribute : Attribute
{
public string? Name { get; }

public CategoryAttribute(string? name)
{
if (string.IsNullOrWhiteSpace(name))
throw new ArgumentNullException(nameof(name), "Command category names cannot be null, empty, or all-whitespace.");

this.Name = name;
}
}
}
4 changes: 4 additions & 0 deletions DSharpPlus.CommandsNext/CommandsNextExtension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -589,6 +589,10 @@ private void RegisterCommands(Type t, CommandGroupBuilder? currentParent, IEnume
commandBuilder.WithHiddenStatus(true);
break;

case CategoryAttribute c:
commandBuilder.WithCategory(c.Name);
break;

default:
commandBuilder.WithCustomAttribute(xa);
break;
Expand Down
16 changes: 15 additions & 1 deletion DSharpPlus.CommandsNext/Converters/DefaultHelpFormatter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,21 @@ public override BaseHelpFormatter WithCommand(Command command)
/// <returns>This help formatter.</returns>
public override BaseHelpFormatter WithSubcommands(IEnumerable<Command> subcommands)
{
this.EmbedBuilder.AddField(this.Command is not null ? "Subcommands" : "Commands", string.Join(", ", subcommands.Select(x => Formatter.InlineCode(x.Name))), false);

var categories = subcommands.GroupBy(xm => xm.Category).OrderBy(xm => xm.Key == null).ThenBy(xm => xm.Key);

// no known categories, proceed without categorization
if (categories.Count() == 1 && categories.Single().Key == null)
{
this.EmbedBuilder.AddField(this.Command is not null ? "Subcommands" : "Commands", string.Join(", ", subcommands.Select(x => Formatter.InlineCode(x.Name))), false);

return this;
}

foreach (var category in categories)
{
this.EmbedBuilder.AddField(category.Key ?? "Uncategorized commands", string.Join(", ", category.Select(xm => Formatter.InlineCode(xm.Name))), false);
}

return this;
}
Expand Down
17 changes: 17 additions & 0 deletions DSharpPlus.CommandsNext/Entities/Builders/CommandBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ public class CommandBuilder
/// </summary>
public string Name { get; private set; } = null!;

/// <summary>
/// Gets the category set for this command.
/// </summary>
public string? Category { get; private set; }

/// <summary>
/// Gets the aliases set for this command.
/// </summary>
Expand Down Expand Up @@ -126,6 +131,17 @@ public CommandBuilder WithName(string name)
return this;
}

/// <summary>
/// Sets the category for this command.
/// </summary>
/// <param name="category">Category for this command. May be <see langword="null"/>.</param>
/// <returns>This builder.</returns>
public CommandBuilder WithCategory(string? category)
{
this.Category = category;
return this;
}

/// <summary>
/// Adds aliases to this command.
/// </summary>
Expand Down Expand Up @@ -265,6 +281,7 @@ internal virtual Command Build(CommandGroup? parent)
? throw new InvalidOperationException($"Cannot build a command with an invalid name. Use the method {nameof(this.WithName)} to set a valid name.")
: this.Name,

Category = this.Category,
Description = this.Description,
Aliases = this.Aliases,
ExecutionChecks = this.ExecutionChecks,
Expand Down
5 changes: 5 additions & 0 deletions DSharpPlus.CommandsNext/Entities/Command.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ public class Command
/// </summary>
public string Name { get; internal set; } = string.Empty;

/// <summary>
/// Gets the category this command belongs to.
/// </summary>
public string? Category { get; internal set; } = null;

/// <summary>
/// Gets this command's qualified name (i.e. one that includes all module names).
/// </summary>
Expand Down
15 changes: 0 additions & 15 deletions DSharpPlus.MSTest/DSharpPlus.MSTest.csproj

This file was deleted.

62 changes: 0 additions & 62 deletions DSharpPlus.MSTest/TestJson.cs

This file was deleted.

62 changes: 62 additions & 0 deletions DSharpPlus.SlashCommands/Attributes/ParameterLimitAttribute.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
// This file is part of the DSharpPlus project.
//
// Copyright (c) 2015 Mike Santiago
// Copyright (c) 2016-2022 DSharpPlus Contributors
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.

using System;

namespace DSharpPlus.SlashCommands.Attributes
{
/// <summary>
/// Intended to be used in conjunction on parameters marked with <see langword="params"/>, this attribute will limit the amount of elements in the array.
/// </summary>
[AttributeUsage(AttributeTargets.Parameter, Inherited = true, AllowMultiple = false)]
public sealed class ParameterLimitAttribute : Attribute
{
/// <summary>
/// The minimum amount of elements required in the parameter array.
/// </summary>
public readonly int Min;

/// <summary>
/// The maximum amount of elements allowed in the parameter array.
/// </summary>
public readonly int Max;

/// <summary>
/// Intended to be used in conjunction on parameters marked with <see langword="params"/>, this attribute will limit the amount of elements in the array.
/// </summary>
/// <param name="min">The minimum amount of elements required in the parameter array.</param>
/// <param name="max">The maximum amount of elements allowed in the parameter array.</param>
public ParameterLimitAttribute(int min, int max)
{
if (min < 0 || min > 25)
throw new ArgumentException("Minimum must be between 0 and 25 inclusive.", nameof(min));
else if (max < 1 || max > 25)
throw new ArgumentException("Maximum must be between 1 and 25 inclusive.", nameof(max));
else if (min > max)
throw new ArgumentException("Minimum cannot be greater than maximum.", nameof(min));

this.Min = min;
this.Max = max;
}
}
}
Loading