fix: a couple more minor reproxy fixes

This commit is contained in:
Ske 2022-06-06 00:59:53 +02:00
parent 6511c04c6c
commit 51fb561841
4 changed files with 12 additions and 10 deletions

View File

@ -140,13 +140,12 @@ public class ProxiedMessage
var editType = isReproxy ? "reproxy" : "edit"; var editType = isReproxy ? "reproxy" : "edit";
var editTypeAction = isReproxy ? "reproxied" : "edited"; 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; FullMessage? msg = null;
var (referencedMessage, _) = ctx.MatchMessage(false); var (referencedMessage, _) = ctx.MatchMessage(false);
if (referencedMessage != null) if (referencedMessage != null)
{ {
await using var conn = await ctx.Database.Obtain();
msg = await ctx.Repository.GetMessage(conn, referencedMessage.Value); msg = await ctx.Repository.GetMessage(conn, referencedMessage.Value);
if (msg == null) if (msg == null)
throw new PKError("This is not a message proxied by PluralKit."); throw new PKError("This is not a message proxied by PluralKit.");
@ -161,6 +160,7 @@ public class ProxiedMessage
if (recent == null) if (recent == null)
throw new PKSyntaxError($"Could not find a recent message to {editType}."); 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); msg = await ctx.Repository.GetMessage(conn, recent.Mid);
if (msg == null) if (msg == null)
throw new PKSyntaxError($"Could not find a recent message to {editType}."); throw new PKSyntaxError($"Could not find a recent message to {editType}.");

View File

@ -211,16 +211,17 @@ public class ProxyService
{ {
Member = member, Member = member,
Content = prevMatched ? prevMatch.Content : originalMsg.Content, Content = prevMatched ? prevMatch.Content : originalMsg.Content,
ProxyTags = member.ProxyTags.First(), ProxyTags = member.ProxyTags.FirstOrDefault(),
}; };
var messageChannel = await _rest.GetChannelOrNull(msg.Channel!); var messageChannel = await _rest.GetChannelOrNull(msg.Channel!);
var rootChannel = messageChannel.IsThread() ? await _rest.GetChannelOrNull(messageChannel.ParentId!.Value) : messageChannel; var rootChannel = messageChannel.IsThread() ? await _rest.GetChannelOrNull(messageChannel.ParentId!.Value) : messageChannel;
var threadId = messageChannel.IsThread() ? messageChannel.Id : (ulong?)null; var threadId = messageChannel.IsThread() ? messageChannel.Id : (ulong?)null;
var guild = await _rest.GetGuildOrNull(msg.Guild!.Value); 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) // Grab user permissions
var senderPermissions = PermissionExtensions.PermissionsFor(guild, rootChannel, trigger.Author.Id, ((MessageCreateEvent) trigger).Member); var senderPermissions = PermissionExtensions.PermissionsFor(guild, rootChannel, trigger.Author.Id, guildMember);
var allowEveryone = senderPermissions.HasFlag(PermissionSet.MentionEveryone); var allowEveryone = senderPermissions.HasFlag(PermissionSet.MentionEveryone);
// Make sure user has permissions to send messages // Make sure user has permissions to send messages
@ -373,8 +374,8 @@ public class ProxyService
{ {
var sentMessage = new PKMessage var sentMessage = new PKMessage
{ {
Channel = triggerMessage.ChannelId, Channel = proxyMessage.ChannelId,
Guild = triggerMessage.GuildId, Guild = proxyMessage.GuildId,
Member = match.Member.Id, Member = match.Member.Id,
Mid = proxyMessage.Id, Mid = proxyMessage.Id,
OriginalMid = triggerMessage.Id, OriginalMid = triggerMessage.Id,

View File

@ -86,7 +86,7 @@ public class LogChannelService
{ {
_logger.Information( _logger.Information(
"Does not have permission to log proxy, ignoring (channel: {ChannelId}, guild: {GuildId}, bot permissions: {BotPermissions})", "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; return null;
} }

View File

@ -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 // 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); 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, private async Task TrySendRemainingAttachments(Webhook webhook, string name, string avatarUrl,