refactor: don't pass through channel ID to LogMessage

This commit is contained in:
spiral 2022-01-14 15:12:10 -05:00
parent df9e7c3eb9
commit 8e119d0d42
No known key found for this signature in database
GPG Key ID: A6059F0CA0E1BD31

View File

@ -37,8 +37,8 @@ public class LogChannelService
public async ValueTask LogMessage(MessageContext ctx, PKMessage proxiedMessage, Message trigger, public async ValueTask LogMessage(MessageContext ctx, PKMessage proxiedMessage, Message trigger,
Message hookMessage, string oldContent = null) Message hookMessage, string oldContent = null)
{ {
var logChannel = await GetAndCheckLogChannel(ctx, trigger, proxiedMessage); var logChannelId = await GetAndCheckLogChannel(ctx, trigger, proxiedMessage);
if (logChannel == null) if (logChannelId == null)
return; return;
var triggerChannel = await _cache.GetChannel(proxiedMessage.Channel); var triggerChannel = await _cache.GetChannel(proxiedMessage.Channel);
@ -51,10 +51,10 @@ public class LogChannelService
oldContent); oldContent);
var url = var url =
$"https://discord.com/channels/{proxiedMessage.Guild.Value}/{proxiedMessage.Channel}/{proxiedMessage.Mid}"; $"https://discord.com/channels/{proxiedMessage.Guild.Value}/{proxiedMessage.Channel}/{proxiedMessage.Mid}";
await _rest.CreateMessage(logChannel.Id, new MessageRequest { Content = url, Embed = embed }); await _rest.CreateMessage(logChannelId.Value, new MessageRequest { Content = url, Embed = embed });
} }
private async Task<Channel?> GetAndCheckLogChannel(MessageContext ctx, Message trigger, private async Task<ulong?> GetAndCheckLogChannel(MessageContext ctx, Message trigger,
PKMessage proxiedMessage) PKMessage proxiedMessage)
{ {
if (proxiedMessage.Guild == null && proxiedMessage.Channel != trigger.ChannelId) if (proxiedMessage.Guild == null && proxiedMessage.Channel != trigger.ChannelId)
@ -90,7 +90,7 @@ public class LogChannelService
return null; return null;
} }
return logChannel; return logChannel.Id;
} }
private async Task<Channel?> FindLogChannel(ulong guildId, ulong channelId) private async Task<Channel?> FindLogChannel(ulong guildId, ulong channelId)