feat: beta bot patches

This commit is contained in:
spiral 2021-11-27 11:09:08 -05:00
parent 997458c9dc
commit 99a9ec7928
No known key found for this signature in database
GPG Key ID: A6059F0CA0E1BD31
4 changed files with 32 additions and 6 deletions

View File

@ -24,6 +24,9 @@ public class BotConfig
public bool DisableErrorReporting { get; set; } = false; public bool DisableErrorReporting { get; set; } = false;
public bool IsBetaBot { get; set; } = false!;
public string BetaBotAPIUrl { get; set; }
public record ClusterSettings public record ClusterSettings
{ {
public string NodeName { get; set; } public string NodeName { get; set; }

View File

@ -14,11 +14,13 @@ public class Api
private static readonly Regex _webhookRegex = private static readonly Regex _webhookRegex =
new("https://(?:\\w+.)?discord(?:app)?.com/api(?:/v.*)?/webhooks/(.*)"); new("https://(?:\\w+.)?discord(?:app)?.com/api(?:/v.*)?/webhooks/(.*)");
private readonly BotConfig _botConfig;
private readonly DispatchService _dispatch; private readonly DispatchService _dispatch;
private readonly ModelRepository _repo; private readonly ModelRepository _repo;
public Api(ModelRepository repo, DispatchService dispatch) public Api(BotConfig botConfig, ModelRepository repo, DispatchService dispatch)
{ {
_botConfig = botConfig;
_repo = repo; _repo = repo;
_dispatch = dispatch; _dispatch = dispatch;
} }
@ -42,6 +44,13 @@ public class Api
}); });
await ctx.Rest.CreateMessage(dm.Id, new MessageRequest { Content = token }); 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 we're not already in a DM, reply with a reminder to check
if (ctx.Channel.Type != Channel.ChannelType.Dm) if (ctx.Channel.Type != Channel.ChannelType.Dm)
await ctx.Reply($"{Emojis.Success} Check your DMs!"); await ctx.Reply($"{Emojis.Success} Check your DMs!");
@ -87,6 +96,13 @@ public class Api
var token = await MakeAndSetNewToken(ctx.System); var token = await MakeAndSetNewToken(ctx.System);
await ctx.Rest.CreateMessage(dm.Id, new MessageRequest { Content = token }); 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 we're not already in a DM, reply with a reminder to check
if (ctx.Channel.Type != Channel.ChannelType.Dm) if (ctx.Channel.Type != Channel.ChannelType.Dm)
await ctx.Reply($"{Emojis.Success} Check your DMs!"); await ctx.Reply($"{Emojis.Success} Check your DMs!");

View File

@ -50,7 +50,9 @@ public class Misc
var invite = var invite =
$"https://discord.com/oauth2/authorize?client_id={clientId}&scope=bot%20applications.commands&permissions={(ulong)permissions}"; $"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) public async Task Stats(Context ctx)

View File

@ -20,11 +20,13 @@ public class ErrorMessageService
private static readonly Duration IntervalFromStartup = Duration.FromMinutes(5); private static readonly Duration IntervalFromStartup = Duration.FromMinutes(5);
private readonly ILogger _logger; private readonly ILogger _logger;
private readonly BotConfig _botConfig;
private readonly IMetrics _metrics; private readonly IMetrics _metrics;
private readonly DiscordApiClient _rest; 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; _metrics = metrics;
_logger = logger; _logger = logger;
_rest = rest; _rest = rest;
@ -46,11 +48,14 @@ public class ErrorMessageService
return; 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() var embed = new EmbedBuilder()
.Color(0xE74C3C) .Color(0xE74C3C)
.Title("Internal error occurred") .Title("Internal error occurred")
.Description( .Description($"For support, please send the error code above in {channelInfo} with a description of what you were doing at the time.")
"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.")
.Footer(new Embed.EmbedFooter(errorId)) .Footer(new Embed.EmbedFooter(errorId))
.Timestamp(now.ToDateTimeOffset().ToString("O")); .Timestamp(now.ToDateTimeOffset().ToString("O"));
@ -77,7 +82,7 @@ public class ErrorMessageService
var startupTime = Instant.FromDateTimeUtc(Process.GetCurrentProcess().StartTime.ToUniversalTime()); var startupTime = Instant.FromDateTimeUtc(Process.GetCurrentProcess().StartTime.ToUniversalTime());
// don't send errors during startup // don't send errors during startup
// mostly because Npgsql throws a bunch of errors when opening connections sometimes??? // mostly because Npgsql throws a bunch of errors when opening connections sometimes???
if (now - startupTime < IntervalFromStartup) if (now - startupTime < IntervalFromStartup && !_botConfig.IsBetaBot)
return false; return false;
var interval = now - lastErrorTime; var interval = now - lastErrorTime;