Skip to content
This repository has been archived by the owner on Feb 14, 2024. It is now read-only.

Commit

Permalink
Fix parsing no-arg commands
Browse files Browse the repository at this point in the history
  • Loading branch information
OoLunar committed Nov 6, 2023
1 parent ca914fc commit 0adb51e
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ namespace DSharpPlus.CommandAll.Examples.Basics.Commands
public sealed class UserInfoCommand
{
[Command("user_info"), DisplayName("User Info"), SlashCommandTypes(ApplicationCommandType.SlashCommand, ApplicationCommandType.UserContextMenu)]
public static async Task ExecuteAsync(CommandContext context, DiscordUser user) => await context.RespondAsync(new DiscordMessageBuilder().WithEmbed(new DiscordEmbedBuilder().WithDescription($"This person's account was created on {user.CreationTimestamp:MMMM dd, yyyy}")));
public static async Task ExecuteAsync(CommandContext context, DiscordUser? user = null) => await context.RespondAsync(new DiscordMessageBuilder().WithEmbed(new DiscordEmbedBuilder().WithDescription($"This person's account was created on {(user ?? context.User).CreationTimestamp:MMMM dd, yyyy}")));
}
}
9 changes: 7 additions & 2 deletions src/Processors/TextCommands/TextCommandProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -157,11 +157,16 @@ public async Task ExecuteTextCommandAsync(DiscordClient client, MessageCreateEve
return;
}

index++; // Skip the space
if (index < commandText.Length && commandText[index] == ' ')
{
// Skip the space
index++;
}

int nextIndex = index;
while (nextIndex != -1)
{
if (nextIndex == commandText.Length)
if (nextIndex >= commandText.Length)
{
break;
}
Expand Down
15 changes: 11 additions & 4 deletions src/Processors/TextCommands/TextConverterContext.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using System;
using DSharpPlus.CommandAll.Converters;
using DSharpPlus.CommandAll.Processors.TextCommands.Parsing;

Expand All @@ -18,9 +17,17 @@ public bool NextTextArgument()
return false;
}

//NextTextIndex = Splicer(Extension, RawArguments, ref NextTextIndex, out ReadOnlySpan<char> argument);
//CurrentTextArgument = argument.Trim().ToString();
return NextTextIndex != -1;
int nextTextIndex = NextTextIndex;
string? nextText = Splicer(Extension, RawArguments, ref nextTextIndex);
if (string.IsNullOrEmpty(nextText))
{
CurrentTextArgument = string.Empty;
return false;
}

NextTextIndex = nextTextIndex;
CurrentTextArgument = nextText;
return true;
}
}
}

0 comments on commit 0adb51e

Please sign in to comment.