Skip to content

Commit

Permalink
Update Fergun.Interactive and use menu selections
Browse files Browse the repository at this point in the history
  • Loading branch information
d4n3436 committed Sep 20, 2024
1 parent 87f510a commit c0dfae9
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 35 deletions.
6 changes: 3 additions & 3 deletions src/Fergun.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
<ItemGroup>
<PackageReference Include="AngleSharp" Version="1.1.2" />
<PackageReference Include="Discord.Addons.Hosting" Version="6.1.0" />
<PackageReference Include="Discord.Net.Interactions" Version="3.15.3" />
<PackageReference Include="Discord.Net.WebSocket" Version="3.15.3" />
<PackageReference Include="Fergun.Interactive" Version="1.7.7" />
<PackageReference Include="Discord.Net.Interactions" Version="3.16.0" />
<PackageReference Include="Discord.Net.WebSocket" Version="3.16.0" />
<PackageReference Include="Fergun.Interactive" Version="1.8.0" />
<PackageReference Include="GScraper" Version="1.1.3" />
<PackageReference Include="GTranslate" Version="2.2.6" />
<PackageReference Include="Humanizer.Core" Version="2.14.1" />
Expand Down
51 changes: 24 additions & 27 deletions src/Modules/UtilityModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -388,13 +388,13 @@ public async Task<RuntimeResult> HelpAsync()
links.Add(Format.Url(_localizer["Donate"], _fergunOptions.DonationUrl));
}

string joinedLinks = string.Join(" | ", links);

var page = new PageBuilder()
.WithTitle(_localizer["FergunHelp"])
.WithDescription(description)
.WithColor(Color.Orange);

string joinedLinks = string.Join(" | ", links);

if (!string.IsNullOrEmpty(joinedLinks))
{
page.AddField(_localizer["Links"], joinedLinks);
Expand All @@ -413,31 +413,28 @@ public async Task<RuntimeResult> HelpAsync()
var modules = _commands.Modules.Where(x => x.Name is not nameof(OwnerModule) and not nameof(BlacklistModule))
.ToDictionary(x => x.Name, x => x);

InteractiveMessageResult<ModuleOption?>? result = null;
var interaction = Context.Interaction;
var responseType = InteractionResponseType.ChannelMessageWithSource;

_logger.LogInformation("Displaying help menu to user {User} ({Id})", Context.User, Context.User.Id);

while (result is null || result.Status == InteractiveStatus.Success)
{
var selection = new SelectionBuilder<ModuleOption>()
.AddUser(Context.User)
.WithOptions(categories)
.WithEmoteConverter(x => x.Emote)
.WithStringConverter(x => x.Name)
.WithInputType(InputType.SelectMenus)
.WithSelectionPage(page)
.WithActionOnTimeout(ActionOnStop.DisableInput)
.Build();
var menu = new MenuSelectionBuilder<ModuleOption>()
.AddUser(Context.User)
.WithOptions(categories)
.WithEmoteConverter(x => x.Emote)
.WithStringConverter(x => x.Name)
.WithPlaceholder(_localizer["HelpMenuPlaceholder"])
.WithInputHandler(SetModule)
.WithSetDefaultValues(true)
.WithInputType(InputType.SelectMenus)
.WithSelectionPage(page)
.WithActionOnTimeout(ActionOnStop.DisableInput)
.Build();

result = await _interactive.SendSelectionAsync(selection, interaction, _fergunOptions.SelectionTimeout, responseType);
await _interactive.SendSelectionAsync(menu, Context.Interaction, _fergunOptions.SelectionTimeout);

if (!result.IsSuccess) break;
return FergunResult.FromSuccess();

responseType = InteractionResponseType.UpdateMessage;
interaction = result.StopInteraction!;
var module = modules[result.Value.Name.Name];
IPage SetModule(ModuleOption option)
{
var module = modules[option.Name.Name];
IEnumerable<string> commandDescriptions;

string locale = Context.Interaction.UserLocale;
Expand All @@ -459,19 +456,19 @@ public async Task<RuntimeResult> HelpAsync()
.Select(x => $"</{x.Name}:{x.Id}> - {x.DescriptionLocalizations.GetValueOrDefault(locale, x.Description)}");
}

page = new PageBuilder()
.WithTitle($"{result.Value.Emote} {_localizer[result.Value.Name]}")
.WithDescription(_localizer[result.Value.Description])
var builder = new PageBuilder()
.WithTitle($"{option.Emote} {_localizer[option.Name]}")
.WithDescription(_localizer[option.Description])
.AddField(_localizer["Commands"], string.Join('\n', commandDescriptions))
.WithColor(Color.Orange);

if (!string.IsNullOrEmpty(joinedLinks))
{
page.AddField(_localizer["Links"], joinedLinks);
}
}

return FergunResult.FromSuccess();
return builder.Build();
}
}

[SlashCommand("ping", "Sends the response time of the bot.")]
Expand Down
13 changes: 8 additions & 5 deletions src/Resources/Modules.OtherModule.es.resx
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,12 @@
<data name="lyrics-spotify.description" xml:space="preserve">
<value>Obtiene la letra de la canción que estás escuchando en Spotify.</value>
</data>
<data name="Note" xml:space="preserve">
<value>Nota</value>
</data>
<data name="UseSpotifyLyricsCommand" xml:space="preserve">
<value>ℹ️ Usa {0} para obtener fácilmente la letra de la canción que estás escuchando.</value>
</data>
<data name="command-stats.description" xml:space="preserve">
<value>Muestra las estadísticas de uso de los comandos.</value>
</data>
Expand Down Expand Up @@ -249,10 +255,7 @@
<data name="lyrics-spotify.name" xml:space="preserve">
<value>letra-spotify</value>
</data>
<data name="Note" xml:space="preserve">
<value>Nota</value>
</data>
<data name="UseSpotifyLyricsCommand" xml:space="preserve">
<value>ℹ️ Usa {0} para obtener fácilmente la letra de la canción que estás escuchando.</value>
<data name="HelpMenuPlaceholder" xml:space="preserve">
<value>Selecciona una categoría</value>
</data>
</root>
3 changes: 3 additions & 0 deletions src/Resources/Modules.OtherModule.resx
Original file line number Diff line number Diff line change
Expand Up @@ -216,4 +216,7 @@
<data name="UseSpotifyLyricsCommand" xml:space="preserve">
<value>ℹ️ Use {0} to easily get the lyrics of the song you're currently listening to.</value>
</data>
<data name="HelpMenuPlaceholder" xml:space="preserve">
<value>Select a category</value>
</data>
</root>

0 comments on commit c0dfae9

Please sign in to comment.