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

Commit

Permalink
Merge branch 'v1.2.0' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
oliverbooth committed Jun 1, 2023
2 parents 44a8292 + b6b98b0 commit d834753
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 4 deletions.
15 changes: 14 additions & 1 deletion Cloak/AutocompleteProviders/GroupAutocompleteProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,19 @@ public Task<IEnumerable<DiscordAutoCompleteChoice>> Provider(AutocompleteContext
{
var roleService = context.Services.GetRequiredService<SelfRoleService>();
IReadOnlyList<string> groups = roleService.GetGroups(context.Guild);
return Task.FromResult(groups.Select(g => new DiscordAutoCompleteChoice(g, g)));
var choices = new List<DiscordAutoCompleteChoice>();

string? query = context.OptionValue?.ToString()?.Trim();
bool isQueryEmpty = string.IsNullOrWhiteSpace(query);

foreach (string group in groups)
{
if (isQueryEmpty || group.Contains(query!, StringComparison.OrdinalIgnoreCase))
{
choices.Add(new DiscordAutoCompleteChoice(group, group));
}
}

return Task.FromResult(choices.AsEnumerable());
}
}
17 changes: 15 additions & 2 deletions Cloak/AutocompleteProviders/SelfRoleAutocompleteProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,20 @@ internal sealed class SelfRoleAutocompleteProvider : IAutocompleteProvider
public Task<IEnumerable<DiscordAutoCompleteChoice>> Provider(AutocompleteContext context)
{
var roleService = context.Services.GetRequiredService<SelfRoleService>();
return Task.FromResult(roleService.GetDiscordRoles(context.Guild)
.Select(role => new DiscordAutoCompleteChoice(role.Name, role.Id.ToString())));
IReadOnlyList<DiscordRole> roles = roleService.GetDiscordRoles(context.Guild);
var choices = new List<DiscordAutoCompleteChoice>();

string? query = context.OptionValue?.ToString()?.Trim();
bool isQueryEmpty = string.IsNullOrWhiteSpace(query);

foreach (DiscordRole role in roles)
{
if (isQueryEmpty || role.Name.Contains(query!, StringComparison.OrdinalIgnoreCase))
{
choices.Add(new DiscordAutoCompleteChoice(role.Name, role.Id.ToString()));
}
}

return Task.FromResult(choices.AsEnumerable());
}
}
2 changes: 1 addition & 1 deletion Cloak/Cloak.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
<VersionPrefix>1.1.1</VersionPrefix>
<VersionPrefix>1.2.0</VersionPrefix>
</PropertyGroup>

<PropertyGroup Condition="'$(VersionSuffix)' != '' And '$(BuildNumber)' == ''">
Expand Down

0 comments on commit d834753

Please sign in to comment.