add: Added dropdown menu for .cmds help and group help (part of cmds). Group help will no longer be on .h

fix: paginated response replies will no longer ping the author
This commit is contained in:
Kwoth
2024-05-20 00:37:29 +00:00
parent e2066f433f
commit 4e570475df
5 changed files with 124 additions and 61 deletions

View File

@@ -6,10 +6,10 @@ public sealed class NadekoButtonInteraction : NadekoInteraction
DiscordSocketClient client,
ulong authorId,
ButtonBuilder button,
Func<SocketMessageComponent, Task> onClick,
Func<SocketMessageComponent, Task> onAction,
bool onlyAuthor,
bool singleUse = true)
: base(client, authorId, button.CustomId, onClick, onlyAuthor, singleUse)
: base(client, authorId, button.CustomId, onAction, onlyAuthor, singleUse)
{
Button = button;
}

View File

@@ -6,10 +6,10 @@ public sealed class NadekoSelectInteraction : NadekoInteraction
DiscordSocketClient client,
ulong authorId,
SelectMenuBuilder menu,
Func<SocketMessageComponent, Task> onClick,
Func<SocketMessageComponent, Task> onAction,
bool onlyAuthor,
bool singleUse = true)
: base(client, authorId, menu.CustomId, onClick, onlyAuthor, singleUse)
: base(client, authorId, menu.CustomId, onAction, onlyAuthor, singleUse)
{
Menu = menu;
}

View File

@@ -3,7 +3,7 @@
public abstract class NadekoInteraction
{
private readonly ulong _authorId;
private readonly Func<SocketMessageComponent, Task> _onClick;
private readonly Func<SocketMessageComponent, Task> _onAction;
private readonly bool _onlyAuthor;
public DiscordSocketClient Client { get; }
@@ -17,13 +17,13 @@ public abstract class NadekoInteraction
DiscordSocketClient client,
ulong authorId,
string customId,
Func<SocketMessageComponent, Task> onClick,
Func<SocketMessageComponent, Task> onAction,
bool onlyAuthor,
bool singleUse = true)
{
_authorId = authorId;
_customId = customId;
_onClick = onClick;
_onAction = onAction;
_onlyAuthor = onlyAuthor;
_singleUse = singleUse;
_interactionCompletedSource = new(TaskCreationOptions.RunContinuationsAsynchronously);
@@ -61,12 +61,19 @@ public abstract class NadekoInteraction
_ = Task.Run(async () =>
{
_interactionCompletedSource.TrySetResult(true);
await ExecuteOnActionAsync(smc);
if (!smc.HasResponded)
try
{
await smc.DeferAsync();
_interactionCompletedSource.TrySetResult(true);
await ExecuteOnActionAsync(smc);
if (!smc.HasResponded)
{
await smc.DeferAsync();
}
}
catch (Exception ex)
{
Log.Warning(ex, "An exception occured while handling an interaction: {Message}", ex.Message);
}
});
@@ -77,5 +84,5 @@ public abstract class NadekoInteraction
public abstract void AddTo(ComponentBuilder cb);
public Task ExecuteOnActionAsync(SocketMessageComponent smc)
=> _onClick(smc);
=> _onAction(smc);
}

View File

@@ -44,9 +44,8 @@ public partial class ResponseBuilder
var leftButton = new ButtonBuilder()
.WithStyle(ButtonStyle.Primary)
.WithCustomId(BUTTON_LEFT)
.WithDisabled(lastPage == 0)
.WithEmote(InteractionHelpers.ArrowLeft)
.WithDisabled(currentPage <= 0);
.WithDisabled(lastPage == 0 || currentPage <= 0);
var leftBtnInter = new NadekoButtonInteraction(_client,
model.User?.Id ?? 0,
@@ -78,9 +77,8 @@ public partial class ResponseBuilder
var rightButton = new ButtonBuilder()
.WithStyle(ButtonStyle.Primary)
.WithCustomId(BUTTON_RIGHT)
.WithDisabled(lastPage == 0)
.WithEmote(InteractionHelpers.ArrowRight)
.WithDisabled(lastPage == 0 || currentPage > lastPage);
.WithDisabled(lastPage == 0 || currentPage >= lastPage);
var rightBtnInter = new NadekoButtonInteraction(_client,
model.User?.Id ?? 0,
@@ -141,6 +139,7 @@ public partial class ResponseBuilder
.SendMessageAsync(model.Text,
embed: embed.Build(),
components: cb.Build(),
allowedMentions: model.SanitizeMentions,
messageReference: model.MessageReference);
if (lastPage == 0 && _paginationBuilder.InteractionFunc is null)