Better help part 1
This commit is contained in:
32
EventBot/Misc/Extensions.cs
Normal file
32
EventBot/Misc/Extensions.cs
Normal file
@@ -0,0 +1,32 @@
|
||||
using Discord;
|
||||
using Discord.Commands;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace EventBot.Misc
|
||||
{
|
||||
public static class Extensions
|
||||
{
|
||||
|
||||
public static ContextType GetContextType(this ICommandContext context)
|
||||
{
|
||||
ContextType type = 0;
|
||||
if (context.Channel is IGuildChannel)
|
||||
type |= ContextType.Guild;
|
||||
if (context.Channel is IDMChannel)
|
||||
type |= ContextType.DM;
|
||||
if (context.Channel is IGroupChannel)
|
||||
type |= ContextType.Group;
|
||||
return type;
|
||||
}
|
||||
|
||||
public static bool IsContextType(this ICommandContext context, ContextType type) => (context.GetContextType() & type) != 0;
|
||||
|
||||
public static string FormatCallHelpString(this CommandInfo command)
|
||||
{
|
||||
return $"{command.Aliases[0]} {string.Join(" ", command.Parameters.Select(p => p.IsOptional ? $"[{p.Name}]" : $"<{p.Name}>"))}";
|
||||
}
|
||||
}
|
||||
}
|
@@ -7,6 +7,8 @@ using System.Threading.Tasks;
|
||||
using System.Linq;
|
||||
using EventBot.Attributes;
|
||||
using EventBot.Services;
|
||||
using Discord.Addons.Interactive;
|
||||
using EventBot.Misc;
|
||||
|
||||
namespace EventBot.Modules
|
||||
{
|
||||
@@ -22,6 +24,7 @@ namespace EventBot.Modules
|
||||
[RequireOwner(Group = "Permission")]
|
||||
[RequireContext(ContextType.Guild)]
|
||||
[Command("prefix")]
|
||||
[Name("Configure prefix")]
|
||||
[Summary("Gets prefix.")]
|
||||
public async Task PrefixCommand()
|
||||
{
|
||||
@@ -38,6 +41,7 @@ namespace EventBot.Modules
|
||||
[RequireOwner(Group = "Permission")]
|
||||
[RequireContext(ContextType.Guild)]
|
||||
[Command("prefix")]
|
||||
[Name("Configure prefix")]
|
||||
[Summary("Sets prefix.")]
|
||||
public async Task PrefixCommand(
|
||||
[Summary("New prefix to set")] string newPrefix)
|
||||
@@ -50,8 +54,9 @@ namespace EventBot.Modules
|
||||
await ReplyAsync($"Prefix has been set to `{guildConfig.Prefix}`");
|
||||
}
|
||||
|
||||
|
||||
[Group("help")]
|
||||
public class HelpModule : ModuleBase<SocketCommandContext>
|
||||
public class HelpModule : InteractiveBase<SocketCommandContext>
|
||||
{
|
||||
|
||||
private readonly CommandService _commands;
|
||||
@@ -61,23 +66,47 @@ namespace EventBot.Modules
|
||||
}
|
||||
|
||||
[Command]
|
||||
[Name("Help")]
|
||||
[Summary("Lists all commands with there descriptions.")]
|
||||
public async Task DefaultHelpAsync()
|
||||
{
|
||||
var embed = new EmbedBuilder()
|
||||
.WithTitle("Command list")
|
||||
.WithColor(Color.DarkBlue)
|
||||
.WithCurrentTimestamp()
|
||||
.WithFields(_commands.Commands
|
||||
.Where(c => c.Attributes.Where(a => a is NoHelpAttribute || (a is RequireContextAttribute requireContext)).Count() == 0)
|
||||
.Select(c =>
|
||||
new EmbedFieldBuilder()
|
||||
var pagedCommands = _commands.Commands
|
||||
.OrderBy(c => c.Aliases[0])
|
||||
.Where(c => c.Attributes
|
||||
.Select(a => {
|
||||
switch (a)
|
||||
{
|
||||
Name = $"`{string.Join(", ", c.Aliases)} {string.Join(" ", c.Parameters.Select(p => p.IsOptional ? $"[{p.Name}]" : $"<{p.Name}>"))}`",
|
||||
Value = c.Summary
|
||||
case NoHelpAttribute _:
|
||||
return false;
|
||||
case RequireContextAttribute rc:
|
||||
return Context.IsContextType(rc.Contexts);
|
||||
default:
|
||||
return true;
|
||||
}
|
||||
})
|
||||
);
|
||||
await Context.User.SendMessageAsync(embed: embed.Build());
|
||||
.Aggregate(true, (a, r) => a && r))
|
||||
.SelectMany(c => c.Aliases.Select(a => new { CI = c, MA = (c.Aliases[0] == a), A = a}).Reverse())
|
||||
.Select((e, i) => new { Command = e, Index = i })
|
||||
.GroupBy(o => o.Index / 20)
|
||||
.Select(g => g.Select(o => o.Command));
|
||||
|
||||
var pager = new PaginatedMessage()
|
||||
{
|
||||
Title = "Command list",
|
||||
Color = Color.DarkBlue,
|
||||
Pages = pagedCommands.Select(p => string.Join("\r\n", p.Select(c => {
|
||||
if (c.MA)
|
||||
return $"`{c.CI.FormatCallHelpString()}` - **{c.CI.Name}**";
|
||||
else
|
||||
return $"`{c.A}` `↪`";
|
||||
}))),
|
||||
Options = new PaginatedAppearanceOptions()
|
||||
{
|
||||
Info = null,
|
||||
JumpDisplayOptions = JumpDisplayOptions.Never
|
||||
}
|
||||
};
|
||||
await PagedReplyAsync(pager);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -24,8 +24,10 @@ namespace EventBot.Modules
|
||||
}
|
||||
|
||||
[Command("join")]
|
||||
[Alias("j")]
|
||||
[Name("Join event")]
|
||||
[Summary("Joins latest or specified event with specified event role.")]
|
||||
public async Task JoinAsync(
|
||||
public async Task JoinEvent(
|
||||
[Summary("Role emote or role ID to join the most recent event.")] string emoteOrId,
|
||||
[Summary("Extra information that might be needed by organizers.")] string extraInformation = null,
|
||||
[Summary("Optional event ID, used to join an event that started before the most recent one.")] Event @event = null)
|
||||
@@ -64,8 +66,9 @@ namespace EventBot.Modules
|
||||
}
|
||||
|
||||
[Command("config logchannel")]
|
||||
[Name("Configure logging channel")]
|
||||
[Summary("Sets logging channel for role changes.")]
|
||||
public async Task SetRoleChannelAsync(
|
||||
public async Task ConfigureEventLogChannel(
|
||||
[Summary("Channel to use for logging.")] IChannel channel)
|
||||
{
|
||||
var guild = _database.GuildConfigs.FirstOrDefault(g => g.GuildId == Context.Guild.Id);
|
||||
@@ -79,8 +82,9 @@ namespace EventBot.Modules
|
||||
}
|
||||
|
||||
[Command("config partrole")]
|
||||
[Name("Configure participant role")]
|
||||
[Summary("Sets discord role to assign when the user selects a role.")]
|
||||
public async Task SetParticipationRole(
|
||||
public async Task ConfigureEventParticipantRole(
|
||||
[Summary("Role to assign.")] IRole role)
|
||||
{
|
||||
var guild = _database.GuildConfigs.FirstOrDefault(g => g.GuildId == Context.Guild.Id);
|
||||
@@ -94,8 +98,10 @@ namespace EventBot.Modules
|
||||
}
|
||||
|
||||
[Command("new")]
|
||||
[Alias("add", "create")]
|
||||
[Name("Create event")]
|
||||
[Summary("Creates a new event.")]
|
||||
public async Task NewEvent(
|
||||
public async Task CreateEvent(
|
||||
[Summary("Title for the event.")] string title,
|
||||
[Summary("Description for the event.")] string description,
|
||||
[Summary("Type of event registration.")] Event.EventParticipactionType type = Event.EventParticipactionType.Quick)
|
||||
@@ -117,6 +123,7 @@ namespace EventBot.Modules
|
||||
}
|
||||
|
||||
[Command("update title")]
|
||||
[Name("Update event's title")]
|
||||
[Summary("Updates the event's title.")]
|
||||
public async Task UpdateEventTitle(
|
||||
[Summary("Title for the event.")] string title,
|
||||
@@ -134,6 +141,8 @@ namespace EventBot.Modules
|
||||
await _events.UpdateEventMessage(@event);
|
||||
}
|
||||
[Command("update description")]
|
||||
[Alias("update desc")]
|
||||
[Name("Update event's description")]
|
||||
[Summary("Updates the event's description.")]
|
||||
public async Task UpdateEventDescription(
|
||||
[Summary("Description for the event.")] string description,
|
||||
@@ -152,6 +161,7 @@ namespace EventBot.Modules
|
||||
}
|
||||
|
||||
[Command("update type")]
|
||||
[Name("Update event's type")]
|
||||
[Summary("Updates the event type.")]
|
||||
public async Task UpdateEventType(
|
||||
[Summary("Type of event registration.")] Event.EventParticipactionType type,
|
||||
@@ -175,6 +185,8 @@ namespace EventBot.Modules
|
||||
|
||||
|
||||
[Command("role new")]
|
||||
[Alias("role add", "role create")]
|
||||
[Name("Add role")]
|
||||
[Summary("Adds a new role to the event.")]
|
||||
public async Task NewEventRole(
|
||||
[Summary("Title of the role.")] string title,
|
||||
@@ -211,7 +223,8 @@ namespace EventBot.Modules
|
||||
}
|
||||
|
||||
[Command("role update title")]
|
||||
[Summary("Updates the role's title")]
|
||||
[Name("Update role's title")]
|
||||
[Summary("Updates the role's title.")]
|
||||
public async Task UpdateEventRoleTitle(
|
||||
[Summary("Which role to update.")] EventRole eventRole,
|
||||
[Summary("The new title for the role.")][Remainder] string title)
|
||||
@@ -227,7 +240,9 @@ namespace EventBot.Modules
|
||||
await _events.UpdateEventMessage(eventRole.Event);
|
||||
}
|
||||
|
||||
[Command("role update desc")]
|
||||
[Command("role update description")]
|
||||
[Alias("role update desc")]
|
||||
[Name("Update role's description")]
|
||||
[Summary("Updates the role's description.")]
|
||||
public async Task UpdateEventRoleDescription(
|
||||
[Summary("Which role to update.")] EventRole eventRole,
|
||||
@@ -245,6 +260,7 @@ namespace EventBot.Modules
|
||||
}
|
||||
|
||||
[Command("role update slots")]
|
||||
[Name("Update role's slots")]
|
||||
[Summary("Updates a role's maximum participants count.")]
|
||||
public async Task UpdateEventRoleMaxParticipants(
|
||||
[Summary("Which role to update.")] EventRole eventRole,
|
||||
@@ -263,6 +279,7 @@ namespace EventBot.Modules
|
||||
|
||||
|
||||
[Command("role update emote")]
|
||||
[Name("Update role's role")]
|
||||
[Summary("Updates a role's emote.")]
|
||||
public async Task UpdateEventRoleEmote(
|
||||
[Summary("Which role to update.")] EventRole eventRole,
|
||||
@@ -286,6 +303,8 @@ namespace EventBot.Modules
|
||||
}
|
||||
|
||||
[Command()]
|
||||
[Alias("info")]
|
||||
[Name("Event info")]
|
||||
[Summary("Get info about event.")]
|
||||
public async Task EventInfo(
|
||||
[Summary("Event ID of event you wish to know more of.")] Event @event = null)
|
||||
@@ -316,6 +335,8 @@ namespace EventBot.Modules
|
||||
}
|
||||
[Priority(1)]
|
||||
[Command("role")]
|
||||
[Alias("role info")]
|
||||
[Name("Role info")]
|
||||
[Summary("Gets info about a role.")]
|
||||
public async Task EventRoleInfo(
|
||||
[Summary("Role you wish to have more info about.")] EventRole eventRole)
|
||||
@@ -339,6 +360,8 @@ namespace EventBot.Modules
|
||||
}
|
||||
|
||||
[Command("open")]
|
||||
[Alias("start", "begin")]
|
||||
[Name("Open event")]
|
||||
[Summary("Open registration for event here.")]
|
||||
public async Task EventOpen(
|
||||
[Summary("Event to open")] Event @event = null)
|
||||
@@ -371,6 +394,8 @@ namespace EventBot.Modules
|
||||
}
|
||||
|
||||
[Command("close")]
|
||||
[Alias("stop", "end")]
|
||||
[Name("Close event")]
|
||||
[Summary("Closes event registration.")]
|
||||
public async Task EventClose(
|
||||
[Summary("Event to close")] Event @event = null)
|
||||
@@ -391,6 +416,8 @@ namespace EventBot.Modules
|
||||
}
|
||||
|
||||
[Command("finalize")]
|
||||
[Alias("archive")]
|
||||
[Name("Archive event")]
|
||||
[Summary("Archives event and reverts all role additions. This is irreversable.")]
|
||||
public async Task EventFinilize(
|
||||
[Summary("Event to finilize")] Event @event = null)
|
||||
@@ -416,6 +443,8 @@ namespace EventBot.Modules
|
||||
}
|
||||
|
||||
[Command("list")]
|
||||
[Alias("all")]
|
||||
[Name("Lists events")]
|
||||
[Summary("Lists all prevous events that took on this server.")]
|
||||
public async Task EventArchive()
|
||||
{
|
||||
@@ -448,6 +477,7 @@ namespace EventBot.Modules
|
||||
}
|
||||
|
||||
[Command("participant add")]
|
||||
[Name("Add participant")]
|
||||
[Summary("Add user to event role. Acts like join command.")]
|
||||
public async Task EventParticipantAdd(
|
||||
[Summary("User ID or discord mention.")] IUser user,
|
||||
@@ -476,6 +506,8 @@ namespace EventBot.Modules
|
||||
}
|
||||
|
||||
[Command("participant remove")]
|
||||
[Alias("participant delete")]
|
||||
[Name("Remove participant")]
|
||||
[Summary("Remove participant from event role.")]
|
||||
public async Task EventParticipantRemove(
|
||||
[Summary("User that is participating's ID or discord mention.")] IUser user,
|
||||
|
Reference in New Issue
Block a user