feat: update to Discord API v10
This commit is contained in:
parent
6a4033b2a9
commit
32a73eef09
@ -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,
|
||||
}
|
@ -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)
|
||||
{
|
||||
|
@ -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;
|
||||
|
@ -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; }
|
||||
|
@ -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; }
|
||||
}
|
@ -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()
|
||||
});
|
||||
|
@ -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() } });
|
||||
}
|
||||
}
|
@ -171,22 +171,21 @@ public class ReactionAdded: IEventHandler<MessageReactionAddEvent>
|
||||
try
|
||||
{
|
||||
var dm = await _dmCache.GetOrCreateDmChannel(evt.UserId);
|
||||
if (msg.Member != null)
|
||||
await _rest.CreateMessage(dm, new MessageRequest
|
||||
{
|
||||
Embed = await _embeds.CreateMemberEmbed(
|
||||
msg.System,
|
||||
msg.Member,
|
||||
guild,
|
||||
LookupContext.ByNonOwner,
|
||||
DateTimeZone.Utc
|
||||
)
|
||||
});
|
||||
|
||||
await _rest.CreateMessage(
|
||||
dm,
|
||||
new MessageRequest { Embed = await _embeds.CreateMessageInfoEmbed(msg, true) }
|
||||
);
|
||||
var embeds = new List<Embed>();
|
||||
|
||||
if (msg.Member != null)
|
||||
embeds.Add(await _embeds.CreateMemberEmbed(
|
||||
msg.System,
|
||||
msg.Member,
|
||||
guild,
|
||||
LookupContext.ByNonOwner,
|
||||
DateTimeZone.Utc
|
||||
));
|
||||
|
||||
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 :(
|
||||
|
||||
|
@ -67,7 +67,7 @@ public abstract class BaseInteractive
|
||||
new MessageRequest
|
||||
{
|
||||
Content = content,
|
||||
Embed = embed,
|
||||
Embeds = embed != null ? new[] { embed } : null,
|
||||
AllowedMentions = mentions,
|
||||
Components = GetComponents()
|
||||
});
|
||||
|
@ -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();
|
||||
|
@ -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");
|
||||
|
@ -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,
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user