feat: add help, invite, dashboard commands

This commit is contained in:
sam 2024-10-24 22:16:19 +02:00
parent 6f002c06a5
commit 301744dd4e
Signed by: sam
GPG key ID: 5F3C3C1B3166639D
3 changed files with 106 additions and 1 deletions

View file

@ -20,6 +20,7 @@ using System.Text.Json;
using System.Web;
using Catalogger.Backend.Cache.InMemoryCache;
using Catalogger.Backend.Extensions;
using Catalogger.Backend.Services;
using Humanizer;
using Humanizer.Localisation;
using Remora.Commands.Attributes;
@ -49,12 +50,109 @@ public class MetaCommands(
RoleCache roleCache,
ChannelCache channelCache,
EmojiCache emojiCache,
IDiscordRestChannelAPI channelApi
IDiscordRestChannelAPI channelApi,
PermissionResolverService permissionResolver
) : CommandGroup
{
private readonly ILogger _logger = logger.ForContext<MetaCommands>();
private readonly HttpClient _client = new();
[Command("help")]
[Description("Learn more about Catalogger.")]
public async Task<IResult> HelpAsync()
{
var embed = new EmbedBuilder()
.WithColour(DiscordUtils.Purple)
.WithTitle("Catalogger")
.WithDescription(
"""
A logging bot that integrates with PluralKit's message proxying.
Use `/configure-channels` to get started!
"""
);
if (config.Discord.EnableDash)
embed.Description +=
$"\n\nYou can also use the dashboard for configuration: {config.Web.BaseUrl}";
embed.AddField(
"Configuration",
"""
`/configure-channels`: Set which events will be logged to which channels
`/ignored-channels`: Set which channels will be ignored entirely
`/redirects`: Override where a channel's messages will be logged
`/key-roles`: Set which roles are treated as key roles and are logged with more detail than others
`/invites`: Manage invites and create new ones
`/check-permissions`: Check for any issues with logging
"""
);
embed.AddField("Creator", "<@694563574386786314> / starshines.gay");
embed.AddField(
"Source code",
"https://codeberg.org/starshine/catalogger / Licensed under the GNU AGPL v3"
);
if (config.Discord.SupportGuild != null)
embed.AddField(
"Support",
$"Use this link to join the support server: {config.Discord.SupportGuild}"
);
return await feedbackService.ReplyAsync(
embeds: [embed.Build().GetOrThrow()],
isEphemeral: true
);
}
[Command("invite")]
[Description("Get a link to invite Catalogger to your server.")]
public async Task<IResult> InviteAsync()
{
var inviteUrl =
$"https://discord.com/oauth2/authorize?client_id={config.Discord.ApplicationId}"
+ "&permissions=537250993&scope=bot+applications.commands";
return await feedbackService.ReplyAsync(
$"Use this link to invite Catalogger to your server: {inviteUrl}",
isEphemeral: true
);
}
[Command("dashboard")]
[Description("Get a link to the dashboard.")]
public async Task<IResult> DashboardLinkAsync()
{
if (!config.Discord.EnableDash)
return await feedbackService.ReplyAsync(
"The dashboard is not enabled for this version of Catalogger.",
isEphemeral: true
);
if (
contextInjection.Context?.TryGetGuildID(out var guildId) != true
|| contextInjection.Context?.TryGetUserID(out var userId) != true
)
return await feedbackService.ReplyAsync(
$"The dashboard is available here: {config.Web.BaseUrl}",
isEphemeral: true
);
var perms = await permissionResolver.GetGuildPermissionsAsync(guildId, userId);
if (
perms.HasPermission(DiscordPermission.ManageGuild)
|| perms.HasPermission(DiscordPermission.Administrator)
)
return await feedbackService.ReplyAsync(
$"The dashboard for this server is available here: {config.Web.BaseUrl}/dash/{guildId}"
);
return await feedbackService.ReplyAsync(
$"The dashboard is available here: {config.Web.BaseUrl}",
isEphemeral: true
);
}
[Command("ping")]
[Description("Ping pong! See the bot's latency")]
public async Task<IResult> PingAsync()

View file

@ -54,6 +54,9 @@ public class Config
public int? ShardCount { get; init; }
public string ClientSecret { get; init; } = string.Empty;
public string? SupportGuild { get; init; }
public bool EnableDash { get; init; } = false;
}
public class WebConfig

View file

@ -27,6 +27,10 @@ SyncCommands = true
GuildLogId = 803961980758261800
# This is not necessary when not using the dashboard.
# ClientSecret = <secret>
# If this is set to false, commands won't mention the dashboard.
# EnableDash = false
# The server where people can ask for support, linked in the help command.
# SupportGuild = https://discord.gg/b5jjJ96Jbv
# Dashboard related settings. You shouldn't need to change these.
[Web]