From ad921e17e340e0c772c05a6518d56cbb44e78fe1 Mon Sep 17 00:00:00 2001 From: Ske Date: Thu, 24 Dec 2020 19:41:46 +0100 Subject: [PATCH 1/9] Fix autoproxy timeout overflow --- PluralKit.Bot/Commands/Autoproxy.cs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/PluralKit.Bot/Commands/Autoproxy.cs b/PluralKit.Bot/Commands/Autoproxy.cs index 94e94dd2..b1d690fd 100644 --- a/PluralKit.Bot/Commands/Autoproxy.cs +++ b/PluralKit.Bot/Commands/Autoproxy.cs @@ -154,6 +154,10 @@ namespace PluralKit.Bot else if (ctx.Match("reset", "default")) newTimeoutHours = -1; else if (!int.TryParse(ctx.RemainderOrNull(), out newTimeoutHours)) throw new PKError("Duration must be a number of hours."); + if (newTimeoutHours > 100000) + // sanity check to prevent seconds overflow if someone types in 999999999 + newTimeoutHours = 0; + var newTimeout = newTimeoutHours > -1 ? Duration.FromHours(newTimeoutHours) : (Duration?) null; await _db.Execute(conn => _repo.UpdateSystem(conn, ctx.System.Id, new SystemPatch { LatchTimeout = (int?) newTimeout?.TotalSeconds })); From 4e67c79154537e260efaa079aa972b6a27bea5a1 Mon Sep 17 00:00:00 2001 From: Ske Date: Thu, 24 Dec 2020 19:42:04 +0100 Subject: [PATCH 2/9] Fix autoproxy timeout message --- PluralKit.Bot/Commands/Autoproxy.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/PluralKit.Bot/Commands/Autoproxy.cs b/PluralKit.Bot/Commands/Autoproxy.cs index b1d690fd..91e2debd 100644 --- a/PluralKit.Bot/Commands/Autoproxy.cs +++ b/PluralKit.Bot/Commands/Autoproxy.cs @@ -167,7 +167,7 @@ namespace PluralKit.Bot else if (newTimeoutHours == 0) await ctx.Reply($"{Emojis.Success} Latch timeout disabled. Latch mode autoproxy will never time out."); else - await ctx.Reply($"{Emojis.Success} Latch timeout set to {newTimeout.Value!.ToTimeSpan().Humanize()} hours."); + await ctx.Reply($"{Emojis.Success} Latch timeout set to {newTimeout.Value!.ToTimeSpan().Humanize()}."); } public async Task AutoproxyAccount(Context ctx) From 50b8685e442ea228cba9daf5729917bf24f86786 Mon Sep 17 00:00:00 2001 From: Ske Date: Thu, 24 Dec 2020 22:27:03 +0100 Subject: [PATCH 3/9] Clarify timeout overflow message --- PluralKit.Bot/Commands/Autoproxy.cs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/PluralKit.Bot/Commands/Autoproxy.cs b/PluralKit.Bot/Commands/Autoproxy.cs index 91e2debd..39615607 100644 --- a/PluralKit.Bot/Commands/Autoproxy.cs +++ b/PluralKit.Bot/Commands/Autoproxy.cs @@ -154,9 +154,13 @@ namespace PluralKit.Bot else if (ctx.Match("reset", "default")) newTimeoutHours = -1; else if (!int.TryParse(ctx.RemainderOrNull(), out newTimeoutHours)) throw new PKError("Duration must be a number of hours."); + int? overflow = null; if (newTimeoutHours > 100000) + { // sanity check to prevent seconds overflow if someone types in 999999999 + overflow = newTimeoutHours; newTimeoutHours = 0; + } var newTimeout = newTimeoutHours > -1 ? Duration.FromHours(newTimeoutHours) : (Duration?) null; await _db.Execute(conn => _repo.UpdateSystem(conn, ctx.System.Id, @@ -164,6 +168,8 @@ namespace PluralKit.Bot if (newTimeoutHours == -1) await ctx.Reply($"{Emojis.Success} Latch timeout reset to default ({ProxyMatcher.DefaultLatchExpiryTime.ToTimeSpan().Humanize()})."); + else if (newTimeoutHours == 0 && overflow != null) + await ctx.Reply($"{Emojis.Success} Latch timeout disabled. Latch mode autoproxy will never time out. ({overflow} hours is too long)"); else if (newTimeoutHours == 0) await ctx.Reply($"{Emojis.Success} Latch timeout disabled. Latch mode autoproxy will never time out."); else From f18a78b59c61351db6e39c2fb9156b524ffcc07b Mon Sep 17 00:00:00 2001 From: Ske Date: Sat, 26 Dec 2020 13:18:31 +0100 Subject: [PATCH 4/9] Ignore broken pipe and dropped connection exceptions --- PluralKit.Bot/Utils/MiscUtils.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/PluralKit.Bot/Utils/MiscUtils.cs b/PluralKit.Bot/Utils/MiscUtils.cs index 7e8eb3b9..38a86618 100644 --- a/PluralKit.Bot/Utils/MiscUtils.cs +++ b/PluralKit.Bot/Utils/MiscUtils.cs @@ -76,7 +76,7 @@ namespace PluralKit.Bot if (e is WebhookExecutionErrorOnDiscordsEnd) return false; // Socket errors are *not our problem* - if (e is SocketException) return false; + if (e.GetBaseException() is SocketException) return false; // Tasks being cancelled for whatver reason are, you guessed it, also not our problem. if (e is TaskCanceledException) return false; From 44fa09790098f004d35e0eda19b43b817fafddc2 Mon Sep 17 00:00:00 2001 From: spiral Date: Mon, 28 Dec 2020 04:47:14 +0000 Subject: [PATCH 5/9] Force PNG image format (remove animations in embeds) --- PluralKit.Bot/Proxy/ProxyService.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/PluralKit.Bot/Proxy/ProxyService.cs b/PluralKit.Bot/Proxy/ProxyService.cs index ed02af8c..3ec2b7d7 100644 --- a/PluralKit.Bot/Proxy/ProxyService.cs +++ b/PluralKit.Bot/Proxy/ProxyService.cs @@ -169,7 +169,7 @@ namespace PluralKit.Bot return new DiscordEmbedBuilder() // unicodes: [three-per-em space] [left arrow emoji] [force emoji presentation] - .WithAuthor($"{username}\u2004\u21a9\ufe0f", iconUrl: original.Author.AvatarUrl) + .WithAuthor($"{username}\u2004\u21a9\ufe0f", iconUrl: original.Author.GetAvatarUrl(ImageFormat.Png, 1024)) .WithDescription(content.ToString()) .Build(); } From 78c693f5ad81a81062c67c83a8804dda33c3d825 Mon Sep 17 00:00:00 2001 From: spiral Date: Sat, 9 Jan 2021 16:59:28 +0000 Subject: [PATCH 6/9] Add authorization header example --- docs/content/api-documentation.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/docs/content/api-documentation.md b/docs/content/api-documentation.md index 4ef72535..5fefb03b 100644 --- a/docs/content/api-documentation.md +++ b/docs/content/api-documentation.md @@ -12,6 +12,11 @@ Accompanying it is an [OpenAPI v3.0 definition](https://github.com/xSke/PluralKi PluralKit has a basic HTTP REST API for querying and modifying your system. The root endpoint of the API is `https://api.pluralkit.me/v1/`. +#### Authorization header token example +``` +Authorization: z865MC7JNhLtZuSq1NXQYVe+FgZJHBfeBCXOPYYRwH4liDCDrsd7zdOuR45mX257 +``` + Endpoints will always return all fields, using `null` when a value is missing. On `PATCH` endpoints, missing fields from the JSON request will be ignored and preserved as is, but on `POST` endpoints will be set to `null` or cleared. From c16600e143082aa8605d14a99ed6d82bbafe2c03 Mon Sep 17 00:00:00 2001 From: Astrid Date: Wed, 13 Jan 2021 09:29:14 +0100 Subject: [PATCH 7/9] Update dotnetcore.yml --- .github/workflows/dotnetcore.yml | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/.github/workflows/dotnetcore.yml b/.github/workflows/dotnetcore.yml index 6091e9df..c81953cd 100644 --- a/.github/workflows/dotnetcore.yml +++ b/.github/workflows/dotnetcore.yml @@ -4,9 +4,7 @@ on: [push, pull_request] jobs: build: - runs-on: ubuntu-latest - steps: - uses: actions/checkout@v1 with: @@ -14,6 +12,6 @@ jobs: - name: Setup .NET Core uses: actions/setup-dotnet@v1 with: - dotnet-version: 3.1.100 + dotnet-version: 5.0.x - name: Build and test with dotnet run: dotnet test --configuration Release From f4ae35f9b83911c11d14990ea1e59d1ff8a55125 Mon Sep 17 00:00:00 2001 From: spiral Date: Wed, 13 Jan 2021 21:10:51 +0000 Subject: [PATCH 8/9] Don't export `IsEmpty` in proxy tags --- PluralKit.Core/Models/ProxyTag.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/PluralKit.Core/Models/ProxyTag.cs b/PluralKit.Core/Models/ProxyTag.cs index c00a5e50..c433f0b5 100644 --- a/PluralKit.Core/Models/ProxyTag.cs +++ b/PluralKit.Core/Models/ProxyTag.cs @@ -16,7 +16,7 @@ namespace PluralKit.Core [JsonIgnore] public string ProxyString => $"{Prefix ?? ""}text{Suffix ?? ""}"; - public bool IsEmpty => Prefix == null && Suffix == null; + [JsonIgnore] public bool IsEmpty => Prefix == null && Suffix == null; public bool Equals(ProxyTag other) => Prefix == other.Prefix && Suffix == other.Suffix; @@ -31,4 +31,4 @@ namespace PluralKit.Core } } } -} \ No newline at end of file +} From e0cc74a7125b8b721d2efe9997fdd0749f47db95 Mon Sep 17 00:00:00 2001 From: Ske Date: Thu, 14 Jan 2021 03:21:56 +0100 Subject: [PATCH 9/9] Don't attempt to create a reply embed when message fetching fails --- PluralKit.Bot/Proxy/ProxyService.cs | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/PluralKit.Bot/Proxy/ProxyService.cs b/PluralKit.Bot/Proxy/ProxyService.cs index 3ec2b7d7..2e1af75c 100644 --- a/PluralKit.Bot/Proxy/ProxyService.cs +++ b/PluralKit.Bot/Proxy/ProxyService.cs @@ -102,9 +102,14 @@ namespace PluralKit.Bot if (trigger.Reference?.Channel?.Id == trigger.ChannelId) { var repliedTo = await FetchReplyOriginalMessage(trigger.Reference); - var embed = await CreateReplyEmbed(repliedTo); - if (embed != null) - embeds.Add(embed); + if (repliedTo != null) + { + var embed = CreateReplyEmbed(repliedTo); + if (embed != null) + embeds.Add(embed); + } + + // TODO: have a clean error for when message can't be fetched instead of just being silent } // Send the webhook @@ -137,7 +142,7 @@ namespace PluralKit.Bot return null; } - private async Task CreateReplyEmbed(DiscordMessage original) + private DiscordEmbed CreateReplyEmbed(DiscordMessage original) { var content = new StringBuilder();