From 1448e0f5bd10b016b50f0806ab116d48a2cbdb71 Mon Sep 17 00:00:00 2001 From: Astrid Date: Sun, 5 Jun 2022 23:19:10 +0200 Subject: [PATCH 1/6] chore: remove legacy api docs from sidebar --- docs/content/.vuepress/config.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/docs/content/.vuepress/config.js b/docs/content/.vuepress/config.js index 9701a8dc..6589bd65 100644 --- a/docs/content/.vuepress/config.js +++ b/docs/content/.vuepress/config.js @@ -67,8 +67,7 @@ module.exports = { "/api/endpoints", "/api/models", "/api/errors", - "/api/dispatch", - "/api/legacy" + "/api/dispatch" ] }, ["https://discord.gg/PczBt78", "Join the support server"], From 995fddf9293e92ca541bc4a7a5d9f9bf56c8e67d Mon Sep 17 00:00:00 2001 From: Ske Date: Sun, 5 Jun 2022 23:26:11 +0200 Subject: [PATCH 2/6] fix: include guild member in reproxy permission check --- PluralKit.Bot/Proxy/ProxyService.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/PluralKit.Bot/Proxy/ProxyService.cs b/PluralKit.Bot/Proxy/ProxyService.cs index 857a561c..e564d64f 100644 --- a/PluralKit.Bot/Proxy/ProxyService.cs +++ b/PluralKit.Bot/Proxy/ProxyService.cs @@ -219,8 +219,8 @@ public class ProxyService var threadId = messageChannel.IsThread() ? messageChannel.Id : (ulong?)null; var guild = await _rest.GetGuildOrNull(msg.Guild!.Value); - // Grab user permissions - var senderPermissions = PermissionExtensions.PermissionsFor(guild, rootChannel, trigger.Author.Id, null); + // Grab user permissions (the MessageCreateEvent cast is gross but so is our permission handling rn) + var senderPermissions = PermissionExtensions.PermissionsFor(guild, rootChannel, trigger.Author.Id, ((MessageCreateEvent) trigger).Member); var allowEveryone = senderPermissions.HasFlag(PermissionSet.MentionEveryone); // Make sure user has permissions to send messages From 6511c04c6c9652ad093993cc46b9560211620202 Mon Sep 17 00:00:00 2001 From: Ske Date: Sun, 5 Jun 2022 23:27:30 +0200 Subject: [PATCH 3/6] fix: don't fetch non-thread channels twice --- 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 e564d64f..e8a01301 100644 --- a/PluralKit.Bot/Proxy/ProxyService.cs +++ b/PluralKit.Bot/Proxy/ProxyService.cs @@ -215,7 +215,7 @@ public class ProxyService }; var messageChannel = await _rest.GetChannelOrNull(msg.Channel!); - var rootChannel = await _rest.GetChannelOrNull(messageChannel.IsThread() ? messageChannel.ParentId!.Value : messageChannel.Id); + var rootChannel = messageChannel.IsThread() ? await _rest.GetChannelOrNull(messageChannel.ParentId!.Value) : messageChannel; var threadId = messageChannel.IsThread() ? messageChannel.Id : (ulong?)null; var guild = await _rest.GetGuildOrNull(msg.Guild!.Value); From 51fb56184148ad23f0425aa31bef0735c0066ee5 Mon Sep 17 00:00:00 2001 From: Ske Date: Mon, 6 Jun 2022 00:59:53 +0200 Subject: [PATCH 4/6] fix: a couple more minor reproxy fixes --- PluralKit.Bot/Commands/Message.cs | 4 ++-- PluralKit.Bot/Proxy/ProxyService.cs | 11 ++++++----- PluralKit.Bot/Services/LogChannelService.cs | 2 +- PluralKit.Bot/Services/WebhookExecutorService.cs | 5 +++-- 4 files changed, 12 insertions(+), 10 deletions(-) diff --git a/PluralKit.Bot/Commands/Message.cs b/PluralKit.Bot/Commands/Message.cs index c5681bb7..527e2805 100644 --- a/PluralKit.Bot/Commands/Message.cs +++ b/PluralKit.Bot/Commands/Message.cs @@ -140,13 +140,12 @@ public class ProxiedMessage var editType = isReproxy ? "reproxy" : "edit"; var editTypeAction = isReproxy ? "reproxied" : "edited"; - // todo: is it correct to get a connection here? - await using var conn = await ctx.Database.Obtain(); FullMessage? msg = null; var (referencedMessage, _) = ctx.MatchMessage(false); if (referencedMessage != null) { + await using var conn = await ctx.Database.Obtain(); msg = await ctx.Repository.GetMessage(conn, referencedMessage.Value); if (msg == null) throw new PKError("This is not a message proxied by PluralKit."); @@ -161,6 +160,7 @@ public class ProxiedMessage if (recent == null) throw new PKSyntaxError($"Could not find a recent message to {editType}."); + await using var conn = await ctx.Database.Obtain(); msg = await ctx.Repository.GetMessage(conn, recent.Mid); if (msg == null) throw new PKSyntaxError($"Could not find a recent message to {editType}."); diff --git a/PluralKit.Bot/Proxy/ProxyService.cs b/PluralKit.Bot/Proxy/ProxyService.cs index e8a01301..5ba39bc8 100644 --- a/PluralKit.Bot/Proxy/ProxyService.cs +++ b/PluralKit.Bot/Proxy/ProxyService.cs @@ -211,16 +211,17 @@ public class ProxyService { Member = member, Content = prevMatched ? prevMatch.Content : originalMsg.Content, - ProxyTags = member.ProxyTags.First(), + ProxyTags = member.ProxyTags.FirstOrDefault(), }; var messageChannel = await _rest.GetChannelOrNull(msg.Channel!); var rootChannel = messageChannel.IsThread() ? await _rest.GetChannelOrNull(messageChannel.ParentId!.Value) : messageChannel; var threadId = messageChannel.IsThread() ? messageChannel.Id : (ulong?)null; var guild = await _rest.GetGuildOrNull(msg.Guild!.Value); + var guildMember = await _rest.GetGuildMember(msg.Guild!.Value, trigger.Author.Id); - // Grab user permissions (the MessageCreateEvent cast is gross but so is our permission handling rn) - var senderPermissions = PermissionExtensions.PermissionsFor(guild, rootChannel, trigger.Author.Id, ((MessageCreateEvent) trigger).Member); + // Grab user permissions + var senderPermissions = PermissionExtensions.PermissionsFor(guild, rootChannel, trigger.Author.Id, guildMember); var allowEveryone = senderPermissions.HasFlag(PermissionSet.MentionEveryone); // Make sure user has permissions to send messages @@ -373,8 +374,8 @@ public class ProxyService { var sentMessage = new PKMessage { - Channel = triggerMessage.ChannelId, - Guild = triggerMessage.GuildId, + Channel = proxyMessage.ChannelId, + Guild = proxyMessage.GuildId, Member = match.Member.Id, Mid = proxyMessage.Id, OriginalMid = triggerMessage.Id, diff --git a/PluralKit.Bot/Services/LogChannelService.cs b/PluralKit.Bot/Services/LogChannelService.cs index 3257dae1..b72b0aee 100644 --- a/PluralKit.Bot/Services/LogChannelService.cs +++ b/PluralKit.Bot/Services/LogChannelService.cs @@ -86,7 +86,7 @@ public class LogChannelService { _logger.Information( "Does not have permission to log proxy, ignoring (channel: {ChannelId}, guild: {GuildId}, bot permissions: {BotPermissions})", - logChannel.Id, trigger.GuildId!.Value, perms); + logChannel.Id, guildId, perms); return null; } diff --git a/PluralKit.Bot/Services/WebhookExecutorService.cs b/PluralKit.Bot/Services/WebhookExecutorService.cs index c9596545..f9ccaf76 100644 --- a/PluralKit.Bot/Services/WebhookExecutorService.cs +++ b/PluralKit.Bot/Services/WebhookExecutorService.cs @@ -173,8 +173,9 @@ public class WebhookExecutorService // We don't care about whether the sending succeeds, and we don't want to *wait* for it, so we just fork it off var _ = TrySendRemainingAttachments(webhook, req.Name, req.AvatarUrl, attachmentChunks, req.ThreadId); - - return webhookMessage; + + // for some reason discord may(?) return a null guildid here??? + return webhookMessage with { GuildId = webhookMessage.GuildId ?? req.GuildId }; } private async Task TrySendRemainingAttachments(Webhook webhook, string name, string avatarUrl, From 937867b047210674e6eff36b460d42bbce1ebf16 Mon Sep 17 00:00:00 2001 From: Jake/Rads Date: Mon, 6 Jun 2022 09:38:43 +0200 Subject: [PATCH 5/6] fix(dashboard): properly parse birthdates --- dashboard/src/lib/member/Edit.svelte | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/dashboard/src/lib/member/Edit.svelte b/dashboard/src/lib/member/Edit.svelte index ff5f3728..4a4959bb 100644 --- a/dashboard/src/lib/member/Edit.svelte +++ b/dashboard/src/lib/member/Edit.svelte @@ -40,15 +40,26 @@ } if (data.birthday) { - if (!moment(data.birthday, 'YYYY-MM-DD').isValid()) { - if (moment(data.birthday, 'MM-DD').isValid()) { - data.birthday = '0004-' + data.birthday; - } else { - err.push(`${data.birthday} is not a valid date, please use the following format: YYYY-MM-DD. (example: 2019-07-21)`); - } - } + let allowedFormats = ['YYYY-MM-DD','YYYY-M-D', 'YYYY-MM-D', 'YYYY-M-DD']; + + // replace all brackets with dashes if (data.birthday.includes('/')) { - data.birthday.replace('/', '-'); + data.birthday = data.birthday.replaceAll('/', '-'); + } + + // add a generic year if there's no year included + // NOTE: for some reason moment parses a date with only a month and day as a YEAR and a month + // so I'm just checking by the amount of dashes in the string + if (data.birthday.split('-').length - 1 === 1) { + data.birthday = '0004-' + data.birthday; + } + + // try matching the birthday to the YYYY-MM-DD format + if (moment(data.birthday, allowedFormats, true).isValid()) { + // convert the format to have months and days as double digits. + data.birthday = moment(data.birthday, 'YYYY-MM-DD').format('YYYY-MM-DD'); + } else { + err.push(`${data.birthday} is not a valid date, please use the following format: YYYY-MM-DD. (example: 2019-07-21)`); } } From 1a0a9e4ef35e80eeb8227c4971e8cc561ecb64fa Mon Sep 17 00:00:00 2001 From: Jake/Rads Date: Tue, 7 Jun 2022 19:05:40 +0200 Subject: [PATCH 6/6] fix(dashboard): correct birthday validation on member creation --- dashboard/src/lib/member/NewMember.svelte | 27 ++++++++++++++++------- 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/dashboard/src/lib/member/NewMember.svelte b/dashboard/src/lib/member/NewMember.svelte index ec351bb4..64ec2dea 100644 --- a/dashboard/src/lib/member/NewMember.svelte +++ b/dashboard/src/lib/member/NewMember.svelte @@ -59,15 +59,26 @@ } if (data.birthday) { - if (!moment(data.birthday, 'YYYY-MM-DD').isValid()) { - if (moment(data.birthday, 'MM-DD').isValid()) { - data.birthday = '0004-' + data.birthday; - } else { - err.push(`${data.birthday} is not a valid date, please use the following format: YYYY-MM-DD. (example: 2019-07-21)`); - } - } + let allowedFormats = ['YYYY-MM-DD','YYYY-M-D', 'YYYY-MM-D', 'YYYY-M-DD']; + + // replace all brackets with dashes if (data.birthday.includes('/')) { - data.birthday.replace('/', '-'); + data.birthday = data.birthday.replaceAll('/', '-'); + } + + // add a generic year if there's no year included + // NOTE: for some reason moment parses a date with only a month and day as a YEAR and a month + // so I'm just checking by the amount of dashes in the string + if (data.birthday.split('-').length - 1 === 1) { + data.birthday = '0004-' + data.birthday; + } + + // try matching the birthday to the YYYY-MM-DD format + if (moment(data.birthday, allowedFormats, true).isValid()) { + // convert the format to have months and days as double digits. + data.birthday = moment(data.birthday, 'YYYY-MM-DD').format('YYYY-MM-DD'); + } else { + err.push(`${data.birthday} is not a valid date, please use the following format: YYYY-MM-DD. (example: 2019-07-21)`); } }