mirror of
https://github.com/TeamOctolings/Octobot.git
synced 2025-04-19 16:33:36 +03:00
fix: resolve breaking API changes
Signed-off-by: Octol1ttle <l1ttleofficial@outlook.com>
This commit is contained in:
parent
68a71cbe89
commit
4f9fea2089
1 changed files with 10 additions and 21 deletions
|
@ -36,40 +36,29 @@ public sealed class MessageEditedResponder : IResponder<IMessageUpdate>
|
||||||
|
|
||||||
public async Task<Result> RespondAsync(IMessageUpdate gatewayEvent, CancellationToken ct = default)
|
public async Task<Result> RespondAsync(IMessageUpdate gatewayEvent, CancellationToken ct = default)
|
||||||
{
|
{
|
||||||
if (!gatewayEvent.ID.IsDefined(out var messageId))
|
|
||||||
{
|
|
||||||
return new ArgumentNullError(nameof(gatewayEvent.ID));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!gatewayEvent.ChannelID.IsDefined(out var channelId))
|
|
||||||
{
|
|
||||||
return new ArgumentNullError(nameof(gatewayEvent.ChannelID));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!gatewayEvent.GuildID.IsDefined(out var guildId)
|
if (!gatewayEvent.GuildID.IsDefined(out var guildId)
|
||||||
|| !gatewayEvent.Author.IsDefined(out var author)
|
|| !gatewayEvent.EditedTimestamp.HasValue
|
||||||
|| !gatewayEvent.EditedTimestamp.IsDefined(out var timestamp)
|
|| gatewayEvent.Author.IsBot.OrDefault(false))
|
||||||
|| !gatewayEvent.Content.IsDefined(out var newContent))
|
|
||||||
{
|
{
|
||||||
return Result.Success;
|
return Result.Success;
|
||||||
}
|
}
|
||||||
|
|
||||||
var cfg = await _guildData.GetSettings(guildId, ct);
|
var cfg = await _guildData.GetSettings(guildId, ct);
|
||||||
if (author.IsBot.OrDefault(false) || GuildSettings.PrivateFeedbackChannel.Get(cfg).Empty())
|
if (GuildSettings.PrivateFeedbackChannel.Get(cfg).Empty())
|
||||||
{
|
{
|
||||||
return Result.Success;
|
return Result.Success;
|
||||||
}
|
}
|
||||||
|
|
||||||
var cacheKey = new KeyHelpers.MessageCacheKey(channelId, messageId);
|
var cacheKey = new KeyHelpers.MessageCacheKey(gatewayEvent.ChannelID, gatewayEvent.ID);
|
||||||
var messageResult = await _cacheService.TryGetValueAsync<IMessage>(
|
var messageResult = await _cacheService.TryGetValueAsync<IMessage>(
|
||||||
cacheKey, ct);
|
cacheKey, ct);
|
||||||
if (!messageResult.IsDefined(out var message))
|
if (!messageResult.IsDefined(out var message))
|
||||||
{
|
{
|
||||||
_ = _channelApi.GetChannelMessageAsync(channelId, messageId, ct);
|
_ = _channelApi.GetChannelMessageAsync(gatewayEvent.ChannelID, gatewayEvent.ID, ct);
|
||||||
return Result.Success;
|
return Result.Success;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (message.Content == newContent)
|
if (message.Content == gatewayEvent.Content)
|
||||||
{
|
{
|
||||||
return Result.Success;
|
return Result.Success;
|
||||||
}
|
}
|
||||||
|
@ -83,22 +72,22 @@ public sealed class MessageEditedResponder : IResponder<IMessageUpdate>
|
||||||
// We don't need to await this since the result is not needed
|
// We don't need to await this since the result is not needed
|
||||||
// NOTE: Because this is not awaited, there may be a race condition depending on how fast clients are able to edit their messages
|
// NOTE: Because this is not awaited, there may be a race condition depending on how fast clients are able to edit their messages
|
||||||
// NOTE: Awaiting this might not even solve this if the same responder is called asynchronously
|
// NOTE: Awaiting this might not even solve this if the same responder is called asynchronously
|
||||||
_ = _channelApi.GetChannelMessageAsync(channelId, messageId, ct);
|
_ = _channelApi.GetChannelMessageAsync(gatewayEvent.ChannelID, gatewayEvent.ID, ct);
|
||||||
|
|
||||||
var diff = InlineDiffBuilder.Diff(message.Content, newContent);
|
var diff = InlineDiffBuilder.Diff(message.Content, gatewayEvent.Content);
|
||||||
|
|
||||||
Messages.Culture = GuildSettings.Language.Get(cfg);
|
Messages.Culture = GuildSettings.Language.Get(cfg);
|
||||||
|
|
||||||
var builder = new StringBuilder()
|
var builder = new StringBuilder()
|
||||||
.AppendLine(diff.AsMarkdown())
|
.AppendLine(diff.AsMarkdown())
|
||||||
.AppendLine(string.Format(Messages.DescriptionActionJumpToMessage,
|
.AppendLine(string.Format(Messages.DescriptionActionJumpToMessage,
|
||||||
$"https://discord.com/channels/{guildId}/{channelId}/{messageId}")
|
$"https://discord.com/channels/{guildId}/{gatewayEvent.ChannelID}/{gatewayEvent.ID}")
|
||||||
);
|
);
|
||||||
|
|
||||||
var embed = new EmbedBuilder()
|
var embed = new EmbedBuilder()
|
||||||
.WithSmallTitle(string.Format(Messages.CachedMessageEdited, message.Author.GetTag()), message.Author)
|
.WithSmallTitle(string.Format(Messages.CachedMessageEdited, message.Author.GetTag()), message.Author)
|
||||||
.WithDescription(builder.ToString())
|
.WithDescription(builder.ToString())
|
||||||
.WithTimestamp(timestamp.Value)
|
.WithTimestamp(gatewayEvent.EditedTimestamp.Value)
|
||||||
.WithColour(ColorsList.Yellow)
|
.WithColour(ColorsList.Yellow)
|
||||||
.Build();
|
.Build();
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue