Merge branch 'main' of ssh://github.com/pluralkit/pluralkit
This commit is contained in:
		@@ -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}.");
 | 
			
		||||
 
 | 
			
		||||
@@ -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 = 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);
 | 
			
		||||
        var guildMember = await _rest.GetGuildMember(msg.Guild!.Value, trigger.Author.Id);
 | 
			
		||||
 | 
			
		||||
        // Grab user permissions
 | 
			
		||||
        var senderPermissions = PermissionExtensions.PermissionsFor(guild, rootChannel, trigger.Author.Id, null);
 | 
			
		||||
        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,
 | 
			
		||||
 
 | 
			
		||||
@@ -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;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -174,7 +174,8 @@ 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,
 | 
			
		||||
 
 | 
			
		||||
@@ -40,17 +40,28 @@
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if (data.birthday) {
 | 
			
		||||
            if (!moment(data.birthday, 'YYYY-MM-DD').isValid()) {
 | 
			
		||||
                if (moment(data.birthday, 'MM-DD').isValid()) {
 | 
			
		||||
            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 = 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)`);
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
            if (data.birthday.includes('/')) {
 | 
			
		||||
                data.birthday.replace('/', '-');
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        err = err;
 | 
			
		||||
        if (err.length > 0) return;
 | 
			
		||||
 
 | 
			
		||||
@@ -59,17 +59,28 @@
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if (data.birthday) {
 | 
			
		||||
            if (!moment(data.birthday, 'YYYY-MM-DD').isValid()) {
 | 
			
		||||
                if (moment(data.birthday, 'MM-DD').isValid()) {
 | 
			
		||||
            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 = 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)`);
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
            if (data.birthday.includes('/')) {
 | 
			
		||||
                data.birthday.replace('/', '-');
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        err = err;
 | 
			
		||||
        if (err.length > 0) return;
 | 
			
		||||
 
 | 
			
		||||
@@ -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"],
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user