diff --git a/.github/workflows/dotnetcore.yml b/.github/workflows/dotnetcore.yml index 3cd0fb37..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: diff --git a/PluralKit.Bot/Commands/Autoproxy.cs b/PluralKit.Bot/Commands/Autoproxy.cs index b3efde4e..d7f51975 100644 --- a/PluralKit.Bot/Commands/Autoproxy.cs +++ b/PluralKit.Bot/Commands/Autoproxy.cs @@ -157,16 +157,26 @@ 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, new SystemPatch { LatchTimeout = (int?) newTimeout?.TotalSeconds })); 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 - 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) diff --git a/PluralKit.Bot/Proxy/ProxyService.cs b/PluralKit.Bot/Proxy/ProxyService.cs index 20330f33..0a362ab4 100644 --- a/PluralKit.Bot/Proxy/ProxyService.cs +++ b/PluralKit.Bot/Proxy/ProxyService.cs @@ -112,9 +112,14 @@ namespace PluralKit.Bot if (trigger.MessageReference?.ChannelId == trigger.ChannelId) { var repliedTo = await FetchReplyOriginalMessage(trigger.MessageReference); - var embed = 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 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; 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 +} 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.