From 99a9ec79287041479164e825baed774d3d70dce2 Mon Sep 17 00:00:00 2001 From: spiral Date: Sat, 27 Nov 2021 11:09:08 -0500 Subject: [PATCH] feat: beta bot patches --- PluralKit.Bot/BotConfig.cs | 3 +++ PluralKit.Bot/Commands/Api.cs | 18 +++++++++++++++++- PluralKit.Bot/Commands/Misc.cs | 4 +++- PluralKit.Bot/Services/ErrorMessageService.cs | 13 +++++++++---- 4 files changed, 32 insertions(+), 6 deletions(-) diff --git a/PluralKit.Bot/BotConfig.cs b/PluralKit.Bot/BotConfig.cs index 746be9e5..db678ddf 100644 --- a/PluralKit.Bot/BotConfig.cs +++ b/PluralKit.Bot/BotConfig.cs @@ -24,6 +24,9 @@ public class BotConfig public bool DisableErrorReporting { get; set; } = false; + public bool IsBetaBot { get; set; } = false!; + public string BetaBotAPIUrl { get; set; } + public record ClusterSettings { public string NodeName { get; set; } diff --git a/PluralKit.Bot/Commands/Api.cs b/PluralKit.Bot/Commands/Api.cs index 7147ecdb..7b0cc3ce 100644 --- a/PluralKit.Bot/Commands/Api.cs +++ b/PluralKit.Bot/Commands/Api.cs @@ -14,11 +14,13 @@ public class Api private static readonly Regex _webhookRegex = new("https://(?:\\w+.)?discord(?:app)?.com/api(?:/v.*)?/webhooks/(.*)"); + private readonly BotConfig _botConfig; private readonly DispatchService _dispatch; private readonly ModelRepository _repo; - public Api(ModelRepository repo, DispatchService dispatch) + public Api(BotConfig botConfig, ModelRepository repo, DispatchService dispatch) { + _botConfig = botConfig; _repo = repo; _dispatch = dispatch; } @@ -42,6 +44,13 @@ public class Api }); await ctx.Rest.CreateMessage(dm.Id, new MessageRequest { Content = token }); + if (_botConfig.IsBetaBot) + await ctx.Rest.CreateMessage(dm.Id, new MessageRequest + { + Content = $"{Emojis.Note} The beta bot's API base URL is currently <{_botConfig.BetaBotAPIUrl}>." + + " You need to use this URL instead of the base URL listed on the documentation website." + }); + // If we're not already in a DM, reply with a reminder to check if (ctx.Channel.Type != Channel.ChannelType.Dm) await ctx.Reply($"{Emojis.Success} Check your DMs!"); @@ -87,6 +96,13 @@ public class Api var token = await MakeAndSetNewToken(ctx.System); await ctx.Rest.CreateMessage(dm.Id, new MessageRequest { Content = token }); + if (_botConfig.IsBetaBot) + await ctx.Rest.CreateMessage(dm.Id, new MessageRequest + { + Content = $"{Emojis.Note} The beta bot's API base URL is currently <{_botConfig.BetaBotAPIUrl}>." + + " You need to use this URL instead of the base URL listed on the documentation website." + }); + // If we're not already in a DM, reply with a reminder to check if (ctx.Channel.Type != Channel.ChannelType.Dm) await ctx.Reply($"{Emojis.Success} Check your DMs!"); diff --git a/PluralKit.Bot/Commands/Misc.cs b/PluralKit.Bot/Commands/Misc.cs index 872417de..d03c3573 100644 --- a/PluralKit.Bot/Commands/Misc.cs +++ b/PluralKit.Bot/Commands/Misc.cs @@ -50,7 +50,9 @@ public class Misc var invite = $"https://discord.com/oauth2/authorize?client_id={clientId}&scope=bot%20applications.commands&permissions={(ulong)permissions}"; - await ctx.Reply($"{Emojis.Success} Use this link to add PluralKit to your server:\n<{invite}>"); + + var botName = _botConfig.IsBetaBot ? "PluralKit Beta" : "PluralKit"; + await ctx.Reply($"{Emojis.Success} Use this link to add {botName} to your server:\n<{invite}>"); } public async Task Stats(Context ctx) diff --git a/PluralKit.Bot/Services/ErrorMessageService.cs b/PluralKit.Bot/Services/ErrorMessageService.cs index 3740544a..41ad263c 100644 --- a/PluralKit.Bot/Services/ErrorMessageService.cs +++ b/PluralKit.Bot/Services/ErrorMessageService.cs @@ -20,11 +20,13 @@ public class ErrorMessageService private static readonly Duration IntervalFromStartup = Duration.FromMinutes(5); private readonly ILogger _logger; + private readonly BotConfig _botConfig; private readonly IMetrics _metrics; private readonly DiscordApiClient _rest; - public ErrorMessageService(IMetrics metrics, ILogger logger, DiscordApiClient rest) + public ErrorMessageService(BotConfig botConfig, IMetrics metrics, ILogger logger, DiscordApiClient rest) { + _botConfig = botConfig; _metrics = metrics; _logger = logger; _rest = rest; @@ -46,11 +48,14 @@ public class ErrorMessageService return; } + var channelInfo = _botConfig.IsBetaBot + ? "**#hi-please-break-the-beta-bot** on **[the support server *(click to join)*](https://discord.gg/THvbH59btW)**" + : "**#bug-reports-and-errors** on **[the support server *(click to join)*](https://discord.gg/PczBt78)**"; + var embed = new EmbedBuilder() .Color(0xE74C3C) .Title("Internal error occurred") - .Description( - "For support, please send the error code above in **#bug-reports-and-errors** on **[the support server *(click to join)*](https://discord.gg/PczBt78)** with a description of what you were doing at the time.") + .Description($"For support, please send the error code above in {channelInfo} with a description of what you were doing at the time.") .Footer(new Embed.EmbedFooter(errorId)) .Timestamp(now.ToDateTimeOffset().ToString("O")); @@ -77,7 +82,7 @@ public class ErrorMessageService var startupTime = Instant.FromDateTimeUtc(Process.GetCurrentProcess().StartTime.ToUniversalTime()); // don't send errors during startup // mostly because Npgsql throws a bunch of errors when opening connections sometimes??? - if (now - startupTime < IntervalFromStartup) + if (now - startupTime < IntervalFromStartup && !_botConfig.IsBetaBot) return false; var interval = now - lastErrorTime;