-
-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
250 additions
and
40 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
using Discord; | ||
using Discord.Interactions; | ||
using FMBot.Bot.Extensions; | ||
|
||
namespace FMBot.Bot.AutoCompleteHandlers; | ||
|
||
public class DecadeAutoComplete : AutocompleteHandler | ||
{ | ||
private readonly List<string> _allPossibleCombinations; | ||
public DecadeAutoComplete() | ||
{ | ||
this._allPossibleCombinations = new List<string>(); | ||
|
||
for (var i = 2020; i >= 1900; i -= 10) | ||
{ | ||
this._allPossibleCombinations.Add($"{i}"); | ||
} | ||
} | ||
|
||
public override async Task<AutocompletionResult> GenerateSuggestionsAsync(IInteractionContext context, | ||
IAutocompleteInteraction autocompleteInteraction, IParameterInfo parameter, IServiceProvider services) | ||
{ | ||
var results = new List<string>(); | ||
|
||
if (autocompleteInteraction?.Data?.Current?.Value == null || | ||
string.IsNullOrWhiteSpace(autocompleteInteraction?.Data?.Current?.Value.ToString())) | ||
{ | ||
results | ||
.ReplaceOrAddToList(this._allPossibleCombinations.Take(12).ToList()); | ||
} | ||
else | ||
{ | ||
var searchValue = autocompleteInteraction.Data.Current.Value.ToString(); | ||
|
||
results.ReplaceOrAddToList(this._allPossibleCombinations | ||
.Where(w => w.StartsWith(searchValue, StringComparison.OrdinalIgnoreCase)) | ||
.Take(6)); | ||
|
||
results.ReplaceOrAddToList(this._allPossibleCombinations | ||
.Where(w => w.Contains(searchValue, StringComparison.OrdinalIgnoreCase)) | ||
.Take(5)); | ||
} | ||
|
||
return await Task.FromResult( | ||
AutocompletionResult.FromSuccess(results.Select(s => new AutocompleteResult($"{s}s", s)))); | ||
} | ||
} |
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
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
Oops, something went wrong.