From 301744dd4e163828ffd0d3b39075b8a2ad7dabd5 Mon Sep 17 00:00:00 2001 From: sam Date: Thu, 24 Oct 2024 22:16:19 +0200 Subject: [PATCH] feat: add help, invite, dashboard commands --- .../Bot/Commands/MetaCommands.cs | 100 +++++++++++++++++- Catalogger.Backend/Config.cs | 3 + Catalogger.Backend/config.example.ini | 4 + 3 files changed, 106 insertions(+), 1 deletion(-) diff --git a/Catalogger.Backend/Bot/Commands/MetaCommands.cs b/Catalogger.Backend/Bot/Commands/MetaCommands.cs index 1319a98..191830b 100644 --- a/Catalogger.Backend/Bot/Commands/MetaCommands.cs +++ b/Catalogger.Backend/Bot/Commands/MetaCommands.cs @@ -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(); private readonly HttpClient _client = new(); + [Command("help")] + [Description("Learn more about Catalogger.")] + public async Task 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 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 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 PingAsync() diff --git a/Catalogger.Backend/Config.cs b/Catalogger.Backend/Config.cs index e8badc9..49bae46 100644 --- a/Catalogger.Backend/Config.cs +++ b/Catalogger.Backend/Config.cs @@ -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 diff --git a/Catalogger.Backend/config.example.ini b/Catalogger.Backend/config.example.ini index 6a41d72..9b74c55 100644 --- a/Catalogger.Backend/config.example.ini +++ b/Catalogger.Backend/config.example.ini @@ -27,6 +27,10 @@ SyncCommands = true GuildLogId = 803961980758261800 # This is not necessary when not using the dashboard. # ClientSecret = +# 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]