-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add "rule" option for infraction-issuing commands
EF migration required
- Loading branch information
1 parent
98d0df7
commit 4dbbe8c
Showing
20 changed files
with
542 additions
and
217 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
using DSharpPlus.Entities; | ||
using DSharpPlus.SlashCommands; | ||
using Hammer.Data; | ||
using Hammer.Services; | ||
using Microsoft.Extensions.DependencyInjection; | ||
|
||
namespace Hammer.AutocompleteProviders; | ||
|
||
/// <summary> | ||
/// Provides autocomplete suggestions for rules. | ||
/// </summary> | ||
internal sealed class RuleAutocompleteProvider : IAutocompleteProvider | ||
{ | ||
/// <inheritdoc /> | ||
public Task<IEnumerable<DiscordAutoCompleteChoice>> Provider(AutocompleteContext context) | ||
{ | ||
var ruleService = context.Services.GetRequiredService<RuleService>(); | ||
IReadOnlyList<Rule> rules = ruleService.GetGuildRules(context.Guild); | ||
return Task.FromResult(rules.Select(rule => new DiscordAutoCompleteChoice(GetRuleDescription(rule), rule.Id))); | ||
} | ||
|
||
private static string GetRuleDescription(Rule rule) | ||
{ | ||
return $"{rule.Id}: {rule.Brief ?? rule.Content}"; | ||
} | ||
} |
Oops, something went wrong.