feat(bot): clean up / paginate help command

This commit is contained in:
spiral 2022-06-14 19:05:15 -04:00
parent f3c02a4254
commit f0b5749d5c
No known key found for this signature in database
GPG Key ID: 244A11E4B0BCF40E
5 changed files with 159 additions and 61 deletions

View File

@ -3,7 +3,7 @@ namespace Myriad.Types;
public record MessageComponent
{
public ComponentType Type { get; init; }
public ButtonStyle? Style { get; init; }
public ButtonStyle? Style { get; set; }
public string? Label { get; init; }
public Emoji? Emoji { get; init; }
public string? CustomId { get; init; }

View File

@ -52,6 +52,7 @@ public record Message
// public bool MentionEveryone { get; init; }
public User.Extra[] Mentions { get; init; }
// public ulong[] MentionRoles { get; init; }
public MessageComponent[]? Components { get; init; }
public Attachment[] Attachments { get; init; }
public Embed[]? Embeds { get; init; }

View File

@ -1,5 +1,5 @@
using Myriad.Builders;
using Myriad.Types;
using Myriad.Rest.Types.Requests;
using PluralKit.Core;
@ -10,10 +10,18 @@ public class Help
private static Embed helpEmbed = new()
{
Title = "PluralKit",
Description = "PluralKit is a bot designed for plural communities on Discord. It allows you to register systems, maintain system information, set up message proxying, log switches, and more.",
Fields = new[]
Description = "PluralKit is a bot designed for plural communities on Discord, and is open for anyone to use. It allows you to register systems, maintain system information, set up message proxying, log switches, and more.",
Footer = new("By @Ske#6201 | Myriad by @Layl#8888 | GitHub: https://github.com/PluralKit/PluralKit/ | Website: https://pluralkit.me/"),
Color = DiscordUtils.Blue,
};
private static Dictionary<string, Embed.Field[]> helpEmbedPages = new Dictionary<string, Embed.Field[]>
{
new Embed.Field
{
"basicinfo",
new Embed.Field[]
{
new
(
"What is this for? What are systems?",
"This bot detects messages with certain tags associated with a profile, then replaces that message under a \"pseudo-account\" of that profile using webhooks."
@ -24,6 +32,12 @@ public class Help
"Why are people's names saying [BOT] next to them?",
"These people are not actually bots, this is just a Discord limitation. See [the documentation](https://pluralkit.me/guide#proxying) for an in-depth explanation."
),
}
},
{
"gettingstarted",
new Embed.Field[]
{
new
(
"How do I get started?",
@ -38,6 +52,12 @@ public class Help
"\nSee [the Getting Started guide](https://pluralkit.me/start) for more information."
})
),
}
},
{
"usefultips",
new Embed.Field[]
{
new
(
"Useful tips",
@ -48,6 +68,12 @@ public class Help
"Type **`pk;invite`** to get a link to invite this bot to your own server!"
})
),
}
},
{
"moreinfo",
new Embed.Field[]
{
new
(
"More information",
@ -61,13 +87,81 @@ public class Help
(
"Support server",
"We also have a Discord server for support, discussion, suggestions, announcements, etc: https://discord.gg/PczBt78"
)
},
Footer = new("By @Ske#6201 | Myriad by @Layl#8888 | GitHub: https://github.com/PluralKit/PluralKit/ | Website: https://pluralkit.me/"),
Color = DiscordUtils.Blue,
),
}
}
};
public Task HelpRoot(Context ctx) => ctx.Reply(embed: helpEmbed);
private static MessageComponent helpPageButtons(ulong userId) => new MessageComponent
{
Type = ComponentType.ActionRow,
Components = new[]
{
new MessageComponent
{
Type = ComponentType.Button,
Style = ButtonStyle.Secondary,
Label = "Basic Info",
CustomId = $"help-menu-basicinfo-{userId}",
Emoji = new() { Name = "\u2139" },
},
new()
{
Type = ComponentType.Button,
Style = ButtonStyle.Secondary,
Label = "Getting Started",
CustomId = $"help-menu-gettingstarted-{userId}",
Emoji = new() { Name = "\u2753", },
},
new()
{
Type = ComponentType.Button,
Style = ButtonStyle.Secondary,
Label = "Useful Tips",
CustomId = $"help-menu-usefultips-{userId}",
Emoji = new() { Name = "\U0001f4a1", },
},
new()
{
Type = ComponentType.Button,
Style = ButtonStyle.Secondary,
Label = "More Info",
CustomId = $"help-menu-moreinfo-{userId}",
Emoji = new() { Id = 986379675066593330, },
}
}
};
public Task HelpRoot(Context ctx)
=> ctx.Rest.CreateMessage(ctx.Channel.Id, new MessageRequest
{
Embeds = new[] { helpEmbed with { Description = helpEmbed.Description + "\n\n**Use the buttons below to see more info!**" } },
Components = new[] { helpPageButtons(ctx.Author.Id) },
});
public static Task ButtonClick(InteractionContext ctx)
{
if (!ctx.CustomId.Contains(ctx.User.Id.ToString()))
return ctx.Ignore();
var buttons = helpPageButtons(ctx.User.Id);
if (ctx.Event.Message.Components.First().Components.Where(x => x.CustomId == ctx.CustomId).First().Style == ButtonStyle.Primary)
return ctx.Respond(InteractionResponse.ResponseType.UpdateMessage, new()
{
Embeds = new[] { helpEmbed with { Description = helpEmbed.Description + "\n\n**Use the buttons below to see more info!**" } },
Components = new[] { buttons }
});
buttons.Components.Where(x => x.CustomId == ctx.CustomId).First().Style = ButtonStyle.Primary;
return ctx.Respond(InteractionResponse.ResponseType.UpdateMessage, new()
{
Embeds = new[] { helpEmbed with { Fields = helpEmbedPages.GetValueOrDefault(ctx.CustomId.Split("-")[2]) } },
Components = new[] { buttons }
});
}
private static string explanation = String.Join("\n\n", new[]
{

View File

@ -21,11 +21,14 @@ public class InteractionCreated: IEventHandler<InteractionCreateEvent>
if (evt.Type == Interaction.InteractionType.MessageComponent)
{
var customId = evt.Data?.CustomId;
if (customId != null)
{
if (customId == null) return;
var ctx = new InteractionContext(evt, _services);
if (customId.Contains("help-menu"))
await Help.ButtonClick(ctx);
else
await _interactionDispatch.Dispatch(customId, ctx);
}
}
}
}

View File

@ -36,7 +36,7 @@ public class InteractionContext
await Respond(InteractionResponse.ResponseType.DeferredUpdateMessage,
new InteractionApplicationCommandCallbackData
{
// Components = _evt.Message.Components
Components = Event.Message.Components
});
}