feat: update to Discord API v10

This commit is contained in:
spiral 2022-02-26 16:28:20 -05:00
parent 6a4033b2a9
commit 32a73eef09
No known key found for this signature in database
GPG Key ID: 244A11E4B0BCF40E
13 changed files with 28 additions and 27 deletions

View File

@ -17,5 +17,6 @@ public enum GatewayIntent
GuildMessageTyping = 1 << 11,
DirectMessages = 1 << 12,
DirectMessageReactions = 1 << 13,
DirectMessageTyping = 1 << 14
DirectMessageTyping = 1 << 14,
MessageContent = 1 << 15,
}

View File

@ -80,7 +80,7 @@ public class ShardConnection: IAsyncDisposable
return null;
}
private Uri GetConnectionUri(string baseUri) => new UriBuilder(baseUri) { Query = "v=9&encoding=json" }.Uri;
private Uri GetConnectionUri(string baseUri) => new UriBuilder(baseUri) { Query = "v=10&encoding=json" }.Uri;
private async Task CloseInner(WebSocketCloseStatus closeStatus, string? description)
{

View File

@ -11,7 +11,7 @@ namespace Myriad.Rest;
public class DiscordApiClient
{
public const string UserAgent = "DiscordBot (https://github.com/xSke/PluralKit/tree/main/Myriad/, v1)";
private const string DefaultApiBaseUrl = "https://discord.com/api/v9";
private const string DefaultApiBaseUrl = "https://discord.com/api/v10";
private readonly BaseRestClient _client;
public EventHandler<(string, int, long)> OnResponseEvent;

View File

@ -11,7 +11,7 @@ public record MessageEditRequest
public Optional<string?> Content { get; init; }
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
public Optional<Embed?> Embed { get; init; }
public Optional<Embed[]?> Embeds { get; init; }
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
public Optional<Message.MessageFlags> Flags { get; init; }

View File

@ -8,6 +8,6 @@ public record MessageRequest
public object? Nonce { get; set; }
public bool Tts { get; set; }
public AllowedMentions? AllowedMentions { get; set; }
public Embed? Embed { get; set; }
public Embed[]? Embeds { get; set; }
public MessageComponent[]? Components { get; set; }
}

View File

@ -89,7 +89,7 @@ public class Context
var msg = await Rest.CreateMessage(Channel.Id, new MessageRequest
{
Content = text,
Embed = embed,
Embeds = embed != null ? new[] { embed } : null,
// Default to an empty allowed mentions object instead of null (which means no mentions allowed)
AllowedMentions = mentions ?? new AllowedMentions()
});

View File

@ -133,6 +133,6 @@ public class Misc
.Timestamp(process.StartTime.ToString("O"));
await ctx.Rest.EditMessage(msg.ChannelId, msg.Id,
new MessageEditRequest { Content = "", Embed = embed.Build() });
new MessageEditRequest { Content = "", Embeds = new[] { embed.Build() } });
}
}

View File

@ -171,22 +171,21 @@ public class ReactionAdded: IEventHandler<MessageReactionAddEvent>
try
{
var dm = await _dmCache.GetOrCreateDmChannel(evt.UserId);
var embeds = new List<Embed>();
if (msg.Member != null)
await _rest.CreateMessage(dm, new MessageRequest
{
Embed = await _embeds.CreateMemberEmbed(
embeds.Add(await _embeds.CreateMemberEmbed(
msg.System,
msg.Member,
guild,
LookupContext.ByNonOwner,
DateTimeZone.Utc
)
});
));
await _rest.CreateMessage(
dm,
new MessageRequest { Embed = await _embeds.CreateMessageInfoEmbed(msg, true) }
);
embeds.Add(await _embeds.CreateMessageInfoEmbed(msg, true));
await _rest.CreateMessage(dm, new MessageRequest { Embeds = embeds.ToArray() });
}
catch (ForbiddenException) { } // No permissions to DM, can't check for this :(

View File

@ -67,7 +67,7 @@ public abstract class BaseInteractive
new MessageRequest
{
Content = content,
Embed = embed,
Embeds = embed != null ? new[] { embed } : null,
AllowedMentions = mentions,
Components = GetComponents()
});

View File

@ -38,7 +38,8 @@ public class BotModule: Module
GatewayIntent.GuildEmojis |
GatewayIntent.GuildMessages |
GatewayIntent.GuildWebhooks |
GatewayIntent.GuildMessageReactions
GatewayIntent.GuildMessageReactions |
GatewayIntent.MessageContent
};
}).AsSelf().SingleInstance();
builder.RegisterType<Cluster>().AsSelf().SingleInstance();

View File

@ -62,7 +62,7 @@ public class ErrorMessageService
try
{
await _rest.CreateMessage(channelId,
new MessageRequest { Content = $"> **Error code:** `{errorId}`", Embed = embed.Build() });
new MessageRequest { Content = $"> **Error code:** `{errorId}`", Embeds = new[] { embed.Build() } });
_logger.Information("Sent error message to {ChannelId} with error code {ErrorId}", channelId, errorId);
_metrics.Measure.Meter.Mark(BotMetrics.ErrorMessagesSent, "sent");

View File

@ -51,7 +51,7 @@ public class LogChannelService
oldContent);
var url =
$"https://discord.com/channels/{proxiedMessage.Guild.Value}/{proxiedMessage.Channel}/{proxiedMessage.Mid}";
await _rest.CreateMessage(logChannelId.Value, new MessageRequest { Content = url, Embed = embed });
await _rest.CreateMessage(logChannelId.Value, new MessageRequest { Content = url, Embeds = new[] { embed } });
}
private async Task<ulong?> GetAndCheckLogChannel(MessageContext ctx, Message trigger,

View File

@ -174,7 +174,7 @@ public static class ContextUtils
// Edit the embed with the new page
var embed = await MakeEmbedForPage(currentPage);
await ctx.Rest.EditMessage(msg.ChannelId, msg.Id, new MessageEditRequest { Embed = embed });
await ctx.Rest.EditMessage(msg.ChannelId, msg.Id, new MessageEditRequest { Embeds = new[] { embed } });
}
}
catch (TimeoutException)