-
Notifications
You must be signed in to change notification settings - Fork 0
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
1 parent
9e1d584
commit b6d0034
Showing
14 changed files
with
232 additions
and
170 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 |
---|---|---|
@@ -1,20 +1,22 @@ | ||
using Discord; | ||
using Discord.Interactions; | ||
using YoutubeExplode; | ||
using YoutubeExplode.Search; | ||
|
||
namespace Musician.Audio | ||
namespace Musician.Audio; | ||
|
||
public class YouTubeAutocompleteHandler : AutocompleteHandler | ||
{ | ||
public class YouTubeAutocompleteHandler : AutocompleteHandler | ||
public override Task<AutocompletionResult> GenerateSuggestionsAsync(IInteractionContext context, | ||
IAutocompleteInteraction autocompleteInteraction, IParameterInfo parameter, IServiceProvider services) | ||
{ | ||
public override async Task<AutocompletionResult> GenerateSuggestionsAsync(IInteractionContext context, IAutocompleteInteraction autocompleteInteraction, IParameterInfo parameter, IServiceProvider services) | ||
{ | ||
var input = autocompleteInteraction.Data.Current.Value as string; | ||
var youtube = new YoutubeClient(); | ||
var videos = youtube.Search.GetVideosAsync(input); | ||
string? input = autocompleteInteraction.Data.Current.Value as string; | ||
YoutubeClient youtube = new(); | ||
IAsyncEnumerable<VideoSearchResult> videos = youtube.Search.GetVideosAsync(input); | ||
|
||
var autocompleteResults = videos.Take(5).Select(video => new AutocompleteResult(video.Title, video.Url)); | ||
IAsyncEnumerable<AutocompleteResult> autocompleteResults = | ||
videos.Take(5).Select(video => new AutocompleteResult(video.Title, video.Url)); | ||
|
||
return AutocompletionResult.FromSuccess(autocompleteResults.ToEnumerable()); | ||
} | ||
return Task.FromResult(AutocompletionResult.FromSuccess(autocompleteResults.ToEnumerable())); | ||
} | ||
} | ||
} |
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.