Merge branch 'main' into newdiscord

This commit is contained in:
Ske
2021-01-15 10:35:20 +01:00
6 changed files with 27 additions and 9 deletions

View File

@@ -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)

View File

@@ -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

View File

@@ -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;